Merge pull request #1756 from leonelcamara/i1752
Make _compat accept ducks
This commit is contained in:
+3
-3
@@ -63,7 +63,7 @@ if PY2:
|
|||||||
return None
|
return None
|
||||||
if isinstance(obj, (bytes, bytearray, buffer)):
|
if isinstance(obj, (bytes, bytearray, buffer)):
|
||||||
return bytes(obj)
|
return bytes(obj)
|
||||||
if isinstance(obj, unicode):
|
if hasattr(obj, 'encode'):
|
||||||
return obj.encode(charset, errors)
|
return obj.encode(charset, errors)
|
||||||
raise TypeError('Expected bytes')
|
raise TypeError('Expected bytes')
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ else:
|
|||||||
return None
|
return None
|
||||||
if isinstance(obj, (bytes, bytearray, memoryview)):
|
if isinstance(obj, (bytes, bytearray, memoryview)):
|
||||||
return bytes(obj)
|
return bytes(obj)
|
||||||
if isinstance(obj, str):
|
if hasattr(obj, 'encode'):
|
||||||
return obj.encode(charset, errors)
|
return obj.encode(charset, errors)
|
||||||
raise TypeError('Expected bytes')
|
raise TypeError('Expected bytes')
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ def with_metaclass(meta, *bases):
|
|||||||
def to_unicode(obj, charset='utf-8', errors='strict'):
|
def to_unicode(obj, charset='utf-8', errors='strict'):
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return None
|
return None
|
||||||
if not isinstance(obj, bytes):
|
if not hasattr(obj, 'decode'):
|
||||||
return text_type(obj)
|
return text_type(obj)
|
||||||
return obj.decode(charset, errors)
|
return obj.decode(charset, errors)
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -18,10 +18,11 @@ import pkgutil
|
|||||||
import logging
|
import logging
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
from gluon.utf8 import Utf8
|
|
||||||
from gluon.utils import local_html_escape
|
from gluon.utils import local_html_escape
|
||||||
|
|
||||||
from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode, to_bytes, iteritems, to_native, pjoin
|
from gluon._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode, to_bytes, iteritems, to_native, pjoin
|
||||||
|
|
||||||
from pydal.contrib.portalocker import read_locked, LockedFile
|
from pydal.contrib.portalocker import read_locked, LockedFile
|
||||||
|
|
||||||
from gluon.fileutils import listdir
|
from gluon.fileutils import listdir
|
||||||
@@ -49,8 +50,10 @@ DEFAULT_CONSTRUCT_PLURAL_FORM = lambda word, plural_id: word
|
|||||||
|
|
||||||
if PY2:
|
if PY2:
|
||||||
NUMBERS = (int, long, float)
|
NUMBERS = (int, long, float)
|
||||||
|
from gluon.utf8 import Utf8
|
||||||
else:
|
else:
|
||||||
NUMBERS = (int, float)
|
NUMBERS = (int, float)
|
||||||
|
Utf8 = str
|
||||||
|
|
||||||
# pattern to find T(blah blah blah) expressions
|
# pattern to find T(blah blah blah) expressions
|
||||||
PY_STRING_LITERAL_RE = r'(?<=[^\w]T\()(?P<name>'\
|
PY_STRING_LITERAL_RE = r'(?<=[^\w]T\()(?P<name>'\
|
||||||
|
|||||||
Reference in New Issue
Block a user