Remove remaining conv_to_unicode calls

This commit is contained in:
Nick Hall 2015-12-05 16:52:41 +00:00
parent 7f3cdb6d71
commit 8dffe6639b
10 changed files with 18 additions and 35 deletions

View File

@ -68,7 +68,6 @@ LOG = logging.getLogger(".gramps.gen")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..const import ARABIC_COMMA, ARABIC_SEMICOLON, GRAMPS_LOCALE as glocale from ..const import ARABIC_COMMA, ARABIC_SEMICOLON, GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from ..constfunc import conv_to_unicode
from ..lib.name import Name from ..lib.name import Name
from ..lib.nameorigintype import NameOriginType from ..lib.nameorigintype import NameOriginType
@ -1005,7 +1004,6 @@ class NameDisplay(object):
d_keys.sort(key=_make_cmp_key, reverse=True) # reverse on length and by ikeyword d_keys.sort(key=_make_cmp_key, reverse=True) # reverse on length and by ikeyword
for (code, ikeyword) in d_keys: for (code, ikeyword) in d_keys:
exp, keyword, ikeyword = d[code] exp, keyword, ikeyword = d[code]
#ikeyword = unicode(ikeyword, "utf8")
format_str = format_str.replace(ikeyword, "%"+ code) format_str = format_str.replace(ikeyword, "%"+ code)
format_str = format_str.replace(ikeyword.title(), "%"+ code) format_str = format_str.replace(ikeyword.title(), "%"+ code)
format_str = format_str.replace(ikeyword.upper(), "%"+ code.upper()) format_str = format_str.replace(ikeyword.upper(), "%"+ code.upper())
@ -1022,8 +1020,6 @@ class NameDisplay(object):
# if in double quotes, just use % codes # if in double quotes, just use % codes
for (code, keyword) in d_keys: for (code, keyword) in d_keys:
exp, keyword, ikeyword = d[code] exp, keyword, ikeyword = d[code]
if not isinstance(keyword, str):
keyword = conv_to_unicode(keyword, "utf-8")
format_str = format_str.replace(keyword, "%"+ code) format_str = format_str.replace(keyword, "%"+ code)
format_str = format_str.replace(keyword.title(), "%"+ code) format_str = format_str.replace(keyword.title(), "%"+ code)
format_str = format_str.replace(keyword.upper(), "%"+ code.upper()) format_str = format_str.replace(keyword.upper(), "%"+ code.upper())

View File

@ -53,7 +53,7 @@ from ..utils.configmanager import safe_eval
from ..config import config from ..config import config
from ..const import GRAMPS_LOCALE as glocale from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from ..constfunc import conv_to_unicode, mac from ..constfunc import mac
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -382,9 +382,8 @@ def load_addon_file(path, callback=None):
gpr_files = set([os.path.split(os.path.join(USER_PLUGINS, name))[0] gpr_files = set([os.path.split(os.path.join(USER_PLUGINS, name))[0]
for name in good_gpr]) for name in good_gpr])
for gpr_file in gpr_files: for gpr_file in gpr_files:
u_gpr_file = conv_to_unicode(gpr_file)
if callback: if callback:
callback(" " + (_("Registered '%s'") % u_gpr_file) + "\n") callback(" " + (_("Registered '%s'") % gpr_file) + "\n")
registered_count += 1 registered_count += 1
file_obj.close() file_obj.close()
if registered_count: if registered_count:

View File

@ -43,7 +43,6 @@ import tempfile
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ..constfunc import conv_to_unicode
from ..const import GRAMPS_LOCALE as glocale from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@ -274,7 +273,6 @@ def resize_to_jpeg_buffer(source, size, crop=None):
scaled = img.scale_simple(int(size[0]), int(size[1]), GdkPixbuf.InterpType.BILINEAR) scaled = img.scale_simple(int(size[0]), int(size[1]), GdkPixbuf.InterpType.BILINEAR)
os.close(filed) os.close(filed)
dest = conv_to_unicode(dest, None)
scaled.savev(dest, "jpeg", "", "") scaled.savev(dest, "jpeg", "", "")
ofile = open(dest, mode='rb') ofile = open(dest, mode='rb')
data = ofile.read() data = ofile.read()

View File

