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


Python sys.filesystemencoding方法代碼示例

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


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

示例1: fc_match

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import filesystemencoding [as 別名]
def fc_match(pattern, fontext):
        fontexts = get_fontext_synonyms(fontext)
        ext = "." + fontext
        try:
            pipe = subprocess.Popen(
                ['fc-match', '-s', '--format=%{file}\\n', pattern],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            output = pipe.communicate()[0]
        except (OSError, IOError):
            return None

        # The bulk of the output from fc-list is ascii, so we keep the
        # result in bytes and parse it as bytes, until we extract the
        # filename, which is in sys.filesystemencoding().
        if pipe.returncode == 0:
            for fname in output.split(b'\n'):
                try:
                    fname = six.text_type(fname, sys.getfilesystemencoding())
                except UnicodeDecodeError:
                    continue
                if os.path.splitext(fname)[1][1:] in fontexts:
                    return fname
        return None 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:26,代碼來源:font_manager.py

示例2: fc_match

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import filesystemencoding [as 別名]
def fc_match(pattern, fontext):
        fontexts = get_fontext_synonyms(fontext)
        ext = "." + fontext
        try:
            pipe = subprocess.Popen(
                ['fc-match', '-s', '--format=%{file}\\n', pattern],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            output = pipe.communicate()[0]
        except OSError:
            return None

        # The bulk of the output from fc-list is ascii, so we keep the
        # result in bytes and parse it as bytes, until we extract the
        # filename, which is in sys.filesystemencoding().
        if pipe.returncode == 0:
            for fname in map(os.fsdecode, output.split(b'\n')):
                if os.path.splitext(fname)[1][1:] in fontexts:
                    return fname
        return None 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:22,代碼來源:font_manager.py

示例3: get_fontconfig_fonts

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import filesystemencoding [as 別名]
def get_fontconfig_fonts(fontext='ttf'):
    """
    Grab a list of all the fonts that are being tracked by fontconfig
    by making a system call to ``fc-list``.  This is an easy way to
    grab all of the fonts the user wants to be made available to
    applications, without needing knowing where all of them reside.
    """
    fontext = get_fontext_synonyms(fontext)

    fontfiles = {}
    try:
        pipe = subprocess.Popen(['fc-list', '--format=%{file}\\n'],
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        output = pipe.communicate()[0]
    except (OSError, IOError):
        # Calling fc-list did not work, so we'll just return nothing
        return fontfiles

    if pipe.returncode == 0:
        # The line breaks between results are in ascii, but each entry
        # is in in sys.filesystemencoding().
        for fname in output.split(b'\n'):
            try:
                fname = six.text_type(fname, sys.getfilesystemencoding())
            except UnicodeDecodeError:
                continue
            if (os.path.splitext(fname)[1][1:] in fontext and
                os.path.exists(fname)):
                fontfiles[fname] = 1

    return fontfiles 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:34,代碼來源:font_manager.py


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