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


Python routing.Rule类代码示例

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


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

示例1: reverse_werkzeug_url

def reverse_werkzeug_url(url, values):
    rule = Rule(url)
    # Rule needs to be bound before building
    m = RuleMap([rule])
    # Note: this seems to be changing in Werkzeug master
    domain_part, url = rule.build(values)
    return url
开发者ID:pombredanne,项目名称:cosmic.py,代码行数:7,代码来源:http.py

示例2: __init__

    def __init__(self, *args, **kwargs):
        """
        :param view_func: a view function.
        """
        # Setup OPTIONS parameter
        methods = kwargs.pop("methods", ("GET",))
        provide_automatic_options = False
        if "OPTIONS" not in methods:
            methods = tuple(methods) + ("OPTIONS",)
            provide_automatic_options = True
        kwargs["methods"] = methods
        self.provide_automatic_options = provide_automatic_options

        # Set the view function
        endpoint = kwargs.get("endpoint", None)
        view_func = kwargs.pop("view_func", None)
        if not view_func:
            if callable(endpoint):
                view_func = endpoint
                endpoint = endpoint.__name__
            elif type(endpoint) is str:
                view_func = import_string(endpoint)

        self.view_func = view_func
        kwargs["endpoint"] = endpoint
        RuleBase.__init__(self, *args, **kwargs)
开发者ID:Davmuz,项目名称:flask,代码行数:26,代码来源:wrappers.py

示例3: define_routes

		def define_routes(cls):
			for route in cls.routes:
				rule = Rule(cls.endpoint + route['route'], endpoint=cls.endpoint + '/' + route['view_function'], methods=route['methods'], strict_slashes=False)
				rule.route = route

				app.view_functions[cls.endpoint + '/' + route['view_function']] = getattr(cls, route['view_function'])
				app.url_map.add(rule)

			return cls.routes
开发者ID:makesaturdays,项目名称:saturdays.core,代码行数:9,代码来源:has_routes.py

示例4: add_url_rule

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        """Connects a URL rule.  Works exactly like the :meth:`route`
        decorator.  If a view_func is provided it will be registered with the
        endpoint.

        Basically this example::

            @app.route('/')
            def index():
                pass

        Is equivalent to the following::

            def index():
                pass
            app.add_url_rule('/', 'index', index)

        If the view_func is not provided you will need to connect the endpoint
        to a view function like so::

            app.view_functions['index'] = index

        .. versionchanged:: 0.2
           `view_func` parameter added.

        .. versionchanged:: 0.6
           `OPTIONS` is added automatically as method.

        :param rule: the URL rule as string
        :param endpoint: the endpoint for the registered URL rule.  Flask
                         itself assumes the name of the view function as
                         endpoint
        :param view_func: the function to call when serving a request to the
                          provided endpoint
        :param options: the options to be forwarded to the underlying
                        :class:`~werkzeug.routing.Rule` object.  A change
                        to Werkzeug is handling of method options.  methods
                        is a list of methods this rule should be limited
                        to (`GET`, `POST` etc.).  By default a rule
                        just listens for `GET` (and implicitly `HEAD`).
                        Starting with Flask 0.6, `OPTIONS` is implicitly
                        added and handled by the standard request handling.
        """
        if endpoint is None:
            endpoint = _endpoint_from_view_func(view_func)
        options['endpoint'] = endpoint
        methods = options.pop('methods', ('GET',))
        provide_automatic_options = False
        if 'OPTIONS' not in methods:
            methods = tuple(methods) + ('OPTIONS',)
            provide_automatic_options = True
        rule = Rule(rule, methods=methods, **options)
        rule.provide_automatic_options = provide_automatic_options
        self.url_map.add(rule)
        if view_func is not None:
            self.view_functions[endpoint] = view_func
开发者ID:khameli,项目名称:flask,代码行数:56,代码来源:app.py

示例5: test_rule_emptying

def test_rule_emptying():
    """Rule emptying"""
    r = Rule("/foo", {"meh": "muh"}, "x", ["POST"], False, "x", True, None)
    r2 = r.empty()
    assert r.__dict__ == r2.__dict__
    r.methods.add("GET")
    assert r.__dict__ != r2.__dict__
    r.methods.discard("GET")
    r.defaults["meh"] = "aha"
    assert r.__dict__ != r2.__dict__
开发者ID:t11e,项目名称:werkzeug,代码行数:10,代码来源:test_routing.py

示例6: test_rule_emptying

def test_rule_emptying():
    """Rule emptying"""
    r = Rule('/foo', {'meh': 'muh'}, 'x', ['POST'],
             False, 'x', True, None)
    r2 = r.empty()
    assert r.__dict__ == r2.__dict__
    r.methods.add('GET')
    assert r.__dict__ != r2.__dict__
    r.methods.discard('GET')
    r.defaults['meh'] = 'aha'
    assert r.__dict__ != r2.__dict__
开发者ID:fmw,项目名称:werkzeug,代码行数:11,代码来源:test_routing.py

