diff --git a/gramps/cli/clidbman.py b/gramps/cli/clidbman.py index 054379973..12889815f 100644 --- a/gramps/cli/clidbman.py +++ b/gramps/cli/clidbman.py @@ -466,7 +466,7 @@ def find_next_db_name(name_list): while True: title = "%s %d" % (DEFAULT_TITLE, i) if title not in name_list: - return title + return conv_to_unicode(title) i += 1 def find_next_db_dir(): diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index a8185383e..b60d85737 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -55,10 +55,10 @@ WINDOWS = ["Windows", "win32"] #python 2 and 3 support, use correct conversion to unicode if sys.version_info[0] < 3: - def conv_to_unicode(x, y): + def conv_to_unicode(x, y=None): if isinstance(x, unicode): return x - return unicode(x, y) + return unicode(x, y) if y else unicode(x) conv_to_unicode_direct = unicode STRTYPE = basestring diff --git a/gramps/gen/filters/_filterlist.py b/gramps/gen/filters/_filterlist.py index b4f9171a4..6469d958d 100644 --- a/gramps/gen/filters/_filterlist.py +++ b/gramps/gen/filters/_filterlist.py @@ -31,6 +31,7 @@ from xml.sax import make_parser, SAXParseException import os import sys import collections +import io #------------------------------------------------------------------------- # @@ -108,7 +109,7 @@ class FilterList(object): if os.path.isfile(self.file): parser = make_parser() parser.setContentHandler(FilterParser(self)) - the_file = open(self.file) + the_file = io.open(self.file, 'r', encoding='utf8') parser.parse(the_file) the_file.close() except (IOError, OSError): @@ -125,7 +126,7 @@ class FilterList(object): return l.replace('"', '"') def save(self): - f = open(self.file.encode(glocale.getfilesystemencoding()), 'w') + f = io.open(self.file, 'w', encoding='utf8') f.write("\n") f.write('\n') for namespace in self.filter_namespaces: diff --git a/gramps/gui/dbman.py b/gramps/gui/dbman.py index e7e8986ed..b6dd586f2 100644 --- a/gramps/gui/dbman.py +++ b/gramps/gui/dbman.py @@ -443,6 +443,7 @@ class DbManager(CLIDbManager): #path is a string, convert to TreePath first path = Gtk.TreePath(path=path) if len(new_text) > 0: + new_text = conv_to_unicode(new_text, 'utf8') node = self.model.get_iter(path) old_text = self.model.get_value(node, NAME_COL) if not old_text.strip() == new_text.strip(): diff --git a/gramps/gui/editors/displaytabs/gallerytab.py b/gramps/gui/editors/displaytabs/gallerytab.py index e39c95fcd..efd2c1cb1 100644 --- a/gramps/gui/editors/displaytabs/gallerytab.py +++ b/gramps/gui/editors/displaytabs/gallerytab.py @@ -526,19 +526,16 @@ class GalleryTab(ButtonTab, DbGUIElement): d = fix_encoding(file.replace('\0',' ').strip()) protocol, site, mfile, j, k, l = urlparse(d) if protocol == "file": - name = fix_encoding(mfile) - name = cuni(url2pathname( - name.encode(glocale.getfilesystemencoding()))) - mime = get_type(name) + mime = get_type(mfile) if not is_valid_type(mime): return photo = MediaObject() self.uistate.set_busy_cursor(True) - photo.set_checksum(create_checksum(name)) + photo.set_checksum(create_checksum(mfile)) self.uistate.set_busy_cursor(False) base_dir = cuni(media_path(self.dbstate.db)) if os.path.exists(base_dir): - name = relative_path(name, base_dir) + name = relative_path(mfile, base_dir) photo.set_path(name) photo.set_mime_type(mime) basename = os.path.basename(name) diff --git a/gramps/gui/viewmanager.py b/gramps/gui/viewmanager.py index 19e36c9d8..757cf2c29 100644 --- a/gramps/gui/viewmanager.py +++ b/gramps/gui/viewmanager.py @@ -1302,13 +1302,10 @@ class ViewManager(CLIManager): basefile = file_entry.get_text() basefile = basefile.replace("/", r"-") filename = os.path.join(path_entry.get_text(), basefile) - if sys.version_info[0] < 3: - filename = filename.encode(glocale.getfilesystemencoding()) if os.path.exists(filename): - sfilename = get_unicode_path_from_env_var(filename) question = QuestionDialog2( _("Backup file already exists! Overwrite?"), - _("The file '%s' exists.") % sfilename, + _("The file '%s' exists.") % filename, _("Proceed and overwrite"), _("Cancel the backup")) yes_no = question.run() diff --git a/gramps/plugins/docgen/cairodoc.py b/gramps/plugins/docgen/cairodoc.py index 04913ed4a..f5f501420 100644 --- a/gramps/plugins/docgen/cairodoc.py +++ b/gramps/plugins/docgen/cairodoc.py @@ -96,8 +96,6 @@ class CairoDocgen(libcairodoc.CairoDoc): # create cairo context and pango layout filename = self._backend.filename - if sys.version_info[0] < 3: - filename = self._backend.filename.encode(glocale.getfilesystemencoding()) try: surface = self.create_cairo_surface(filename, paper_width, paper_height) except IOError as msg: diff --git a/gramps/plugins/lib/maps/geography.py b/gramps/plugins/lib/maps/geography.py index 599311007..2f4541092 100644 --- a/gramps/plugins/lib/maps/geography.py +++ b/gramps/plugins/lib/maps/geography.py @@ -154,16 +154,10 @@ class GeoGraphyView(OsmGps, NavigationView): self.geo_mainmap = None path = os.path.join(IMAGE_DIR, "48x48", ('gramps-geo-mainmap' + '.png' )) - pathu = path - if sys.version_info[0] < 3: - pathu = path.encode(glocale.getfilesystemencoding()) - self.geo_mainmap = cairo.ImageSurface.create_from_png(pathu) + self.geo_mainmap = cairo.ImageSurface.create_from_png(path) path = os.path.join(IMAGE_DIR, "48x48", ('gramps-geo-altmap' + '.png' )) - pathu = path - if sys.version_info[0] < 3: - pathu = path.encode(glocale.getfilesystemencoding()) - self.geo_altmap = cairo.ImageSurface.create_from_png(pathu) + self.geo_altmap = cairo.ImageSurface.create_from_png(path) if ( config.get('geography.map_service') in ( constants.OPENSTREETMAP, constants.MAPS_FOR_FREE, @@ -179,10 +173,7 @@ class GeoGraphyView(OsmGps, NavigationView): EventType.MARRIAGE ): path = os.path.join(IMAGE_DIR, "48x48", (constants.ICONS.get(int(ident), default_image) + '.png' )) - pathu = path - if sys.version_info[0] < 3: - pathu = path.encode(glocale.getfilesystemencoding()) - self.geo_othermap[ident] = cairo.ImageSurface.create_from_png(pathu) + self.geo_othermap[ident] = cairo.ImageSurface.create_from_png(path) def add_bookmark(self, menu, handle): if handle: diff --git a/gramps/plugins/view/mediaview.py b/gramps/plugins/view/mediaview.py index 220fda2e8..5f4715974 100644 --- a/gramps/plugins/view/mediaview.py +++ b/gramps/plugins/view/mediaview.py @@ -190,11 +190,7 @@ class MediaView(ListView): file.replace('\0',' ').replace("\r", " ").strip()) protocol, site, mfile, j, k, l = urlparse(clean_string) if protocol == "file": - if sys.version_info[0] < 3: - name = cuni(url2pathname( - mfile.encode(glocale.getfilesystemencoding()))) - else: - name = cuni(url2pathname(mfile)) + name = mfile mime = get_type(name) if not is_valid_type(mime): return diff --git a/gramps/plugins/view/pedigreeview.py b/gramps/plugins/view/pedigreeview.py index 5943abc9d..61661f888 100644 --- a/gramps/plugins/view/pedigreeview.py +++ b/gramps/plugins/view/pedigreeview.py @@ -208,8 +208,6 @@ class PersonBoxWidgetCairo(_PersonWidgetBase): self.img_surf = None if image: image_path = self.get_image(dbstate, person) - if sys.version_info[0] < 3 and isinstance(image_path, STRTYPE): - image_path = image_path.encode(glocale.getfilesystemencoding()) if image_path and os.path.exists(image_path): self.img_surf = cairo.ImageSurface.create_from_png(image_path)