<commit_before>"""Morepath request implementation.

Entirely documented in :class:`morepath.Request` and
:class:`morepath.Response` in the public API.
"""

from webob import BaseRequest, Response as BaseResponse
import reg

from .reify import reify
from .traject import create_path, parse_path
from .error import LinkError
from .authentication import NO_IDENTITY

SAME_APP = reg.Sentinel('SAME_APP')


class Request(BaseRequest):
    """Request.

    Extends :class:`webob.request.BaseRequest`
    """
    def __init__(self, environ, app, **kw):
        super(Request, self).__init__(environ, **kw)
        # parse path, normalizing dots away in
        # in case the client didn't do the normalization
        segments = parse_path(self.path_info)
        # Webob updates the environ as well
        self.path_info = create_path(segments)
        # reverse to get unconsumed
        segments.reverse()
        self.unconsumed = segments
        """Stack of path segments that have not yet been consumed.

        See :mod:`morepath.publish`.
        """

        self._root_app = app
<commit_msg>Optimize setting path info only if really needed.<commit_after>"""Morepath request implementation.

Entirely documented in :class:`morepath.Request` and
:class:`morepath.Response` in the public API.
"""

from webob import BaseRequest, Response as BaseResponse
import reg

from .reify import reify
from .traject import create_path, parse_path
from .error import LinkError
from .authentication import NO_IDENTITY

SAME_APP = reg.Sentinel('SAME_APP')


class Request(BaseRequest):
    """Request.

    Extends :class:`webob.request.BaseRequest`
    """
    def __init__(self, environ, app, **kw):
        super(Request, self).__init__(environ, **kw)
        # parse path, normalizing dots away in
        # in case the client didn't do the normalization
        path_info = self.path_info
        segments = parse_path(path_info)
        # optimization: only if the normalized path is different from the
        # original path do we set it to the webob request, as this is
        # relatively expensive. Webob updates the environ as well
        new_path_info = create_path(segments)
        if new_path_info != path_info:
            self.path_info = new_path_info
        # reverse to get unconsumed
        segments.reverse()
        self.unconsumed = segments
        """Stack of path segments that have not yet been consumed.

        See :mod:`morepath.publish`.
        """

        self._root_app = app

{'fraction_non_alphanumeric': 0.0841643398484244, 'fraction_numerical': 0.0, 'mean_word_length': 3.0913539967373573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '615045', 'n_tokens_mistral': 704, 'n_tokens_neox': 696, 'n_words': 237}