python 3 support, avoid use of unicode

svn: r20699
This commit is contained in:
Benny Malengier 2012-11-23 17:22:00 +00:00
parent db6a462bc2
commit a1591a964c
2 changed files with 10 additions and 7 deletions

View File

@ -53,6 +53,7 @@ except:
# gramps modules # gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..constfunc import cuni
from ..utils.cast import get_type_converter from ..utils.cast import get_type_converter
from .menu import Menu from .menu import Menu
from ..plug import BasePluginManager from ..plug import BasePluginManager
@ -224,12 +225,12 @@ class OptionListCollection(object):
f.write(' <listitem ' f.write(' <listitem '
'number="%d" value=%s/>\n' % ( 'number="%d" value=%s/>\n' % (
list_index, list_index,
quoteattr(unicode(list_data))) ) quoteattr(cuni(list_data))) )
f.write(' </option>\n') f.write(' </option>\n')
else: else:
f.write(' <option name=%s value=%s/>\n' % ( f.write(' <option name=%s value=%s/>\n' % (
quoteattr(option_name), quoteattr(option_name),
quoteattr(unicode(option_data))) ) quoteattr(cuni(option_data))) )
for docgen_name in self.docgen_names: for docgen_name in self.docgen_names:
if module_docgen_opts[docgen_name]: if module_docgen_opts[docgen_name]:
for ix, data in enumerate(module_docgen_opts[docgen_name]): for ix, data in enumerate(module_docgen_opts[docgen_name]):
@ -237,7 +238,7 @@ class OptionListCollection(object):
'name=%s value=%s/>\n' % 'name=%s value=%s/>\n' %
(quoteattr(docgen_name), (quoteattr(docgen_name),
quoteattr(data[0]), quoteattr(data[0]),
quoteattr(unicode(data[1])) )) quoteattr(cuni(data[1])) ))
self.write_module_common(f, option_list) self.write_module_common(f, option_list)
f.write('</module>\n') f.write('</module>\n')

View File

@ -42,7 +42,7 @@ import logging
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..const import PREFIXDIR, ROOT_DIR from ..const import PREFIXDIR, ROOT_DIR
from ..constfunc import mac from ..constfunc import mac, UNITYPE
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Public Constants # Public Constants
@ -267,15 +267,17 @@ def get_addon_translator(filename=None, domain="addon", languages=None):
path = os.path.dirname(os.path.abspath(filename)) path = os.path.dirname(os.path.abspath(filename))
# Check if path is of type str. Do import and conversion if so. # Check if path is of type str. Do import and conversion if so.
# The import cannot be done at the top as that will conflict with the translation system. # The import cannot be done at the top as that will conflict with the translation system.
if type(path) == str: if not isinstance(path, UNITYPE) == str:
from .file import get_unicode_path_from_env_var from .file import get_unicode_path_from_env_var
path = get_unicode_path_from_env_var(path) path = get_unicode_path_from_env_var(path)
if languages: if languages:
addon_translator = gettext.translation(domain, os.path.join(path,"locale"), addon_translator = gettext.translation(domain,
os.path.join(path, "locale"),
languages=languages, languages=languages,
fallback=True) fallback=True)
else: else:
addon_translator = gettext.translation(domain, os.path.join(path,"locale"), addon_translator = gettext.translation(domain,
os.path.join(path, "locale"),
fallback=True) fallback=True)
gramps_translator.add_fallback(addon_translator) gramps_translator.add_fallback(addon_translator)
return gramps_translator # with a language fallback return gramps_translator # with a language fallback