How many examples of jsbeautifier in python are there?

The following are 30 code examples of jsbeautifier.beautify(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module jsbeautifier, or try the search function

.

Example #1

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

Example #2

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)

Example #3

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))

Example #4

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'

Example #5

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) match2 = 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=//cdn.shidurlive.com/player.swf live=true pageUrl=' + url return ''

Example #6

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'

Example #7

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

Example #8

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)

Example #9

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>"

Example #10

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))

Example #11

def beautifier_test_underscore(): jsbeautifier.beautify(data, options)

Example #12

def beautifier_test_underscore_min(): jsbeautifier.beautify(data_min, options)

Example #13

def beautifier_test_github_min(): jsbeautifier.beautify(github_min, options)

Example #14

def decodesto(self, input, expectation=None): self.assertEqual( jsbeautifier.beautify(input, self.options), expectation or input)

Example #15

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

Example #16

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

Example #17

def pretty(self): return jsbeautifier.beautify(str(self))

Example #18

def js_beautify_string(string): if HAVE_JSBEAUTIFY: string = beautify(string) return string

Example #19

def beautifier_test_underscore(): jsbeautifier.beautify(data, options)

Example #20

def beautifier_test_underscore_min(): jsbeautifier.beautify(data_min, options)

Example #21

def decodesto(self, input, expectation=None): self.assertEqual( jsbeautifier.beautify(input, self.options), expectation or input)

Example #22

def parserVIDEOMEGA(self,url, referer,options): if not 'iframe.php?ref' in url: url = url.replace('?ref','iframe.php?ref') HEADER = {'Referer': referer,'User-Agent': HOST_CHROME} query_data = { 'url': url, 'use_host': False, 'use_header': True, 'header': HEADER, 'use_cookie': False, 'use_post': False, 'return_data': True } link = self.cm.getURLRequestData(query_data) match2= re.compile('eval\((.*?)\n\n\n\t</script>').findall(link) if len(match2) > 0: match2 = re.compile('attr\("src", "(.*?)"\)').findall(beautify("eval(" + match2[0])) linkVideo= match2[0] self.log.info ('linkVideo ' + linkVideo) return linkVideo else: return False

Example #23

def castalbatv(self, url, referer,options): myhost = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0" req = urllib2.Request(url) req.add_header('Referer', referer) req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/20.0') response = urllib2.urlopen(req) link = response.read() response.close() match = re.compile("'file': (.*?),").findall(link) match2 = re.compile("'flashplayer': \"(.*?)\"", ).findall(link) match2 = re.compile("'streamer': (.*?),").findall(link) linkVideo='' if len(match) > 0: plik = beautify(match[0]) plik1 = re.compile("unescape\('(.*?)'\n").findall(plik) plik2 = re.compile("unescape\(unescape\('(.*?)'\)").findall(plik) plik4 = beautify('unescape(' + plik2[0]+ ')') plik5 = plik4.replace('unescape(','').replace(')','') if len(plik1) > 0: if len(match2)>0: malina2 = re.compile("unescape\('(.*?)'\)").findall(beautify(match2[0])) linkVideo = malina2[0].replace(' ','') + ' playpath=' + plik1[0] + '?'+ plik5 + ' swfUrl=' + match2[0] + ' live=true timeout=30 swfVfy=true pageUrl=' + url return linkVideo else: return linkVideo

Example #24

