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

Python compat.url_quote函数代码示例

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

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



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

示例1: cookie_value

 def cookie_value(self):
     v = '%s%08x%s!' % (self.digest(), int(self.time),
                        url_quote(self.userid))
     if self.tokens:
         v += self.tokens + '!'
     v += self.user_data
     return v
开发者ID:AndreaCrotti,项目名称:pyramid,代码行数:7,代码来源:authentication.py


示例2: test_utf8

 def test_utf8(self):
     la = b'La Pe\xc3\xb1a'
     encoded = url_quote(la)
     decoded = text_(la, 'utf-8')
     path = '/'.join([encoded, encoded])
     result = self._callFUT(path)
     self.assertEqual(result, (decoded, decoded))
开发者ID:ShakataGaNai,项目名称:learning-pyramid,代码行数:7,代码来源:test_traversal.py


示例3: test_highchars_in_filename

 def test_highchars_in_filename(self):
     url = url_quote('/static/héhé.html')
     res = self.testapp.get(url, status=200)
     _assertBody(
         res.body,
         os.path.join(here,
                      text_('fixtures/static/héhé.html', 'utf-8'))
         )
开发者ID:HorizonXP,项目名称:pyramid,代码行数:8,代码来源:test_integration.py


示例4: test_highchars_in_filename

 def test_highchars_in_filename(self):
     path = os.path.join(
         here,
         text_('fixtures/static/héhé.html', 'utf-8'))
     body = b'<html>hehe file</html>\n'
     with open(path, 'wb') as fp:
         fp.write(body)
     try:
         url = url_quote('/static/héhé.html')
         res = self.testapp.get(url, status=200)
         self.assertEqual(res.body, body)
     finally:
         os.unlink(path)
开发者ID:heng4fun,项目名称:SQLAlchemy---URL-Dispatch-Wiki-Tutorial,代码行数:13,代码来源:test_integration.py


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


示例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:Subbarker,项目名称:online-binder,代码行数:49,代码来源:url.py


示例7: 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:mitchellrj,项目名称:pyramid,代码行数:49,代码来源:url.py


示例8: test_highchars_in_pathelement

 def test_highchars_in_pathelement(self):
     path = os.path.join(
         here,
         text_('fixtures/static/héhé/index.html', 'utf-8'))
     pathdir = os.path.dirname(path)
     body = b'<html>hehe</html>\n'
     try:
         os.makedirs(pathdir)
         with open(path, 'wb') as fp:
             fp.write(body)
         url = url_quote('/static/héhé/index.html')
         res = self.testapp.get(url, status=200)
         self.assertEqual(res.body, body)
     finally:
         os.unlink(path)
         os.rmdir(pathdir)
开发者ID:heng4fun,项目名称:SQLAlchemy---URL-Dispatch-Wiki-Tutorial,代码行数:16,代码来源:test_integration.py


示例9: static_url

    def static_url(self, path, **kw):
        if not isabs(path) and ':' not in path:
            package = caller_package()
            package_name = package.__name__
            path = '%s:%s' % (package_name, path)
        else:
            package_name = path.split(':', 1)[0]

        if package_name == self.package_name:
            registry = self.registry
        else:
            for application_name, config in APPLICATIONS.items():
                if config.package_name == package_name:
                    registry = config.registry
                    break
            else:
                registry = get_current_registry() # b/c

        info = registry.queryUtility(IStaticURLInfo)
        if info is None:
            raise ValueError('No static URL definition matching %s' % path)

        registrations = info._get_registrations(registry)
        api_route_url = getattr(self.applications, registry.application_name).route_url

        for (url, spec, route_name, cachebust) in registrations:
            if path.startswith(spec):
                subpath = path[len(spec):]
                if WIN: # pragma: no cover
                    subpath = subpath.replace('\\', '/') # windows
                if cachebust:
                    subpath, kw = cachebust(subpath, kw)
                if url is None:
                    kw['subpath'] = subpath
                    return api_route_url(route_name, **kw)
                else:
                    app_url, scheme, host, port, qs, anchor = parse_url_overrides(kw)
                    parsed = urlparse(url)
                    if not parsed.scheme:
                        url = urlunparse(parsed._replace(scheme=self.environ['wsgi.url_scheme']))
                    subpath = url_quote(subpath)
                    result = urljoin(url, subpath)
                    return result + qs + anchor

        raise ValueError('No static URL definition matching %s' % path)
开发者ID:hugobranquinho,项目名称:ines,代码行数:45,代码来源:request.py


示例10: get_file

def get_file(request):
    # TODO: Add a route that enables the call to have the filename
    # appended to the end. This is so that gmail can read the services
    # Read more here:
    # http://stackoverflow.com/questions/20903967/gmails-new-image-caching-is-breaking-image-links-in-newsletter
    ctx = request.context
    document = ctx._instance
    f = File.get(document.id)
    if f.infected:
        raise HTTPNotAcceptable("Infected with a virus")
    escaped_double_quotes_filename = (f.title
        .replace(u'"', u'\\"')
        .encode('iso-8859-1', 'replace'))
    url_quoted_utf8_filename = url_quote(f.title.encode('utf-8'))
    handoff_to_nginx = asbool(config.get('handoff_to_nginx', False))
    if handoff_to_nginx:
        kwargs = dict(body='')
    else:
        if 'Range' in request.headers:
            raise HTTPRequestRangeNotSatisfiable()
        fs = open(f.path, 'rb')
        app_iter = None
        environ = request.environ
        if 'wsgi.file_wrapper' in environ:
            app_iter = environ['wsgi.file_wrapper'](fs, _BLOCK_SIZE)
        if app_iter is None:
            app_iter = FileIter(fs, _BLOCK_SIZE)
        kwargs=dict(app_iter=app_iter)

    r = Response(
        content_length=f.size,
        content_type=str(f.mime_type),
        last_modified=f.creation_date,
        expires=datetime.now()+timedelta(days=365),
        accept_ranges="bytes" if handoff_to_nginx else "none",
        content_disposition=
            'attachment; filename="%s"; filename*=utf-8\'\'%s' # RFC 6266
            % (escaped_double_quotes_filename, url_quoted_utf8_filename),
        **kwargs
    )
    if handoff_to_nginx:
        r.headers[b'X-Accel-Redirect'] = f.handoff_url
    return r
开发者ID:assembl,项目名称:assembl,代码行数:43,代码来源:attachments.py


示例11: test_utf16

 def test_utf16(self):
     from pyramid.exceptions import URLDecodeError
     la = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
     encoded = url_quote(la)
     path = '/'.join([encoded, encoded])
     self.assertRaises(URLDecodeError, self._callFUT, path)
开发者ID:ShakataGaNai,项目名称:learning-pyramid,代码行数:6,代码来源:test_traversal.py


示例12: _

	def _(self):
		q = 'foo bar'
		res = self.testapp.post('/search?query=foo bar', status=302)
		ok(res.location) == 'http://localhost/find/'+url_quote(q)
开发者ID:domoritz,项目名称:Professors,代码行数:4,代码来源:tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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