Here are the examples of the python api sys.getfilesystemencoding taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
3
View Complete Implementation : glob.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def glob1(dirname, pattern):
if not dirname:
dirname = os.curdir
if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
dirname = unicode(dirname, sys.getfilesystemencoding() or
sys.getdefaultencoding())
try:
names = os.listdir(dirname)
except os.error:
return []
if pattern[0] != '.':
names = filter(lambda x: x[0] != '.', names)
return fnmatch.filter(names, pattern)
3
View Complete Implementation : test_imghdr.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def test_data(self):
for filename, expected in TEST_FILES:
filename = findfile(filename, subdir='imghdrdata')
self.astertEqual(imghdr.what(filename), expected)
ufilename = filename.decode(sys.getfilesystemencoding())
self.astertEqual(imghdr.what(ufilename), expected)
with open(filename, 'rb') as stream:
self.astertEqual(imghdr.what(stream), expected)
with open(filename, 'rb') as stream:
data = stream.read()
self.astertEqual(imghdr.what(None, data), expected)
3
View Complete Implementation : test_fileinput.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def test_unicode_filenames(self):
try:
t1 = writeTmp(1, ["A\nB"])
encoding = sys.getfilesystemencoding()
if encoding is None:
encoding = 'ascii'
fi = FileInput(files=unicode(t1, encoding))
lines = list(fi)
self.astertEqual(lines, ["A\n", "B"])
finally:
remove_tempfiles(t1)
3
View Complete Implementation : test_fileinput.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def test_unicode_filenames(self):
try:
t1 = writeTmp(1, ["A\nB"])
encoding = sys.getfilesystemencoding()
if encoding is None:
encoding = 'ascii'
fi = FileInput(files=unicode(t1, encoding))
lines = list(fi)
self.astertEqual(lines, ["A\n", "B"])
finally:
remove_tempfiles(t1)
3
View Complete Implementation : glob.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def glob1(dirname, pattern):
if not dirname:
dirname = os.curdir
if isinstance(pattern, _unicode) and not isinstance(dirname, unicode):
dirname = unicode(dirname, sys.getfilesystemencoding() or
sys.getdefaultencoding())
try:
names = os.listdir(dirname)
except os.error:
return []
if pattern[0] != '.':
names = filter(lambda x: x[0] != '.', names)
return fnmatch.filter(names, pattern)
3
View Complete Implementation : test_archive_util.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def can_fs_encode(filename):
"""
Return True if the filename can be saved in the file system.
"""
if os.path.supports_unicode_filenames:
return True
try:
filename.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
return False
return True
3
View Complete Implementation : test_archive_util.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
def can_fs_encode(filename):
"""
Return True if the filename can be saved in the file system.
"""
if os.path.supports_unicode_filenames:
return True
try:
filename.encode(sys.getfilesystemencoding())
except UnicodeEncodeError:
return False
return True
3
View Complete Implementation : test_posixpath.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
@test_support.requires_unicode
def test_expandvars_nonascii_word(self):
encoding = sys.getfilesystemencoding()
# Non-ASCII word characters
letters = test_support.u(r'\xe6\u0130\u0141\u03c6\u041a\u05d0\u062a\u0e01')
uwnonascii = letters.encode(encoding, 'ignore').decode(encoding)[:3]
swnonascii = uwnonascii.encode(encoding)
if not swnonascii:
self.skipTest('Needs non-ASCII word characters')
with test_support.EnvironmentVarGuard() as env:
env.clear()
env[swnonascii] = 'baz' + swnonascii
self.astertEqual(posixpath.expandvars(u'$%s bar' % uwnonascii),
u'baz%s bar' % uwnonascii)
3
View Complete Implementation : test_warnings.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
@test_support.requires_unicode
@unittest.skipUnless(test_support.FS_NONASCII, 'need test_support.FS_NONASCII')
def test_formatwarning_unicode_msg_nonascii_filename(self):
message = u"msg"
category = Warning
unicode_file_name = test_support.FS_NONASCII + u'.py'
file_name = unicode_file_name.encode(sys.getfilesystemencoding())
line_num = 3
file_line = 'spam'
format = "%s:%s: %s: %s\n %s\n"
expect = format % (file_name, line_num, category.__name__, str(message),
file_line)
self.astertEqual(expect, self.module.formatwarning(message,
category, file_name, line_num, file_line))
message = u"\xb5sg"
expect = format % (unicode_file_name, line_num, category.__name__, message,
file_line)
self.astertEqual(expect, self.module.formatwarning(message,
category, file_name, line_num, file_line))
3
View Complete Implementation : test_posixpath.py
Copyright GNU General Public License v3.0
Author : sk1project
Copyright GNU General Public License v3.0
Author : sk1project
@test_support.requires_unicode
def test_expandvars_nonascii_word(self):
encoding = sys.getfilesystemencoding()
# Non-ASCII word characters
letters = test_support.u(r'\xe6\u0130\u0141\u03c6\u041a\u05d0\u062a\u0e01')
uwnonascii = letters.encode(encoding, 'ignore').decode(encoding)[:3]
swnonascii = uwnonascii.encode(encoding)
if not swnonascii:
self.skipTest('Needs non-ASCII word characters')
with test_support.EnvironmentVarGuard() as env:
env.clear()
env[swnonascii] = 'baz' + swnonascii
self.astertEqual(posixpath.expandvars(u'$%s bar' % uwnonascii),
u'baz%s bar' % uwnonascii)