예제 #1
0
        def get_bad_name():
            if PY3:  # pragma: nocover
                name = b'La Pe\xc3\xb1a'
            else:  # pragma: nocover
                name = text_(b'La Pe\xc3\xb1a', 'utf-8')

            get_callable_name(name)
예제 #2
0
        def get_bad_name():
            if PY2:
                name = text_(b'La Pe\xc3\xb1a', 'utf-8')
            else:
                name = b'La Pe\xc3\xb1a'

            get_callable_name(name)
예제 #3
0
        def get_bad_name():
            if PY3:  # pragma: nocover
                name = b'La Pe\xc3\xb1a'
            else:  # pragma: nocover
                name = text_(b'La Pe\xc3\xb1a', 'utf-8')

            get_callable_name(name)
예제 #4
0
파일: test_util.py 프로젝트: JDeuce/pyramid
        def get_bad_name():
            if PY2:
                name = text_(b'La Pe\xc3\xb1a', 'utf-8')
            else:
                name = b'La Pe\xc3\xb1a'

            get_callable_name(name)
예제 #5
0
파일: __init__.py 프로젝트: Pylons/pyramid
    def add_directive(self, name, directive, action_wrap=True):
        """
        Add a directive method to the configurator.

        .. warning:: This method is typically only used by :app:`Pyramid`
           framework extension authors, not by :app:`Pyramid` application
           developers.

        Framework extenders can add directive methods to a configurator by
        instructing their users to call ``config.add_directive('somename',
        'some.callable')``.  This will make ``some.callable`` accessible as
        ``config.somename``.  ``some.callable`` should be a function which
        accepts ``config`` as a first argument, and arbitrary positional and
        keyword arguments following.  It should use config.action as
        necessary to perform actions.  Directive methods can then be invoked
        like 'built-in' directives such as ``add_view``, ``add_route``, etc.

        The ``action_wrap`` argument should be ``True`` for directives which
        perform ``config.action`` with potentially conflicting
        discriminators.  ``action_wrap`` will cause the directive to be
        wrapped in a decorator which provides more accurate conflict
        cause information.

        ``add_directive`` does not participate in conflict detection, and
        later calls to ``add_directive`` will override earlier calls.
        """
        name = get_callable_name(name)
        c = self.maybe_dotted(directive)
        if not hasattr(self.registry, '_directives'):
            self.registry._directives = {}
        self.registry._directives[name] = (c, action_wrap)
예제 #6
0
    def add_directive(self, name, directive, action_wrap=True):
        """
        Add a directive method to the configurator.

        .. warning:: This method is typically only used by :app:`Pyramid`
           framework extension authors, not by :app:`Pyramid` application
           developers.

        Framework extenders can add directive methods to a configurator by
        instructing their users to call ``config.add_directive('somename',
        'some.callable')``.  This will make ``some.callable`` accessible as
        ``config.somename``.  ``some.callable`` should be a function which
        accepts ``config`` as a first argument, and arbitrary positional and
        keyword arguments following.  It should use config.action as
        necessary to perform actions.  Directive methods can then be invoked
        like 'built-in' directives such as ``add_view``, ``add_route``, etc.

        The ``action_wrap`` argument should be ``True`` for directives which
        perform ``config.action`` with potentially conflicting
        discriminators.  ``action_wrap`` will cause the directive to be
        wrapped in a decorator which provides more accurate conflict
        cause information.

        ``add_directive`` does not participate in conflict detection, and
        later calls to ``add_directive`` will override earlier calls.
        """
        name = get_callable_name(name)
        c = self.maybe_dotted(directive)
        if not hasattr(self.registry, '_directives'):
            self.registry._directives = {}
        self.registry._directives[name] = (c, action_wrap)
예제 #7
0
    def test_valid_ascii(self):
        from pyramid.util import get_callable_name
        from pyramid.compat import text_

        if PY2:
            name = text_(b'hello world', 'utf-8')
        else:
            name = b'hello world'

        self.assertEqual(get_callable_name(name), 'hello world')
예제 #8
0
    def test_valid_ascii(self):
        from pyramid.util import get_callable_name
        from pyramid.compat import text_, PY3

        if PY3:  # pragma: nocover
            name = b'hello world'
        else:  # pragma: nocover
            name = text_(b'hello world', 'utf-8')

        self.assertEqual(get_callable_name(name), 'hello world')
예제 #9
0
파일: test_util.py 프로젝트: JDeuce/pyramid
    def test_valid_ascii(self):
        from pyramid.util import get_callable_name
        from pyramid.compat import text_

        if PY2:
            name = text_(b'hello world', 'utf-8')
        else:
            name = b'hello world'

        self.assertEqual(get_callable_name(name), 'hello world')
예제 #10
0
    def test_valid_ascii(self):
        from pyramid.util import get_callable_name
        from pyramid.compat import text_, PY3

        if PY3:  # pragma: nocover
            name = b'hello world'
        else:  # pragma: nocover
            name = text_(b'hello world', 'utf-8')

        self.assertEqual(get_callable_name(name), 'hello world')
예제 #11
0
    def _callFUT(self, val):
        from pyramid.util import get_callable_name

        return get_callable_name(val)
예제 #12
0
    def add_request_method(self,
                           callable=None,
                           name=None,
                           property=False,
                           reify=False):
        """ Add a property or method to the request object.

        When adding a method to the request, ``callable`` may be any
        function that receives the request object as the first
        parameter. If ``name`` is ``None`` then it will be computed
        from the name of the ``callable``.

        When adding a property to the request, ``callable`` can either
        be a callable that accepts the request as its single positional
        parameter, or it can be a property descriptor. If ``callable`` is
        a property descriptor, it has to be an instance of a class which is
        a subclass of ``property``. If ``name`` is ``None``, the name of
        the property will be computed from the name of the ``callable``.

        If the ``callable`` is a property descriptor a ``ValueError``
        will be raised if ``name`` is ``None`` or ``reify`` is ``True``.

        See :meth:`pyramid.request.Request.set_property` for more
        details on ``property`` vs ``reify``. When ``reify`` is
        ``True``, the value of ``property`` is assumed to also be
        ``True``.

        In all cases, ``callable`` may also be a
        :term:`dotted Python name` which refers to either a callable or
        a property descriptor.

        If ``callable`` is ``None`` then the method is only used to
        assist in conflict detection between different addons requesting
        the same attribute on the request object.

        This is the recommended method for extending the request object
        and should be used in favor of providing a custom request
        factory via
        :meth:`pyramid.config.Configurator.set_request_factory`.

        .. versionadded:: 1.4
        """
        if callable is not None:
            callable = self.maybe_dotted(callable)

        property = property or reify
        if property:
            name, callable = InstancePropertyHelper.make_property(callable,
                                                                  name=name,
                                                                  reify=reify)
        elif name is None:
            name = callable.__name__
        else:
            name = get_callable_name(name)

        def register():
            exts = self.registry.queryUtility(IRequestExtensions)

            if exts is None:
                exts = _RequestExtensions()
                self.registry.registerUtility(exts, IRequestExtensions)

            plist = exts.descriptors if property else exts.methods
            plist[name] = callable

        if callable is None:
            self.action(('request extensions', name), None)
        elif property:
            intr = self.introspectable('request extensions', name,
                                       self.object_description(callable),
                                       'request property')
            intr['callable'] = callable
            intr['property'] = True
            intr['reify'] = reify
            self.action(('request extensions', name),
                        register,
                        introspectables=(intr, ))
        else:
            intr = self.introspectable('request extensions', name,
                                       self.object_description(callable),
                                       'request method')
            intr['callable'] = callable
            intr['property'] = False
            intr['reify'] = False
            self.action(('request extensions', name),
                        register,
                        introspectables=(intr, ))
예제 #13
0
    def add_request_method(self,
                           callable=None,
                           name=None,
                           property=False,
                           reify=False):
        """ Add a property or method to the request object.

        When adding a method to the request, ``callable`` may be any
        function that receives the request object as the first
        parameter. If ``name`` is ``None`` then it will be computed
        from the name of the ``callable``.

        When adding a property to the request, ``callable`` can either
        be a callable that accepts the request as its single positional
        parameter, or it can be a property descriptor. If ``name`` is
        ``None``, the name of the property will be computed from the
        name of the ``callable``.

        If the ``callable`` is a property descriptor a ``ValueError``
        will be raised if ``name`` is ``None`` or ``reify`` is ``True``.

        See :meth:`pyramid.request.Request.set_property` for more
        details on ``property`` vs ``reify``. When ``reify`` is
        ``True``, the value of ``property`` is assumed to also be
        ``True``.

        In all cases, ``callable`` may also be a
        :term:`dotted Python name` which refers to either a callable or
        a property descriptor.

        If ``callable`` is ``None`` then the method is only used to
        assist in conflict detection between different addons requesting
        the same attribute on the request object.

        This is the recommended method for extending the request object
        and should be used in favor of providing a custom request
        factory via
        :meth:`pyramid.config.Configurator.set_request_factory`.

        .. versionadded:: 1.4
        """
        if callable is not None:
            callable = self.maybe_dotted(callable)

        property = property or reify
        if property:
            name, callable = InstancePropertyHelper.make_property(
                callable, name=name, reify=reify)
        elif name is None:
            name = callable.__name__
        else:
            name = get_callable_name(name)

        def register():
            exts = self.registry.queryUtility(IRequestExtensions)

            if exts is None:
                exts = _RequestExtensions()
                self.registry.registerUtility(exts, IRequestExtensions)

            plist = exts.descriptors if property else exts.methods
            plist[name] = callable

        if callable is None:
            self.action(('request extensions', name), None)
        elif property:
            intr = self.introspectable('request extensions', name,
                                       self.object_description(callable),
                                       'request property')
            intr['callable'] = callable
            intr['property'] = True
            intr['reify'] = reify
            self.action(('request extensions', name), register,
                        introspectables=(intr,))
        else:
            intr = self.introspectable('request extensions', name,
                                       self.object_description(callable),
                                       'request method')
            intr['callable'] = callable
            intr['property'] = False
            intr['reify'] = False
            self.action(('request extensions', name), register,
                        introspectables=(intr,))