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

Python utils.process函数代码示例

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

本文整理汇总了Python中pyjade.utils.process函数的典型用法代码示例。如果您正苦于以下问题:Python process函数的具体用法?Python process怎么用?Python process使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了process函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: load_template

    def load_template(self, template_name, template_dirs=None):
        key = template_name
        if template_dirs:
            # If template directories were specified, use a hash to differentiate
            key = '-'.join([template_name, hashlib.sha1('|'.join(template_dirs)).hexdigest()])

        
        if settings.DEBUG or key not in self.template_cache:

            if os.path.splitext(template_name)[1] in ('.jade',):
                source, display_name = self.load_template_source(template_name, template_dirs)
                source=process(source,filename=template_name,compiler=Compiler)
                origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
                template = get_template_from_string(source, origin, template_name)
            else:
                template, origin = self.find_template(template_name, template_dirs)
            if not hasattr(template, 'render'):
                try:
                    template = get_template_from_string(process(source,filename=template_name,compiler=Compiler), origin, template_name)
                except TemplateDoesNotExist:
                    # If compiling the template we found raises TemplateDoesNotExist,
                    # back off to returning he source and display name for the template
                    # we were asked to load. This allows for correct identification (later)
                    # of the actual template that does not exist.
                    return template, origin
            self.template_cache[key] = template
        return self.template_cache[key], None
开发者ID:dustinfarris,项目名称:pyjade,代码行数:27,代码来源:loader.py


示例2: templatize

 def templatize(src, origin=None):
     src = to_text(src, settings.FILE_CHARSET)
     if origin.endswith(".jade"):
         html = process(src,compiler=Compiler)
     else:
         html = src
     return func(html, origin)
开发者ID:KooroshTorabi,项目名称:pyjade,代码行数:7,代码来源:compiler.py


示例3: preprocess

 def preprocess(self, source, name, filename=None):
     if (not name or
        (name and not os.path.splitext(name)[1] in self.file_extensions)):
         msg = "return {}".format(name)
         logging.info(msg)
         return source
     return process(source,filename=name,compiler=Compiler,**self.options)
开发者ID:luke0922,项目名称:pyjade,代码行数:7,代码来源:jinja.py


示例4: django_process

    def django_process(str):
        compiled = process(str,filename=None,compiler = DjangoCompiler)
        print(compiled)
        t = django.template.Template(compiled)

        ctx = django.template.Context()
        return t.render(ctx)
开发者ID:holidare,项目名称:pyjade,代码行数:7,代码来源:test_cases.py


示例5: django_process

    def django_process(src, filename):
        compiled = process(src, filename=filename,compiler = DjangoCompiler)
        print compiled
        t = django.template.Template(compiled)

        ctx = django.template.Context()
        return t.render(ctx)
开发者ID:h-hirokawa,项目名称:pyjade,代码行数:7,代码来源:test_cases.py


示例6: upgrade

def upgrade():
    op.add_column('application_template', sa.Column('jinja2', sa.Text))
    op.add_column('application_template', sa.Column('key', sa.String(255)))


    meta = sa.MetaData()
    table = sa.schema.Table(
        'application_template', meta,
        sa.Column('id', sa.BigInteger, primary_key=True),
        sa.Column('key', sa.String(255)),
        sa.Column('jinja2', sa.Text)
    )

    # converting original jade template_source into jinja2 preprocessed source
    conn = op.get_bind()
    rows = conn.execute('select id, template_key, template_source from application_template')
    for row in rows:
        rid = row[0]
        name = row[1]
        source = row[2]
        results = process(source,filename=name,compiler=Compiler)
        where = 'id=%d' % rid
        update_expression = sa.sql.expression.update(
            table, whereclause=where,
            values={
                'jinja2': results,
                'key': name
            }
        )
        conn.execute(update_expression)
开发者ID:glennyonemitsu,项目名称:MarkupHiveServer,代码行数:30,代码来源:20130403225415-template_table_moved.py


示例7: convert_file

