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

Python encode.url_quote函数代码示例

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

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



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

示例1: parse_url_overrides

def parse_url_overrides(request, kw):
    """
    Parse special arguments passed when generating urls.

    The supplied dictionary is mutated when we pop arguments.
    Returns a 3-tuple of the format:

      ``(app_url, qs, anchor)``.

    """
    app_url = kw.pop('_app_url', None)
    scheme = kw.pop('_scheme', None)
    host = kw.pop('_host', None)
    port = kw.pop('_port', None)
    query = kw.pop('_query', '')
    anchor = kw.pop('_anchor', '')

    if app_url is None:
        if (scheme is not None or host is not None or port is not None):
            app_url = request._partial_application_url(scheme, host, port)
        else:
            app_url = request.application_url

    qs = ''
    if query:
        if isinstance(query, string_types):
            qs = '?' + url_quote(query, QUERY_SAFE)
        else:
            qs = '?' + urlencode(query, doseq=True)

    frag = ''
    if anchor:
        frag = '#' + url_quote(anchor, ANCHOR_SAFE)

    return app_url, qs, frag
开发者ID:invisibleroads,项目名称:pyramid,代码行数:35,代码来源:url.py


示例2: quote_path_segment

 def quote_path_segment(segment, safe=""):
     """ %s """ % quote_path_segment_doc
     # The bit of this code that deals with ``_segment_cache`` is an
     # optimization: we cache all the computation of URL path segments
     # in this module-scope dictionary with the original string (or
     # unicode value) as the key, so we can look it up later without
     # needing to reencode or re-url-quote it
     try:
         return _segment_cache[(segment, safe)]
     except KeyError:
         if segment.__class__ is text_type:  # isinstance slighly slower (~15%)
             result = url_quote(segment.encode("utf-8"), safe)
         else:
             result = url_quote(str(segment), safe)
         # we don't need a lock to mutate _segment_cache, as the below
         # will generate exactly one Python bytecode (STORE_SUBSCR)
         _segment_cache[(segment, safe)] = result
         return result
开发者ID:dylfaust,项目名称:pyramid,代码行数:18,代码来源:traversal.py


示例3: quote_path_segment

def quote_path_segment(segment, safe=""):
    """ Return a quoted representation of a 'path segment' (such as
    the string ``__name__`` attribute of a resource) as a string.  If the
    ``segment`` passed in is a unicode object, it is converted to a
    UTF-8 string, then it is URL-quoted using Python's
    ``urllib.quote``.  If the ``segment`` passed in is a string, it is
    URL-quoted using Python's :mod:`urllib.quote`.  If the segment
    passed in is not a string or unicode object, an error will be
    raised.  The return value of ``quote_path_segment`` is always a
    string, never Unicode.

    You may pass a string of characters that need not be encoded as
    the ``safe`` argument to this function.  This corresponds to the
    ``safe`` argument to :mod:`urllib.quote`.

    .. note:: The return value for each segment passed to this
              function is cached in a module-scope dictionary for
              speed: the cached version is returned when possible
              rather than recomputing the quoted version.  No cache
              emptying is ever done for the lifetime of an
              application, however.  If you pass arbitrary
              user-supplied strings to this function (as opposed to
              some bounded set of values from a 'working set' known to
              your application), it may become a memory leak.
    """
    # The bit of this code that deals with ``_segment_cache`` is an
    # optimization: we cache all the computation of URL path segments
    # in this module-scope dictionary with the original string (or
    # unicode value) as the key, so we can look it up later without
    # needing to reencode or re-url-quote it
    try:
        return _segment_cache[(segment, safe)]
    except KeyError:
        if segment.__class__ is unicode:  # isinstance slighly slower (~15%)
            result = url_quote(segment.encode("utf-8"), safe)
        else:
            result = url_quote(str(segment), safe)
        # we don't need a lock to mutate _segment_cache, as the below
        # will generate exactly one Python bytecode (STORE_SUBSCR)
        _segment_cache[(segment, safe)] = result
        return result
开发者ID:sundisee,项目名称:appsync-vendor,代码行数:41,代码来源:traversal.py


示例4: parse_url_overrides

def parse_url_overrides(kw):
    """Parse special arguments passed when generating urls.

    The supplied dictionary is mutated, popping arguments as necessary.
    Returns a 6-tuple of the format ``(app_url, scheme, host, port,
    qs, anchor)``.
    """
    anchor = ''
    qs = ''
    app_url = None
    host = None
    scheme = None
    port = None

    if '_query' in kw:
        query = kw.pop('_query')
        if isinstance(query, string_types):
            qs = '?' + url_quote(query, QUERY_SAFE)
        elif query:
            qs = '?' + urlencode(query, doseq=True)

    if '_anchor' in kw:
        anchor = kw.pop('_anchor')
        anchor = url_quote(anchor, ANCHOR_SAFE)
        anchor = '#' + anchor

    if '_app_url' in kw:
        app_url = kw.pop('_app_url')

    if '_host' in kw:
        host = kw.pop('_host')

    if '_scheme' in kw:
        scheme = kw.pop('_scheme')

    if '_port' in kw:
        port = kw.pop('_port')

    return app_url, scheme, host, port, qs, anchor
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:39,代码来源:url.py


示例5: 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


示例6: _partial_application_url

    def _partial_application_url(self, scheme=None, host=None, port=None):
        """
        Construct the URL defined by request.application_url, replacing any
        of the default scheme, host, or port portions with user-supplied
        variants.

        If ``scheme`` is passed as ``https``, and the ``port`` is *not*
        passed, the ``port`` value is assumed to ``443``.  Likewise, if
        ``scheme`` is passed as ``http`` and ``port`` is not passed, the
        ``port`` value is assumed to be ``80``.
        """
        e = self.environ
        if scheme is None:
            scheme = e['wsgi.url_scheme']
        else:
            if scheme == 'https':
                if port is None:
                    port = '443'
            if scheme == 'http':
                if port is None:
                    port = '80'
        url = scheme + '://'
        if port is not None:
            port = str(port)
        if host is None:
            host = e.get('HTTP_HOST')
        if host is None:
            host = e['SERVER_NAME']
        if port is None:
            if ':' in host:
                host, port = host.split(':', 1)
            else:
                port = e['SERVER_PORT']
        else:
            if ':' in host:
                host, _ = host.split(':', 1)
        if scheme == 'https':
            if port == '443':
                port = None
        elif scheme == 'http':
            if port == '80':
                port = None
        url += host
        if port:
            url += ':%s' % port

        url_encoding = getattr(self, 'url_encoding', 'utf-8') # webob 1.2b3+
        bscript_name = bytes_(self.script_name, url_encoding)
        return url + url_quote(bscript_name, PATH_SAFE)
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:49,代码来源:url.py


示例7: quote_path_segment

 def quote_path_segment(segment, safe=PATH_SEGMENT_SAFE):
     """ %s """ % quote_path_segment_doc
     # The bit of this code that deals with ``_segment_cache`` is an
     # optimization: we cache all the computation of URL path segments
     # in this module-scope dictionary with the original string (or
     # unicode value) as the key, so we can look it up later without
     # needing to reencode or re-url-quote it
     try:
         return _segment_cache[(segment, safe)]
     except KeyError:
         if segment.__class__ not in (text_type, binary_type):
             segment = str(segment)
         result = url_quote(native_(segment, 'utf-8'), safe)
         # we don't need a lock to mutate _segment_cache, as the below
         # will generate exactly one Python bytecode (STORE_SUBSCR)
         _segment_cache[(segment, safe)] = result
         return result
开发者ID:JDeuce,项目名称:pyramid,代码行数:17,代码来源:traversal.py


示例8: _callFUT

 def _callFUT(self, val, safe=''):
     from pyramid.encode import url_quote
     return url_quote(val, safe)
开发者ID:mozilla,项目名称:appsync-vendor,代码行数:3,代码来源:test_encode.py


示例9: quote

def quote(path):
    """URL encode the path"""
    return url_quote(path, safe=PATH_SAFE)
开发者ID:Connexions,项目名称:cnx-archive,代码行数:3,代码来源:test_extras.py


示例10: resource_url


#.........这里部分代码省略.........
                'resource URL; any "app_url", "host", "port", or "scheme" '
                'arguments passed to resource_url are being ignored.  To '
                'avoid this behavior, as of Pyramid 1.3, register an '
                'IResourceURL adapter instead of an IContextURL '
                'adapter for the resource type(s).  IContextURL adapters '
                'will be ignored in a later major release of Pyramid.',
                DeprecationWarning,
                2)

            resource_url = url_adapter()

        else:
            # IResourceURL adapter (Pyramid 1.3 and after)
            app_url = None
            scheme = None
            host = None
            port = None

            if 'route_name' in kw:
                newkw = {}
                route_name = kw['route_name']
                remainder = getattr(url_adapter, 'virtual_path_tuple', None)
                if remainder is None:
                    # older user-supplied IResourceURL adapter without 1.5
                    # virtual_path_tuple
                    remainder = tuple(url_adapter.virtual_path.split('/'))
                remainder_name = kw.get('route_remainder_name', 'traverse')
                newkw[remainder_name] = remainder

                for name in (
                    'app_url', 'scheme', 'host', 'port', 'query', 'anchor'
                    ):
                    val = kw.get(name, None)
                    if val is not None:
                        newkw['_' + name] = val
                    
                if 'route_kw' in kw:
                    route_kw = kw.get('route_kw')
                    if route_kw is not None:
                        newkw.update(route_kw)

                return self.route_url(route_name, *elements, **newkw)

            if 'app_url' in kw:
                app_url = kw['app_url']

            if 'scheme' in kw:
                scheme = kw['scheme']

            if 'host' in kw:
                host = kw['host']

            if 'port' in kw:
                port = kw['port']

            if app_url is None:
                if scheme or host or port:
                    app_url = self._partial_application_url(scheme, host, port)
                else:
                    app_url = self.application_url

            resource_url = None
            local_url = getattr(resource, '__resource_url__', None)

            if local_url is not None:
                # the resource handles its own url generation
                d = dict(
                    virtual_path = virtual_path,
                    physical_path = url_adapter.physical_path,
                    app_url = app_url,
                    )
                # allow __resource_url__ to punt by returning None
                resource_url = local_url(self, d)

            if resource_url is None:
                # the resource did not handle its own url generation or the
                # __resource_url__ function returned None
                resource_url = app_url + virtual_path

        qs = ''
        anchor = ''

        if 'query' in kw:
            query = kw['query']
            if isinstance(query, string_types):
                qs = '?' + url_quote(query, QUERY_SAFE)
            elif query:
                qs = '?' + urlencode(query, doseq=True)

        if 'anchor' in kw:
            anchor = kw['anchor']
            anchor = url_quote(anchor, ANCHOR_SAFE)
            anchor = '#' + anchor

        if elements:
            suffix = _join_elements(elements)
        else:
            suffix = ''

        return resource_url + suffix + qs + anchor
开发者ID:AdrianTeng,项目名称:pyramid,代码行数:101,代码来源:url.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python encode.urlencode函数代码示例发布时间:2022-05-27
下一篇:
Python configuration.Configurator类代码示例发布时间: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