• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python traversal.quote_path_segment函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.traversal.quote_path_segment函数的典型用法代码示例。如果您正苦于以下问题:Python quote_path_segment函数的具体用法?Python quote_path_segment怎么用?Python quote_path_segment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了quote_path_segment函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: generator

    def generator(dict):
        newdict = {}
        for k, v in dict.items():
            if PY3: # pragma: no cover
                if v.__class__ is binary_type:
                    # url_quote below needs a native string, not bytes on Py3
                    v = v.decode('utf-8')
            else:
                if v.__class__ is text_type:
                    # url_quote below needs bytes, not unicode on Py2
                    v = v.encode('utf-8')

            if k == remainder:
                # a stararg argument
                if is_nonstr_iter(v):
                    v = '/'.join([quote_path_segment(x) for x in v]) # native
                else:
                    if v.__class__ not in string_types:
                        v = str(v)
                    v = quote_path_segment(v, safe='/')
            else:
                if v.__class__ not in string_types:
                    v = str(v)
                # v may be bytes (py2) or native string (py3)
                v = quote_path_segment(v)

            # at this point, the value will be a native string
            newdict[k] = v

        result = gen % newdict # native string result
        return result
开发者ID:IDSGPlayground,项目名称:pyramid-tutorial-yuxin-aaron,代码行数:31,代码来源:urldispatch.py


示例2: decorator

    def decorator(context, request):
        script_name = ''

        # first consider URL routing
        if request.matched_route:
            matchdictCopy = {}
            matchdictCopy.update(request.matchdict)
            matchdictCopy['subpath'] = ''
            script_name = request.matched_route.generate(matchdictCopy)

        # now consider traversed paths
        traversed = request.traversed
        vroot_path = request.virtual_root_path or ()
        view_name = request.view_name
        subpath = request.subpath or ()
        script_tuple = traversed[len(vroot_path):]
        script_list = [ quote_path_segment(name) for name in script_tuple ]
        if view_name:
            script_list.append(quote_path_segment(view_name))
        script_name = script_name + '/' + '/'.join(script_list)
        path_list = [ quote_path_segment(name) for name in subpath ]
        path_info = '/' + '/'.join(path_list)
        request.environ['PATH_INFO'] = path_info
        script_name = request.environ['SCRIPT_NAME'] + script_name
        if script_name.endswith('/'):
            script_name = script_name[:-1]
        request.environ['SCRIPT_NAME'] = script_name
        return request.get_response(wrapped)
开发者ID:bshanks,项目名称:pyramid,代码行数:28,代码来源:wsgi.py


示例3: intranets_info

def intranets_info(context, request):
    """Get information for the footer and intranets listing"""
    intranets_info = []
    intranets = find_intranets(context)
    if intranets:
        intranets_url = resource_url(intranets, request)
        for name, entry in intranets.items():
            try:
                content_iface = get_content_type(entry)
            except ValueError:
                continue
            if content_iface == ICommunity:
                if not has_permission('view', entry, request):
                    continue
                href = '%s%s/' % (intranets_url, quote_path_segment(name))
                intranets_info.append({
                        'title': entry.title,
                        'intranet_href': href,
                        'edit_href': href + '/edit_intranet.html',
                        })
        # Sort the list
        def intranet_sort(x, y):
            if x['title'] > y['title']:
                return 1
            else:
                return -1
        intranets_info.sort(intranet_sort)
    return intranets_info
开发者ID:mindreframer,项目名称:python-pyramid-stuff,代码行数:28,代码来源:panels.py


示例4: intranets_info

 def intranets_info(self):
     """Get information for the footer and intranets listing"""
     if self._intranets_info is None:
         intranets_info = []
         intranets = find_intranets(self.context)
         if not intranets:
             # Maybe there aren't any intranets defined yet
             return []
         request = self.request
         intranets_url = resource_url(intranets, request)
         for name, entry in intranets.items():
             try:
                 content_iface = get_content_type(entry)
             except ValueError:
                 continue
             href = '%s%s/' % (intranets_url, quote_path_segment(name))
             if content_iface == ICommunity:
                 intranets_info.append({
                         'title': entry.title,
                         'intranet_href': href,
                         'edit_href': href + '/edit_intranet.html',
                         })
         # Sort the list
         def intranet_sort(x, y):
             if x['title'] > y['title']:
                 return 1
             else:
                 return -1
         self._intranets_info = sorted(intranets_info, intranet_sort)
     return self._intranets_info