def sevencastnet(self, url, referer,options): query_data = {'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True} link = self.cm.getURLRequestData(query_data) match = re.compile('<script type="text/javascript">eval\(function\(p,a,c,k,e,d\)(.*?)\n</script>').findall(link) txtjs = "eval(function(p,a,c,k,e,d)" + match[0] link2 = beautify(txtjs) match_myScrT = re.compile('myScrT.push\(\\\\\'(.*?)\\\\\'\);').findall(link2) match_myRtk = re.compile('myRtk.push\(\\\\\'(.*?)\\\\\'\);').findall(link2) myScrT = beautify('unescape(\'' + ''.join(match_myScrT) + '\');') myRtk = beautify('unescape(\'' + ''.join(match_myRtk) + '\');') match_file = re.compile('unescape\(\'(.*?)\'\);').findall(myScrT) match_server = re.compile('unescape\(\'(.*?)\'\);').findall(myRtk) nUrl = match_server[0] + ' playpath=' + match_file[ 0] + ' live=true timeout=12 swfVfy=true swfUrl=//7cast.net/jplayer.swf timeout=30 pageUrl=' + referer return nUrl

Example #25

def parserSAWLIVE(self, url, referer,options): def decode(tmpurl): host = self.getHostName(tmpurl) result = '' for i in host: result += hex(ord(i)).split('x')[1] return result query = urlparse.urlparse(url) channel = query.path channel = channel.replace("/embed/", "") print("chanel",channel) query_data = {'url': '//www.sawlive.tv/embed/' + channel, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True, 'header' : {'Referer': referer, 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0'}} link21 = self.cm.getURLRequestData(query_data) match = re.compile('eval\(function\(p,a,c,k,e,d\)(.*?)split\(\'\|\'\),0,{}\)\)').findall(link21) txtjs = "eval(function(p,a,c,k,e,d)" + match[-1] +"split('|'),0,{}))" link2 = beautify(txtjs) match21 = re.compile("var escapa = unescape\('(.*?)'\);").findall(link21) start = urllib.unquote(match21[0]).find('src="') end = len(urllib.unquote(match21[0])) url = urllib.unquote(match21[0])[start + 5:end] + '/' + decode(referer) query_data = {'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True} link22 = self.cm.getURLRequestData(query_data) match22 = re.compile("SWFObject\('(.*?)','mpl','100%','100%','9'\);").findall(link22) match23 = re.compile("so.addVariable\('file', '(.*?)'\);").findall(link22) match24 = re.compile("so.addVariable\('streamer', '(.*?)'\);").findall(link22) print ("Match", match22, match23, match24, link22) videolink = match24[0] + ' playpath=' + match23[0] + ' swfUrl=' + match22[ 0] + ' pageUrl=//sawlive.tv/embed/' + channel + ' live=true swfVfy=true' return videolink

Example #26

def beautifier_test_underscore_min(): jsbeautifier.beautify(data_min, options)

Example #27

def decodesto(self, input, expectation=None): self.assertEqual( jsbeautifier.beautify(input, self.options), expectation or input)

Example #28

def castalbatv(self, url, referer,options): myhost = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0" req = urllib2.Request(url) req.add_header('Referer', referer) req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/20.0') response = urllib2.urlopen(req) link = response.read() response.close() match = re.compile("'file': (.*?),").findall(link) match2 = re.compile("'flashplayer': \"(.*?)\"", ).findall(link) match2 = re.compile("'streamer': (.*?),").findall(link) linkVideo='' if len(match) > 0: plik = beautify(match[0]) plik1 = re.compile("unescape\('(.*?)'\n").findall(plik) plik2 = re.compile("unescape\(unescape\('(.*?)'\)").findall(plik) plik4 = beautify('unescape(' + plik2[0]+ ')') plik5 = plik4.replace('unescape(','').replace(')','') if len(plik1) > 0: if len(match2)>0: malina2 = re.compile("unescape\('(.*?)'\)").findall(beautify(match2[0])) linkVideo = malina2[0].replace(' ','') + ' playpath=' + plik1[0] + '?'+ plik5 + ' swfUrl=' + match2[0] + ' live=true timeout=30 swfVfy=true pageUrl=' + url return linkVideo else: return linkVideo

Example #29

def sevencastnet(self, url, referer,options): query_data = {'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True} link = self.cm.getURLRequestData(query_data) match = re.compile('<script type="text/javascript">eval\(function\(p,a,c,k,e,d\)(.*?)\n</script>').findall(link) txtjs = "eval(function(p,a,c,k,e,d)" + match[0] link2 = beautify(txtjs) match_myScrT = re.compile('myScrT.push\(\\\\\'(.*?)\\\\\'\);').findall(link2) match_myRtk = re.compile('myRtk.push\(\\\\\'(.*?)\\\\\'\);').findall(link2) myScrT = beautify('unescape(\'' + ''.join(match_myScrT) + '\');') myRtk = beautify('unescape(\'' + ''.join(match_myRtk) + '\');') match_file = re.compile('unescape\(\'(.*?)\'\);').findall(myScrT) match_server = re.compile('unescape\(\'(.*?)\'\);').findall(myRtk) nUrl = match_server[0] + ' playpath=' + match_file[ 0] + ' live=true timeout=12 swfVfy=true swfUrl=//7cast.net/jplayer.swf timeout=30 pageUrl=' + referer return nUrl

Example #30

def parserSAWLIVE(self, url, referer,options): def decode(tmpurl): host = self.getHostName(tmpurl) result = '' for i in host: result += hex(ord(i)).split('x')[1] return result query = urlparse.urlparse(url) channel = query.path channel = channel.replace("/embed/", "") print("chanel",channel) query_data = {'url': '//www.sawlive.tv/embed/' + channel, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True, 'header' : {'Referer': referer, 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0'}} link21 = self.cm.getURLRequestData(query_data) match = re.compile('eval\(function\(p,a,c,k,e,d\)(.*?)split\(\'\|\'\),0,{}\)\)').findall(link21) txtjs = "eval(function(p,a,c,k,e,d)" + match[-1] +"split('|'),0,{}))" link2 = beautify(txtjs) match21 = re.compile("var escapa = unescape\('(.*?)'\);").findall(link21) start = urllib.unquote(match21[0]).find('src="') end = len(urllib.unquote(match21[0])) url = urllib.unquote(match21[0])[start + 5:end] + '/' + decode(referer) query_data = {'url': url, 'use_host': False, 'use_cookie': False, 'use_post': False, 'return_data': True} link22 = self.cm.getURLRequestData(query_data) match22 = re.compile("SWFObject\('(.*?)','mpl','100%','100%','9'\);").findall(link22) match23 = re.compile("so.addVariable\('file', '(.*?)'\);").findall(link22) match24 = re.compile("so.addVariable\('streamer', '(.*?)'\);").findall(link22) print ("Match", match22, match23, match24, link22) videolink = match24[0] + ' playpath=' + match23[0] + ' swfUrl=' + match22[ 0] + ' pageUrl=//sawlive.tv/embed/' + channel + ' live=true swfVfy=true' return videolink

Chủ đề