当前位置: 首页>>代码示例>>Python>>正文


Python Rule.compile方法代码示例

本文整理汇总了Python中werkzeug.routing.Rule.compile方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.compile方法的具体用法?Python Rule.compile怎么用?Python Rule.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.routing.Rule的用法示例。


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

示例1: compile

# 需要导入模块: from werkzeug.routing import Rule [as 别名]
# 或者: from werkzeug.routing.Rule import compile [as 别名]
	def compile(self):
		Rule.compile(self)
		self._regex = re.compile(self._regex.pattern, 
			re.UNICODE | re.IGNORECASE)
开发者ID:MaayanLab,项目名称:creeds,代码行数:6,代码来源:__init__.py

示例2: route_

# 需要导入模块: from werkzeug.routing import Rule [as 别名]
# 或者: from werkzeug.routing.Rule import compile [as 别名]
    def route_(self, rule, methods=None, werkzeug_route=None,
                    tornado_route=None, handler_bases=None, fn=None, nowrap=None):
        if not methods:
            methods = ['GET']

        clsname = '%sHandler' % fn.__name__.capitalize()
        # TODO: things get complicated if you use your own base class and debug=True
        if not handler_bases:
            if self.debug:
                bases = (DebuggableHandler,)
            else:
                bases = (tornado.web.RequestHandler,)
        else:
            bases = (DebuggableHandler,) + handler_bases
        m = {}
        for method in methods:
            inspected = inspect.getargspec(fn)

            can_be_wrapped = True
            if nowrap == None:
                # are we using a tornado.coroutine or something similar,
                # we dont wrap
                if 'tornado' in inspect.getsourcefile(fn):
                    can_be_wrapped = False
                else:
                    can_be_wrapped = nowrap != True
            else:
                can_be_wrapped = nowrap

            self_in_args = inspected.args and inspected.args[0] in ['self', 'handler']

            if not self_in_args and can_be_wrapped==True:
                def wrapper(self, *args, **kwargs):
                    with StackContext(functools.partial(ctx_man, self)) as cm:
                        w = fn #wrap(fn)
                        result = w(*args, **kwargs)

                    if isinstance(result, TemplateProxy):
                        if self._template_engine == 'tornado':
                            self.render(*result.args, **result.kwargs)
                        else:
                            template = self._template_env.get_template(result.args[0])
                            self.finish(template.render(handler=self, **result.kwargs))
                    else:
                        self.finish(result)

                    # import gc
                    # # gc.collect()
                    # print "is gc enabled", gc.isenabled()
                    # print "-----------------"
                    # for obj in gc.get_objects():
                    #     if isinstance(obj, DebuggableHandler):
                    #         print ">>>", type(obj), "<<<"
                    #
                    # print "-----------------"


                m[method.lower()] = wrapper
            else:
                m[method.lower()] = fn

        klass = type(clsname, bases, m)
        klass._template_engine = self.template_engine
        if self.template_engine != 'tornado':
            klass._template_env = self.template_env

        use_werkzeug_route = None

        if tornado_route:
            use_werkzeug_route = False

        if werkzeug_route:
            use_werkzeug_route = True

        if use_werkzeug_route == None:
            use_werkzeug_route = self.is_werkzeug_route(rule)

        if use_werkzeug_route:
            r = Rule(rule, methods=methods)
            self.url_map.add(r)
            r.compile()
            pattern = r._regex.pattern.replace('^\\|', "")
            self.registery[pattern] = klass
        else:
            self.registery[rule] = klass
开发者ID:lowks,项目名称:tornado_smack,代码行数:87,代码来源:app.py


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