• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python template.parse_template函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python template.render函数代码示例发布时间:2022-05-27
下一篇:
Python tempfile.TemporaryFile类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap