| | |
| | | IRequestExtensions, |
| | | IResponse, |
| | | ISessionFactory, |
| | | ) |
| | | ) |
| | | |
| | | from pyramid.compat import ( |
| | | text_, |
| | | bytes_, |
| | | native_, |
| | | iteritems_, |
| | | ) |
| | | from pyramid.compat import text_, bytes_, native_, iteritems_ |
| | | |
| | | from pyramid.decorator import reify |
| | | from pyramid.i18n import LocalizerRequestMixin |
| | | from pyramid.response import Response, _get_response_factory |
| | | from pyramid.security import ( |
| | | AuthenticationAPIMixin, |
| | | AuthorizationAPIMixin, |
| | | ) |
| | | from pyramid.security import AuthenticationAPIMixin, AuthorizationAPIMixin |
| | | from pyramid.url import URLMethodsMixin |
| | | from pyramid.util import ( |
| | | InstancePropertyHelper, |
| | | InstancePropertyMixin, |
| | | ) |
| | | from pyramid.util import InstancePropertyHelper, InstancePropertyMixin |
| | | from pyramid.view import ViewMethodsMixin |
| | | |
| | | |
| | | class TemplateContext(object): |
| | | pass |
| | | |
| | | |
| | | class CallbackMethodsMixin(object): |
| | | @reify |
| | |
| | | callback = callbacks.popleft() |
| | | callback(self) |
| | | |
| | | |
| | | @implementer(IRequest) |
| | | class Request( |
| | | BaseRequest, |
| | |
| | | AuthenticationAPIMixin, |
| | | AuthorizationAPIMixin, |
| | | ViewMethodsMixin, |
| | | ): |
| | | ): |
| | | """ |
| | | A subclass of the :term:`WebOb` Request class. An instance of |
| | | this class is created by the :term:`router` and is provided to a |
| | |
| | | release of this :app:`Pyramid` version. See |
| | | https://webob.org/ for further information. |
| | | """ |
| | | |
| | | exception = None |
| | | exc_info = None |
| | | matchdict = None |
| | |
| | | if factory is None: |
| | | raise AttributeError( |
| | | 'No session factory registered ' |
| | | '(see the Sessions chapter of the Pyramid documentation)') |
| | | '(see the Sessions chapter of the Pyramid documentation)' |
| | | ) |
| | | return factory(self) |
| | | |
| | | @reify |
| | |
| | | # zope.interface.interface.Element.__init__ and |
| | | # https://github.com/Pylons/pyramid/issues/232; as a result, always pass |
| | | # __doc__ to the InterfaceClass constructor. |
| | | iface = InterfaceClass('%s_IRequest' % name, bases=bases, |
| | | __doc__="route_request_iface-generated interface") |
| | | iface = InterfaceClass( |
| | | '%s_IRequest' % name, |
| | | bases=bases, |
| | | __doc__="route_request_iface-generated interface", |
| | | ) |
| | | # for exception view lookups |
| | | iface.combined = InterfaceClass( |
| | | '%s_combined_IRequest' % name, |
| | | bases=(iface, IRequest), |
| | | __doc__='route_request_iface-generated combined interface') |
| | | __doc__='route_request_iface-generated combined interface', |
| | | ) |
| | | return iface |
| | | |
| | | |
| | |
| | | def add_headers(request, response): |
| | | for k, v in headerlist: |
| | | response.headerlist.append((k, v)) |
| | | |
| | | request.add_response_callback(add_headers) |
| | | |
| | | |
| | | def call_app_with_subpath_as_path_info(request, app): |
| | | # Copy the request. Use the source request's subpath (if it exists) as |
| | |
| | | new_script_name = '' |
| | | |
| | | # compute new_path_info |
| | | new_path_info = '/' + '/'.join([native_(x.encode('utf-8'), 'latin-1') |
| | | for x in subpath]) |
| | | new_path_info = '/' + '/'.join( |
| | | [native_(x.encode('utf-8'), 'latin-1') for x in subpath] |
| | | ) |
| | | |
| | | if new_path_info != '/': # don't want a sole double-slash |
| | | if path_info != '/': # if orig path_info is '/', we're already done |
| | | if new_path_info != '/': # don't want a sole double-slash |
| | | if path_info != '/': # if orig path_info is '/', we're already done |
| | | if path_info.endswith('/'): |
| | | # readd trailing slash stripped by subpath (traversal) |
| | | # conversion |
| | |
| | | |
| | | return new_request.get_response(app) |
| | | |
| | | |
| | | def apply_request_extensions(request, extensions=None): |
| | | """Apply request extensions (methods and properties) to an instance of |
| | | :class:`pyramid.interfaces.IRequest`. This method is dependent on the |
| | |
| | | setattr(request, name, method) |
| | | |
| | | InstancePropertyHelper.apply_properties( |
| | | request, extensions.descriptors) |
| | | request, extensions.descriptors |
| | | ) |