diff --git a/thriftpy2/_compat.py b/thriftpy2/_compat.py index 84d77c9..c886e35 100644 --- a/thriftpy2/_compat.py +++ b/thriftpy2/_compat.py @@ -11,11 +11,9 @@ import platform import sys -from urllib.parse import urlparse -from urllib.request import urlopen +from urllib.parse import urlparse # noqa +from urllib.request import urlopen # noqa -PY3 = sys.version_info[0] == 3 -PY35 = sys.version_info >= (3, 5) PYPY = "__pypy__" in sys.modules UNIX = platform.system() in ("Linux", "Darwin") diff --git a/thriftpy2/parser/parser.py b/thriftpy2/parser/parser.py index 5948d0f..d20081d 100644 --- a/thriftpy2/parser/parser.py +++ b/thriftpy2/parser/parser.py @@ -9,16 +9,15 @@ import collections import os -import sys import types + from ply import lex, yacc -from .lexer import * # noqa -from .exc import ThriftParserError, ThriftGrammarError -from thriftpy2._compat import urlopen, urlparse, PY3 -from ..thrift import gen_init, TType, TPayload, TException -if not PY3: - from io import open +from thriftpy2._compat import urlopen, urlparse + +from ..thrift import TException, TPayload, TType, gen_init +from .exc import ThriftGrammarError, ThriftParserError +from .lexer import * # noqa def p_error(p): @@ -582,11 +581,8 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None, 'with path in protocol \'{}\''.format( url_scheme)) - if PY3: - if isinstance(data, bytes): - data = data.decode(encoding) - else: - data = data.encode(encoding) + if isinstance(data, bytes): + data = data.decode(encoding) if module_name is not None and not module_name.endswith('_thrift'): raise ThriftParserError('thriftpy2 can only generate module with ' diff --git a/thriftpy2/protocol/compact.py b/thriftpy2/protocol/compact.py index 0481119..8823236 100644 --- a/thriftpy2/protocol/compact.py +++ b/thriftpy2/protocol/compact.py @@ -8,12 +8,9 @@ import six -from .exc import TProtocolException +from ..thrift import TException, TType from .base import TProtocolBase -from ..thrift import TException -from ..thrift import TType - -from thriftpy2._compat import PY3 +from .exc import TProtocolException CLEAR = 0 FIELD_WRITE = 1 @@ -66,10 +63,7 @@ def write_varint(trans, n): n = n >> 7 data = array.array('B', out) - if PY3: - trans.write(data.tobytes()) - else: - trans.write(data.tostring()) + trans.write(data.tobytes()) def read_varint(trans): diff --git a/thriftpy2/rpc.py b/thriftpy2/rpc.py index c9e7664..ab6d567 100644 --- a/thriftpy2/rpc.py +++ b/thriftpy2/rpc.py @@ -7,7 +7,8 @@ import urllib import warnings -from thriftpy2._compat import PY35 +from thriftpy2.contrib.aio.rpc import make_client as make_aio_client # noqa +from thriftpy2.contrib.aio.rpc import make_server as make_aio_server # noqa from thriftpy2.protocol import TBinaryProtocolFactory from thriftpy2.server import TThreadedServer from thriftpy2.thrift import TClient, TProcessor @@ -122,9 +123,3 @@ def client_context(service, host="localhost", port=9090, unix_socket=None, finally: transport.close() - - -if PY35: - from thriftpy2.contrib.aio.rpc import make_client as make_aio_client - from thriftpy2.contrib.aio.rpc import \ - make_server as make_aio_server # noqa diff --git a/thriftpy2/thrift.py b/thriftpy2/thrift.py index 30cc517..6454ea5 100644 --- a/thriftpy2/thrift.py +++ b/thriftpy2/thrift.py @@ -12,12 +12,9 @@ import functools import linecache import types +from itertools import zip_longest -from ._compat import with_metaclass, PY3 -if PY3: - from itertools import zip_longest -else: - from itertools import izip_longest as zip_longest +from ._compat import with_metaclass def args_to_kwargs(thrift_spec, *args, **kwargs):