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


Python Rule.provide_automatic_options方法代码示例

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


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

示例1: add_url_rule

# 需要导入模块: from werkzeug.routing import Rule [as 别名]
# 或者: from werkzeug.routing.Rule import provide_automatic_options [as 别名]
    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,代码行数:58,代码来源:app.py

示例2: add_url_rule

# 需要导入模块: from werkzeug.routing import Rule [as 别名]
# 或者: from werkzeug.routing.Rule import provide_automatic_options [as 别名]
    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,代码行数:20,代码来源:websocket.py

示例3: __new__

# 需要导入模块: from werkzeug.routing import Rule [as 别名]
# 或者: from werkzeug.routing.Rule import provide_automatic_options [as 别名]
    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,代码行数:38,代码来源:view.py


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