def setUp(self): self.runtimes = list(execjs.available_runtimes().values()) self.compilers = [] self.compilers.append(coffeescript) #default compiler from os.path import join, dirname with io.open(join(dirname(coffeescript.__file__), "coffee-script.js")) as fp: compiler_script = fp.read() for runtime in self.runtimes: self.compilers.append(coffeescript.Compiler(compiler_script, runtime))
def list_js_runtimes(): ajsr = execjs.available_runtimes() if len(ajsr) > 0: print('Detected {0} JavaScript runtimes:'.format(len(ajsr))) for js in ajsr: jsr = execjs.get(js) pref_str = '' if js == 'Node': pref_str = ' <== I prefer this one!' print(' {0}: {1}{2}'.format(js, jsr.name, pref_str)) else: print('No JS runtimes detected! Install Node.js, spidermonkey or something!') sys.exit(0)
def setUp(self): self.runtimes = list(execjs.available_runtimes().values()) self.compilers = [] self.compilers.append(coffeescript) # default compiler from os.path import join, dirname script_path = join(dirname(coffeescript.__file__), "coffee-script.js") with io.open(script_path) as fp: compiler_script = fp.read() for runtime in self.runtimes: self.compilers.append( coffeescript.Compiler(compiler_script, runtime))
def setUp(self): self.runtimes = list(execjs.available_runtimes().values()) self.encodings = "shift-jis utf-8 euc-jp".split() self.compilers = [] self.compilers.append(coffeescript) # default compiler from os.path import join, dirname script_path = join(dirname(coffeescript.__file__), "coffee-script.js") with io.open(script_path) as fp: compiler_script = fp.read() for runtime in self.runtimes: self.compilers.append( coffeescript.Compiler(compiler_script, runtime))
def unscramble_galaxy_script(self): if not self.script_body.startswith('var Deuterium = '): logger.error('Invalid format of script body: cannot parse it!') return None eval_start = self.script_body.find('eval(function(p,a,c,k,e,d)') if eval_start == -1: logger.error('parse error (1)') return None eval_end = self.script_body.find("$('#galaxy').append(PrintRow());") if eval_end == -1: logger.error('parse error (2)') return None eval_text = self.script_body[eval_start:eval_end] eval_text = eval_text.strip() logger.debug('eval [{0}]'.format(eval_text)) # ^^ [eval(function(p,a,c,k,e,d){e=function(c){r... ...141|7866|u0426'.split('|')))] inner_eval = eval_text[5:-1] logger.debug('inner eval [{0}]'.format(inner_eval)) # ^^ [function(p,a,c,k,e,d){e=functi... ...0426'.split('|'))] # # create JS interptreter and eval that js_runtimes = execjs.available_runtimes() if 'Node' in js_runtimes: js = execjs.get('Node') else: js = execjs.get() # default logger.debug('Using [{0}] as JS runtime.'.format(js.name)) eval_res = js.eval(inner_eval) # Now, eval_res is a string: # row[12]={"planet":12,"id_planet":54448,"ally_planet":0,"metal":0,"crystal":0, # "name":"\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u043f\u043b\u0430\u043d\u0435\u0442\u0430", # "planet_type":1,"destruyed":0,"image":"normaltempplanet02","last_active":60,"parent_planet":0, # "luna_id":null,"luna_name":null,"luna_destruyed":null,"luna_diameter":null,"luna_temp":null, # "user_id":71992,"username":"******", # "race":4,"ally_id":0,"authlevel":0,"onlinetime":1,"urlaubs_modus_time":0,"banaday":0,"sex":1, # "avatar":7,"user_image":"","ally_name":null,"ally_members":null,"ally_web":null,"ally_tag":null, # "type":null,"total_rank":7865,"total_points":0};row[9]={"planet":9,"id_planet":54450,"ally_planet":0, # "metal":0,"crystal":0,"name":"Arnon","planet_type":1,"destruyed":0,"image":"normaltempplanet08", # "last_active":0,"parent_planet":0,"luna_id":null,"luna_name":null,"luna_destruyed":null, # "luna_diameter":null,"luna_temp":null,"user_id":71995,"username":"******","race":4,"ally_id":389, # "authlevel":0,"onlinetime":0,"urlaubs_modus_time":0,"banaday":0,"sex":1,"avatar":5, # "user_image":"71995_1440872455.jpg","ally_name":"Fury","ally_members":8,"ally_web":"", # "ally_tag":"Fury","type":null,"total_rank":141,"total_points":115582}; # ... # we ned to eval() this string again, slightly modified, to get resulting row: eval_res = 'var row = []; ' + eval_res + "\nreturn row;" ctx = js.compile(eval_res) self.galaxy_rows = ctx.exec_(eval_res)
def initialize_javascript_runtime(): global jsrt, jsctx, jsinitcnt pac_content = main_gfwlist2pac() jsrts = execjs.available_runtimes() logging.debug(str(jsrts.keys())) # [u'Node', u'SpiderMonkey', u'Spidermonkey'] # SpiderMonkey 引擎比Node引擎用内存与CPU资源少,速度更快。 # 在archlinux上是包会自动使用js185,js包和js17包都不认。 # 好像有很严重的内存泄漏 # 内存问题好像不是出在execjs上的,而是mitmproxy本身就有问题 # https://github.com/mitmproxy/mitmproxy/issues/620 # 如果这有真有内存问题的话,可以考虑试用pacparser包。 jsrt = execjs.get('SpiderMonkey') # jsrt = execjs.get('Node') jsctx = jsrt.compile(pac_content) jsinitcnt += 1 return
def initialize_javascript_runtime(): global jsrt, jsctx, jsinitcnt pac_content = main_gfwlist2pac() jsrts = execjs.available_runtimes() logging.debug(str( jsrts.keys())) # [u'Node', u'SpiderMonkey', u'Spidermonkey'] # SpiderMonkey 引擎比Node引擎用内存与CPU资源少,速度更快。 # 在archlinux上是包会自动使用js185,js包和js17包都不认。 # 好像有很严重的内存泄漏 # 内存问题好像不是出在execjs上的,而是mitmproxy本身就有问题 # https://github.com/mitmproxy/mitmproxy/issues/620 # 如果这有真有内存问题的话,可以考虑试用pacparser包。 jsrt = execjs.get('SpiderMonkey') # jsrt = execjs.get('Node') jsctx = jsrt.compile(pac_content) jsinitcnt += 1 return
def list_js_runtimes(): # AttributeError: module 'execjs' has no attribute 'available_runtimes' try: ajsr = execjs.available_runtimes() except AttributeError: # Newer execjs does not have available_runtimes() method? ajsr = [] supported_runtimes = execjs.runtimes() for sr in supported_runtimes: if supported_runtimes[sr].is_available(): ajsr.append(sr) if len(ajsr) > 0: print('Detected {0} JavaScript runtimes:'.format(len(ajsr))) for js in ajsr: jsr = execjs.get(js) pref_str = '' if js == 'Node': pref_str = ' <== I prefer this one!' print(' {0}: {1}{2}'.format(js, jsr.name, pref_str)) else: print('No JS runtimes detected! Install Node.js, spidermonkey or something!') sys.exit(0)
def setUp(self): self.runtime = execjs @unittest.FunctionTestCase def test_runtime_available(self): runtime = execjs.ExternalRuntime(command=["nonexistent"], name=None, runner_path=None) self.assertFalse(runtime.is_available()) runtime = execjs.ExternalRuntime(command=["python"], name=None, runner_path=None) self.assertTrue(runtime.is_available()) raise Exception for name, runtime in execjs.available_runtimes().items(): class_name = name.capitalize() + "RuntimeTest" def f(runtime=runtime): class RuntimeTest(unittest.TestCase, RuntimeTestBase): def setUp(self): self.runtime = runtime RuntimeTest.__name__ = str(class_name) # 2.x compatibility return RuntimeTest exec("{class_name} = f()".format(class_name=class_name)) def load_tests(loader, tests, ignore): tests.addTests(doctest.DocTestSuite(execjs)) return tests
port = str(eval(s)) checked = td_list[5].text_content().strip() h, m, s = re.search('(\d+):(\d+):(\d+)', checked).groups() checked = 360*int(h)+60*int(m)+int(s) if checked >= 300: continue results.append('http://'+ip+':'+port) return results try: import execjs except: pass else: if execjs.available_runtimes(): def samair(): """ http://www.samair.ru/proxy """ base_uri = 'http://www.samair.ru/proxy/' page = requests.get(base_uri) tree = lxml.html.fromstring(page.text) js_uri = urllib.basejoin(base_uri, tree.xpath('.//script[@type="text/javascript"]/@src')[0]) js_vars = re.search('eval\((.*)\)', requests.get(js_uri).text.strip()).group(1) js_vars = execjs.eval(js_vars) uri_list = [base_uri]+[urllib.basejoin(base_uri, u) \
def test_thrown_exception(self): with self.assertRaises(execjs.ProgramError): self.runtime.exec_("throw 'hello'") def test_broken_substitutions(self): s = '#{source}#{encoded_source}#{json2_source}' self.assertEqual(s, self.runtime.eval('"' + s + '"')) class DefaultRuntimeTest(unittest.TestCase, RuntimeTestBase): def setUp(self): self.runtime = execjs for name, runtime in execjs.available_runtimes().items(): class_name = name.capitalize() + "RuntimeTest" def f(runtime=runtime): class RuntimeTest(unittest.TestCase, RuntimeTestBase): def setUp(self): self.runtime = runtime RuntimeTest.__name__ = str(class_name) # 2.x compatibility return RuntimeTest exec("{class_name} = f()".format(class_name=class_name)) class CommonTest(unittest.TestCase): def test_empty_path_environ(self):