开发者ID:claytron,项目名称:karl,代码行数:30,代码来源:api.py


示例5: _secure_path

def _secure_path(path_tuple):
    if '' in path_tuple:
        return None
    for item in path_tuple:
        for val in ['.', '/']:
            if item.startswith(val):
                return None
    return '/'.join([quote_path_segment(x) for x in path_tuple])
开发者ID:velox-zz,项目名称:pyramid,代码行数:8,代码来源:static.py


示例6: decorator

 def decorator(context, request):
     traversed = request.traversed
     vroot_path = request.virtual_root_path or ()
     view_name = request.view_name
     subpath = request.subpath or ()
     script_tuple = traversed[len(vroot_path):]
     script_list = [ quote_path_segment(name) for name in script_tuple ]
     if view_name:
         script_list.append(quote_path_segment(view_name))
     script_name =  '/' + '/'.join(script_list)
     path_list = [ quote_path_segment(name) for name in subpath ]
     path_info = '/' + '/'.join(path_list)
     request.environ['PATH_INFO'] = path_info
     script_name = request.environ['SCRIPT_NAME'] + script_name
     if script_name.endswith('/'):
         script_name = script_name[:-1]
     request.environ['SCRIPT_NAME'] = script_name
     return request.get_response(wrapped)
开发者ID:junkafarian,项目名称:pyramid,代码行数:18,代码来源:wsgi.py


示例7: generator

 def generator(dict):
     newdict = {}
     for k, v in dict.items():
         if v.__class__ is text_type:
             v = native_(v, "utf-8")
         if k == star and is_nonstr_iter(v):
             v = "/".join([quote_path_segment(x) for x in v])
         elif k != star:
             if v.__class__ not in string_types:
                 v = str(v)
             v = url_quote(v, safe="")
         newdict[k] = v
     return gen % newdict
开发者ID:rfk,项目名称:pyramid,代码行数:13,代码来源:urldispatch.py


示例8: generator

 def generator(dict):
     newdict = {}
     for k, v in dict.items():
         if isinstance(v, unicode):
             v = v.encode('utf-8')
         if k == star and hasattr(v, '__iter__'):
             v = '/'.join([quote_path_segment(x) for x in v])
         elif k != star:
             try:
                 v = url_quote(v)
             except TypeError:
                 pass
         newdict[k] = v
     return gen % newdict
开发者ID:MattBurgess,项目名称:pyramid,代码行数:14,代码来源:urldispatch.py


示例9: _join_elements

def _join_elements(elements):
    return '/'.join([quote_path_segment(s, safe=':@&+$,') for s in elements])
开发者ID:Subbarker,项目名称:online-binder,代码行数:2,代码来源:url.py


示例10: _callFUT

 def _callFUT(self, s):
     from pyramid.traversal import quote_path_segment
     return quote_path_segment(s)
开发者ID:SMFOSS,项目名称:pyramid,代码行数:3,代码来源:test_traversal.py


示例11: _compile_route

