From 8c18eae777fa9885c9c3cc45cd6a4fb23d277ae0 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 14 Mar 2015 21:49:45 +0000 Subject: [PATCH] Replace conv_to_unicode_direct with str --- gramps/cli/plug/__init__.py | 6 +++--- gramps/gen/constfunc.py | 3 +-- gramps/gen/filters/rules/_rule.py | 8 +++----- gramps/gen/filters/rules/person/_probablyalive.py | 3 +-- gramps/gen/simple/_simpletable.py | 10 +++++----- gramps/gen/soundex.py | 4 +--- gramps/gen/utils/cast.py | 2 +- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/gramps/cli/plug/__init__.py b/gramps/cli/plug/__init__.py index 23b981c64..28aa5c041 100644 --- a/gramps/cli/plug/__init__.py +++ b/gramps/cli/plug/__init__.py @@ -59,7 +59,7 @@ from gramps.gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, from gramps.gen.plug.report._paper import paper_sizes from gramps.gen.const import USER_HOME from gramps.gen.dbstate import DbState -from gramps.gen.constfunc import STRTYPE, conv_to_unicode_direct +from gramps.gen.constfunc import STRTYPE from ..grampscli import CLIManager from ..user import User from gramps.gen.const import GRAMPS_LOCALE as glocale @@ -81,9 +81,9 @@ def _convert_str_to_match_type(str_val, type_val): if ( str_val.startswith("'") and str_val.endswith("'") ) or \ ( str_val.startswith('"') and str_val.endswith('"') ): # Remove enclosing quotes - return conv_to_unicode_direct(str_val[1:-1]) + return str(str_val[1:-1]) else: - return conv_to_unicode_direct(str_val) + return str(str_val) elif ret_type == int: if str_val.isdigit(): diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index fae5aa75c..f5fc11d02 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -51,10 +51,9 @@ WINDOWS = ["Windows", "win32"] # #------------------------------------------------------------------------- -conv_to_unicode_direct = str STRTYPE = str UNITYPE = str -cuni = conv_to_unicode_direct +cuni = str def conv_to_unicode(x, y='utf8'): return x if x is None or isinstance(x, UNITYPE) else cuni(x, y) if y else cuni(x) diff --git a/gramps/gen/filters/rules/_rule.py b/gramps/gen/filters/rules/_rule.py index 8584a461a..bdf8f8a3a 100644 --- a/gramps/gen/filters/rules/_rule.py +++ b/gramps/gen/filters/rules/_rule.py @@ -40,8 +40,6 @@ import re import logging LOG = logging.getLogger(".") -from ...constfunc import conv_to_unicode_direct - #------------------------------------------------------------------------- # # Rule @@ -85,7 +83,7 @@ class Rule(object): if self.list[i]: try: self.regex[i] = re.compile( - conv_to_unicode_direct(self.list[i]), + str(self.list[i]), re.I|re.U|re.L) except re.error: self.regex[i] = re.compile('') @@ -152,7 +150,7 @@ class Rule(object): """ # make str_var unicode so that search for ΓΌ works # see issue 3188 - str_var = conv_to_unicode_direct(str_var) + str_var = str(str_var) if self.list[param_index] and \ (str_var.upper().find(self.list[param_index].upper()) == -1): return False @@ -165,7 +163,7 @@ class Rule(object): matches filter element indicated by param_index using a regular expression search. """ - str_var = conv_to_unicode_direct(str_var) + str_var = str(str_var) if (self.list[param_index] and self.regex[param_index].search(str_var) is None): return False diff --git a/gramps/gen/filters/rules/person/_probablyalive.py b/gramps/gen/filters/rules/person/_probablyalive.py index b5f1241d7..0e9ea4390 100644 --- a/gramps/gen/filters/rules/person/_probablyalive.py +++ b/gramps/gen/filters/rules/person/_probablyalive.py @@ -34,7 +34,6 @@ _ = glocale.translation.gettext from ....utils.alive import probably_alive from .. import Rule from ....datehandler import parser -from ....constfunc import conv_to_unicode_direct #------------------------------------------------------------------------- # "People probably alive" @@ -49,7 +48,7 @@ class ProbablyAlive(Rule): def prepare(self,db): try: - self.current_date = parser.parse(conv_to_unicode_direct(self.list[0])) + self.current_date = parser.parse(str(self.list[0])) except: self.current_date = None diff --git a/gramps/gen/simple/_simpletable.py b/gramps/gen/simple/_simpletable.py index 9e313aa9e..4ed6a7d88 100644 --- a/gramps/gen/simple/_simpletable.py +++ b/gramps/gen/simple/_simpletable.py @@ -31,7 +31,7 @@ from ..lib import (Person, Family, Event, Source, Place, Citation, Repository, MediaObject, Note, Date, Span) from ..config import config from ..datehandler import displayer -from ..constfunc import STRTYPE, conv_to_unicode_direct +from ..constfunc import STRTYPE class SimpleTable(object): """ @@ -70,7 +70,7 @@ class SimpleTable(object): """ Set the columns """ - self._columns = [conv_to_unicode_direct(col) for col in cols] + self._columns = [str(col) for col in cols] self._sort_vals = [[] for i in range(len(self._columns))] def row_sort_val(self, col, val): @@ -107,7 +107,7 @@ class SimpleTable(object): else: retval.append(item) elif isinstance(item, (int, float)): - retval.append(conv_to_unicode_direct(item)) + retval.append(str(item)) self.row_sort_val(col, item) elif isinstance(item, bool): retval.append(repr(item)) @@ -166,7 +166,7 @@ class SimpleTable(object): if (self._link_col == col or link is None): link = ('Date', item) elif isinstance(item, Span): - text = conv_to_unicode_direct(item) + text = str(item) retval.append(text) self.row_sort_val(col, item) elif isinstance(item, list): # [text, "PersonList", handle, ...] @@ -239,7 +239,7 @@ class SimpleTable(object): else: doc.start_link("/%s/%s" % (obj_type.lower(), handle)) - doc.write_text(conv_to_unicode_direct(col), 'Normal') + doc.write_text(str(col), 'Normal') if obj_type and handle: doc.stop_link() doc.end_cell() diff --git a/gramps/gen/soundex.py b/gramps/gen/soundex.py index 0221795c7..635995fa3 100644 --- a/gramps/gen/soundex.py +++ b/gramps/gen/soundex.py @@ -38,8 +38,6 @@ IGNORE = "HW~!@#$%^&*()_+=-`[]\|;:'/?.,<>\" \t\f\v" TABLE = bytes.maketrans(b'ABCDEFGIJKLMNOPQRSTUVXYZ', b'012301202245501262301202') -from .constfunc import conv_to_unicode_direct - #------------------------------------------------------------------------- # # soundex - returns the soundex value for the specified string @@ -49,7 +47,7 @@ def soundex(strval): "Return the soundex value to a string argument." strval = unicodedata.normalize('NFKD', - conv_to_unicode_direct(strval.upper().strip())).encode('ASCII', 'ignore') + str(strval.upper().strip())).encode('ASCII', 'ignore') if not strval: return "Z000" strval = strval.decode('ASCII', 'ignore') diff --git a/gramps/gen/utils/cast.py b/gramps/gen/utils/cast.py index c791e8a85..cb3ab30ce 100644 --- a/gramps/gen/utils/cast.py +++ b/gramps/gen/utils/cast.py @@ -41,7 +41,7 @@ LOG = logging.getLogger(".") #------------------------------------------------------------------------- from ..const import GRAMPS_LOCALE as glocale _ = glocale.translation.gettext -from ..constfunc import conv_to_unicode, conv_to_unicode_direct, UNITYPE, STRTYPE +from ..constfunc import conv_to_unicode, UNITYPE, STRTYPE #strings in database are utf-8 conv_dbstr_to_unicode = lambda x: conv_to_unicode(x, 'UTF-8')