本文整理汇总了Python中urllib._quote函数的典型用法代码示例。如果您正苦于以下问题:Python _quote函数的具体用法?Python _quote怎么用?Python _quote使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_quote函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quote
def quote(value, safe="/"):
"""
Patched version of urllib.quote that encodes utf8 strings before quoting
"""
if isinstance(value, unicode):
value = value.encode("utf8")
return _quote(value, safe)
示例2: quote
def quote(s, safe=b'/'):
s = _quote(s.encode('utf-8'), safe)
# PY3 always returns unicode. PY2 may return either, depending on whether
# it had to modify the string.
if isinstance(s, bytes_type):
s = s.decode('utf-8')
return s
示例3: quote
def quote(s, safe=b"/"):
s = s.encode("utf-8") if isinstance(s, unicode_type) else s
s = _quote(s, safe)
# PY3 always returns unicode. PY2 may return either, depending on whether
# it had to modify the string.
if isinstance(s, bytes_type):
s = s.decode("utf-8")
return s
示例4: quote
def quote(string):
try:
if type(string) is unicode:
string = string.encode('utf-8')
return _quote(string)
except:
print 'quoted string is:', string
raise
示例5: quote
def quote(value, safe='/'):
"""
Patched version of urllib.quote that encodes utf8 strings before quoting
"""
value = encode_utf8(value)
if isinstance(value, str):
return _quote(value, safe)
else:
return value
示例6: quote
def quote(text, *args, **kwargs):
t = type(text)
if t is str:
converted_text = text
elif t is unicode:
converted_text = str(text.encode('utf-8'))
else:
try:
converted_text = str(text)
except:
converted_text = text
return _quote(converted_text, *args, **kwargs)
示例7: quote
def quote(value, safe='/'):
if isinstance(value, unicode):
(value, _len) = utf8_encoder(value, 'replace')
(valid_utf8_str, _len) = utf8_decoder(value, 'replace')
return _quote(valid_utf8_str.encode('utf-8'), safe)
示例8: _quote
try:
import httplib
except ImportError:
import http.client as httplib
try:
from urllib import quote as _quote
from urllib import quote as _quote_from_bytes
from urllib import unquote as unquote_to_bytes
except ImportError:
from urllib.parse import quote as _quote
from urllib.parse import quote_from_bytes as _quote_from_bytes
from urllib.parse import unquote_to_bytes
quote = lambda s: _quote(s, safe='')
quote_from_bytes = lambda s: _quote_from_bytes(s, safe='')
try:
import cPickle as pickle
except ImportError:
import pickle
import json
KT_HTTP_HEADER = {'Content-Type' : 'text/tab-separated-values; colenc=U'}
def _dict_to_tsv(kv_dict):
lines = []
for k, v in kv_dict.items():
quoted = quote_from_bytes(v) if isinstance(v, bytes) else quote(str(v))
示例9: quote
def quote(value):
value = value.encode('utf8', errors='ignore') if isinstance(value, unicode) else str(value)
return _quote(value, safe='')
示例10: _quote
# Copyright 2011, Toru Maesaka
#
# Redistribution and use of this source code is licensed under
# the BSD license. See COPYING file for license description.
import base64
import httplib
import struct
import time
import kt_error
try:
from percentcoding import quote, unquote
except ImportError:
from urllib import quote as _quote
from urllib import unquote
quote = lambda s: _quote(s, safe="")
try:
import cPickle as pickle
except ImportError:
import pickle
# Stick with URL encoding for now. Eventually run a benchmark
# to evaluate what the most approariate encoding algorithm is.
KT_HTTP_HEADER = {
'Content-Type' : 'text/tab-separated-values; colenc=U',
}
KT_PACKER_CUSTOM = 0
KT_PACKER_PICKLE = 1
KT_PACKER_JSON = 2
示例11: quote
def quote(s, safe='/'):
if isinstance(s, unicode):
s = s.encode('utf-8', 'ignore') # hope we're using utf-8!
return _quote(s, safe).replace('/', encoded_slash)
示例12: quote
def quote(*l):
return tuple(_quote(unicodeToStr(s)) for s in l) if len(l) != 1 else _quote(unicodeToStr(l[0]))
示例13: quote
def quote(string):
assert(type(string) in [unicode, str])
return _quote(string.encode('utf-8')) if isinstance(string, unicode) else _quote(string)
示例14: quote
def quote(_i):
return _quote(_i, "")
示例15: quote
def quote(string, safe=b'/'):
if not isinstance(safe, bytes):
safe = safe.encode('ascii', 'ignore')
if not isinstance(string, bytes):
string = string.encode('utf8')
return _quote(string, safe)