本文整理汇总了Python中jsbeautifier.beautify方法的典型用法代码示例。如果您正苦于以下问题:Python jsbeautifier.beautify方法的具体用法?Python jsbeautifier.beautify怎么用?Python jsbeautifier.beautify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsbeautifier
的用法示例。
在下文中一共展示了jsbeautifier.beautify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_testcase
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def read_testcase(self, testcase_path):
self.testcase_path = testcase_path
if self.should_skip():
return
LOG.info("Attempting to beautify %s", testcase_path)
self.lithium.strategy = self.strategy_type() # pylint: disable=not-callable
self.lithium.testcase = self.testcase_type() # pylint: disable=not-callable
# Beautify testcase
with open(testcase_path) as testcase_fp:
self.original_testcase = testcase_fp.read()
beautified_testcase = jsbeautifier.beautify(self.original_testcase)
# All try/catch pairs will be expanded on their own lines
# Collapse these pairs when only a single instruction is contained
# within
regex = r"(\s*try {)\n\s*(.*)\n\s*(}\s*catch.*)"
beautified_testcase = re.sub(regex, r"\1 \2 \3", beautified_testcase)
with open(testcase_path, 'w') as testcase_fp:
testcase_fp.write(beautified_testcase)
self.lithium.testcase.readTestcase(testcase_path)
示例2: add_answer_to_ccr_csqa
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def add_answer_to_ccr_csqa(ccr_path, dataset_path, output_path):
with open(ccr_path, "r", encoding="utf8") as f:
ccr = json.load(f)
with open(dataset_path, "r", encoding="utf8") as f:
for i, line in enumerate(f.readlines()):
csqa_json = json.loads(line)
for j, ans in enumerate(csqa_json["question"]["choices"]):
ccr[i * 5 + j]["stem"] = csqa_json["question"]["stem"].lower()
ccr[i * 5 + j]["answer"] = ans["text"].lower()
with open(output_path, "w", encoding="utf8") as f:
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
f.write(jsbeautifier.beautify(json.dumps(ccr), opts))
示例3: add_answer_to_ccr_swag
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def add_answer_to_ccr_swag(ccr_path, dataset_path, output_path):
with open(ccr_path, "r", encoding="utf8") as f:
ccr = json.load(f)
with open(dataset_path, "r", encoding="utf8") as csvfile:
reader = csv.reader(csvfile)
next(reader) # Skip first line (header).
for i, row in tqdm(enumerate(reader)):
stem = row[4] + " " + row[5]
answers = row[7:11]
for j, ans in enumerate(answers):
ccr[i * 4 + j]["stem"] = stem.lower()
ccr[i * 4 + j]["answer"] = ans.lower()
with open(output_path, "w", encoding="utf8") as f:
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
f.write(jsbeautifier.beautify(json.dumps(ccr), opts))
#json.dump(ccr, f)
# python add_answer_to_ccr.py --mode csqa --ccr_path csqa_new/train_rand_split.jsonl.statements.ccr --dataset_path csqa_new/train_rand_split.jsonl.statements --output_path csqa_new/train_rand_split.jsonl.statements.ccr.a
示例4: decodesto
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def decodesto(self, input, expectation=None):
if expectation == None:
expectation = input
self.assertMultiLineEqual(
jsbeautifier.beautify(input, self.options), expectation)
# if the expected is different from input, run it again
# expected output should be unchanged when run twice.
if not expectation == None:
self.assertMultiLineEqual(
jsbeautifier.beautify(expectation, self.options), expectation)
# Everywhere we do newlines, they should be replaced with opts.eol
self.options.eol = '\r\\n';
expectation = expectation.replace('\n', '\r\n')
self.assertMultiLineEqual(
jsbeautifier.beautify(input, self.options), expectation)
input = input.replace('\n', '\r\n')
self.assertMultiLineEqual(
jsbeautifier.beautify(input, self.options), expectation)
self.options.eol = '\n'
示例5: shidurlive
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def shidurlive(self, url, referer,options):
myhost = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
HEADER = {'Accept-Language': 'pl,en-US;q=0.7,en;q=0.3', 'Referer': referer, 'User-Agent': myhost}
query_data = {'url': url, 'use_host': False, 'use_header': True, 'header': HEADER, 'use_post': False,'return_data': True}
link = self.cm.getURLRequestData(query_data)
match = re.compile('src="(.*?)"').findall(link)
if len(match) > 0:
url1 = match[0].replace("'+kol+'", "")
host = self.getHostName(referer)
result = ''
query_data = {'url': match[0], 'use_host': False, 'use_header': True, 'header': HEADER, 'use_cookie': False, 'use_post': False,'return_data': True}
link = self.cm.getURLRequestData(query_data)
match1 = re.compile("so.addVariable\(\'file\', \'(.*?)\'\);").findall(link)
match2 = re.compile("so.addVariable\(\'streamer\', \'(.*?)\'\);").findall(link)
match3 = re.compile("so.addVariable\('file', unescape\('(.*?)'\)\);").findall(link)
if match3:
txtjs = "unescape('" + match3[0] + "');"
txtjs = match3[0]
link2 = beautify(txtjs)
return match2[0] + ' playpath=' + link2.replace(' ','') + ' swfVfy=1 swfUrl=http://cdn.shidurlive.com/player.swf live=true pageUrl=' + url
return ''
示例6: parserVIDTO
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def parserVIDTO(self,url,referer,options):
#url = url.replace('v/','/')
if not 'embed' in url:
myparts = urlparse.urlparse(url)
media_id = myparts.path.split('/')[-1].replace('.html','')
url = myparts.scheme +'://'+ myparts.netloc + '/embed-' + media_id + '.html'
query_data = { 'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True }
link = self.cm.getURLRequestData(query_data)
print("Link",link)
linkvideo = ''
match = re.compile("<script type=\'text/javascript\'>eval\(function\(p,a,c,k,e,d\)(.*?)\n</script>").findall(link)
if len(match)>0:
moje = beautify("eval(function(p,a,c,k,e,d)" + match[0])
match2 = re.compile('\{label:"(.*?)",file:"(.*?)"\}').findall(moje)
match3 = re.compile('hd_default:"(.*?)"').findall(moje)
if len(match2)>0:
for i in range(len(match2)):
if match2[i][0] == match3[0]:
linkvideo = match2[i][1]
return linkvideo
else:
return linkvideo
示例7: do_jsbeautify
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def do_jsbeautify(self,line):
try:
import jsbeautifier
l = line.split(" ")
if len(l) < 2:
self.help_jsbeautify()
else:
OPTIONS = ['slice','obj']
option = l[0]
if option not in OPTIONS:
print "Invalid option"
return False
id = l[1]
response, size = CTCore.get_response_and_size(id, "all")
name = CTCore.get_name(id)
if option == "slice":
offset = int(l[2])
length = l[3]
bytes, length = get_bytes(response,offset,length)
js_bytes = bytes
res = jsbeautifier.beautify(js_bytes)
print res
if option == "obj":
res = jsbeautifier.beautify(response)
obj_num = CTCore.add_object("jsbeautify",res,id=id)
print " JavaScript Beautify of object {} ({}) successful!".format(str(id), name)
print " New object created: {}".format(obj_num) + newLine
except Exception,e:
print str(e)
示例8: help_jsbeautify
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def help_jsbeautify(self):
print newLine + "Display JavaScript code after beautify"
print newLine + "Usage: jsbeautify <obj / slice> <object_id> <offset> <length>"
print newLine + "Example: jsbeautify slice <object_id> <offset> <len | eob>"
print newLine + "Example: jsbeautify obj <object_id>"
示例9: combine
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def combine():
final_json = []
PATH = sys.argv[2]
for i in range(NUM_BATCHES):
with open(PATH + ".%d.mcp"%i) as fp:
tmp_list = json.load(fp)
final_json += tmp_list
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
with open(PATH + ".mcp", 'w') as fp:
fp.write(jsbeautifier.beautify(json.dumps(final_json), opts))
示例10: beautifier_test_underscore
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def beautifier_test_underscore():
jsbeautifier.beautify(data, options)
示例11: beautifier_test_underscore_min
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def beautifier_test_underscore_min():
jsbeautifier.beautify(data_min, options)
示例12: beautifier_test_github_min
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def beautifier_test_github_min():
jsbeautifier.beautify(github_min, options)
示例13: decodesto
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def decodesto(self, input, expectation=None):
self.assertEqual(
jsbeautifier.beautify(input, self.options), expectation or input)
示例14: test_str
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def test_str(str, expected):
global fails
res = jsbeautifier.beautify(str, opts)
if(res == expected):
print(".")
return True
else:
print("___got:" + res + "\n___expected:" + expected + "\n")
fails = fails + 1
return False
示例15: pretty
# 需要导入模块: import jsbeautifier [as 别名]
# 或者: from jsbeautifier import beautify [as 别名]
def pretty(self):
return jsbeautifier.beautify(str(self))