Python sys.filesystemencoding() Examples
The following are 8
code examples of sys.filesystemencoding().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: font_manager.py From neural-network-animation with MIT License | 6 votes |
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
Example #2
Source File: font_manager.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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
Example #3
Source File: font_manager.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #4
Source File: font_manager.py From ImageFusion with MIT License | 6 votes |
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
Example #5
Source File: font_manager.py From coffeegrindsize with MIT License | 6 votes |
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
Example #6
Source File: font_manager.py From twitter-stock-recommendation with MIT License | 6 votes |
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
Example #7
Source File: font_manager.py From neural-network-animation with MIT License | 5 votes |
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
Example #8
Source File: font_manager.py From ImageFusion with MIT License | 5 votes |
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