Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 5416:56c9bcdea47f
Python 3 preparation: unicode.
This patch introduces roundup/anypy/strings.py, which has a comment
explaining the string representations generally used and common
functions to handle the required conversions. Places in the code that
explicitly reference the "unicode" type / built-in function are
generally changed to use the new functions (or, in a few places where
those new functions don't seem to fit well, other approaches such as
references to type(u'') or use of the codecs module). This patch does
not generally attempt to address text conversions in any places not
currently referencing the "unicode" type (although
scripts/import_sf.py is made to use binary I/O in places as fixing the
"unicode" reference didn't seem coherent otherwise).
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 09:05:58 +0000 |
| parents | 3fa026621f69 |
| children | 55f09ca366c4 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Wed Jul 25 00:40:26 2018 +0000 +++ b/roundup/cgi/templating.py Wed Jul 25 09:05:58 2018 +0000 @@ -29,6 +29,7 @@ from roundup import hyperdb, date, support from roundup import i18n from roundup.i18n import _ +from roundup.anypy.strings import is_us, us2s, s2u, u2s from .KeywordsExpr import render_keywords_expression_editor @@ -1774,7 +1775,7 @@ return self.plain(escape=1) value = self._value - if isinstance(value, str) or isinstance(value, unicode): + if is_us(value): value = value.strip().lower() in ('checked', 'yes', 'true', 'on', '1') @@ -1827,8 +1828,7 @@ anonymous=0, offset=None): HTMLProperty.__init__(self, client, classname, nodeid, prop, name, value, anonymous=anonymous) - if self._value and not (isinstance(self._value, str) or - isinstance(self._value, unicode)): + if self._value and not is_us(self._value): self._value.setTranslator(self._client.translator) self._offset = offset if self._offset is None : @@ -1910,9 +1910,9 @@ raise ValueError(self._('default value for ' 'DateHTMLProperty must be either DateHTMLProperty ' 'or string date representation.')) - elif isinstance(value, str) or isinstance(value, unicode): + elif is_us(value): # most likely erroneous input to be passed back to user - if isinstance(value, unicode): value = value.encode('utf8') + value = us2s(value) s = self.input(name=self._formname, value=value, size=size, **kwargs) if popcal: @@ -1923,7 +1923,7 @@ if raw_value is None: value = '' - elif isinstance(raw_value, str) or isinstance(raw_value, unicode): + elif is_us(raw_value): if format is self._marker: value = raw_value else: @@ -2012,7 +2012,7 @@ anonymous=0): HTMLProperty.__init__(self, client, classname, nodeid, prop, name, value, anonymous) - if self._value and not isinstance(self._value, (str, unicode)): + if self._value and not is_us(self._value): self._value.setTranslator(self._client.translator) def plain(self, escape=0): @@ -2967,9 +2967,9 @@ klass = self.client.db.getclass(self.classname) if self.search_text: matches = self.client.db.indexer.search( - [w.upper().encode("utf-8", "replace") for w in re.findall( + [u2s(w.upper()) for w in re.findall( r'(?u)\b\w{2,25}\b', - unicode(self.search_text, "utf-8", "replace") + s2u(self.search_text, "replace") )], klass) else: matches = None