def convert_file():
    support_compilers_list = ['django', 'jinja', 'underscore', 'mako', 'tornado', 'html']
    available_compilers = {}
    for i in support_compilers_list:
        try:
            compiler_class = __import__('pyjade.ext.%s' % i, fromlist=['pyjade']).Compiler
        except ImportError as e:
            logging.warning(e)
        else:
            available_compilers[i] = compiler_class

    usage = "usage: %prog [options] [file [output]]"
    parser = OptionParser(usage)
    parser.add_option("-o", "--output", dest="output",
                    help="Write output to FILE", metavar="FILE")
    # use a default compiler here to sidestep making a particular
    # compiler absolutely necessary (ex. django)
    default_compiler = sorted(available_compilers.keys())[0]
    parser.add_option("-c", "--compiler", dest="compiler",
                    choices=list(available_compilers.keys()),
                    default=default_compiler,
                    type="choice",
                    help=("COMPILER must be one of %s, default is %s" %
                          (', '.join(list(available_compilers.keys())), default_compiler)))
    parser.add_option("-e", "--ext", dest="extension",
                      help="Set import/extends default file extension",
                      metavar="FILE")

    options, args = parser.parse_args()

    file_output = options.output or (args[1] if len(args) > 1 else None)
    compiler = options.compiler

    if options.extension:
        extension = '.%s' % options.extension
    elif options.output:
        extension = os.path.splitext(options.output)[1]
    else:
        extension = None

    if compiler in available_compilers:
        import six
        if len(args) >= 1:
            template = codecs.open(args[0], 'r', encoding='utf-8').read()
        elif six.PY3:
            template = sys.stdin.read()
        else:
            template = codecs.getreader('utf-8')(sys.stdin).read()
        output = process(template, compiler=available_compilers[compiler],
                         staticAttrs=True, extension=extension)
        if file_output:
            outfile = codecs.open(file_output, 'w', encoding='utf-8')
            outfile.write(output)
        elif six.PY3:
            sys.stdout.write(output)
        else:
            codecs.getwriter('utf-8')(sys.stdout).write(output)
    else:
        raise Exception('You must have %s installed!' % compiler)
开发者ID:KooroshTorabi,项目名称:pyjade,代码行数:59,代码来源:convert.py


示例8: __init__

    def __init__(self, template_string, name="<string>", *args, **kwargs):
        is_jade = name.endswith(".jade")
        if is_jade:
            template_string = process(template_string, filename=name, compiler=Compiler)

        super(Template, self).__init__(template_string, name, *args, **kwargs)
        if is_jade:
            self.namespace.update({ATTRS_FUNC: attrs, ESCAPE_FUNC: escape, ITER_FUNC: iteration})
开发者ID:thenoviceoof,项目名称:pyjade,代码行数:8,代码来源:__init__.py


示例9: _convert

def _convert(src, dst):
    template = codecs.open(src, "r", encoding="utf-8").read()
    output = process(template, compiler=UnderscoreCompiler)
    outfile = codecs.open(dst, "w", encoding="utf-8")
    outfile.write(output)
    outfile.close()

    print 'compiled "%s" into "%s"' % (src, dst)
开发者ID:weapp,项目名称:flask-jade2underscore,代码行数:8,代码来源:jade2underscore.py


示例10: preprocess

    def preprocess(self, source, name, filename=None):
        if name and not os.path.splitext(name)[1] in self.environment.jade_file_extensions:
            return source

        return process(source,filename=name,compiler=Compiler)
        # parser = Parser(source,filename=name)
        # block = parser.parse()
        # compiler = Compiler(block)
        # return compiler.compile()
        # procesed= process(source,name)
        # print procesed
        # return procesed
开发者ID:dustinfarris,项目名称:pyjade,代码行数:12,代码来源:jinja.py


示例11: convert_file

