本文整理匯總了Python中setuptools.extern.six.text_type方法的典型用法代碼示例。如果您正苦於以下問題:Python six.text_type方法的具體用法?Python six.text_type怎麽用?Python six.text_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類setuptools.extern.six
的用法示例。
在下文中一共展示了six.text_type方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: filesys_decode
# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import text_type [as 別名]
def filesys_decode(path):
"""
Ensure that the given path is decoded,
NONE when no expected encoding works
"""
if isinstance(path, six.text_type):
return path
fs_enc = sys.getfilesystemencoding() or 'utf-8'
candidates = fs_enc, 'utf-8'
for enc in candidates:
try:
return path.decode(enc)
except UnicodeDecodeError:
continue
示例2: test_bad_url_double_scheme
# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import text_type [as 別名]
def test_bad_url_double_scheme(self):
"""
A bad URL with a double scheme should raise a DistutilsError.
"""
index = setuptools.package_index.PackageIndex(
hosts=('www.example.com',)
)
# issue 20
url = 'http://http://svn.pythonpaste.org/Paste/wphp/trunk'
try:
index.open_url(url)
except distutils.errors.DistutilsError as error:
msg = six.text_type(error)
assert (
'nonnumeric port' in msg
or 'getaddrinfo failed' in msg
or 'Name or service not known' in msg
)
return
raise RuntimeError("Did not raise")
示例3: decompose
# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import text_type [as 別名]
def decompose(path):
if isinstance(path, six.text_type):
return unicodedata.normalize('NFD', path)
try:
path = path.decode('utf-8')
path = unicodedata.normalize('NFD', path)
path = path.encode('utf-8')
except UnicodeError:
pass # Not UTF-8
return path
示例4: b
# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import text_type [as 別名]
def b(s, encoding='utf-8'):
if isinstance(s, six.text_type):
return s.encode(encoding, errors)
return s
示例5: isascii
# 需要導入模塊: from setuptools.extern import six [as 別名]
# 或者: from setuptools.extern.six import text_type [as 別名]
def isascii(s):
try:
six.text_type(s, 'ascii')
return True
except UnicodeError:
return False