Remove gramps.gen.utils.file.fix_encoding()
Yet another overly complicated way to spell conv_to_unicode(). Note that unicode() and str.decode() are alternate spellings of the same function in Py2, and unicode(); note as well that this was used on strings coming from the GUI or the database, not the shell, so that using glocale.encoding was also incorrect.
This commit is contained in:
parent
55610b6f0a
commit
f0ffd6e9b9
@ -186,24 +186,6 @@ def search_for(name):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def fix_encoding(value, errors='strict'):
|
||||
# The errors argument specifies the response when the input string can't be
|
||||
# converted according to the encoding's rules. Legal values for this
|
||||
# argument are 'strict' (raise a UnicodeDecodeError exception), 'replace'
|
||||
# (add U+FFFD, 'REPLACEMENT CHARACTER'), or 'ignore' (just leave the
|
||||
# character out of the Unicode result).
|
||||
if not isinstance(value, UNITYPE):
|
||||
try:
|
||||
return cuni(value)
|
||||
except:
|
||||
codeset = glocale.encoding
|
||||
if sys.version_info[0] < 3:
|
||||
return unicode(value, codeset, errors)
|
||||
else:
|
||||
return value.decode(encoding=codeset, errors=errors)
|
||||
else:
|
||||
return value
|
||||
|
||||
def create_checksum(full_path):
|
||||
"""
|
||||
Create a md5 hash for the given file.
|
||||
|
@ -24,8 +24,6 @@
|
||||
# Python classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
import os
|
||||
import sys
|
||||
if sys.version_info[0] < 3:
|
||||
@ -59,18 +57,19 @@ from gi.repository import GLib
|
||||
from ...utils import is_right_click, open_file_with_default_application
|
||||
from ...dbguielement import DbGUIElement
|
||||
from ...selectors import SelectorFactory
|
||||
from gramps.gen.constfunc import cuni
|
||||
from gramps.gen.constfunc import cuni, win, conv_to_unicode
|
||||
from gramps.gen.lib import MediaObject, MediaRef
|
||||
from gramps.gen.db import DbTxn
|
||||
from gramps.gen.utils.file import (media_path_full, media_path, relative_path,
|
||||
fix_encoding, create_checksum)
|
||||
create_checksum)
|
||||
from ...thumbnails import get_thumbnail_image
|
||||
from gramps.gen.errors import WindowActiveError
|
||||
from gramps.gen.mime import get_type, is_valid_type
|
||||
from ...ddtargets import DdTargets
|
||||
from .buttontab import ButtonTab
|
||||
from gramps.gen.constfunc import win
|
||||
from gramps.gen.const import THUMBSCALE
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
@ -521,7 +520,7 @@ class GalleryTab(ButtonTab, DbGUIElement):
|
||||
else:
|
||||
files = sel_data.get_uris()
|
||||
for file in files:
|
||||
d = fix_encoding(file.replace('\0',' ').strip())
|
||||
d = conv_to_unicode((file.replace('\0',' ').strip()), None)
|
||||
protocol, site, mfile, j, k, l = urlparse(d)
|
||||
if protocol == "file":
|
||||
mime = get_type(mfile)
|
||||
|
@ -69,7 +69,7 @@ from gramps.gen.config import config
|
||||
from gramps.gen.utils.id import create_id
|
||||
from gramps.gen.utils.db import family_name
|
||||
from gramps.gen.utils.unknown import make_unknown
|
||||
from gramps.gen.utils.file import (media_path_full, find_file, fix_encoding)
|
||||
from gramps.gen.utils.file import (media_path_full, find_file)
|
||||
from gramps.gui.managedwindow import ManagedWindow
|
||||
from gramps.gen.utils.file import create_checksum
|
||||
from gramps.gui.plug import tool
|
||||
@ -351,8 +351,8 @@ class CheckIntegrity(object):
|
||||
data = self.db.media_map[bhandle]
|
||||
if not isinstance(data[2], UNITYPE) or not isinstance(data[4], UNITYPE):
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
obj.path = fix_encoding( obj.path, errors='ignore')
|
||||
obj.desc = fix_encoding( obj.desc, errors='ignore')
|
||||
obj.path = conv_to_unicode(obj.path, None)
|
||||
obj.desc = conv_to_unicode(obj.desc, None)
|
||||
self.db.commit_media_object(obj, self.trans)
|
||||
if not isinstance(data[2], UNITYPE):
|
||||
logging.warning(' FAIL: encoding error on media object '
|
||||
|
@ -60,8 +60,8 @@ from gramps.gui.views.listview import ListView, TEXT, MARKUP, ICON
|
||||
from gramps.gui.views.treemodels import MediaModel
|
||||
from gramps.gen.constfunc import win, cuni
|
||||
from gramps.gen.config import config
|
||||
from gramps.gen.utils.file import (media_path, relative_path, media_path_full,
|
||||
fix_encoding, create_checksum)
|
||||
from gramps.gen.utils.file import (media_path, relative_path, media_path_full,
|
||||
create_checksum)
|
||||
from gramps.gen.utils.db import get_media_referents
|
||||
from gramps.gui.views.bookmarks import MediaBookmarks
|
||||
from gramps.gen.mime import get_type, is_valid_type
|
||||
@ -184,8 +184,9 @@ class MediaView(ListView):
|
||||
#modern file managers provide URI_LIST. For Windows split sel_data.data
|
||||
files = sel_data.get_uris()
|
||||
for file in files:
|
||||
clean_string = fix_encoding(
|
||||
file.replace('\0',' ').replace("\r", " ").strip())
|
||||
clean_string = conv_to_unicode(
|
||||
file.replace('\0',' ').replace("\r", " ").strip(),
|
||||
None)
|
||||
protocol, site, mfile, j, k, l = urlparse(clean_string)
|
||||
if protocol == "file":
|
||||
name = mfile
|
||||
|
@ -51,7 +51,7 @@ from django.db import transaction
|
||||
import gramps.webapp.grampsdb.models as models
|
||||
from gramps.gen.lib import Name
|
||||
from gramps.gen.utils.id import create_id
|
||||
from gramps.gen.utils.file import fix_encoding
|
||||
gramps.gen.utils.constfunc import conv_to_unicode
|
||||
|
||||
# To get a django person from a django database:
|
||||
# djperson = dji.Person.get(handle='djhgsdh324hjg234hj24')
|
||||
@ -457,7 +457,7 @@ class DjangoInterface(object):
|
||||
date = self.get_date(media)
|
||||
return (str(media.handle),
|
||||
media.gramps_id,
|
||||
fix_encoding(media.path),
|
||||
conv_to_unicode(media.path, None),
|
||||
str(media.mime),
|
||||
fix_encoding(media.desc),
|
||||
media.checksum,
|
||||
|
Loading…
Reference in New Issue
Block a user