@ -76,8 +76,7 @@ from gramps.gen.utils.cast import conv_dbstr_to_unicode
from gramps.gen.utils.id import create_id from gramps.gen.utils.id import create_id
from gramps.gen.updatecallback import UpdateCallback from gramps.gen.updatecallback import UpdateCallback
from gramps.gen.errors import DbError from gramps.gen.errors import DbError
from gramps.gen.constfunc import (win, conv_to_unicode, handle2internal, from gramps.gen.constfunc import win, handle2internal, get_env_var
get_env_var)
from gramps.gen.const import HOME_DIR, GRAMPS_LOCALE as glocale from gramps.gen.const import HOME_DIR, GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
@ -1809,8 +1808,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
""" """
if batch_transaction: if batch_transaction:
return return
name = conv_to_unicode(find_surname_name(person.handle, name = find_surname_name(person.handle,
person.get_primary_name().serialize()), 'utf-8') person.get_primary_name().serialize())
i = bisect.bisect(self.surname_list, name) i = bisect.bisect(self.surname_list, name)
if 0 < i <= len(self.surname_list): if 0 < i <= len(self.surname_list):
if self.surname_list[i-1] != name: if self.surname_list[i-1] != name:

View File

@ -61,7 +61,7 @@ from gramps.gen.lib import Date, Person
from gramps.gen.updatecallback import UpdateCallback from gramps.gen.updatecallback import UpdateCallback
from gramps.gen.db.exceptions import DbWriteFailure from gramps.gen.db.exceptions import DbWriteFailure
from gramps.version import VERSION from gramps.version import VERSION
from gramps.gen.constfunc import win, conv_to_unicode from gramps.gen.constfunc import win
from gramps.gui.plug.export import WriterOptionBox from gramps.gui.plug.export import WriterOptionBox
import gramps.plugins.lib.libgrampsxml as libgrampsxml import gramps.plugins.lib.libgrampsxml as libgrampsxml
@ -438,11 +438,7 @@ class GrampsXmlWriter(UpdateCallback):
self.g.write(' priority="%d"' % tag.get_priority()) self.g.write(' priority="%d"' % tag.get_priority())
self.g.write('/>\n') self.g.write('/>\n')
def fix(self,line): def fix(self, line):
try:
l = str(line)
except:
l = conv_to_unicode(str(line), errors='replace')
l = l.strip().translate(strip_dict) l = l.strip().translate(strip_dict)
return escxml(l) return escxml(l)

View File

@ -48,7 +48,6 @@ from functools import partial
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.constfunc import conv_to_unicode
from gramps.gen.plug.menu import (BooleanOption, EnumeratedListOption, from gramps.gen.plug.menu import (BooleanOption, EnumeratedListOption,
FilterOption, PersonOption, ColorOption) FilterOption, PersonOption, ColorOption)
from gramps.gen.plug.report import Report from gramps.gen.plug.report import Report
@ -193,8 +192,7 @@ class RelGraphReport(Report):
children children
""" """
# Hash people in a dictionary for faster inclusion checking # Hash people in a dictionary for faster inclusion checking
person_dict = dict([conv_to_unicode(handle, 'utf-8'), 1] person_dict = dict([handle, 1] for handle in self.person_handles)
for handle in self.person_handles)
for person_handle in self.person_handles: for person_handle in self.person_handles:
person = self.database.get_person_from_handle(person_handle) person = self.database.get_person_from_handle(person_handle)
@ -204,7 +202,7 @@ class RelGraphReport(Report):
father_handle = family.get_father_handle() father_handle = family.get_father_handle()
mother_handle = family.get_mother_handle() mother_handle = family.get_mother_handle()
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
if child_ref.ref == conv_to_unicode(person_handle, 'utf-8'): if child_ref.ref == person_handle:
frel = child_ref.frel frel = child_ref.frel
mrel = child_ref.mrel mrel = child_ref.mrel
break break
@ -265,7 +263,7 @@ class RelGraphReport(Report):
(shape, style, color, fill) = self.get_gender_style(person) (shape, style, color, fill) = self.get_gender_style(person)
url = "" url = ""
if self.includeurl: if self.includeurl:
h = conv_to_unicode(person_handle, 'utf-8') h = person_handle
dirpath = "ppl/%s/%s" % (h[-1], h[-2]) dirpath = "ppl/%s/%s" % (h[-1], h[-2])
dirpath = dirpath.lower() dirpath = dirpath.lower()
url = "%s/%s.html" % (dirpath, h) url = "%s/%s.html" % (dirpath, h)

View File

@ -53,7 +53,6 @@ from gramps.gen.lib import (Attribute, AttributeType, ChildRef, Citation,
Family, FamilyRelType, Name, NameType, Note, Person, PersonRef, Family, FamilyRelType, Name, NameType, Note, Person, PersonRef,
Place, Source, LdsOrd) Place, Source, LdsOrd)
from gramps.gen.db import DbTxn from gramps.gen.db import DbTxn
from gramps.gen.constfunc import conv_to_unicode
from html.entities import name2codepoint from html.entities import name2codepoint
_date_parse = re.compile('([kmes~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?') _date_parse = re.compile('([kmes~?<>]+)?([0-9/]+)([J|H|F])?(\.\.)?([0-9/]+)?([J|H|F])?')
@ -180,7 +179,7 @@ class GeneWebParser(object):
line = self.f.readline() line = self.f.readline()
try: try:
line = conv_to_unicode(line) line = line.decode('utf-8')
except GrampsImportError as err: except GrampsImportError as err:
self.errmsg(str(err)) self.errmsg(str(err))
@ -188,7 +187,7 @@ class GeneWebParser(object):
try: try:
line = str(line.strip()) line = str(line.strip())
except UnicodeDecodeError: except UnicodeDecodeError:
line = conv_to_unicode(line.strip(), self.encoding) line = line.decode(self.encoding).strip()
else: else:
line = None line = None
return line return line

