Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #243 from cclauss/patch-2
Browse files Browse the repository at this point in the history
Simplify native_to_unicode() & unicode_to_native()
  • Loading branch information
lukaszkaiser authored Aug 25, 2017
2 parents f616cd0 + 33e798a commit 860fe0a
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions tensor2tensor/data_generators/text_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,13 @@
_ESCAPE_CHARS = set(u"\\_u;0123456789")


def native_to_unicode_py2(s):
"""Python 2: transform native string to Unicode."""
return s if isinstance(s, unicode) else s.decode("utf8")


# Conversion between Unicode and UTF-8, if required (on Python2)
if six.PY2:
native_to_unicode = native_to_unicode_py2
unicode_to_native = lambda s: s.encode("utf-8")
def native_to_unicode(s): return s if isinstance(s, unicode) else s.decode("utf8") # noqa: F821
def unicode_to_native(s): return s.encode("utf-8")
else:
# No conversion required on Python3
native_to_unicode = lambda s: s
unicode_to_native = lambda s: s
# No conversion required on Python >= 3
def native_to_unicode(s): return s
def unicode_to_native(s): return s


class TextEncoder(object):
Expand Down

0 comments on commit 860fe0a

Please sign in to comment.