예제 #1
0
파일: testing.py 프로젝트: Hquant/pyramid
 def __call__(self, request):
     path = request.environ['PATH_INFO']
     ob = resources[path]
     traversed = traversal_path_info(path)
     return {'context':ob, 'view_name':'','subpath':(),
             'traversed':traversed, 'virtual_root':ob,
             'virtual_root_path':(), 'root':ob}
예제 #2
0
파일: util.py 프로젝트: HorizonXP/pyramid
 def traverse_predicate(context, request):
     if 'traverse' in context:
         return True
     m = context['match']
     tvalue = tgenerate(m)
     m['traverse'] = traversal_path_info(tvalue)
     return True
예제 #3
0
    def __call__(self, context, request):
        if self.use_subpath:
            path_tuple = request.subpath
        else:
            path_tuple = traversal_path_info(request.environ['PATH_INFO'])

        path = _secure_path(path_tuple)

        if path is None:
            raise HTTPNotFound('Out of bounds: %s' % request.url)

        if self.package_name: # package resource

            resource_path ='%s/%s' % (self.docroot.rstrip('/'), path)
            if resource_isdir(self.package_name, resource_path):
                if not request.path_url.endswith('/'):
                    self.add_slash_redirect(request)
                resource_path = '%s/%s' % (resource_path.rstrip('/'),self.index)
            if not resource_exists(self.package_name, resource_path):
                raise HTTPNotFound(request.url)
            filepath = resource_filename(self.package_name, resource_path)

        else: # filesystem file

            # os.path.normpath converts / to \ on windows
            filepath = normcase(normpath(join(self.norm_docroot, path)))
            if isdir(filepath):
                if not request.path_url.endswith('/'):
                    self.add_slash_redirect(request)
                filepath = join(filepath, self.index)
            if not exists(filepath):
                raise HTTPNotFound(request.url)

        return FileResponse(filepath, request, self.cache_max_age)
예제 #4
0
 def traverse_predicate(context, request):
     if 'traverse' in context:
         return True
     m = context['match']
     tvalue = tgenerate(m)
     m['traverse'] = traversal_path_info(tvalue)
     return True
예제 #5
0
 def matcher(path):
     m = match(path)
     if m is None:
         return m
     d = {}
     for k, v in m.groupdict().iteritems():
         if k == star:
             d[k] = traversal_path_info(v)
         else:
             try:
                 d[k] = v.decode("utf-8")
             except UnicodeDecodeError, e:
                 raise URLDecodeError(e.encoding, e.object, e.start, e.end, e.reason)
예제 #6
0
 def __call__(self, request):
     path = request.environ['PATH_INFO']
     ob = resources[path]
     traversed = traversal_path_info(path)
     return {
         'context': ob,
         'view_name': '',
         'subpath': (),
         'traversed': traversed,
         'virtual_root': ob,
         'virtual_root_path': (),
         'root': ob
     }
예제 #7
0
    def matcher(path):
        m = match(path)
        if m is None:
            return m
        d = {}
        for k, v in m.groupdict().items():
            if k == star:
                d[k] = traversal_path_info(v)
            else:
                try:
                    val = bytes_(v).decode('utf-8', 'strict')
                    d[k] = val
                except UnicodeDecodeError as e:
                    raise URLDecodeError(e.encoding, e.object, e.start, e.end,
                                         e.reason)

        return d
예제 #8
0
 def matcher(path):
     m = match(path)
     if m is None:
         return m
     d = {}
     for k, v in m.groupdict().items():
         if k == star:
             d[k] = traversal_path_info(v)
         else:
             try:
                 val = bytes_(v).decode('utf-8', 'strict')
                 d[k] = val
             except UnicodeDecodeError as e:
                 raise URLDecodeError(
                     e.encoding, e.object, e.start, e.end, e.reason
                     )
                     
                     
     return d
예제 #9
0
    def __call__(self, context, request):
        if self.use_subpath:
            path_tuple = request.subpath
        else:
            path_tuple = traversal_path_info(request.environ['PATH_INFO'])

        if self.cachebust_match:
            path_tuple = self.cachebust_match(path_tuple)
        path = _secure_path(path_tuple)

        if path is None:
            raise HTTPNotFound('Out of bounds: %s' % request.url)

        use_gzip = 'gzip' in request.accept_encoding
        if self.package_name: # package resource
            docroot = use_gzip and self.gzip_docroot or self.docroot
            resource_path ='%s/%s' % (docroot.rstrip('/'), path)
            if resource_isdir(self.package_name, resource_path):
                if not request.path_url.endswith('/'):
                    self.add_slash_redirect(request)
                resource_path = '%s/%s' % (resource_path.rstrip('/'),self.index)
            if not resource_exists(self.package_name, resource_path):
                raise HTTPNotFound(request.url)
            filepath = resource_filename(self.package_name, resource_path)

        else:
            norm_docroot = use_gzip and self.gzip_norm_docroot or self.norm_docroot
            filepath = normcase(normpath(join_path(norm_docroot, path)))
            if isdir(filepath):
                if not request.path_url.endswith('/'):
                    self.add_slash_redirect(request)
                filepath = join_path(filepath, self.index)
            if not exists(filepath):
                raise HTTPNotFound(request.url)

        response = FileResponse(filepath, request, self.cache_max_age)
        if use_gzip:
            response.content_encoding = 'gzip'

        return response
예제 #10
0
    def get_resource_name(self, request):
        """
        Return the computed name of the requested resource.

        The returned file is not guaranteed to exist.

        """
        if self.use_subpath:
            path_tuple = request.subpath
        else:
            path_tuple = traversal_path_info(request.path_info)
        path = _secure_path(path_tuple)

        if path is None:
            raise HTTPNotFound('Out of bounds: %s' % request.url)

        # normalize asset spec or fs path into resource_path
        if self.package_name:  # package resource
            resource_path = '%s/%s' % (self.docroot.rstrip('/'), path)
            if resource_isdir(self.package_name, resource_path):
                if not request.path_url.endswith('/'):
                    raise self.add_slash_redirect(request)
                resource_path = '%s/%s' % (
                    resource_path.rstrip('/'),
                    self.index,
                )

        else:  # filesystem file
            # os.path.normpath converts / to \ on windows
            resource_path = normcase(normpath(join(self.norm_docroot, path)))
            if isdir(resource_path):
                if not request.path_url.endswith('/'):
                    raise self.add_slash_redirect(request)
                resource_path = join(resource_path, self.index)

        return resource_path
예제 #11
0
    def _callFUT(self, path):
        from pyramid.traversal import traversal_path_info

        return traversal_path_info(path)
 def _callFUT(self, path):
     from pyramid.traversal import traversal_path_info
     return traversal_path_info(path)