本文整理匯總了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

​點讚 6

# 需要導入模塊: from urllib import parse [as 別名]

# 或者: from urllib.parse import quote_from_bytes [as 別名]

def encode_default(obj):

if isinstance(obj, JSONBytes):

return {'': quote_from_bytes(obj.data)}

elif isinstance(obj, bytes):

return {'': quote_from_bytes(obj)}

elif isinstance(obj, NamedStruct):

# Hacked in the internal getstate implementation...

state = obj.__getstate__()

if state[2] is not obj:

return {'':{'type':state[1], 'data':base64.b64encode(state[0]), 'target':state[2]}}

else:

return {'':{'type':state[1], 'data':base64.b64encode(state[0])}}

else:

if hasattr(obj, 'jsonencode'):

try:

key = ''

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,

示例2: test_as_uri

​點讚 6

# 需要導入模塊: 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,

示例3: make_uri

​點讚 5

# 需要導入模塊: 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,

示例4: path_to_url

​點讚 5

# 需要導入模塊: 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,

示例5: rewrite

​點讚 5

# 需要導入模塊: 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,

示例6: redirect

​點讚 5

# 需要導入模塊: 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'' + self.escape(location) + b'')

await self.flush(True)

開發者ID:hubo1016,項目名稱:vlcp,代碼行數:15,

示例7: group

​點讚 5

# 需要導入模塊: 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,

示例8: make_uri

​點讚 5

# 需要導入模塊: 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,

示例9: test_as_uri_non_ascii

​點讚 5

# 需要導入模塊: 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,

注:本文中的urllib.parse.quote_from_bytes方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

python的from_bytes属性_Python parse.quote_from_bytes方法代碼示例相关推荐

  1. python里turtle.circle什么意思_Python turtle.circle方法代碼示例

    本文整理匯總了Python中turtle.circle方法的典型用法代碼示例.如果您正苦於以下問題:Python turtle.circle方法的具體用法?Python turtle.circle怎麽 ...

  2. python中startout是什么意思_Python socket.timeout方法代碼示例

    本文整理匯總了Python中gevent.socket.timeout方法的典型用法代碼示例.如果您正苦於以下問題:Python socket.timeout方法的具體用法?Python socket ...

  3. python markdown2 样式_Python markdown2.markdown方法代碼示例

    本文整理匯總了Python中markdown2.markdown方法的典型用法代碼示例.如果您正苦於以下問題:Python markdown2.markdown方法的具體用法?Python markd ...

  4. python socketio例子_Python socket.SocketIO方法代碼示例

    本文整理匯總了Python中socket.SocketIO方法的典型用法代碼示例.如果您正苦於以下問題:Python socket.SocketIO方法的具體用法?Python socket.Sock ...

  5. python unescape函数_Python escape.url_unescape方法代碼示例

    本文整理匯總了Python中tornado.escape.url_unescape方法的典型用法代碼示例.如果您正苦於以下問題:Python escape.url_unescape方法的具體用法?Py ...

  6. python linspace函数_Python torch.linspace方法代碼示例

    本文整理匯總了Python中torch.linspace方法的典型用法代碼示例.如果您正苦於以下問題:Python torch.linspace方法的具體用法?Python torch.linspac ...

  7. pythonitems方法_Python environ.items方法代碼示例

    本文整理匯總了Python中os.environ.items方法的典型用法代碼示例.如果您正苦於以下問題:Python environ.items方法的具體用法?Python environ.item ...

  8. python wheel使用_Python wheel.Wheel方法代碼示例

    # 需要導入模塊: from pip import wheel [as 別名] # 或者: from pip.wheel import Wheel [as 別名] def from_line(cls, ...

  9. python helper方法_Python io_utils.ImportHelper方法代碼示例

    # 需要導入模塊: from bpy_extras import io_utils [as 別名] # 或者: from bpy_extras.io_utils import ImportHelper ...

最新文章

  1. 一个女生写的如何追mm.看完后嫩头青变高手.zz(转贴)
  2. Oracle SQL Optimizer IN VS Exists Again
  3. 我阅读的第一个程序GridView遇到的问题
  4. Spring Boot集成Thymeleaf模板引擎
  5. 现代软件工程 作业 结对编程 模板
  6. python自学笔记_Python 自学笔记
  7. [独家放送]Unity2019更新规划速览,将有官方的可视化编程!
  8. python和java的区别-python 和 java 的区别
  9. 学习Java需要用到那些软件?
  10. 机器学习-对线性回归、逻辑回归、各种回归的概念学习
  11. 苹果电脑关于命令行的操作
  12. python第三方库re库实例之爬取古诗词网上诗歌
  13. Benchmarking Learned Indexes(VLDB2021)
  14. 求1!+2!+....+10!
  15. mysql数据库应用题库_MySQL数据库设计与应用题库免费期末考试2021答案
  16. Facebook SDK for iOS 2.4 iOS 6 上运行崩溃
  17. 【毕业设计】大数据分析的航空公司客户价值分析 - python
  18. 实测,so easy的数据管理!
  19. REXROTH力士乐比例阀4WRZE25W8-220-7X/6EG24N9K31/A1D3M
  20. tomcat官网如何下载旧版本

热门文章

  1. php 实现背景图片轮换,纯js实现背景图片切换效果代码
  2. Visual Studio 2008下设置OpenCV
  3. php 保護連接字符串,PHP字符串操作
  4. pycharm配置后执行RF脚本
  5. LeetCode31.下一个排列 JavaScript
  6. 25个Linux相关的网站【转】
  7. 大数据改变中国交通浙江用阿里云看未来
  8. Appcan开发笔记:结合JQuery的$.Deferred()完善批量异步发送
  9. linux下更新JDK版本
  10. Java Web ConnectionPool (连接池技术)