diff options
Diffstat (limited to 'logilab/common/compat.py')
-rw-r--r-- | logilab/common/compat.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/logilab/common/compat.py b/logilab/common/compat.py index 4ca540b..e601b26 100644 --- a/logilab/common/compat.py +++ b/logilab/common/compat.py @@ -38,18 +38,25 @@ from typing import Union # not used here, but imported to preserve API import builtins + def str_to_bytes(string): return str.encode(string) + + # we have to ignore the encoding in py3k to be able to write a string into a # TextIOWrapper or like object (which expect an unicode string) def str_encode(string: Union[int, str], encoding: str) -> str: return str(string) + # See also http://bugs.python.org/issue11776 if sys.version_info[0] == 3: + def method_type(callable, instance, klass): # api change. klass is no more considered return types.MethodType(callable, instance) + + else: # alias types otherwise method_type = types.MethodType @@ -57,6 +64,7 @@ else: # Pythons 2 and 3 differ on where to get StringIO if sys.version_info < (3, 0): from cStringIO import StringIO + FileIO = file BytesIO = StringIO reload = reload |