Author: junglecow Date: 2006-12-22 14:49:38 +0100 (Fri, 22 Dec 2006) New Revision: 7710
Modified: trunk/src/common/configpaths.py Log: - Use bytestrings instead of unicode for filesystem paths. See #2812 and close if fix works.
Modified: trunk/src/common/configpaths.py =================================================================== --- trunk/src/common/configpaths.py 2006-12-21 18:08:17 UTC (rev 7709) +++ trunk/src/common/configpaths.py 2006-12-22 13:49:38 UTC (rev 7710) @@ -20,11 +20,12 @@ # 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. +# +# 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.)
-def fse(s): - '''Convert from filesystem encoding if not already Unicode''' - return unicode(s, sys.getfilesystemencoding()) - class ConfigPaths: def __init__(self, root=None): self.root = root @@ -38,13 +39,12 @@ # 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 @@ 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 @@ 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 @@ 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))