本文整理汇总了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