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


Python compat.unicode方法代碼示例

本文整理匯總了Python中setuptools.compat.unicode方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.unicode方法的具體用法?Python compat.unicode怎麽用?Python compat.unicode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在setuptools.compat的用法示例。


在下文中一共展示了compat.unicode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_bad_url_double_scheme

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [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:
            error = sys.exc_info()[1]
            msg = unicode(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:sugarguo,項目名稱:Flask_Blog,代碼行數:20,代碼來源:test_packageindex.py

示例2: decode_as_string

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [as 別名]
def decode_as_string(text, encoding=None):
    """
    Decode the console or file output explicitly using getpreferredencoding.
    The text paraemeter should be a encoded string, if not no decode occurs
    If no encoding is given, getpreferredencoding is used.  If encoding is
    specified, that is used instead.  This would be needed for SVN --xml
    output.  Unicode is explicitly put in composed NFC form.

    --xml should be UTF-8 (SVN Issue 2938) the discussion on the Subversion
    DEV List from 2007 seems to indicate the same.
    """
    #text should be a byte string

    if encoding is None:
        encoding = _console_encoding

    if not isinstance(text, unicode):
        text = text.decode(encoding)

    text = unicodedata.normalize('NFC', text)

    return text 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:24,代碼來源:svn_utils.py

示例3: test_bad_url_double_scheme

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [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 = unicode(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:ayush1997,項目名稱:Sudoku-Solver,代碼行數:19,代碼來源:test_packageindex.py

示例4: b

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [as 別名]
def b(s, encoding='utf-8'):
    if isinstance(s, unicode):
        return s.encode(encoding, errors)
    return s 
開發者ID:sugarguo,項目名稱:Flask_Blog,代碼行數:6,代碼來源:upload_docs.py

示例5: decompose

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [as 別名]
def decompose(path):
    if isinstance(path, unicode):
        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:sugarguo,項目名稱:Flask_Blog,代碼行數:12,代碼來源:test_sdist.py

示例6: decompose

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [as 別名]
def decompose(path):
    if isinstance(path, decoded_string):
        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:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:12,代碼來源:unicode_utils.py

示例7: filesys_decode

# 需要導入模塊: from setuptools import compat [as 別名]
# 或者: from setuptools.compat import unicode [as 別名]
def filesys_decode(path):
    """
    Ensure that the given path is decoded,
    NONE when no expected encoding works
    """

    fs_enc = sys.getfilesystemencoding()
    if isinstance(path, decoded_string):
        return path

    for enc in (fs_enc, "utf-8"):
        try:
            return path.decode(enc)
        except UnicodeDecodeError:
            continue 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:17,代碼來源:unicode_utils.py


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