def _compile_route(route):
    # This function really wants to consume Unicode patterns natively, but if
    # someone passes us a bytestring, we allow it by converting it to Unicode
    # using the ASCII decoding.  We decode it using ASCII because we don't
    # want to accept bytestrings with high-order characters in them here as
    # we have no idea what the encoding represents.
    if route.__class__ is not text_type:
        try:
            route = text_(route, 'ascii')
        except UnicodeDecodeError:
            raise ValueError(
                'The pattern value passed to add_route must be '
                'either a Unicode string or a plain string without '
                'any non-ASCII characters (you provided %r).' % route)

    if old_route_re.search(route) and not route_re.search(route):
        route = old_route_re.sub(update_pattern, route)

    if not route.startswith('/'):
        route = '/' + route

    remainder = None
    if star_at_end.search(route):
        route, remainder = route.rsplit('*', 1)

    pat = route_re.split(route)

    # every element in "pat" will be Unicode (regardless of whether the
    # route_re regex pattern is itself Unicode or str)
    pat.reverse()
    rpat = []
    gen = []
    prefix = pat.pop() # invar: always at least one element (route='/'+route)

    # We want to generate URL-encoded URLs, so we url-quote the prefix, being
    # careful not to quote any embedded slashes.  We have to replace '%' with
    # '%%' afterwards, as the strings that go into "gen" are used as string
    # replacement targets.
    gen.append(quote_path_segment(prefix, safe='/').replace('%', '%%')) # native
    rpat.append(re.escape(prefix)) # unicode

    while pat:
        name = pat.pop() # unicode
        name = name[1:-1]
        if ':' in name:
            name, reg = name.split(':')
        else:
            reg = '[^/]+'
        gen.append('%%(%s)s' % native_(name)) # native
        name = '(?P<%s>%s)' % (name, reg) # unicode
        rpat.append(name)
        s = pat.pop() # unicode
        if s:
            rpat.append(re.escape(s)) # unicode
            # We want to generate URL-encoded URLs, so we url-quote this
            # literal in the pattern, being careful not to quote the embedded
            # slashes.  We have to replace '%' with '%%' afterwards, as the
            # strings that go into "gen" are used as string replacement
            # targets.  What is appended to gen is a native string.
            gen.append(quote_path_segment(s, safe='/').replace('%', '%%'))

    if remainder:
        rpat.append('(?P<%s>.*?)' % remainder) # unicode
        gen.append('%%(%s)s' % native_(remainder)) # native

    pattern = ''.join(rpat) + '$' # unicode

    match = re.compile(pattern).match
    def matcher(path):
        # This function really wants to consume Unicode patterns natively,
        # but if someone passes us a bytestring, we allow it by converting it
        # to Unicode using the ASCII decoding.  We decode it using ASCII
        # because we don't want to accept bytestrings with high-order
        # characters in them here as we have no idea what the encoding
        # represents.
        if path.__class__ is not text_type:
            path = text_(path, 'ascii')
        m = match(path)
        if m is None:
            return None
        d = {}
        for k, v in m.groupdict().items():
            # k and v will be Unicode 2.6.4 and lower doesnt accept unicode
            # kwargs as **kw, so we explicitly cast the keys to native
            # strings in case someone wants to pass the result as **kw
            nk = native_(k, 'ascii')
            if k == remainder:
                d[nk] = split_path_info(v)
            else:
                d[nk] = v
        return d

    gen = ''.join(gen)
    def generator(dict):
        newdict = {}
        for k, v in dict.items():
            if PY3: # pragma: no cover
                if v.__class__ is binary_type:
                    # url_quote below needs a native string, not bytes on Py3
                    v = v.decode('utf-8')
#.........这里部分代码省略.........
开发者ID:IDSGPlayground,项目名称:pyramid-tutorial-yuxin-aaron,代码行数:101,代码来源:urldispatch.py


示例12: _join_elements

def _join_elements(elements):
    return '/'.join([quote_path_segment(s, safe=PATH_SEGMENT_SAFE) for s in elements])
开发者ID:invisibleroads,项目名称:pyramid,代码行数:2,代码来源:url.py


示例13: q

 def q(v):
     return quote_path_segment(v, safe=PATH_SAFE)
开发者ID:Pylons,项目名称:pyramid,代码行数:2,代码来源:urldispatch.py


示例14: _join_elements

def _join_elements(elements):
    return '/'.join([quote_path_segment(s) for s in elements])
开发者ID:csenger,项目名称:pyramid,代码行数:2,代码来源:url.py



注:本文中的pyramid.traversal.quote_path_segment函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python traversal.resource_path函数代码示例发布时间:2022-05-27
下一篇:
Python traversal.find_root函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap