当前位置: 首页>>代码示例>>Python>>正文


Python parse.quote_from_bytes方法代码示例

本文整理汇总了Python中urllib.parse.quote_from_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python parse.quote_from_bytes方法的具体用法?Python parse.quote_from_bytes怎么用?Python parse.quote_from_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.parse的用法示例。


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

示例1: encode_default

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def encode_default(obj):
    if isinstance(obj, JSONBytes):
        return {'<vlcpjsonencode/urlencoded-bytes>': quote_from_bytes(obj.data)}
    elif isinstance(obj, bytes):
        return {'<vlcpjsonencode/urlencoded-bytes>': quote_from_bytes(obj)}
    elif isinstance(obj, NamedStruct):
        # Hacked in the internal getstate implementation...
        state = obj.__getstate__()
        if state[2] is not obj:
            return {'<vlcpjsonencode/namedstruct.NamedStruct>':{'type':state[1], 'data':base64.b64encode(state[0]), 'target':state[2]}}
        else:
            return {'<vlcpjsonencode/namedstruct.NamedStruct>':{'type':state[1], 'data':base64.b64encode(state[0])}}
    else:
        if hasattr(obj, 'jsonencode'):
            try:
                key = '<vlcpjsonencode/' + type(obj).__module__ + '.' + type(obj).__name__ + '>'
            except AttributeError:
                raise TypeError(repr(obj) + " is not JSON serializable")
            else:
                return {key : obj.jsonencode()}
        else:
            raise TypeError(repr(obj) + " is not JSON serializable") 
开发者ID:hubo1016,项目名称:vlcp,代码行数:24,代码来源:jsonencoder.py

示例2: test_as_uri

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def test_as_uri(self):
        from urllib.parse import quote_from_bytes
        P = self.cls
        with self.assertRaises(ValueError):
            P('/a/b').as_uri()
        with self.assertRaises(ValueError):
            P('c:a/b').as_uri()
        self.assertEqual(P('c:/').as_uri(), 'file:///c:/')
        self.assertEqual(P('c:/a/b.c').as_uri(), 'file:///c:/a/b.c')
        self.assertEqual(P('c:/a/b%#c').as_uri(), 'file:///c:/a/b%25%23c')
        self.assertEqual(P('c:/a/b\xe9').as_uri(), 'file:///c:/a/b%C3%A9')
        self.assertEqual(P('//some/share/').as_uri(), 'file://some/share/')
        self.assertEqual(P('//some/share/a/b.c').as_uri(),
                         'file://some/share/a/b.c')
        self.assertEqual(P('//some/share/a/b%#c\xe9').as_uri(),
                         'file://some/share/a/b%25%23c%C3%A9') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:18,代码来源:test_pathlib.py

示例3: make_uri

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def make_uri(self, path):
        # Under Windows, file URIs use the UTF-8 encoding.
        drive = path.drive
        if len(drive) == 2 and drive[1] == ':':
            # It's a path on a local drive => 'file:///c:/a/b'
            rest = path.as_posix()[2:].lstrip('/')
            return 'file:///%s/%s' % (
                drive, urlquote_from_bytes(rest.encode('utf-8')))
        else:
            # It's a path on a network drive => 'file://host/share/a/b'
            return 'file:' + urlquote_from_bytes(
                path.as_posix().encode('utf-8')) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:14,代码来源:__init__.py

示例4: path_to_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def path_to_url(path):
    # type: (TPath) -> Text
    """Convert the supplied local path to a file uri.

    :param str path: A string pointing to or representing a local path
    :return: A `file://` uri for the same location
    :rtype: str

    >>> path_to_url("/home/user/code/myrepo/myfile.zip")
    'file:///home/user/code/myrepo/myfile.zip'
    """
    from .misc import to_bytes

    if not path:
        return path  # type: ignore
    normalized_path = Path(normalize_drive(os.path.abspath(path))).as_posix()
    if os.name == "nt" and normalized_path[1] == ":":
        drive, _, path = normalized_path.partition(":")
        # XXX: This enables us to handle half-surrogates that were never
        # XXX: actually part of a surrogate pair, but were just incidentally
        # XXX: passed in as a piece of a filename
        quoted_path = quote(fs_encode(path))
        return fs_decode("file:///{}:{}".format(drive, quoted_path))
    # XXX: This is also here to help deal with incidental dangling surrogates
    # XXX: on linux, by making sure they are preserved during encoding so that
    # XXX: we can urlencode the backslash correctly
    bytes_path = to_bytes(normalized_path, errors="backslashreplace")
    return fs_decode("file://{}".format(quote(bytes_path))) 
开发者ID:pypa,项目名称:pipenv,代码行数:30,代码来源:path.py

示例5: rewrite

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def rewrite(self, path, method = None, keepresponse = True):
        "Rewrite this request to another processor. Must be called before header sent"
        if self._sendHeaders:
            raise HttpProtocolException('Cannot modify response, headers already sent')
        if getattr(self.event, 'rewritedepth', 0) >= getattr(self.protocol, 'rewritedepthlimit', 32):
            raise HttpRewriteLoopException
        newpath = urljoin(quote_from_bytes(self.path).encode('ascii'), path)
        if newpath == self.fullpath or newpath == self.originalpath:
            raise HttpRewriteLoopException
        extraparams = {}
        if keepresponse:
            if hasattr(self, 'status'):
                extraparams['status'] = self.status
            extraparams['sent_headers'] = self.sent_headers
            extraparams['sent_cookies'] = self.sent_cookies
        r = HttpRequestEvent(self.host,
                               newpath,
                               self.method if method is None else method,
                               self.connection,
                               self.connmark,
                               self.xid,
                               self.protocol,
                               headers = self.headers,
                               headerdict = self.headerdict,
                               setcookies = self.setcookies,
                               stream = self.inputstream,
                               rewritefrom = self.fullpath,
                               originalpath = self.originalpath,
                               rewritedepth = getattr(self.event, 'rewritedepth', 0) + 1,
                               **extraparams
                               )
        await self.connection.wait_for_send(r)
        self._sendHeaders = True
        self.outputstream = None 
开发者ID:hubo1016,项目名称:vlcp,代码行数:36,代码来源:http.py

示例6: redirect

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def redirect(self, path, status = 302):
        """
        Redirect this request with 3xx status
        """
        location = urljoin(urlunsplit((b'https' if self.https else b'http',
                                                                     self.host,
                                                                     quote_from_bytes(self.path).encode('ascii'),
                                                                     '',
                                                                     ''
                                                                     )), path)
        self.start_response(status, [(b'Location', location)])
        await self.write(b'<a href="' + self.escape(location, True) + b'">' + self.escape(location) + b'</a>')
        await self.flush(True) 
开发者ID:hubo1016,项目名称:vlcp,代码行数:15,代码来源:http.py

示例7: group

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def group(self, index = 0):
            return quote_from_bytes(self.__innerobj.group(index)).encode('ascii') 
开发者ID:hubo1016,项目名称:vlcp,代码行数:4,代码来源:http.py

示例8: make_uri

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def make_uri(self, path):
        # Under Windows, file URIs use the UTF-8 encoding.
        drive = path.drive
        if len(drive) == 2 and drive[1] == ':':
            # It's a path on a local drive => 'file:///c:/a/b'
            rest = path.as_posix()[2:].lstrip('/')
            return 'file:///%s/%s' % (
                drive, urlquote_from_bytes(rest.encode('utf-8')))
        else:
            # It's a path on a network drive => 'file://host/share/a/b'
            return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:pathlib.py

示例9: test_as_uri_non_ascii

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import quote_from_bytes [as 别名]
def test_as_uri_non_ascii(self):
        from urllib.parse import quote_from_bytes
        P = self.cls
        try:
            os.fsencode('\xe9')
        except UnicodeEncodeError:
            self.skipTest("\\xe9 cannot be encoded to the filesystem encoding")
        self.assertEqual(P('/a/b\xe9').as_uri(),
                         'file:///a/b' + quote_from_bytes(os.fsencode('\xe9'))) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_pathlib.py


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