diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index 92c1def22..cfe496acf 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -480,7 +480,7 @@ def find_locker_name(dirpath): """ try: fname = os.path.join(dirpath, "lock") - ifile = open(fname) + ifile = open(fname, 'rb') username = ifile.read().strip() # Convert username to unicode according to system encoding # Otherwise problems with non ASCII characters in diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index d27d67b4c..7144ed264 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -55,7 +55,11 @@ if sys.version_info[0] < 3: STRTYPE = basestring UNITYPE = unicode else: - conv_to_unicode = lambda x,y: str(x) + def conv_to_unicode(x, y): + if isinstance(x, str): + return x + else: + return x.decode(y) conv_to_unicode_direct = str STRTYPE = str UNITYPE = str diff --git a/gramps/gen/datehandler/_grampslocale.py b/gramps/gen/datehandler/_grampslocale.py index 8245c2f18..0fd81916f 100644 --- a/gramps/gen/datehandler/_grampslocale.py +++ b/gramps/gen/datehandler/_grampslocale.py @@ -35,67 +35,71 @@ strftime. Since these routines return values encoded into selected character set, we have to convert to unicode. """ - +if sys.version_info[0] < 3: + to_uni = conv_to_unicode +else: + #locale returns unicode in python 3 + to_uni = lambda x, y: x try: codeset = locale.nl_langinfo(locale.CODESET) month_to_int = { - conv_to_unicode(locale.nl_langinfo(locale.MON_1),codeset).lower() : 1, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_1),codeset).lower() : 1, - conv_to_unicode(locale.nl_langinfo(locale.MON_2),codeset).lower() : 2, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_2),codeset).lower() : 2, - conv_to_unicode(locale.nl_langinfo(locale.MON_3),codeset).lower() : 3, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_3),codeset).lower() : 3, - conv_to_unicode(locale.nl_langinfo(locale.MON_4),codeset).lower() : 4, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_4),codeset).lower() : 4, - conv_to_unicode(locale.nl_langinfo(locale.MON_5),codeset).lower() : 5, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_5),codeset).lower() : 5, - conv_to_unicode(locale.nl_langinfo(locale.MON_6),codeset).lower() : 6, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_6),codeset).lower() : 6, - conv_to_unicode(locale.nl_langinfo(locale.MON_7),codeset).lower() : 7, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_7),codeset).lower() : 7, - conv_to_unicode(locale.nl_langinfo(locale.MON_8),codeset).lower() : 8, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_8),codeset).lower() : 8, - conv_to_unicode(locale.nl_langinfo(locale.MON_9),codeset).lower() : 9, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_9),codeset).lower() : 9, - conv_to_unicode(locale.nl_langinfo(locale.MON_10),codeset).lower() : 10, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_10),codeset).lower(): 10, - conv_to_unicode(locale.nl_langinfo(locale.MON_11),codeset).lower() : 11, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_11),codeset).lower(): 11, - conv_to_unicode(locale.nl_langinfo(locale.MON_12),codeset).lower() : 12, - conv_to_unicode(locale.nl_langinfo(locale.ABMON_12),codeset).lower(): 12, + to_uni(locale.nl_langinfo(locale.MON_1), codeset).lower() : 1, + to_uni(locale.nl_langinfo(locale.ABMON_1), codeset).lower() : 1, + to_uni(locale.nl_langinfo(locale.MON_2), codeset).lower() : 2, + to_uni(locale.nl_langinfo(locale.ABMON_2), codeset).lower() : 2, + to_uni(locale.nl_langinfo(locale.MON_3), codeset).lower() : 3, + to_uni(locale.nl_langinfo(locale.ABMON_3), codeset).lower() : 3, + to_uni(locale.nl_langinfo(locale.MON_4), codeset).lower() : 4, + to_uni(locale.nl_langinfo(locale.ABMON_4), codeset).lower() : 4, + to_uni(locale.nl_langinfo(locale.MON_5), codeset).lower() : 5, + to_uni(locale.nl_langinfo(locale.ABMON_5), codeset).lower() : 5, + to_uni(locale.nl_langinfo(locale.MON_6), codeset).lower() : 6, + to_uni(locale.nl_langinfo(locale.ABMON_6), codeset).lower() : 6, + to_uni(locale.nl_langinfo(locale.MON_7), codeset).lower() : 7, + to_uni(locale.nl_langinfo(locale.ABMON_7), codeset).lower() : 7, + to_uni(locale.nl_langinfo(locale.MON_8), codeset).lower() : 8, + to_uni(locale.nl_langinfo(locale.ABMON_8), codeset).lower() : 8, + to_uni(locale.nl_langinfo(locale.MON_9), codeset).lower() : 9, + to_uni(locale.nl_langinfo(locale.ABMON_9), codeset).lower() : 9, + to_uni(locale.nl_langinfo(locale.MON_10), codeset).lower() : 10, + to_uni(locale.nl_langinfo(locale.ABMON_10), codeset).lower(): 10, + to_uni(locale.nl_langinfo(locale.MON_11), codeset).lower() : 11, + to_uni(locale.nl_langinfo(locale.ABMON_11), codeset).lower(): 11, + to_uni(locale.nl_langinfo(locale.MON_12), codeset).lower() : 12, + to_uni(locale.nl_langinfo(locale.ABMON_12), codeset).lower(): 12, } long_months = ( "", - conv_to_unicode(locale.nl_langinfo(locale.MON_1),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_2),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_3),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_4),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_5),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_6),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_7),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_8),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_9),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_10),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_11),codeset), - conv_to_unicode(locale.nl_langinfo(locale.MON_12),codeset), + to_uni(locale.nl_langinfo(locale.MON_1), codeset), + to_uni(locale.nl_langinfo(locale.MON_2), codeset), + to_uni(locale.nl_langinfo(locale.MON_3), codeset), + to_uni(locale.nl_langinfo(locale.MON_4), codeset), + to_uni(locale.nl_langinfo(locale.MON_5), codeset), + to_uni(locale.nl_langinfo(locale.MON_6), codeset), + to_uni(locale.nl_langinfo(locale.MON_7), codeset), + to_uni(locale.nl_langinfo(locale.MON_8), codeset), + to_uni(locale.nl_langinfo(locale.MON_9), codeset), + to_uni(locale.nl_langinfo(locale.MON_10), codeset), + to_uni(locale.nl_langinfo(locale.MON_11), codeset), + to_uni(locale.nl_langinfo(locale.MON_12), codeset), ) short_months = ( "", - conv_to_unicode(locale.nl_langinfo(locale.ABMON_1),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_2),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_3),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_4),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_5),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_6),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_7),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_8),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_9),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_10),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_11),codeset), - conv_to_unicode(locale.nl_langinfo(locale.ABMON_12),codeset), + to_uni(locale.nl_langinfo(locale.ABMON_1), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_2), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_3), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_4), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_5), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_6), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_7), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_8), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_9), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_10), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_11), codeset), + to_uni(locale.nl_langinfo(locale.ABMON_12), codeset), ) # Gramps day number: Sunday => 1, Monday => 2, etc @@ -106,24 +110,24 @@ try: # see http://docs.python.org/library/locale.html long_days = ( "", - conv_to_unicode(locale.nl_langinfo(locale.DAY_1),codeset), # Sunday - conv_to_unicode(locale.nl_langinfo(locale.DAY_2),codeset), # Monday - conv_to_unicode(locale.nl_langinfo(locale.DAY_3),codeset), # Tuesday - conv_to_unicode(locale.nl_langinfo(locale.DAY_4),codeset), # Wednesday - conv_to_unicode(locale.nl_langinfo(locale.DAY_5),codeset), # Thursday - conv_to_unicode(locale.nl_langinfo(locale.DAY_6),codeset), # Friday - conv_to_unicode(locale.nl_langinfo(locale.DAY_7),codeset), # Saturday + to_uni(locale.nl_langinfo(locale.DAY_1), codeset), # Sunday + to_uni(locale.nl_langinfo(locale.DAY_2), codeset), # Monday + to_uni(locale.nl_langinfo(locale.DAY_3), codeset), # Tuesday + to_uni(locale.nl_langinfo(locale.DAY_4), codeset), # Wednesday + to_uni(locale.nl_langinfo(locale.DAY_5), codeset), # Thursday + to_uni(locale.nl_langinfo(locale.DAY_6), codeset), # Friday + to_uni(locale.nl_langinfo(locale.DAY_7), codeset), # Saturday ) short_days = ( "", - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_1),codeset), # Sunday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_2),codeset), # Monday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_3),codeset), # Tuesday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_4),codeset), # Wednesday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_5),codeset), # Thursday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_6),codeset), # Friday - conv_to_unicode(locale.nl_langinfo(locale.ABDAY_7),codeset), # Saturday + to_uni(locale.nl_langinfo(locale.ABDAY_1), codeset), # Sunday + to_uni(locale.nl_langinfo(locale.ABDAY_2), codeset), # Monday + to_uni(locale.nl_langinfo(locale.ABDAY_3), codeset), # Tuesday + to_uni(locale.nl_langinfo(locale.ABDAY_4), codeset), # Wednesday + to_uni(locale.nl_langinfo(locale.ABDAY_5), codeset), # Thursday + to_uni(locale.nl_langinfo(locale.ABDAY_6), codeset), # Friday + to_uni(locale.nl_langinfo(locale.ABDAY_7), codeset), # Saturday ) tformat = locale.nl_langinfo(locale.D_FMT).replace('%y','%Y') @@ -140,62 +144,62 @@ except: codeset = locale.getpreferredencoding() month_to_int = { - conv_to_unicode(time.strftime('%B',(0,1,1,1,1,1,1,1,1)),codeset).lower() : 1, - conv_to_unicode(time.strftime('%b',(0,1,1,1,1,1,1,1,1)),codeset).lower() : 1, - conv_to_unicode(time.strftime('%B',(0,2,1,1,1,1,1,1,1)),codeset).lower() : 2, - conv_to_unicode(time.strftime('%b',(0,2,1,1,1,1,1,1,1)),codeset).lower() : 2, - conv_to_unicode(time.strftime('%B',(0,3,1,1,1,1,1,1,1)),codeset).lower() : 3, - conv_to_unicode(time.strftime('%b',(0,3,1,1,1,1,1,1,1)),codeset).lower() : 3, - conv_to_unicode(time.strftime('%B',(0,4,1,1,1,1,1,1,1)),codeset).lower() : 4, - conv_to_unicode(time.strftime('%b',(0,4,1,1,1,1,1,1,1)),codeset).lower() : 4, - conv_to_unicode(time.strftime('%B',(0,5,1,1,1,1,1,1,1)),codeset).lower() : 5, - conv_to_unicode(time.strftime('%b',(0,5,1,1,1,1,1,1,1)),codeset).lower() : 5, - conv_to_unicode(time.strftime('%B',(0,6,1,1,1,1,1,1,1)),codeset).lower() : 6, - conv_to_unicode(time.strftime('%b',(0,6,1,1,1,1,1,1,1)),codeset).lower() : 6, - conv_to_unicode(time.strftime('%B',(0,7,1,1,1,1,1,1,1)),codeset).lower() : 7, - conv_to_unicode(time.strftime('%b',(0,7,1,1,1,1,1,1,1)),codeset).lower() : 7, - conv_to_unicode(time.strftime('%B',(0,8,1,1,1,1,1,1,1)),codeset).lower() : 8, - conv_to_unicode(time.strftime('%b',(0,8,1,1,1,1,1,1,1)),codeset).lower() : 8, - conv_to_unicode(time.strftime('%B',(0,9,1,1,1,1,1,1,1)),codeset).lower() : 9, - conv_to_unicode(time.strftime('%b',(0,9,1,1,1,1,1,1,1)),codeset).lower() : 9, - conv_to_unicode(time.strftime('%B',(0,10,1,1,1,1,1,1,1)),codeset).lower() : 10, - conv_to_unicode(time.strftime('%b',(0,10,1,1,1,1,1,1,1)),codeset).lower() : 10, - conv_to_unicode(time.strftime('%B',(0,11,1,1,1,1,1,1,1)),codeset).lower() : 11, - conv_to_unicode(time.strftime('%b',(0,11,1,1,1,1,1,1,1)),codeset).lower() : 11, - conv_to_unicode(time.strftime('%B',(0,12,1,1,1,1,1,1,1)),codeset).lower() : 12, - conv_to_unicode(time.strftime('%b',(0,12,1,1,1,1,1,1,1)),codeset).lower() : 12, + to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1, + to_uni(time.strftime('%b',(0,1,1,1,1,1,1,1,1)), codeset).lower() : 1, + to_uni(time.strftime('%B',(0,2,1,1,1,1,1,1,1)), codeset).lower() : 2, + to_uni(time.strftime('%b',(0,2,1,1,1,1,1,1,1)), codeset).lower() : 2, + to_uni(time.strftime('%B',(0,3,1,1,1,1,1,1,1)), codeset).lower() : 3, + to_uni(time.strftime('%b',(0,3,1,1,1,1,1,1,1)), codeset).lower() : 3, + to_uni(time.strftime('%B',(0,4,1,1,1,1,1,1,1)), codeset).lower() : 4, + to_uni(time.strftime('%b',(0,4,1,1,1,1,1,1,1)), codeset).lower() : 4, + to_uni(time.strftime('%B',(0,5,1,1,1,1,1,1,1)), codeset).lower() : 5, + to_uni(time.strftime('%b',(0,5,1,1,1,1,1,1,1)), codeset).lower() : 5, + to_uni(time.strftime('%B',(0,6,1,1,1,1,1,1,1)), codeset).lower() : 6, + to_uni(time.strftime('%b',(0,6,1,1,1,1,1,1,1)), codeset).lower() : 6, + to_uni(time.strftime('%B',(0,7,1,1,1,1,1,1,1)), codeset).lower() : 7, + to_uni(time.strftime('%b',(0,7,1,1,1,1,1,1,1)), codeset).lower() : 7, + to_uni(time.strftime('%B',(0,8,1,1,1,1,1,1,1)), codeset).lower() : 8, + to_uni(time.strftime('%b',(0,8,1,1,1,1,1,1,1)), codeset).lower() : 8, + to_uni(time.strftime('%B',(0,9,1,1,1,1,1,1,1)), codeset).lower() : 9, + to_uni(time.strftime('%b',(0,9,1,1,1,1,1,1,1)), codeset).lower() : 9, + to_uni(time.strftime('%B',(0,10,1,1,1,1,1,1,1)), codeset).lower() : 10, + to_uni(time.strftime('%b',(0,10,1,1,1,1,1,1,1)), codeset).lower() : 10, + to_uni(time.strftime('%B',(0,11,1,1,1,1,1,1,1)), codeset).lower() : 11, + to_uni(time.strftime('%b',(0,11,1,1,1,1,1,1,1)), codeset).lower() : 11, + to_uni(time.strftime('%B',(0,12,1,1,1,1,1,1,1)), codeset).lower() : 12, + to_uni(time.strftime('%b',(0,12,1,1,1,1,1,1,1)), codeset).lower() : 12, } long_months = ( "", - conv_to_unicode(time.strftime('%B',(0,1,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,2,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,3,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,4,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,5,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,6,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,7,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,8,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,9,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,10,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,11,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%B',(0,12,1,1,1,1,1,1,1)),codeset), + to_uni(time.strftime('%B',(0,1,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,2,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,3,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,4,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,5,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,6,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,7,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,8,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,9,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,10,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,11,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%B',(0,12,1,1,1,1,1,1,1)), codeset), ) short_months = ( "", - conv_to_unicode(time.strftime('%b',(0,1,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,2,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,3,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,4,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,5,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,6,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,7,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,8,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,9,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,10,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,11,1,1,1,1,1,1,1)),codeset), - conv_to_unicode(time.strftime('%b',(0,12,1,1,1,1,1,1,1)),codeset), + to_uni(time.strftime('%b',(0,1,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,2,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,3,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,4,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,5,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,6,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,7,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,8,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,9,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,10,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,11,1,1,1,1,1,1,1)), codeset), + to_uni(time.strftime('%b',(0,12,1,1,1,1,1,1,1)), codeset), ) # Gramps day number: Sunday => 1, Monday => 2, etc @@ -209,24 +213,24 @@ except: # just a dummy. long_days = ( "", - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,6,1,1)),codeset), # Sunday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,0,1,1)),codeset), # Monday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,1,1,1)),codeset), # Tuesday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,2,1,1)),codeset), # Wednesday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,3,1,1)),codeset), # Thursday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,4,1,1)),codeset), # Friday - conv_to_unicode(time.strftime('%A',(0,1,1,1,1,1,5,1,1)),codeset), # Saturday + to_uni(time.strftime('%A',(0,1,1,1,1,1,6,1,1)), codeset), # Sunday + to_uni(time.strftime('%A',(0,1,1,1,1,1,0,1,1)), codeset), # Monday + to_uni(time.strftime('%A',(0,1,1,1,1,1,1,1,1)), codeset), # Tuesday + to_uni(time.strftime('%A',(0,1,1,1,1,1,2,1,1)), codeset), # Wednesday + to_uni(time.strftime('%A',(0,1,1,1,1,1,3,1,1)), codeset), # Thursday + to_uni(time.strftime('%A',(0,1,1,1,1,1,4,1,1)), codeset), # Friday + to_uni(time.strftime('%A',(0,1,1,1,1,1,5,1,1)), codeset), # Saturday ) short_days = ( "", - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,6,1,1)),codeset), # Sunday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,0,1,1)),codeset), # Monday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,1,1,1)),codeset), # Tuesday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,2,1,1)),codeset), # Wednesday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,3,1,1)),codeset), # Thursday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,4,1,1)),codeset), # Friday - conv_to_unicode(time.strftime('%a',(0,1,1,1,1,1,5,1,1)),codeset), # Saturday + to_uni(time.strftime('%a',(0,1,1,1,1,1,6,1,1)), codeset), # Sunday + to_uni(time.strftime('%a',(0,1,1,1,1,1,0,1,1)), codeset), # Monday + to_uni(time.strftime('%a',(0,1,1,1,1,1,1,1,1)), codeset), # Tuesday + to_uni(time.strftime('%a',(0,1,1,1,1,1,2,1,1)), codeset), # Wednesday + to_uni(time.strftime('%a',(0,1,1,1,1,1,3,1,1)), codeset), # Thursday + to_uni(time.strftime('%a',(0,1,1,1,1,1,4,1,1)), codeset), # Friday + to_uni(time.strftime('%a',(0,1,1,1,1,1,5,1,1)), codeset), # Saturday ) # depending on the locale, the value returned for 20th Feb 2009 could be diff --git a/gramps/gen/display/name.py b/gramps/gen/display/name.py index 163390088..13ffa0de7 100644 --- a/gramps/gen/display/name.py +++ b/gramps/gen/display/name.py @@ -61,7 +61,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------- -from ..constfunc import cuni, conv_to_unicode +from ..constfunc import cuni, conv_to_unicode, UNITYPE from ..lib.name import Name from ..lib.nameorigintype import NameOriginType @@ -986,7 +986,8 @@ class NameDisplay(object): # if in double quotes, just use % codes for (code, keyword) in d_keys: exp, keyword, ikeyword = d[code] - keyword = conv_to_unicode(keyword, "utf8") + if not isinstance(keyword, UNITYPE): + keyword = conv_to_unicode(keyword, "utf-8") format_str = format_str.replace(keyword, "%"+ code) format_str = format_str.replace(keyword.title(), "%"+ code) format_str = format_str.replace(keyword.upper(), "%"+ code.upper()) diff --git a/gramps/gui/views/treemodels/mediamodel.py b/gramps/gui/views/treemodels/mediamodel.py index 7825c7fc9..0c4e7ca0e 100644 --- a/gramps/gui/views/treemodels/mediamodel.py +++ b/gramps/gui/views/treemodels/mediamodel.py @@ -44,7 +44,7 @@ from gi.repository import Gtk #------------------------------------------------------------------------- from gramps.gen.datehandler import displayer, format_time from gramps.gen.lib import Date, MediaObject -from gramps.gen.constfunc import cuni, conv_to_unicode +from gramps.gen.constfunc import cuni, conv_to_unicode, UNITYPE from .flatbasemodel import FlatBaseModel #------------------------------------------------------------------------- @@ -107,21 +107,30 @@ class MediaModel(FlatBaseModel): def do_get_n_columns(self): return len(self.fmap)+1 - def column_description(self,data): + def column_description(self, data): + descr = data[4] + if isinstance(descr, UNITYPE): + return descr try: - return cuni(data[4]) + return cuni(descr) except: - return conv_to_unicode(data[4], 'latin1') + return conv_to_unicode(descr, 'latin1') - def column_path(self,data): + def column_path(self, data): + path = data[2] + if isinstance(path, UNITYPE): + return path try: - return cuni(data[2]) + return cuni(path) except: - return cuni(data[2].encode('iso-8859-1')) + return cuni(path.encode('iso-8859-1')) - def column_mime(self,data): - if data[3]: - return cuni(data[3]) + def column_mime(self, data): + mime = data[3] + if mime and isinstance(mime, UNITYPE): + return mime + if mime: + return cuni(mime) else: return _('Note') diff --git a/gramps/gui/views/treemodels/peoplemodel.py b/gramps/gui/views/treemodels/peoplemodel.py index b6131c146..b652b1c14 100644 --- a/gramps/gui/views/treemodels/peoplemodel.py +++ b/gramps/gui/views/treemodels/peoplemodel.py @@ -194,8 +194,8 @@ class PeopleBaseModel(object): def sort_name(self, data): name = name_displayer.raw_sorted_name(data[COLUMN_NAME]) # internally we work with utf-8 - if isinstance(name, UNITYPE): - name = name.encode('utf-8') + if not isinstance(name, UNITYPE): + name = name.decode('utf-8') return name def column_name(self, data): @@ -209,7 +209,6 @@ class PeopleBaseModel(object): name = name.encode('utf-8') if not self._in_build: self.lru_name[handle] = name - return name def column_spouse(self, data): @@ -537,8 +536,8 @@ class PersonTreeModel(PeopleBaseModel, TreeBaseModel): name_data = data[COLUMN_NAME] group_name = ngn(self.db, name_data) - if isinstance(group_name, UNITYPE): - group_name = group_name.encode('utf-8') + #if isinstance(group_name, UNITYPE): + # group_name = group_name.encode('utf-8') sort_key = self.sort_func(data) #if group_name not in self.group_list: diff --git a/gramps/gui/views/treemodels/treebasemodel.py b/gramps/gui/views/treemodels/treebasemodel.py index baf31eb61..6f5b82696 100644 --- a/gramps/gui/views/treemodels/treebasemodel.py +++ b/gramps/gui/views/treemodels/treebasemodel.py @@ -37,6 +37,7 @@ This module provides the model that is used for all hierarchical treeviews. import time import locale +import sys from gramps.gen.ggettext import gettext as _ import logging @@ -90,13 +91,16 @@ class Node(object): def __init__(self, ref, parent, sortkey, handle, secondary): if sortkey: if isinstance(sortkey, UNITYPE): - self.name = sortkey.encode('utf-8') + self.name = sortkey #sortkey must be localized sort, so self.sortkey = conv_unicode_tosrtkey(sortkey) else: - self.name = sortkey + self.name = sortkey.decode('utf-8') #sortkey must be localized sort, so - self.sortkey = conv_str_tosrtkey(sortkey) + if sys.version_info[0] < 3: + self.sortkey = conv_str_tosrtkey(sortkey) + else: + self.sortkey = conv_unicode_tosrtkey(self.name) else: self.name = '' self.sortkey = None @@ -832,7 +836,7 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): not correspond to a gramps object. """ handle = node.handle - if not isinstance(handle, UNITYPE): + if handle and not isinstance(handle, UNITYPE): handle = handle.decode('utf-8') return handle @@ -881,24 +885,25 @@ class TreeBaseModel(GObject.Object, Gtk.TreeModel): if node.handle is None: # Header rows dont get the foreground color set if col == self.color_column(): + #color must not be utf-8 return "#000000000000" # Return the node name for the first column if col == 0: - return self.column_header(node) + val = self.column_header(node) else: #no value to show in other header column - return '' + val = '' else: # return values for 'data' row, calling a function # according to column_defs table val = self._get_value(node.handle, col, node.secondary) - #GTK 3 should convert unicode objects automatically, but this - # gives wrong column values, so we convert, so we convert for python 2.7 - if not isinstance(val, str): - return val.encode('utf-8') - else: - return val + #GTK 3 should convert unicode objects automatically, but this + # gives wrong column values, so we convert, so we convert for python 2.7 + if not isinstance(val, str): + return val.encode('utf-8') + else: + return val def _get_value(self, handle, col, secondary=False): """ diff --git a/gramps/gui/widgets/undoableentry.py b/gramps/gui/widgets/undoableentry.py index 1db8f918f..1cb93f44a 100644 --- a/gramps/gui/widgets/undoableentry.py +++ b/gramps/gui/widgets/undoableentry.py @@ -48,7 +48,7 @@ from gi.repository import Gtk # Gramps modules # #------------------------------------------------------------------------- -from gramps.gen.constfunc import conv_to_unicode +from gramps.gen.constfunc import conv_to_unicode, UNITYPE from .undoablebuffer import Stack class UndoableInsertEntry(object): @@ -57,7 +57,9 @@ class UndoableInsertEntry(object): self.offset = position self.text = str(text) #unicode char can have length > 1 as it points in the buffer - charlength = len(conv_to_unicode(text, 'utf-8')) + if not isinstance(text, UNITYPE): + text = conv_to_unicode(text, 'utf-8') + charlength = len(text) self.length = charlength if charlength > 1 or self.text in ("\r", "\n", " "): self.mergeable = False