Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove python2 historical compatibility code #251

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions thriftpy2/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import platform
import sys
from urllib.parse import urlparse
from urllib.request import urlopen

PY3 = sys.version_info[0] == 3
PY35 = sys.version_info >= (3, 5)
Expand All @@ -19,24 +21,12 @@
UNIX = platform.system() in ("Linux", "Darwin")
CYTHON = UNIX and not PYPY # Cython always disabled in pypy and windows

if PY3:
text_type = str
string_types = (str,)
from urllib.request import urlopen
from urllib.parse import urlparse

def u(s):
return s
else:
text_type = unicode # noqa
string_types = (str, unicode) # noqa
from urllib2 import urlopen # noqa
from urlparse import urlparse # noqa

def u(s):
if not isinstance(s, text_type):
s = s.decode("utf-8")
return s
text_type = str
string_types = (str,)


def u(s):
return s


def with_metaclass(meta, *bases):
Expand Down
15 changes: 4 additions & 11 deletions thriftpy2/contrib/aio/rpc.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
# -*- coding: utf-8 -*-
import urllib
import warnings

from thriftpy2._compat import PY3
if PY3:
import urllib
else:
import urllib2 as urllib
import urlparse
urllib.parse = urlparse

from .processor import TAsyncProcessor
from .client import TAsyncClient
from .processor import TAsyncProcessor
from .protocol.binary import TAsyncBinaryProtocolFactory
from .transport.buffered import TAsyncBufferedTransportFactory
from .socket import TAsyncSocket, TAsyncServerSocket
from .server import TAsyncServer
from .socket import TAsyncServerSocket, TAsyncSocket
from .transport.buffered import TAsyncBufferedTransportFactory


async def make_client(service, host='localhost', port=9090, unix_socket=None,
Expand Down
27 changes: 7 additions & 20 deletions thriftpy2/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,20 @@

from __future__ import absolute_import

import http.client as http_client
import http.server as http_server
import os
import socket
import sys
import urllib
from contextlib import contextmanager
from io import BytesIO

from thriftpy2._compat import PY3
if PY3:
import http.client as http_client
import http.server as http_server
import urllib
else:
import httplib as http_client
import BaseHTTPServer as http_server
import urllib2 as urllib
import urlparse
urllib.parse = urlparse
urllib.parse.quote = urllib.quote


from thriftpy2.thrift import TProcessor, TClient
from thriftpy2.server import TServer
from thriftpy2.transport import TTransportBase, TMemoryBuffer

from thriftpy2.protocol import TBinaryProtocolFactory
from thriftpy2.transport import TBufferedTransportFactory

from thriftpy2.server import TServer
from thriftpy2.thrift import TClient, TProcessor
from thriftpy2.transport import (TBufferedTransportFactory, TMemoryBuffer,
TTransportBase)

HTTP_URI = '{scheme}://{host}:{port}{path}'
DEFAULT_HTTP_CLIENT_TIMEOUT_MS = 30000 # 30 seconds
Expand Down
29 changes: 8 additions & 21 deletions thriftpy2/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@

import contextlib
import socket
import urllib
import warnings

from thriftpy2._compat import PY3, PY35
if PY3:
import urllib
else:
import urllib2 as urllib
import urlparse
urllib.parse = urlparse
urllib.parse.quote = urllib.quote

from thriftpy2._compat import PY35
from thriftpy2.protocol import TBinaryProtocolFactory
from thriftpy2.server import TThreadedServer
from thriftpy2.thrift import TProcessor, TClient
from thriftpy2.transport import (
TBufferedTransportFactory,
TServerSocket,
TSSLServerSocket,
TSocket,
TSSLSocket,
)
from thriftpy2.thrift import TClient, TProcessor
from thriftpy2.transport import (TBufferedTransportFactory, TServerSocket,
TSocket, TSSLServerSocket, TSSLSocket)


def make_client(service, host="localhost", port=9090, unix_socket=None,
Expand Down Expand Up @@ -137,7 +125,6 @@ def client_context(service, host="localhost", port=9090, unix_socket=None,


if PY35:
from thriftpy2.contrib.aio.rpc import ( # noqa
make_server as make_aio_server,
make_client as make_aio_client
)
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
30 changes: 10 additions & 20 deletions thriftpy2/tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,22 @@

from __future__ import absolute_import

import logging
import socket
import struct
import urllib
from contextlib import contextmanager
from tornado import tcpserver, iostream, gen
from tornado import version as tornado_version
from io import BytesIO
from datetime import timedelta
from io import BytesIO

from .transport import TTransportException, TTransportBase
from .transport.memory import TMemoryBuffer
from .thrift import TApplicationException, TProcessor, TClient
from tornado import gen, iostream, tcpserver
from tornado import version as tornado_version

# TODO need TCyTornadoStreamTransport to work with cython binary protocol
from .protocol.binary import TBinaryProtocolFactory
from ._compat import PY3

if PY3:
import urllib
else:
import urllib2 as urllib
import urlparse

urllib.parse = urlparse
urllib.parse.quote = urllib.quote

import logging
import socket
import struct
from .thrift import TApplicationException, TClient, TProcessor
from .transport import TTransportBase, TTransportException
from .transport.memory import TMemoryBuffer

try:
from tornado.locks import Lock
Expand Down
Loading