本文整理匯總了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)
示例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