def salam(request, *args, **kwargs): """ Returns a HttpResponse whose content is filled with the result of calling django.template.loader.render_to_string() with the passed arguments. Uses a RequestContext by default. """ httpresponse_kwargs = { 'content_type': kwargs.pop('content_type', None), 'status': kwargs.pop('status', None), } if 'context_instance' in kwargs: context_instance = kwargs.pop('context_instance') if kwargs.get('current_app', None): raise ValueError('If you provide a context_instance you must ' 'set its current_app before calling render()') else: current_app = kwargs.pop('current_app', None) context_instance = RequestContext(request, current_app=current_app) kwargs['context_instance'] = context_instance s = loader.render_to_string('index.htm', {'PASTE_FUNCS':(convert_py2js(inspect.getsource(scopeFunc)))+registerFunc(scopeFunc)}) s = s.replace("<[", "{{").replace("]>", "}}") # <- magic happens *here* s = s.replace("'", "'") # <- magic happens *here* s = s.replace(""", "'") # <- magic happens *here* return HttpResponse(s, **httpresponse_kwargs)
def main(): parser = OptionParser(usage="%prog [options] filename", description="Python to JavaScript compiler.") parser.add_option("--output", action="store", dest="output", help="write output to OUTPUT") parser.add_option("--include-builtins", action="store_true", dest="include_builtins", default=False, help="include py-builtins.js library in the output") options, args = parser.parse_args() if len(args) == 1: filename = args[0] if options.output: output = open(options.output, "w") else: output = sys.stdout if options.include_builtins: if os.path.dirname(__file__): builtins = open(os.path.join(os.path.dirname(__file__)), "py-builtins.js").read() else: builtins = open("py-builtins.js").read() output.write(builtins) s = open(filename).read() #unsafe for large files! output.write(convert_py2js(s)) else: parser.print_help()
def main(): funcs = [ ExtObject, Window, Panel, TabPanel, Toolbar, info_box, Canvas, menu_about, menu_help, get_toolbar, get_panel, toolbar_mesh1, toolbar_mesh2, toolbar_mesh3, initialize, ] source = "" for f in funcs: source += inspect.getsource(f) + "\n" js = convert_py2js(source) print """\ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--[if IE]><script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script><![endif]--> <link rel="stylesheet" type="text/css" href="http://www.extjs.com/deploy/dev/resources/css/ext-all.css"> <script type="text/javascript" src="http://www.extjs.com/deploy/dev/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="http://www.extjs.com/deploy/dev/ext-all.js"></script> <script language="JavaScript" src="../py-builtins.js"></script> <title id="page-title">Title</title> <script type="text/javascript"> %s Ext.onReady(initialize); </script> </head> <body></body> </html>""" % (js)
def main(): parser = OptionParser(usage="%prog [options] filename", description="Python to JavaScript compiler.") parser.add_option("--output", action="store", dest="output", help="write output to OUTPUT") parser.add_option("--include-builtins", action="store_true", dest="include_builtins", default=False, help="include py-builtins.js library in the output") options, args = parser.parse_args() if len(args) == 1: filename = args[0] if options.output: output = open(options.output, "w") else: output = sys.stdout if options.include_builtins: if os.path.dirname(__file__): builtins = open( os.path.join(os.path.dirname(__file__), "py-builtins.js")).read() else: builtins = open("py-builtins.js").read() output.write(builtins) s = open(filename).read() #unsafe for large files! output.write(convert_py2js(s)) else: parser.print_help()
def __init__(self, obj): self._obj = obj obj_source = inspect.getsource(obj) self._js = convert_py2js(obj_source)