當前位置: 首頁>>代碼示例>>Python>>正文


Python six.text_type方法代碼示例

本文整理匯總了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 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:unicode_utils.py

示例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") 
開發者ID:pypa,項目名稱:setuptools,代碼行數:23,代碼來源:test_packageindex.py

示例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 
開發者ID:jpush,項目名稱:jbox,代碼行數:12,代碼來源:unicode_utils.py

示例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 
開發者ID:jpush,項目名稱:jbox,代碼行數:6,代碼來源:upload_docs.py

示例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 
開發者ID:jpush,項目名稱:jbox,代碼行數:8,代碼來源:easy_install.py


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