def convert_file():
    import codecs
    aviable_compilers = {}
    try:
        from pyjade.ext.django import Compiler as DjancoCompiler
        aviable_compilers['django'] = DjancoCompiler
    except:
        pass
    try:
        from pyjade.ext.jinja import Compiler as JinjaCompiler
        aviable_compilers['jinja'] = JinjaCompiler
    except:
        pass
    try:
        from pyjade.ext.underscore import Compiler as UnderscoreCompiler
        aviable_compilers['underscore'] = UnderscoreCompiler
    except:
        pass
    try:
        from pyjade.ext.mako import Compiler as MakoCompiler
        aviable_compilers['mako'] = MakoCompiler
    except:
        pass
    from optparse import OptionParser
    usage = "usage: %prog [options] file [output]"
    parser = OptionParser(usage)
    parser.add_option("-o", "--output", dest="output",
                      help="write output to FILE", metavar="FILE")
    parser.add_option("-c", "--compiler", dest="compiler",
                        choices=['django', 'jinja', 'mako', 'underscore',],
                        default='django',
                        type="choice",
                      help="COMPILER must be django (default), jinja, underscore or mako ")
    # parser.add_option("-q", "--quiet",
    #                   action="store_false", dest="verbose", default=True,
    #                   help="don't print status messages to stdout")
    (options, args) = parser.parse_args()
    if len(args)<1:
        print "Specify the input file as the first argument."
        exit()
    file_output = options.output or (args[1] if len(args)>1 else None)
    compiler = options.compiler
    if compiler in aviable_compilers:
        template = codecs.open(args[0], 'r', encoding='utf-8').read()
        output = process(template,compiler=aviable_compilers[compiler])
        if file_output:
            outfile = codecs.open(file_output, 'w', encoding='utf-8')
            outfile.write(output)
        else:
            print output
    else:
        raise Exception('You must have %s installed!'%compiler)
开发者ID:BigDataSwami,项目名称:myTime,代码行数:52,代码来源:convert.py


示例12: load_template

 def load_template(self, template_name, template_dirs=None):
     if os.path.splitext(str(template_name))[1] in ('.jade',):
         try:
             source, display_name = self.load_template_source(template_name, template_dirs)
             source=process(source,filename=template_name,compiler=Compiler)
             origin = make_origin(display_name, self.load_template_source, template_name, template_dirs)
             template = get_template_from_string(source, origin, template_name)
         except NotImplementedError:
             template, origin = self.find_template(template_name, template_dirs)
     else:
         template, origin = self.find_template(template_name, template_dirs)
     if not hasattr(template, 'render'):
         try:
             template = get_template_from_string(process(source,filename=template_name,compiler=Compiler), origin, template_name)
         except TemplateDoesNotExist:
             # If compiling the template we found raises TemplateDoesNotExist,
             # back off to returning he source and display name for the template
             # we were asked to load. This allows for correct identification (later)
             # of the actual template that does not exist.
             return template, origin
     
     return template, None
开发者ID:webcube,项目名称:pyjade,代码行数:22,代码来源:loader.py


示例13: run_case

def run_case(case,process):
    global processors
    process = processors[process]
    jade_file = open('cases/%s.jade'%case)
    jade_src = jade_file.read().decode('utf-8')
    jade_file.close()

    html_file = open('cases/%s.html'%case)
    html_src = html_file.read().strip('\n').decode('utf-8')
    html_file.close()
    try:
        processed_jade = process(jade_src).strip('\n')
        print 'PROCESSED\n',processed_jade,len(processed_jade)
        print 'EXPECTED\n',html_src,len(html_src)
        assert processed_jade==html_src
    except CurrentlyNotSupported:
        pass
开发者ID:dustinfarris,项目名称:pyjade,代码行数:17,代码来源:test_cases.py