示例7: __init__

 def __init__(self, string, defaults=None, subdomain=None, methods=None,
              build_only=False, endpoint=None, strict_slashes=None,
              redirect_to=None, permission=None, template=None, func=None,
              authRequired=False, expires=None, mimetype=None, nocache=False):
     Rule.__init__(self, string, defaults, subdomain, methods, build_only,
                   endpoint, strict_slashes, redirect_to)
     self.permission = permission
     self.template = template
     self.func = func
     self.authRequired = authRequired
     self.expires = expires
     self.mimetype = mimetype
     self.nocache = nocache
开发者ID:pomke,项目名称:Pangur,代码行数:13,代码来源:utils.py

示例8: add_url_rule

    def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
        assert view_func is not None, 'view_func is mandatory'
        if endpoint is None:
            endpoint = view_func.__name__
        options['endpoint'] = endpoint
        # supposed to be GET
        methods = set(('GET', ))
        provide_automatic_options = False

        rule = Rule(rule, methods=methods, **options)
        rule.provide_automatic_options = provide_automatic_options
        self.url_map.add(rule)
        if view_func is not None:
            old_func = self.view_functions.get(endpoint)
            if old_func is not None and old_func != view_func:
                raise AssertionError('View function mapping is overwriting an '
                                     'existing endpoint function: %s' % endpoint)
            self.view_functions[endpoint] = view_func
开发者ID:huangwu5717,项目名称:flask-uwsgi-websocket,代码行数:18,代码来源:websocket.py

示例9: match

 def match(self, path):
     values = Rule.match(self, path)
     if values is not None:
         values['authRequired'] = self.authRequired
         values['permission'] = self.permission
         values['template'] = self.template
         values['func'] = self.func
         values['expires'] = self.expires
         values['mimetype'] = self.mimetype
         values['nocache'] = self.nocache
     return values
开发者ID:pomke,项目名称:Pangur,代码行数:11,代码来源:utils.py

示例10: __new__

    def __new__(cls, name, bases, attrs):
        # Add a url_map to the class
        url_map = UrlMap(strict_slashes=False)
        # Add a collection of (unbound) view functions
        view_functions = {}
        for base in bases:
            # Extend from url_map of base class
            if hasattr(base, 'url_map') and isinstance(base.url_map, UrlMap):
                for rule in base.url_map.iter_rules():
                    url_map.add(rule.empty())
            # Extend from view_functions of base class
            if hasattr(base, 'view_functions') and isinstance(base.view_functions, dict):
                view_functions.update(base.view_functions)
        for routeattr, route in attrs.items():
            if isinstance(route, _NodeRoute):
                # For wrapped routes, add a rule for each layer of wrapping
                endpoints = []
                while isinstance(route, _NodeRoute):
                    # Save the endpoint name
                    endpoints.append(route.endpoint)
                    # Construct the url rule
                    url_rule = UrlRule(route.rule, endpoint=route.endpoint, methods=route.methods, defaults=route.defaults)
                    url_rule.provide_automatic_options = True
                    url_map.add(url_rule)
                    route = route.f
                # Make a list of endpoints
                for e in endpoints:
                    view_functions[e] = route
                # Restore the original function
                attrs[routeattr] = route
        # Finally, update the URL map and insert it into the class
        url_map.update()
        attrs['url_map'] = url_map
        attrs['view_functions'] = view_functions

        return type.__new__(cls, name, bases, attrs)
开发者ID:hasgeek,项目名称:nodular,代码行数:36,代码来源:view.py

示例11: empty

 def empty(self):
     new_rule = Rule.empty(self)
     new_rule.gmg_controller = self.gmg_controller
     return new_rule
开发者ID:imclab,项目名称:mediagoblin,代码行数:4,代码来源:routing.py

示例12: __init__

 def __init__(self, endpoint, url, controller):
     Rule.__init__(self, url, endpoint=endpoint)
     self.gmg_controller = controller
开发者ID:imclab,项目名称:mediagoblin,代码行数:3,代码来源:routing.py

示例13: __init__

 def __init__(self, string, defaults=None, subdomain=None, methods=None,
              build_only=False, endpoint=None, strict_slashes=None,
              redirect_to=None, alias=False, host=None, mimetype=None):
     _Rule.__init__(self, string, defaults, subdomain, methods, build_only,
                    endpoint, strict_slashes, redirect_to, alias, host)
     self.mimetype = mimetype
开发者ID:matejamateusz,项目名称:OLDPLOTTING_FLASK,代码行数:6,代码来源:flask_mime.py

示例14: __init__

 def __init__(self, pattern, **kwargs):
   try:
     self.view = kwargs.pop('view')
   except KeyError:
     self.view = None
   OriginalRule.__init__(self, pattern, **kwargs)
开发者ID:IanLewis,项目名称:kay,代码行数:6,代码来源:routing.py

示例15: __init__

 def __init__(self, endpoint, methods=['get']):
     Rule.__init__(self, '/', endpoint=endpoint, methods=methods)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:2,代码来源:routing.py


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