-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from dyus/master
add support for python3.10
- Loading branch information
Showing
11 changed files
with
123 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Compatibility between Python versions | ||
""" | ||
from collections import namedtuple | ||
import inspect | ||
import sys | ||
import six | ||
|
||
|
||
PY3 = six.PY3 | ||
PY34 = sys.version_info[0:2] == (3, 4) | ||
PY35 = sys.version_info[0:2] >= (3, 5) | ||
from inspect import Parameter | ||
|
||
|
||
def force_text(obj, encoding='utf-8'): | ||
if isinstance(obj, six.text_type): | ||
if isinstance(obj, str): | ||
return obj | ||
elif not isinstance(obj, six.binary_type): | ||
return six.text_type(obj) | ||
elif not isinstance(obj, bytes): | ||
return str(obj) | ||
|
||
try: | ||
return six.text_type(obj, encoding=encoding) | ||
return str(obj, encoding=encoding) | ||
except UnicodeDecodeError: | ||
return obj.decode(encoding) | ||
|
||
|
||
def force_binary(obj, encoding='utf-8'): | ||
if isinstance(obj, six.binary_type): | ||
if isinstance(obj, bytes): | ||
return obj | ||
elif not isinstance(obj, six.text_type): | ||
return six.binary_type(obj) | ||
elif not isinstance(obj, str): | ||
return bytes(obj) | ||
|
||
try: | ||
if PY3: | ||
return six.binary_type(obj, encoding=encoding) | ||
return six.binary_type(obj) | ||
return bytes(obj, encoding=encoding) | ||
except UnicodeEncodeError: | ||
return obj.encode(encoding) | ||
|
||
|
||
if PY3: | ||
ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults') | ||
from inspect import Parameter | ||
ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults') | ||
|
||
|
||
def getargspec(func): | ||
signature = inspect.signature(func) | ||
def getargspec(func): | ||
signature = inspect.signature(func) | ||
|
||
args = [] | ||
varargs = None | ||
keywords = None | ||
defaults = [] | ||
args = [] | ||
varargs = None | ||
keywords = None | ||
defaults = [] | ||
|
||
for param in signature.parameters.values(): # type: Parameter | ||
if param.kind == Parameter.VAR_POSITIONAL: | ||
varargs = param.name | ||
elif param.kind in ( | ||
Parameter.POSITIONAL_ONLY, | ||
Parameter.KEYWORD_ONLY, | ||
Parameter.POSITIONAL_OR_KEYWORD): | ||
args.append(param.name) | ||
elif param.kind == Parameter.VAR_KEYWORD: | ||
keywords = param.name | ||
for param in signature.parameters.values(): # type: Parameter | ||
if param.kind == Parameter.VAR_POSITIONAL: | ||
varargs = param.name | ||
elif param.kind in ( | ||
Parameter.POSITIONAL_ONLY, | ||
Parameter.KEYWORD_ONLY, | ||
Parameter.POSITIONAL_OR_KEYWORD): | ||
args.append(param.name) | ||
elif param.kind == Parameter.VAR_KEYWORD: | ||
keywords = param.name | ||
|
||
# noinspection PyProtectedMember | ||
if param.default is not inspect._empty: | ||
defaults.append(param.default) | ||
# noinspection PyProtectedMember | ||
if param.default is not inspect._empty: | ||
defaults.append(param.default) | ||
|
||
return ArgSpec(args, varargs, keywords, tuple(defaults)) | ||
else: | ||
def getargspec(func): | ||
return inspect.getargspec(func) | ||
return ArgSpec(args, varargs, keywords, tuple(defaults)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.