Пример #1
0
    def _get_dispatchable(self, thread_locals, url_path):
        """
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        """
        req = thread_locals.request
        conf = thread_locals.config

        enable_request_extensions = not conf.get('disable_request_extensions',
                                                 False)
        dispatch_path_translator = conf.get('dispatch_path_translator', True)

        params = req.args_params
        state = DispatchState(weakref.proxy(req),
                              self,
                              params,
                              url_path.split('/'),
                              conf.get('ignore_parameters', []),
                              strip_extension=enable_request_extensions,
                              path_translator=dispatch_path_translator)
        url_path = state.path  # Get back url_path as crank performs some cleaning

        if enable_request_extensions:
            try:
                mimetypes = conf['mimetypes']
            except KeyError:
                mimetypes = default_mimetypes

            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file' + ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.controller._dispatch(state, url_path)

        #save the controller state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        if conf.get('enable_routing_args', False):
            state.routing_args.update(params)
            if hasattr(state.dispatcher, '_setup_wsgiorg_routing_args'):
                state.dispatcher._setup_wsgiorg_routing_args(
                    url_path, state.remainder, state.routing_args)

        return state, params
Пример #2
0
    def _get_dispatchable(self, context, url_path):
        """
        Returns a :class:`DispatchState` instance.

        :param context: The Request context.
        :param url_path: The url to dispatch.
        """
        req = context.request
        conf = context.config

        enable_request_extensions = not conf.get('disable_request_extensions',
                                                 False)
        dispatch_path_translator = conf.get('dispatch_path_translator', True)

        state = DispatchState(weakref.proxy(req),
                              self,
                              req.args_params,
                              url_path.split('/'),
                              conf.get('ignore_parameters', []),
                              strip_extension=enable_request_extensions,
                              path_translator=dispatch_path_translator)

        if enable_request_extensions:
            try:
                mimetypes = conf['mimetypes']
            except KeyError:
                mimetypes = default_mimetypes

            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file' + ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.resolve()

        # Save the dispatch state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        if conf.get('enable_routing_args', False):
            state.routing_args.update(state.params)
            if hasattr(state.root_dispatcher, '_setup_wsgiorg_routing_args'):
                state.root_dispatcher._setup_wsgiorg_routing_args(
                    state.path, state.remainder, state.routing_args)

        return state
Пример #3
0
    def _get_dispatchable(self, url_path):
        """Return a tuple (controller, remainder, params).

        :Parameters:
          url
            url as string

        """
        if not pylons.config.get('disable_request_extensions', False):
            pylons.request.response_type = None
            pylons.request.response_ext = None
            if url_path and '.' in url_path[-1]:
                last_remainder = url_path[-1]
                mime_type, encoding = mimetypes.guess_type(last_remainder)
                if mime_type:
                    extension_spot = last_remainder.rfind('.')
                    extension = last_remainder[extension_spot:]
                    url_path[-1] = last_remainder[:extension_spot]
                    pylons.request.response_type = mime_type
                    pylons.request.response_ext = extension

        params = pylons.request.params.mixed()

        state = DispatchState(pylons.request,
            self, params, url_path, pylons.config.get('ignore_parameters', []))
        state = state.controller._dispatch(state, url_path)

        pylons.tmpl_context.controller_url = '/'.join(
            url_path[:-len(state.remainder)])

        state.routing_args.update(params)
        if hasattr(state.dispatcher, '_setup_wsgiorg_routing_args'):
            state.dispatcher._setup_wsgiorg_routing_args(
                url_path, state.remainder, state.routing_args)

        #save the controller state for possible use within the controller methods
        pylons.request.controller_state = state

        return state.method, state.controller, state.remainder, params
Пример #4
0
    def _get_dispatchable(self, thread_locals, url_path):
        """
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        """
        req = thread_locals.request
        conf = thread_locals.config

        params = req.args_params
        state = DispatchState(req, self, params, url_path,
                              conf.get('ignore_parameters', []))

        if not conf.get('disable_request_extensions', False):
            ext = state.extension
            if ext is not None:
                ext = '.' + ext
                mime_type, encoding = mimetypes.guess_type('file' + ext)
                req._fast_setattr('_response_type', mime_type)
            req._fast_setattr('_response_ext', ext)

        state = state.controller._dispatch(state, url_path)
        thread_locals.tmpl_context.controller_url = '/'.join(
            url_path[:-len(state.remainder)])

        if conf.get('enable_routing_args', False):
            state.routing_args.update(params)
            if hasattr(state.dispatcher, '_setup_wsgiorg_routing_args'):
                state.dispatcher._setup_wsgiorg_routing_args(
                    url_path, state.remainder, state.routing_args)

        #save the controller state for possible use within the controller methods
        req._fast_setattr('_controller_state', state)

        return state.method, state.controller, state.remainder, params