Skip to content

Commit

Permalink
Remove python2/python3.5 historical compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
cocolato committed Mar 20, 2024
1 parent 4ec6f58 commit f8e4b0e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
6 changes: 2 additions & 4 deletions thriftpy2/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 8 additions & 12 deletions thriftpy2/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 '
Expand Down
12 changes: 3 additions & 9 deletions thriftpy2/protocol/compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 2 additions & 7 deletions thriftpy2/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 2 additions & 5 deletions thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f8e4b0e

Please sign in to comment.