示例14: render_jade_with_json

 def render_jade_with_json(self, jade_template_path, json_file_path,
                           template_path_base, base_file):
     logger.debug('Working with jade template %s', jade_template_path)
     tmpl = loader.get_template(jade_template_path)
     if settings.DEBUG:
         logger.debug('Template is: %s',
                      process(open(os.path.join(self.template_path,
                                                jade_template_path)).read()))
     # We need to simulate request middleware but without short-circuiting
     # the response
     request_factory = RequestFactory()
     req = request_factory.get('/%s/%s.html' % (template_path_base,
                                                base_file),
                               data={})
     handler = WSGIHandler()
     handler.load_middleware()
     for middleware_method in handler._request_middleware:
         middleware_method(req)
     # Render the template with a RequestContext
     ctx = RequestContext(req, json.load(open(json_file_path)))
     return tmpl.render(ctx)
开发者ID:dancashman,项目名称:django-jade-tools,代码行数:21,代码来源:compiler.py


示例15: compile

 def compile(self, base_file_name, path, template_path):
     jade_template_path = os.path.join(template_path,
                                       '%s.jade' % (base_file_name,))
     logger.debug('Working with jade template %s', jade_template_path)
     # Change the pwd to the template's location
     current_pwd = os.getcwd()
     os.chdir(path)
     # Hackery to allow for pre-processing the jade source
     jade_loader = Loader(
         ('django.template.loaders.filesystem.Loader',))
     tmpl_src, display_name = jade_loader.load_template_source(
         jade_template_path, [self.template_path,])
     if self.INCLUDE_RE.search(tmpl_src):
         tmpl_src = self.preprocess_includes(tmpl_src)
     # WHITESPACE! HUH! WHAAAAT IS IT GOOD FOR? ABSOLUTELY NOTHING!
     tmpl_src = u'\n'.join([line for line in tmpl_src.split('\n')
                            if line.strip()])
     origin = loader.make_origin(display_name,
                                 jade_loader.load_template_source,
                                 jade_template_path, None)
     if settings.DEBUG:
         logger.debug(
             u'Template is: \n%s',
             u'\n'.join(['%4d: %s' % (i, s)
                        for i, s in enumerate(tmpl_src.split('\n'))]))
     compiled_jade = process(tmpl_src, filename=jade_template_path,
                             compiler=Compiler)
     try:
         tmpl = loader.get_template_from_string(compiled_jade, origin,
                                                jade_template_path)
     except Exception, e:
         logger.exception('Failed to compile Jade-derived HTML template:')
         logger.exception(
             u'\n'.join(['%4d: %s' % (i, s)
                        for i, s in enumerate(compiled_jade.split(u'\n'))]))
         raise
开发者ID:celerityweb,项目名称:django-jade-tools,代码行数:36,代码来源:compiler.py


示例16: templatize

 def templatize(src, origin=None):
     html = process(src,compiler=Compiler)
     return func(html, origin)
开发者ID:christophercurrie,项目名称:pyjade,代码行数:3,代码来源:__init__.py


示例17: preprocess

 def preprocess(self, source, name, filename=None):
     if name and not os.path.splitext(name)[1] in self.file_extensions:
         return source
     return process(source,filename=name,compiler=Compiler,**self.options)
开发者ID:glennyonemitsu,项目名称:pyjade,代码行数:4,代码来源:jinja.py


示例18: preprocessor

def preprocessor(source):
    return process(source,compiler=Compiler)
开发者ID:BigDataSwami,项目名称:myTime,代码行数:2,代码来源:mako.py


示例19: preprocess

 def preprocess(self, source, name, filename=None):
     if name and not os.path.splitext(name)[1] in self.environment.jade_file_extensions:
         return source
     return process(source,filename=name,compiler=Compiler)
开发者ID:weapp,项目名称:backbone-full-stack,代码行数:4,代码来源:jinja.py


示例20: templatize

 def templatize(src, origin=None):
     src = force_text(src, settings.FILE_CHARSET)
     html = process(src, compiler=Compiler)
     return func(html, origin)
开发者ID:thenoviceoof,项目名称:pyjade,代码行数:4,代码来源:compiler.py



注:本文中的pyjade.utils.process函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pyjamas.DOM类代码示例发布时间:2022-05-25
下一篇:
Python base.BaseClient类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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