本文整理汇总了Python中pyramid.request.Request.path_info方法的典型用法代码示例。如果您正苦于以下问题:Python Request.path_info方法的具体用法?Python Request.path_info怎么用?Python Request.path_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.request.Request
的用法示例。
在下文中一共展示了Request.path_info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sdi_mgmt_views
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import path_info [as 别名]
def sdi_mgmt_views(context, request, names=None):
if not hasattr(context, '__name__'):
# shortcut if the context doesn't have a name (usually happens if the
# context is an exception); we do this because mgmt_path uses Pyramid's
# resource_path_tuple, which wants every object in the lineage to have
# a __name__.
return []
registry = request.registry
introspector = registry.introspector
unordered = []
# create a dummy request signaling our intent
req = Request(request.environ.copy())
req.script_name = request.script_name
req.context = context
req.matched_route = request.matched_route
req.method = 'GET'
req.registry = request.registry
sro_enum = list(enumerate(providedBy(context).__sro__[:-1]))
for data in introspector.get_category('sdi views'):
related = data['related']
sdi_intr = data['introspectable']
tab_title = sdi_intr['tab_title']
tab_condition = sdi_intr['tab_condition']
tab_before = sdi_intr['tab_before']
tab_after = sdi_intr['tab_after']
def is_view(intr):
return intr.category_name == 'views'
for view_intr in filter(is_view, related):
# NB: in reality, the above loop will execute exactly once because
# each "sdi view" is associated with exactly one pyramid view
view_name = view_intr['name']
req.path_info = request.sdiapi.mgmt_path(context, view_name)
if names is not None and not view_name in names:
continue
# do a passable job at figuring out whether, if we visit the
# url implied by this view, we'll be permitted to view it and
# something reasonable will show up
intr_context = view_intr['context']
sro_index = MAX_ORDER
if intr_context is None:
intr_context = Interface
if IInterface.providedBy(intr_context):
if not intr_context.providedBy(context):
continue
for i, spec in sro_enum:
if spec is intr_context:
sro_index = i
break
elif isinstance(context, intr_context):
for i, spec in sro_enum:
if spec.implementedBy(intr_context):
sro_index = i
break
else: # pragma: no cover (coverage bug, this is reached)
continue
if tab_condition is not None and names is None:
if callable(tab_condition):
if not tab_condition(context, request):
continue
elif not tab_condition:
continue
derived = view_intr['derived_callable']
if hasattr(derived, '__predicated__'):
if not derived.__predicated__(context, req):
continue
if hasattr(derived, '__permitted__'):
if not derived.__permitted__(context, req):
continue
predicate_order = getattr(derived, '__order__', MAX_ORDER)
if view_name == request.view_name:
css_class = 'active'
else:
css_class = None
unordered.append(
{'view_name': view_name,
'tab_before':tab_before,
'tab_after':tab_after,
'title': tab_title or view_name.capitalize(),
'class': css_class,
'predicate_order':predicate_order,
'sro_index':sro_index,
'url': request.sdiapi.mgmt_path(
request.context, '@@%s' % view_name)
}
)
# De-duplicate the unordered list of tabs with the same view_name. Prefer
# the tab with the lowest (sro_index, predicate_order) tuple, because this
# is the view that's most likely to be executed when visited and we'd
# like to get its title right.
unordered.sort(key=lambda s: (s['sro_index'], s['predicate_order']))
deduplicated = []
view_names = {}
#.........这里部分代码省略.........
示例2: get_mgmt_views
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import path_info [as 别名]
def get_mgmt_views(request, context=None, names=None):
registry = request.registry
if context is None:
context = request.context
introspector = registry.introspector
L = []
# create a dummy request signaling our intent
req = Request(request.environ.copy())
req.script_name = request.script_name
req.context = context
req.matched_route = request.matched_route
req.method = 'GET'
req.registry = request.registry
for data in introspector.get_category('sdi views'):
related = data['related']
sdi_intr = data['introspectable']
tab_title = sdi_intr['tab_title']
tab_condition = sdi_intr['tab_condition']
if tab_condition is not None and names is None:
if tab_condition is False or not tab_condition(request):
continue
for intr in related:
view_name = intr['name']
if names is not None and not view_name in names:
continue
if intr.category_name == 'views' and not view_name in L:
derived = intr['derived_callable']
# do a passable job at figuring out whether, if we visit the
# url implied by this view, we'll be permitted to view it and
# something reasonable will show up
if IInterface.providedBy(intr['context']):
if not intr['context'].providedBy(context):
continue
elif intr['context'] and not isinstance(
context, intr['context']):
continue
req.path_info = request.mgmt_path(context, view_name)
if hasattr(derived, '__predicated__'):
if not derived.__predicated__(context, req):
continue
if hasattr(derived, '__permitted__'):
if not derived.__permitted__(context, req):
continue
L.append(
{'view_name':view_name,
'tab_title':tab_title or view_name.capitalize()}
)
ordered = []
if hasattr(context, '__tab_order__'):
tab_order = context.__tab_order__
ordered_names_available = [ y for y in tab_order if y in
[ x['view_name'] for x in L ] ]
for ordered_name in ordered_names_available:
for view_data in L:
if view_data['view_name'] == ordered_name:
L.remove(view_data)
ordered.append(view_data)
return ordered + sorted(L, key=operator.itemgetter('tab_title'))
示例3: sdi_mgmt_views
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import path_info [as 别名]
def sdi_mgmt_views(request, context=None, names=None):
registry = request.registry
if context is None:
context = request.context
introspector = registry.introspector
L = []
# create a dummy request signaling our intent
req = Request(request.environ.copy())
req.script_name = request.script_name
req.context = context
req.matched_route = request.matched_route
req.method = 'GET'
req.registry = request.registry
for data in introspector.get_category('sdi views'):
related = data['related']
sdi_intr = data['introspectable']
tab_title = sdi_intr['tab_title']
tab_condition = sdi_intr['tab_condition']
def is_view(intr):
return intr.category_name == 'views'
for view_intr in filter(is_view, related):
# NB: in reality, the above loop will execute exactly once because
# each "sdi view" is associated with exactly one pyramid view
view_name = view_intr['name']
req.path_info = request.mgmt_path(context, view_name)
if names is not None and not view_name in names:
continue
# do a passable job at figuring out whether, if we visit the
# url implied by this view, we'll be permitted to view it and
# something reasonable will show up
intr_context = view_intr['context']
if IInterface.providedBy(intr_context):
if not intr_context.providedBy(context):
continue
elif intr_context and not isinstance(context, intr_context):
continue
if tab_condition is not None and names is None:
if tab_condition is False or not tab_condition(
context, request):
continue
derived = view_intr['derived_callable']
if hasattr(derived, '__predicated__'):
if not derived.__predicated__(context, req):
continue
if hasattr(derived, '__permitted__'):
if not derived.__permitted__(context, req):
continue
if view_name == request.view_name:
css_class = 'active'
else:
css_class = None
L.append({'view_name': view_name,
'title': tab_title or view_name.capitalize(),
'class': css_class,
'url': request.mgmt_path(request.context,
'@@%s' % view_name)
})
ordered = []
tab_order = request.registry.content.metadata(context, 'tab_order')
if tab_order is not None:
ordered_names_available = [ y for y in tab_order if y in
[ x['view_name'] for x in L ] ]
for ordered_name in ordered_names_available:
for view_data in L:
if view_data['view_name'] == ordered_name:
L.remove(view_data)
ordered.append(view_data)
return ordered + sorted(L, key=operator.itemgetter('title'))
示例4: sdi_mgmt_views
# 需要导入模块: from pyramid.request import Request [as 别名]
# 或者: from pyramid.request.Request import path_info [as 别名]
def sdi_mgmt_views(context, request, names=None):
if not hasattr(context, '__name__'):
# shortcut if the context doesn't have a name (usually happens if the
# context is an exception); we do this because mgmt_path uses Pyramid's
# resource_path_tuple, which wants every object in the lineage to have
# a __name__.
return []
registry = request.registry
introspector = registry.introspector
unordered = []
# create a dummy request signaling our intent
req = Request(request.environ.copy())
req.script_name = request.script_name
req.context = context
req.matched_route = request.matched_route
req.method = 'GET'
req.registry = request.registry
for data in introspector.get_category('sdi views'):
related = data['related']
sdi_intr = data['introspectable']
tab_title = sdi_intr['tab_title']
tab_condition = sdi_intr['tab_condition']
tab_before = sdi_intr['tab_before']
tab_after = sdi_intr['tab_after']
def is_view(intr):
return intr.category_name == 'views'
for view_intr in filter(is_view, related):
# NB: in reality, the above loop will execute exactly once because
# each "sdi view" is associated with exactly one pyramid view
view_name = view_intr['name']
req.path_info = request.mgmt_path(context, view_name)
if names is not None and not view_name in names:
continue
# do a passable job at figuring out whether, if we visit the
# url implied by this view, we'll be permitted to view it and
# something reasonable will show up
intr_context = view_intr['context']
if IInterface.providedBy(intr_context):
if not intr_context.providedBy(context):
continue
elif intr_context and not isinstance(context, intr_context):
continue
if tab_condition is not None and names is None:
if callable(tab_condition):
if not tab_condition(context, request):
continue
elif not tab_condition:
continue
derived = view_intr['derived_callable']
if hasattr(derived, '__predicated__'):
if not derived.__predicated__(context, req):
continue
if hasattr(derived, '__permitted__'):
if not derived.__permitted__(context, req):
continue
if view_name == request.view_name:
css_class = 'active'
else:
css_class = None
unordered.append(
{'view_name': view_name,
'tab_before':tab_before,
'tab_after':tab_after,
'title': tab_title or view_name.capitalize(),
'class': css_class,
'url': request.mgmt_path(request.context, '@@%s' % view_name)
}
)
manually_ordered = []
tab_order = request.registry.content.metadata(context, 'tab_order')
if tab_order is not None:
ordered_names = [ y for y in tab_order if y in
[ x['view_name'] for x in unordered ] ]
for ordered_name in ordered_names:
for view_data in unordered[:]:
if view_data['view_name'] == ordered_name:
unordered.remove(view_data)
manually_ordered.append(view_data)
# first sort non-manually-ordered views lexically by title
lexically_ordered = sorted(unordered, key=operator.itemgetter('title'))
# then sort the lexically-presorted unordered views topologically based on
# any tab_before and tab_after values in the view data
tsorter = TopologicalSorter(default_before=MIDDLE, default_after=None)
tsorter.add(
MIDDLE,
None,
before=LAST,
after=FIRST,
)
for view_data in lexically_ordered:
#.........这里部分代码省略.........