View File

@ -44,7 +44,6 @@ import re
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.constfunc import conv_to_unicode
from gramps.gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, ParagraphStyle, from gramps.gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, ParagraphStyle,
TableCellStyle, SOLID, FONT_SANS_SERIF, FONT_SERIF, TableCellStyle, SOLID, FONT_SANS_SERIF, FONT_SERIF,
FONT_MONOSPACE, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT) FONT_MONOSPACE, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT)
@ -501,7 +500,7 @@ class GtkDocParagraph(GtkDocBaseElement):
Internal method to allow for splitting of paragraphs Internal method to allow for splitting of paragraphs
""" """
if not isinstance(plaintext, str): if not isinstance(plaintext, str):
self._plaintext = conv_to_unicode(plaintext, 'utf-8') self._plaintext = plaintext.decode('utf-8')
else: else:
self._plaintext = plaintext self._plaintext = plaintext

View File

@ -71,7 +71,7 @@ from gramps.gui.plug import tool
from gramps.gui.dialog import OkDialog, MissingMediaDialog from gramps.gui.dialog import OkDialog, MissingMediaDialog
from gramps.gen.display.name import displayer as _nd from gramps.gen.display.name import displayer as _nd
from gramps.gui.glade import Glade from gramps.gui.glade import Glade
from gramps.gen.constfunc import handle2internal, conv_to_unicode from gramps.gen.constfunc import handle2internal
# table for handling control chars in notes. # table for handling control chars in notes.
# All except 09, 0A, 0D are replaced with space. # All except 09, 0A, 0D are replaced with space.
@ -356,17 +356,17 @@ class CheckIntegrity(object):
data = self.db.media_map[bhandle] data = self.db.media_map[bhandle]
if not isinstance(data[2], str) or not isinstance(data[4], str): if not isinstance(data[2], str) or not isinstance(data[4], str):
obj = self.db.get_object_from_handle(handle) obj = self.db.get_object_from_handle(handle)
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], str): if not isinstance(data[2], str):
obj.path = obj.path.decode('utf-8')
logging.warning(' FAIL: encoding error on media object ' logging.warning(' FAIL: encoding error on media object '
'"%(gid)s" path "%(path)s"' % '"%(gid)s" path "%(path)s"' %
{'gid' : obj.gramps_id, 'path' : obj.path}) {'gid' : obj.gramps_id, 'path' : obj.path})
if not isinstance(data[4], str): if not isinstance(data[4], str):
obj.desc = obj.desc.decode('utf-8')
logging.warning(' FAIL: encoding error on media object ' logging.warning(' FAIL: encoding error on media object '
'"%(gid)s" description "%(desc)s"' % '"%(gid)s" description "%(desc)s"' %
{'gid' : obj.gramps_id, 'desc' : obj.desc}) {'gid' : obj.gramps_id, 'desc' : obj.desc})
self.db.commit_media_object(obj, self.trans)
error_count += 1 error_count += 1
# Once we are here, fix the mime string if not str # Once we are here, fix the mime string if not str
if not isinstance(data[3], str): if not isinstance(data[3], str):

View File

@ -46,7 +46,6 @@ from django.db import transaction
import gramps.webapp.grampsdb.models as models import gramps.webapp.grampsdb.models as models
from gramps.gen.lib import Name from gramps.gen.lib import Name
from gramps.gen.utils.id import create_id from gramps.gen.utils.id import create_id
from gramps.gen.constfunc import conv_to_unicode
# To get a django person from a django database: # To get a django person from a django database:
# djperson = dji.Person.get(handle='djhgsdh324hjg234hj24') # djperson = dji.Person.get(handle='djhgsdh324hjg234hj24')
@ -454,7 +453,7 @@ class DjangoInterface(object):
date = self.get_date(media) date = self.get_date(media)
return (str(media.handle), return (str(media.handle),
media.gramps_id, media.gramps_id,
conv_to_unicode(media.path, None), media.path,
str(media.mime), str(media.mime),
str(media.desc), str(media.desc),
media.checksum, media.checksum,