- Use bytestrings instead of unicode for filesystem paths. See #2812 and close if fix works.

This commit is contained in:
junglecow 2006-12-22 13:49:38 +00:00
parent 35ecad1188
commit 7f44b60267
1 changed files with 23 additions and 20 deletions

View File

@ -20,10 +20,11 @@ import tempfile
# happily pass to functions that operate on files and directories, so we can
# just leave it as is. Since these paths are meant to be internal to Gajim and
# not displayed to the user, Unicode is not really necessary here.
def fse(s):
'''Convert from filesystem encoding if not already Unicode'''
return unicode(s, sys.getfilesystemencoding())
#
# Update: Python stdlib seems broken, and uses sys.getdefaultencoding() instead
# of sys.getfilesystemencoding() for converting unicode paths in file operations.
# Additionally, PyGTK overrides defaultencoding to utf-8, overriding site.py.
# Therefore, we now use bytestrings and never unicode. (See #2812.)
class ConfigPaths:
def __init__(self, root=None):
@ -38,13 +39,12 @@ class ConfigPaths:
# How are we supposed to know what encoding the environment
# variable 'appdata' is in? Assuming it to be in filesystem
# encoding.
self.root = os.path.join(fse(os.environ[u'appdata']), u'Gajim')
self.root = os.path.join(os.environ['appdata'], 'Gajim')
except KeyError:
# win9x, in cwd
self.root = u''
self.root = ''
else: # Unices
# Pass in an Unicode string, and hopefully get one back.
self.root = os.path.expanduser(u'~/.gajim')
self.root = os.path.expanduser('~/.gajim')
def add_from_root(self, name, path):
self.paths[name] = (True, path)
@ -77,8 +77,8 @@ def init():
paths = ConfigPaths()
# LOG is deprecated
k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons')
k = ('LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
v = ('logs', 'logs.db', 'vcards', 'avatars', 'emoticons')
if os.name == 'nt':
v = map(lambda x: x.capitalize(), v)
@ -86,9 +86,9 @@ def init():
for n, p in zip(k, v):
paths.add_from_root(n, p)
paths.add('DATA', os.path.join(u'..', windowsify(u'data')))
paths.add('HOME', fse(os.path.expanduser('~')))
paths.add('TMP', fse(tempfile.gettempdir()))
paths.add('DATA', os.path.join('..', windowsify('data')))
paths.add('HOME', os.path.expanduser('~'))
paths.add('TMP', tempfile.gettempdir())
try:
import svn_config
@ -96,20 +96,23 @@ def init():
except (ImportError, AttributeError):
pass
#for k, v in paths.iteritems():
# print "%s: %s" % (k, v)
# for k, v in paths.iteritems():
# print "%s: %s" % (repr(k), repr(v))
return paths
gajimpaths = init()
def init_profile(profile, paths=gajimpaths):
conffile = windowsify(u'config')
pidfile = windowsify(u'gajim')
conffile = windowsify('config')
pidfile = windowsify('gajim')
if len(profile) > 0:
conffile += u'.' + profile
pidfile += u'.' + profile
pidfile += u'.pid'
conffile += '.' + profile
pidfile += '.' + profile
pidfile += '.pid'
paths.add_from_root('CONFIG_FILE', conffile)
paths.add_from_root('PID_FILE', pidfile)
# for k, v in paths.iteritems():
# print "%s: %s" % (repr(k), repr(v))