import js2py import time print("Testing ECMA 5...") assert js2py.eval_js('(new Date("2008-9-03T20:56:35.450686Z")).toString()') assert js2py.eval_js('/ser/.test("Mleko + ser to nabial")') assert js2py.eval_js('1 + "1"') == '11' assert js2py.eval_js('function (r) {return r}')(5) == 5 x, c = js2py.run_file('examples/esprima.js') assert c.esprima.parse('var abc = 40').to_dict() == {'type': 'Program', 'body': [{'type': 'VariableDeclaration', 'kind': 'var', 'declarations': [{'id': {'type': 'Identifier', 'name': 'abc'}, 'type': 'VariableDeclarator', 'init': {'type': 'Literal', 'raw': '40', 'value': 40}}]}], 'sourceType': 'script'} try: assert js2py.eval_js('syntax error!') and 0 except js2py.PyJsException as err: assert str(err).startswith('SyntaxError: ') assert js2py.eval_js('pyimport time; time.time()') <= time.time() js2py.disable_pyimport() try: assert js2py.eval_js('pyimport time') and 0 except js2py.PyJsException as err: assert str(err).startswith('SyntaxError: ')
env_file.close() dictToSend = { 'type': "CNAME", 'name': sFolder, 'content': oCreds["Site"], 'proxied': True } dictHeaders = { "X-Auth-Email": oCreds["EmailID"], "X-Auth-Key": oCreds["SecretKey"] } res = requests.post('https://api.cloudflare.com/client/v4/zones/' + oCreds["ZoneID"] + "/dns_records", json=dictToSend, headers=dictHeaders) print('response from server:', res.text) dir_path = os.path.dirname(os.path.realpath(__file__)) eval_result, example = js2py.run_file(dir_path + '/static/scripts/proxyport.js') with open('cloudflare.json') as json_data_file: oCreds = loads(json_data_file.read()) if len(sys.argv) > 1: createProject(sys.argv[1]) else: for item in os.listdir("users"): if os.path.isdir(os.path.join("users", item)): createProject(item)
def decrypt_url(p1, p2): jsc, _ = js2py.run_file('md5.js') return jsc.encrypt(p1, p2)
def get_reference_parse_fn(): # lets use js2py translated esprima for similicity. import js2py _, ctx = js2py.run_file(REFERENCE_ESPRIMA_PATH) return lambda x: ctx.esprima.parse(x).to_dict()
def get_reference_escodegen_fn(): # lets use js2py translated escodegen for similicity. import js2py _, ctx = js2py.run_file(REFERENCE_ESCODEGEN_PATH) return lambda x: ctx.escodegen.generate(x)
"%d") + " " + x.strftime("%Y") + " " + x.strftime( "%X") + " GMT+0600 (Bangladesh Standard Time)" print(date) s = "" with requests.session() as s: URL = "http://biis.buet.ac.bd/BIIS_WEB/keyGeneration.do?date=" + date # gr = s.get(url=URL) print(gr.content) s = str(gr.content) l = s.split("<modulus>") l = l[1].split("</modulus>") print("modulus :", l[0]) eval_res, jsFile = js2py.run_file("full.js") password = jsFile.jsrsaenc("17", l[0], "256", "27D46DeFN") password = password.strip() print("password :"******"27D46DeFN" # response = muterun_js('full.js') # if response.exitcode == 0: # print(response.stdout) # else: # print(response.stderr) guessed_pass = "******" URL = "http://biis.buet.ac.bd/" # 27D46DeFN #sending get request and saving the response as response object
import js2py eval_res, jsFile = js2py.run_file("sketch.js") jsFile.setup()
js2py.translate_file('phkConverter.js', 'phkConverter.py') # Converted from JavaScript # import phkConverter # Using readlines() outputLines = [] infileName = '/Users/craig/Desktop/Projects/PhakeData/joined.txt' # Originally wasq'Phake_Dictionary_Ailot_Final.txt' count = 0 # These should be converted.:wq phakeFields = ['lx', 'le', 'pl', 'se', 'xv'] banchobFields = ['ph', 'pd', 'xr'] textFields = ['de', 'ge', 'xe'] eval_res, converterFile = js2py.run_file('phkConverter.js') encodingIndex = 0 banchobMap = { 'N': 'ŋ', 'M': 'ñ', 'j': 'ɛ', 'v': 'ü', 'z': 'ə', 'q': 'ɔ', 'I': 'ī', 'E': 'ē', 'J': 'ɛ̄', 'V': 'ǖ', 'Z': 'ə̄',
import js2py # there are 2 easy methods to run js file from Js2Py # Method 1: eval_result, example = js2py.run_file('example.js') # Method 2: js2py.translate_file( 'example.js', 'example.py') # this translates and saves equivalent Py file from example import example # yes, it is: import lib_name from lib_name ##### Now you can use your JS code as if it was Python! print((example.someVariable)) print((example.someVariable.a)) print((example.someVariable['a'])) example.sayHello('Piotrek!') example.sayHello() # told you, just like JS. example['$nonPyName']( ) # non py names have to be accessed through [] example.$ is a syntax error in Py. # but there is one problem - it is not possible to write 'new example.Rectangle(4,3)' in Python # so you have to use .new(4,3) instead, to create the object. rect = example.Rectangle.new(4, 3) print((rect.getArea())) # should print 12
import js2py # there are 2 easy methods to run js file from Js2Py # Method 1: eval_result, example = js2py.run_file('example.js') # Method 2: js2py.translate_file('example.js', 'example.py') # this translates and saves equivalent Py file from example import example # yes, it is: import lib_name from lib_name ##### Now you can use your JS code as if it was Python! print(example.someVariable) print(example.someVariable.a) print(example.someVariable['a']) example.sayHello('Piotrek!') example.sayHello() # told you, just like JS. example['$nonPyName']() # non py names have to be accessed through [] example.$ is a syntax error in Py. # but there is one problem - it is not possible to write 'new example.Rectangle(4,3)' in Python # so you have to use .new(4,3) instead, to create the object. rect = example.Rectangle.new(4,3) print(rect.getArea()) # should print 12
import js2py from js2py import require res, jsfile = js2py.run_file('example.js') print(jsfile.fibonacci_series(8)) random_int = require('random-int') print(random_int) print(random_int(10, 40))
import js2py import pandas as pd import pickle import glob import requests from flask import render_template import json from geopy.geocoders import Nominatim #results = js2py.run_file("data/affiliationList.js") #affil_dict = results[0].to_dict() jsdatafiles = [f for f in glob.glob("data/js/*.js")] js_data_contents = {} for f in jsdatafiles: results = js2py.run_file(f) key = str(f.split("data/js/")[1]) js_data_contents[key] = results[0].to_dict() jsondatafiles = [f for f in glob.glob("data/js/*.json")] json_data_contents = {} for name in jsondatafiles: with open(name, 'rb') as f: results = json.load(f) key = str(name.split("data/js/")[1]) json_data_contents[key] = results #results[0].to_dict() global py_geo_map py_geo_map = {} results = js2py.run_file("data/affiliationList.js") holding = results[0].to_dict()