def parse_event_template(event, type, prefix, input, output_directory): event_name = event["event"][1][1][len(prefix):] full_name = event["event"][1][1] fields = "" to_string = "" getters = "" for field in event["type"][1][0]: field_name = field[0][2:] camel_field_name = template_generator.capital_first_letter(field_name) field_type = extract_field_type(field[1]) if field_type: fields += "\t/** @var {0} */\n".format(field_type) fields += "\tpublic ${0};\n\n".format(field_name) # if protocol.typeinfos[field[1]][0] == '_array': # exit() to_string += "{0} = $this->{0}, ".format(field_name) if field_type: getters += "\t/** @return {0} */\n".format(field_type) getters += "\tpublic function get{0}() {{ return $this->{1}; }}\n\n".format(camel_field_name, field_name) template_vars = { 'Name': event_name, 'FullName': full_name, 'Type': type, 'Fields': fields.rstrip('\n'), 'ToString': to_string[:-2], 'Getters': getters.rstrip('\n') } template_generator.parse_template(input, "{0}/{1}.php".format(output_directory, event_name), template_vars)
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment["request"] response = environment["response"] view = response.view folder = request.folder path = pjoin(folder, "compiled") badv = "invalid view (%s)" % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile("|".join(map(fnmatch.translate, patterns))) short_action = "%(controller)s/%(function)s.%(extension)s" % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, "views"), context=environment) restricted(ccode, environment, "file stream") elif os.path.exists(path): x = view.replace("/", "_") files = ["views_%s.pyc" % x] if allow_generic: files.append("views_generic.%s.pyc" % request.extension) # for backward compatibility if request.extension == "html": files.append("views_%s.pyc" % x[:-5]) if allow_generic: files.append("views_generic.pyc") # end backward compatibility code for f in files: filename = pjoin(path, f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, "views", view) if not os.path.exists(filename) and allow_generic: view = "generic." + request.extension filename = pjoin(folder, "views", view) if not os.path.exists(filename): raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs( layer, filename, lambda: compile2(parse_template(view, pjoin(folder, "views"), context=environment), layer), ) else: ccode = parse_template(view, pjoin(folder, "views"), context=environment) restricted(ccode, environment, layer)
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] folder = request.folder path = os.path.join(folder, 'compiled') badv = 'invalid view (%s)' % response.view if not isinstance(response.view, str): ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = response.view.replace('/', '_') if request.extension == 'html': # for backward compatibility files = [os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_%s.pyc' % x[:-5]), os.path.join(path, 'views_generic.html.pyc'), os.path.join(path, 'views_generic.pyc')] else: files = [os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_generic.%s.pyc' % request.extension)] for filename in files: if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(400, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): response.view = 'generic.' + request.extension filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): raise HTTP(400, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(response.view, os.path.join(folder, 'views'), context=environment),layer)) else: ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def run_view_in(environment): """ executes the view in response.view or generic.html. it tries the precompiled views_controller_function.pyc first. """ folder = environment["request"].folder response = environment["response"] path = os.path.join(folder, "compiled/") if os.path.exists(path): filename = os.path.join(path, "views_%s.pyc" % response.view[:-5].replace("/", "_")) if not os.path.exists(filename): filename = os.path.join(folder, "compiled/", "views_generic.pyc") if not os.path.exists(filename): raise HTTP(400, error_message_custom % "invalid view", web2py_error="invalid view") code = read_pyc(filename) restricted(code, environment, layer=filename) else: filename = os.path.join(folder, "views/", response.view) if not os.path.exists(filename): response.view = "generic.html" filename = os.path.join(folder, "views/", response.view) if not os.path.exists(filename): raise HTTP(400, error_message_custom % "invalid view", web2py_error="invalid view") layer = filename if is_gae: ccode = getcfs( layer, filename, lambda: compile( parse_template(response.view, os.path.join(folder, "views/"), context=environment).replace( "\r\n", "\n" ), layer, "exec", ), ) else: ccode = parse_template(response.view, os.path.join(folder, "views/"), context=environment) restricted(ccode, environment, layer)
def compile_views(folder): """ Compiles all the views in the application specified by `folder` """ path = pjoin(folder, 'views') for file in listdir(path, '^[\w/\-]+(\.\w+)+$'): data = parse_template(file, path) filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_') filename = pjoin(folder, 'compiled', filename) write_file(filename, data) save_pyc(filename) os.unlink(filename)
def show_main(wxbot): global main_frame groups = parse_group(wxbot, encoding) templates = parse_template() window.geometry('1080x680+200+50') main_frame = MainFrame(window, wxbot, groups, templates, send_period=config.getint('basic', 'send.period'), thumbnail=config.getboolean('basic', 'send.thumbnail')) main_frame.grid()
def compile_views(folder): """ Compiles all the views in the application specified by `folder` """ path = os.path.join(folder, 'views') for file in listdir(path, '^[\w/\-]+(\.\w+)+$'): data = parse_template(file, path) filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_') filename = os.path.join(folder, 'compiled', filename) write_file(filename, data) save_pyc(filename) os.unlink(filename)
def compile_views(folder): """ Compiles all the views in the application specified by `folder` """ path = pjoin(folder, "views") for file in listdir(path, "^[\w/\-]+(\.\w+)+$"): data = parse_template(file, path) filename = ("views/%s.py" % file).replace("/", "_").replace("\\", "_") filename = pjoin(folder, "compiled", filename) write_file(filename, data) save_pyc(filename) os.unlink(filename)
def compile_views(folder): """ Compiles all the views in the application specified by `folder` """ path = os.path.join(folder, 'views/') for file in listdir(path, '^[\w/]+\.\w+$'): data = parse_template(file, path) filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_') filename = os.path.join(folder, 'compiled', filename) fp = open(filename, 'w') fp.write(data) fp.close() save_pyc(filename) os.unlink(filename)
def compile_views(folder): """ compiles all the views in the applicaiton specified by the current folder """ path = os.path.join(folder, "views/") for file in listdir(path, ".+\.html$"): data = parse_template(file, path) filename = os.path.join( folder, "compiled/", ("views/" + file[:-5] + ".py").replace("/", "_").replace("\\", "_") ) open(filename, "w").write(data) save_pyc(filename) os.unlink(filename)
def compile_views(folder): """ compiles all the views in the applicaiton specified by the current folder """ path = os.path.join(folder, 'views/') for file in listdir(path, '.+\.html$'): data = parse_template(file, path) filename = os.path.join(folder, 'compiled/', ('views/' + file[:-5] + '.py').replace( '/', '_').replace('\\', '_')) open(filename, 'w').write(data) save_pyc(filename) os.unlink(filename)
def compile_views(folder): """ Compiles all the views in the application specified by `folder` """ path = pjoin(folder, 'views') for file in listdir(path, '^[\w/\-]+(\.\w+)*$'): try: data = parse_template(file, path) except Exception, e: raise Exception("%s in %s" % (e, file)) filename = ('views/%s.py' % file).replace('/', '_').replace('\\', '_') filename = pjoin(folder, 'compiled', filename) write_file(filename, data) save_pyc(filename) os.unlink(filename)
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] folder = request.folder path = os.path.join(folder, 'compiled') badv = 'invalid view (%s)' % response.view patterns = response.generic_patterns or [] regex = re.compile('|'.join(fnmatch.translate(r) for r in patterns)) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = patterns and regex.search(short_action) if not isinstance(response.view, str): ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = response.view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = os.path.join(path,f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename) and allow_generic: response.view = 'generic.' + request.extension filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): # Troubleshoot suggested by http://groups.google.com/group/web2py/browse_thread/thread/1c9ed82b640d04a9/82c734b68b79a16a?lnk=gst&q=invalid+view#82c734b68b79a16a badv = filename raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(response.view, os.path.join(folder, 'views'), context=environment),layer)) else: ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] folder = request.folder path = os.path.join(folder, 'compiled') badv = 'invalid view (%s)' % response.view if not isinstance(response.view, str): ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = response.view.replace('/', '_') if request.extension == 'html': # for backward compatibility files = [ os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_%s.pyc' % x[:-5]), os.path.join(path, 'views_generic.html.pyc'), os.path.join(path, 'views_generic.pyc') ] else: files = [ os.path.join(path, 'views_%s.pyc' % x), os.path.join(path, 'views_generic.%s.pyc' % request.extension) ] for filename in files: if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) else: filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): response.view = 'generic.' + request.extension filename = os.path.join(folder, 'views', response.view) if not os.path.exists(filename): raise HTTP(404, rewrite.thread.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs( layer, filename, lambda: compile2( parse_template(response.view, os.path.join(folder, 'views'), context=environment), layer)) else: ccode = parse_template(response.view, os.path.join(folder, 'views'), context=environment) restricted(ccode, environment, layer)
'UserNode': useridNode, 'GameEventNode': protocol.game_eventid_typeid, 'MessageEventNode': protocol.message_eventid_typeid, 'TrackerEventNode': tracker_eventid_typeid, 'GameEvents': events, 'MessageEvents': message_events, 'TrackerEvents': tracker_events, 'HeaderNode': protocol.replay_header_typeid, 'GameDetailsNode': protocol.game_details_typeid, 'InitDataNode': protocol.replay_initdata_typeid } if not os.path.exists(output_directory): os.makedirs(output_directory) template_generator.parse_template(current_path + "/Template/Version.php", "{0}/Version{1}.php".format(output_directory, version), template_vars) all_versions_generated = "[\n" for version in all_versions: all_versions_generated += "\t\t\t{0} => 'Rogiel\StarReplay\Version\Version{0}',\n".format(version) all_versions_generated = all_versions_generated[:-2] + "\n\t\t]" template_vars = { 'Versions': all_versions_generated, } template_generator.parse_template(current_path + "/Template/Versions.php", "{0}/Versions.php".format(output_directory), template_vars) def extract_field_type(field): field_type = classes.get(field) if field_type: field_type = "\\"+field_type else:
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] view = response.view folder = request.folder path = pjoin(folder, 'compiled') badv = 'invalid view (%s)' % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile('|'.join(map(fnmatch.translate, patterns))) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = pjoin(path,f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, 'views', view) if not os.path.exists(filename) and allow_generic: view = 'generic.' + request.extension filename = pjoin(folder, 'views', view) if not os.path.exists(filename): raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(view, pjoin(folder, 'views'), context=environment),layer)) else: ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def parse( stream ): return default_parser.parse( parse_template(stream) ) def parse_file( filename ): return parse( open( filename ) )
def run_view_in(environment): """ Executes the view for the requested action. The view is the one specified in `response.view` or determined by the url or `view/generic.extension` It tries the pre-compiled views_controller_function.pyc before compiling it. """ request = environment['request'] response = environment['response'] view = response.view folder = request.folder path = pjoin(folder, 'compiled') badv = 'invalid view (%s)' % view if response.generic_patterns: patterns = response.generic_patterns regex = re_compile('|'.join(map(fnmatch.translate, patterns))) short_action = '%(controller)s/%(function)s.%(extension)s' % request allow_generic = regex.search(short_action) else: allow_generic = False if not isinstance(view, str): ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, 'file stream') elif os.path.exists(path): x = view.replace('/', '_') files = ['views_%s.pyc' % x] if allow_generic: files.append('views_generic.%s.pyc' % request.extension) # for backward compatibility if request.extension == 'html': files.append('views_%s.pyc' % x[:-5]) if allow_generic: files.append('views_generic.pyc') # end backward compatibility code for f in files: filename = pjoin(path, f) if os.path.exists(filename): code = read_pyc(filename) restricted(code, environment, layer=filename) return raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) else: filename = pjoin(folder, 'views', view) if not os.path.exists(filename) and allow_generic: view = 'generic.' + request.extension filename = pjoin(folder, 'views', view) if not os.path.exists(filename): raise HTTP(404, rewrite.THREAD_LOCAL.routes.error_message % badv, web2py_error=badv) layer = filename if is_gae: ccode = getcfs(layer, filename, lambda: compile2(parse_template(view, pjoin(folder, 'views'), context=environment), layer)) else: ccode = parse_template(view, pjoin(folder, 'views'), context=environment) restricted(ccode, environment, layer)
def parse(stream): return default_parser.parse(parse_template(stream))