本文整理汇总了Python中template.parse_template函数的典型用法代码示例。如果您正苦于以下问题:Python parse_template函数的具体用法?Python parse_template怎么用?Python parse_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_template函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: parse_event_template
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)
开发者ID:Rogiel,项目名称:star-replay,代码行数:34,代码来源:generator.py
示例2: run_view_in
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)
开发者ID:dbarnett,项目名称:web2py,代码行数:59,代码来源:compileapp.py
示例3: run_view_in
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)
开发者ID:trosa,项目名称:listool,代码行数:57,代码来源:compileapp.py
示例4: compile_views
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)
开发者ID:kingiol,项目名称:web2py,代码行数:13,代码来源:compileapp.py
示例5: compile_views
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)
开发者ID:ramanan12345,项目名称:fog-web2py,代码行数:15,代码来源:compileapp.py
示例6: run_view_in
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)
开发者ID:luisibanez,项目名称:openshift_web2py,代码行数:64,代码来源:compileapp.py
示例7: parse
def parse( stream ): return default_parser.parse( parse_template(stream) )
def parse_file( filename ): return parse( open( filename ) )
开发者ID:danse-inelastic,项目名称:pyregui,代码行数:3,代码来源:__init__.py
示例8: extract_field_type
'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:
开发者ID:Rogiel,项目名称:star-replay,代码行数:32,代码来源:generator.py
注:本文中的template.parse_template函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论