本文整理汇总了Python中pyramid.traversal.traversal_path函数的典型用法代码示例。如果您正苦于以下问题:Python traversal_path函数的具体用法?Python traversal_path怎么用?Python traversal_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了traversal_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, context, request):
if self.use_subpath:
path_tuple = request.subpath
else:
path_tuple = traversal_path(request.path_info)
path = _secure_path(path_tuple)
if path is None:
return 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('/'):
return self.add_slash_redirect(request)
resource_path = '%s/%s' % (resource_path.rstrip('/'),self.index)
if not resource_exists(self.package_name, resource_path):
return 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('/'):
return self.add_slash_redirect(request)
filepath = join(filepath, self.index)
if not exists(filepath):
return HTTPNotFound(request.url)
return _FileResponse(filepath ,self.cache_max_age)
开发者ID:mozilla,项目名称:appsync-vendor,代码行数:34,代码来源:static.py
示例2: __call__
def __call__(self, request):
path = request.environ['PATH_INFO']
ob = resources[path]
traversed = traversal_path(path)
return {'context':ob, 'view_name':'','subpath':(),
'traversed':traversed, 'virtual_root':ob,
'virtual_root_path':(), 'root':ob}
开发者ID:DeanHodgkinson,项目名称:pyramid,代码行数:7,代码来源:testing.py
示例3: traverse_predicate
def traverse_predicate(context, request):
if 'traverse' in context:
return True
m = context['match']
tvalue = tgenerate(m)
m['traverse'] = traversal_path(tvalue)
return True
开发者ID:MattBurgess,项目名称:pyramid,代码行数:7,代码来源:util.py
示例4: traverse_predicate
def traverse_predicate(context, request):
if 'traverse' in context:
return True
m = context['match']
tvalue = tgenerate(m) # tvalue will be urlquoted string
m['traverse'] = traversal_path(tvalue) # will be seq of unicode
return True
开发者ID:rpatterson,项目名称:pyramid,代码行数:7,代码来源:util.py
示例5: url_to_resource
def url_to_resource(self, url):
"""
Returns the resource that is addressed by the given URL.
:param str url: URL to convert
:return: member or collection resource
:note: If the query string in the URL has multiple values for a
query parameter, the last definition in the query string wins.
"""
parsed = urlparse.urlparse(url)
parsed_path = parsed.path # namedtupble problem pylint: disable=E1101
rc = find_resource(self.__request.root, traversal_path(parsed_path))
if ICollectionResource in provided_by(rc):
# In case we found a collection, we have to filter, order, slice.
parsed_query = parsed.query # namedtuple problem pylint: disable=E1101
params = dict(parse_qsl(parsed_query))
filter_string = params.get('q')
if not filter_string is None:
rc.filter = \
UrlPartsConverter.make_filter_specification(filter_string)
order_string = params.get('sort')
if not order_string is None:
rc.order = \
UrlPartsConverter.make_order_specification(order_string)
start_string = params.get('start')
size_string = params.get('size')
if not (start_string is None or size_string is None):
rc.slice = \
UrlPartsConverter.make_slice_key(start_string, size_string)
elif not IMemberResource in provided_by(rc):
raise ValueError('Traversal found non-resource object "%s".' % rc)
return rc
开发者ID:b8va,项目名称:everest,代码行数:33,代码来源:url.py
示例6: __call__
def __call__(self, context, request):
if 'traverse' in context:
return True
m = context['match']
tvalue = self.tgenerate(m) # tvalue will be urlquoted string
m['traverse'] = traversal_path(tvalue)
# This isn't actually a predicate, it's just a infodict modifier that
# injects ``traverse`` into the matchdict. As a result, we just
# return True.
return True
开发者ID:XiaonuoGantan,项目名称:pyramid,代码行数:10,代码来源:predicates.py
示例7: __call__
def __call__(self, request):
"""
1. Split the PATH_INFO into traversal segments.
2. The 'current controller' is the root controller.
2. While there are segments:
a) Pop the first segment off the traversal stack. This is the
'current segment'.
b) Ask the 'current controller' for an attribute named
after the current segment. This becomes the 'next controller'.
c) If the 'next controller' is not a Controller instance, stop
traversing and return the 'current controller' as the context.
d) If the 'next controller' *is* a Controller instance, the
'next controller' becomes the 'current controller'. Goto a).
3. If we run out of path segments before running out of
controllers to traverse, return the last controller found
as the context.
. """
path_info = request.path_info
path = list(traversal_path(path_info))
traversed = []
controller = self.root
controllers = [controller]
while path:
segment = path[-1]
next = getattr(controller, segment, None)
if next is None or not IController.providedBy(next):
break
controller = next
controllers.append(next)
traversed.append(segment)
path.pop(0)
return dict(
context=controller,
view_name='',
subpath=tuple(path),
traversed=tuple(traversed),
virtual_root=self.root,
virtual_root_path=None,
controllers=controllers,
)
开发者ID:Pylons,项目名称:pyramid_metatg,代码行数:50,代码来源:__init__.py
示例8: matcher
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(v)
else:
encoded = unquote(v)
try:
d[k] = encoded.decode('utf-8')
except UnicodeDecodeError, e:
raise URLDecodeError(
e.encoding, e.object, e.start, e.end, e.reason
)
开发者ID:MattBurgess,项目名称:pyramid,代码行数:16,代码来源:urldispatch.py
示例9: __call__
def __call__(self, environ):
if 'bfg.routes.matchdict' in environ:
matchdict = environ['bfg.routes.matchdict']
path = matchdict.get('traverse', '/')
subpath = matchdict.get('subpath', '')
subpath = tuple(filter(None, subpath.split('/')))
else:
# this request did not match a Routes route
subpath = ()
try:
path = environ['PATH_INFO'] or '/'
except KeyError:
path = '/'
try:
vroot_path = environ[VH_ROOT_KEY]
except KeyError:
vroot_tuple = ()
vpath = path
vroot_idx = -1
else:
vroot_tuple = traversal_path(vroot_path)
vpath = vroot_path + path
vroot_idx = len(vroot_tuple) -1
ob = vroot = LocationProxy(self.root)
if vpath == '/' or (not vpath):
# prevent a call to traversal_path if we know it's going
# to return the empty tuple
vpath_tuple = ()
else:
# we do dead reckoning here via tuple slicing instead of
# pushing and popping temporary lists for speed purposes
# and this hurts readability; apologies
i = 0
vpath_tuple = traversal_path(vpath)
for segment in vpath_tuple:
if segment[:2] =='@@':
return dict(context=ob, view_name=segment[2:],
subpath=vpath_tuple[i+1:],
traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
virtual_root_path=vroot_tuple,
root=self.root)
try:
getitem = ob.__getitem__
except AttributeError:
return dict(context=ob, view_name=segment,
subpath=vpath_tuple[i+1:],
traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
virtual_root_path=vroot_tuple,
root=self.root)
try:
next = getitem(segment)
except KeyError:
return dict(context=ob, view_name=segment,
subpath=vpath_tuple[i+1:],
traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
virtual_root_path=vroot_tuple,
root=self.root)
next = LocationProxy(next, ob, segment)
if i == vroot_idx:
vroot = next
ob = next
i += 1
return dict(context=ob, view_name=u'', subpath=subpath,
traversed=vpath_tuple, virtual_root=vroot,
virtual_root_path=vroot_tuple, root=self.root)
开发者ID:Pylons,项目名称:pyramid_traversalwrapper,代码行数:73,代码来源:__init__.py
示例10: _callFUT
def _callFUT(self, path):
from pyramid.traversal import traversal_path
return traversal_path(path)
开发者ID:SMFOSS,项目名称:pyramid,代码行数:3,代码来源:test_traversal.py
示例11: __call__
def __call__(self, request, queries=_path_queries):
environ = request.environ
context = root = self.root
if root.__default_root__ and 'bfg.routes.route' in environ:
return ResourceTreeTraverser(root)(request)
path = '/%s/'%'/'.join(traversal_path(environ.get('PATH_INFO','/')))
vroot_tuple = ()
l_path = len(root.__root_path__)
# build paths for all parents in content hierarchy
idx = 0
paths = {}
current = root.__path__
for sec in path[l_path:].split('/'):
if sec:
current = '%s%s/'%(current, sec)
paths[str(idx)] = current
idx += 1
if idx:
if idx not in queries:
bindparams = [sql.bindparam(str(p)) for p in range(idx)]
queries[idx] = ptah.QueryFreezer(
lambda: ptah.get_session().query(BaseContent)\
.filter(BaseContent.__path__.in_(bindparams)))
parents = sorted(queries[idx].all(**paths), reverse=True,
key = lambda item: item.__path__)
else:
parents = []
if parents:
# set __parent__
parents[-1].__parent__ = root
for idx in range(len(parents)-1):
parents[idx].__parent__ = parents[idx+1]
context = parents[0]
node = context.__path__[len(root.__path__):]
leaf = path[l_path+len(node):].split('/')
leaf, subpath = leaf[0], leaf[1:]
return {'context': context,
'view_name': leaf,
'subpath': subpath,
'traversed': traversal_path(node),
'virtual_root': root,
'virtual_root_path': vroot_tuple,
'root': root}
else:
vpath_tuple = ()
leaf = path[l_path:].split('/')
leaf, subpath = leaf[0], leaf[1:]
return {'context': context,
'view_name': leaf,
'subpath': subpath,
'traversed': vpath_tuple,
'virtual_root': root,
'virtual_root_path': (),
'root': root}
开发者ID:djedproject,项目名称:ptahcms,代码行数:67,代码来源:traverser.py
示例12: mgmt_url
def mgmt_url(self, obj, *arg, **kw):
request = self.request
traverse = ('',) + traversal_path(request.resource_path(obj))
kw['traverse'] = traverse
return request.route_url(MANAGE_ROUTE_NAME, *arg, **kw)
开发者ID:domenkozar,项目名称:substanced,代码行数:5,代码来源:__init__.py
示例13: __call__
def __call__(self, request):
environ = request.environ
registry = request.registry
if 'bfg.routes.matchdict' in environ:
matchdict = environ['bfg.routes.matchdict']
path = matchdict.get('traverse', '/')
subpath = matchdict.get('subpath', '')
subpath = tuple(filter(None, subpath.split('/')))
else:
# this request did not match a Routes route
subpath = ()
try:
path = environ['PATH_INFO'] or '/'
except KeyError:
path = '/'
try:
vroot_path = environ[VH_ROOT_KEY]
except KeyError:
vroot_tuple = ()
vpath = path
vroot_idx = -1
else:
vroot_tuple = traversal_path(vroot_path)
vpath = vroot_path + path
vroot_idx = len(vroot_tuple) -1
ob = self.root
proxy = registry.queryUtility(ISecurityProxyFactory, default=None)
if proxy:
ob = proxy(ob)
vroot = root = ob
if vpath == '/' or (not vpath):
# prevent a call to traversal_path if we know it's going
# to return the empty tuple
vpath_tuple = ()
else:
# we do dead reckoning here via tuple slicing instead of
# pushing and popping temporary lists for speed purposes
# and this hurts readability; apologies
i = 0
vpath_tuple = traversal_path(vpath)
marker = object()
for segment in vpath_tuple:
if segment[:2] == self.VIEW_SELECTOR:
return dict(context=ob, view_name=segment[2:],
subpath=vpath_tuple[i+1:],
traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
virtual_root_path=vroot_tuple,
root=self.root)
ns_match = namespace_pattern.match(segment)
namespace = u""
if ns_match:
prefix, namespace = ns_match.group(0, 1)
segment = segment[len(prefix):]
adapter = registry.getMultiAdapter((ob, request),
IPluggableTraverser,
name=namespace)
try:
next = adapter[segment]
except KeyError:
return dict(context=ob, view_name=segment,
subpath=vpath_tuple[i+1:],
traversed=vpath_tuple[:vroot_idx+i+1],
virtual_root=vroot,
virtual_root_path=vroot_tuple,
root=self.root)
if not is_locateable(next):
next = LocationProxy(next, ob, segment)
if proxy:
next = proxy(next)
if i == vroot_idx:
vroot = next
ob = next
i += 1
default_view = registry.getMultiAdapter((ob, request), IDefaultView)
return dict(context=ob,
view_name=default_view.view_name,
subpath=subpath,
traversed=vpath_tuple, virtual_root=vroot,
virtual_root_path=vroot_tuple, root=self.root)
开发者ID:avnik,项目名称:composite.traverser,代码行数:94,代码来源:traverser.py
示例14: __call__
def __call__(self, request):
environ = request.environ
if 'bfg.routes.matchdict' in environ:
matchdict = environ['bfg.routes.matchdict']
path = matchdict.get('traverse', '/')
if hasattr(path, '__iter__'):
# this is a *traverse stararg (not a :traverse)
path = '/'.join([quote_path_segment(x) for x in path]) or '/'
subpath = matchdict.get('subpath', ())
if not hasattr(subpath, '__iter__'):
# this is not a *subpath stararg (just a :subpath)
subpath = traversal_path(subpath)
else:
# this request did not match a route
subpath = ()
try:
path = environ['PATH_INFO'] or '/'
except KeyError:
path = '/'
if VH_ROOT_KEY in environ:
vroot_path = environ[VH_ROOT_KEY]
vroot_tuple = traversal_path(vroot_path)
vpath = vroot_path + path
vroot_idx = len(vroot_tuple) -1
else:
vroot_tuple = ()
vpath = path
vroot_idx = -1
root = self.root
ob = vroot = root
if vpath == '/' or (not vpath):
vpath_tuple = ()
else:
i = 0
view_selector = self.VIEW_SELECTOR
vpath_tuple = traversal_path(vpath)
for segment in vpath_tuple:
if segment[:2] == view_selector:
return {'context':ob,
'view_name':segment[2:],
'subpath':vpath_tuple[i+1:],
'traversed':vpath_tuple[:vroot_idx+i+1],
'virtual_root':vroot,
'virtual_root_path':vroot_tuple,
'root':root}
cont = IContainer(ob, None)
if cont is None:
return {'context':ob,
'view_name':segment,
'subpath':vpath_tuple[i+1:],
'traversed':vpath_tuple[:vroot_idx+i+1],
'virtual_root':vroot,
'virtual_root_path':vroot_tuple,
'root':root}
else:
try:
next = LocationProxy(cont[segment], ob, segment)
except KeyError:
return {'context':ob,
'view_name':segment,
'subpath':vpath_tuple[i+1:],
'traversed':vpath_tuple[:vroot_idx+i+1],
'virtual_root':vroot,
'virtual_root_path':vroot_tuple,
'root':root}
if i == vroot_idx:
vroot = next
ob = next
i += 1
return {'context':ob, 'view_name':u'', 'subpath':subpath,
'traversed':vpath_tuple, 'virtual_root':vroot,
'virtual_root_path':vroot_tuple, 'root':root}
开发者ID:fafhrd91,项目名称:memphis-dev,代码行数:82,代码来源:traversal.py
示例15: __call__
def __call__(self, request, queries=_path_queries):
environ = request.environ
context = root = self.root
if root.__default_root__ and "bfg.routes.route" in environ:
return ResourceTreeTraverser(root)(request)
path = "/%s/" % "/".join(traversal_path(environ.get("PATH_INFO", "/")))
vroot_tuple = ()
vpath = path
vroot_idx = -1
l_path = len(root.__root_path__)
# build paths for all parents in content hierarchy
idx = 0
paths = {}
current = root.__path__
for sec in path[l_path:].split("/"):
if sec:
current = "%s%s/" % (current, sec)
paths[str(idx)] = current
idx += 1
if idx:
if idx not in queries:
bindparams = [sql.bindparam(str(p)) for p in range(idx)]
queries[idx] = ptah.QueryFreezer(
lambda: Session.query(Content)
.filter(Content.__path__.in_(bindparams))
.order_by(sql.desc(Content.__path__))
)
parents = queries[idx].all(**paths)
else:
parents = []
if parents:
# set __parent__
parents[-1].__parent__ = root
for idx in range(len(parents) - 1):
parents[idx].__parent__ = parents[idx + 1]
context = parents[0]
node = context.__path__[len(root.__path__) :]
leaf = path[l_path + len(node) :].split("/")
leaf, subpath = leaf[0], leaf[1:]
return {
"context": context,
"view_name": leaf,
"subpath": subpath,
"traversed": traversal_path(node),
"virtual_root": root,
"virtual_root_path": vroot_tuple,
"root": root,
}
else:
vpath_tuple = ()
leaf = path[l_path:].split("/")
leaf, subpath = leaf[0], leaf[1:]
return {
"context": context,
"view_name": leaf,
"subpath": subpath,
"traversed": vpath_tuple,
"virtual_root": root,
"virtual_root_path": (),
"root": root,
}
开发者ID:blaflamme,项目名称:ptah,代码行数:74,代码来源:traverser.py
注:本文中的pyramid.traversal.traversal_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论