Browse Source

Remove old unicode helpers

tags/nilmdb-2.0.0
Jim Paris 2 years ago
parent
commit
1c005518d8
2 changed files with 0 additions and 30 deletions
  1. +0
    -1
      nilmdb/utils/__init__.py
  2. +0
    -29
      nilmdb/utils/unicode.py

+ 0
- 1
nilmdb/utils/__init__.py View File

@@ -14,4 +14,3 @@ import nilmdb.utils.iterator
import nilmdb.utils.interval
import nilmdb.utils.lock
import nilmdb.utils.sort
import nilmdb.utils.unicode

+ 0
- 29
nilmdb/utils/unicode.py View File

@@ -1,29 +0,0 @@
import sys

if sys.version_info[0] >= 3: # pragma: no cover (future Python3 compat)
text_type = str
else:
text_type = str

def encode(u):
"""Try to encode something from Unicode to a string using the
default encoding. If it fails, try encoding as UTF-8."""
if not isinstance(u, text_type):
return u
try:
return u.encode()
except UnicodeEncodeError:
return u.encode("utf-8")

def decode(s):
"""Try to decode someting from string to Unicode using the
default encoding. If it fails, try decoding as UTF-8."""
if isinstance(s, text_type):
return s
try:
return s.decode()
except UnicodeDecodeError:
try:
return s.decode("utf-8")
except UnicodeDecodeError:
return s # best we can do

Loading…
Cancel
Save