Skip to content

Commit

Permalink
Remove some legacy Python compatible codes
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Feb 29, 2024
1 parent d81f47c commit 79a5117
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 50 deletions.
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import sys

collect_ignore = ["setup.py"]
if sys.version_info < (3, 5):
collect_ignore.append("test_aio.py")
5 changes: 0 additions & 5 deletions tests/test_framed_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import absolute_import

import sys
import logging
import socket
import threading
Expand All @@ -11,7 +10,6 @@
from os import path
from unittest import TestCase

import pytest
from tornado import ioloop

import thriftpy2
Expand Down Expand Up @@ -103,23 +101,20 @@ def setUp(self):
def tearDown(self):
self.io_loop.stop()

@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_make_client(self):
linus = addressbook.Person('Linus Torvalds')
success = self.client_created_using_url.add(linus)
assert success
success = self.client.add(linus)
assert not success

@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_able_to_communicate(self):
dennis = addressbook.Person(name='Dennis Ritchie')
success = self.client.add(dennis)
assert success
success = self.client.add(dennis)
assert not success

@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_zero_length_string(self):
dennis = addressbook.Person(name='')
success = self.client.add(dennis)
Expand Down
8 changes: 0 additions & 8 deletions tests/test_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging
import socket

import pytest
from tornado import gen, testing

import thriftpy2
Expand Down Expand Up @@ -104,7 +103,6 @@ def tearDown(self):
super(TornadoRPCTestCase, self).tearDown()

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_make_client(self):
linus = addressbook.Person(name='Linus Torvalds')
success = yield self.client_with_url.add(linus)
Expand All @@ -113,7 +111,6 @@ def test_make_client(self):
assert not success

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_synchronous_result(self):
dennis = addressbook.Person(name='Dennis Ritchie')
success = yield self.client.add(dennis)
Expand All @@ -124,7 +121,6 @@ def test_synchronous_result(self):
assert person.name == dennis.name

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_synchronous_exception(self):
exc = None
try:
Expand All @@ -135,7 +131,6 @@ def test_synchronous_exception(self):
assert isinstance(exc, addressbook.PersonNotExistsError)

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_synchronous_undeclared_exception(self):
exc = None
try:
Expand All @@ -146,15 +141,13 @@ def test_synchronous_undeclared_exception(self):
assert isinstance(exc, TTransportException)

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_asynchronous_result(self):
dennis = addressbook.Person(name='Dennis Ritchie')
yield self.client.add(dennis)
success = yield self.client.remove(dennis.name)
assert success

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_asynchronous_exception(self):
exc = None
try:
Expand All @@ -164,7 +157,6 @@ def test_asynchronous_exception(self):
assert isinstance(exc, addressbook.PersonNotExistsError)

@testing.gen_test
@pytest.mark.skipif(sys.version_info[:2] == (2, 6), reason="not support")
def test_asynchronous_undeclared_exception(self):
exc = None
try:
Expand Down
47 changes: 17 additions & 30 deletions thriftpy2/hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import absolute_import

import importlib.abc
import importlib.util
import sys

from .parser import load_module
Expand All @@ -10,41 +12,26 @@
# TODO: The load process does not compatible with Python standard, e.g., if the
# specified thrift file does not exists, it raises FileNotFoundError, and skiped
# the other meta finders in the sys.meta_path.
if sys.version_info >= (3, 4):
import importlib.abc
import importlib.util
class ThriftImporter(importlib.abc.MetaPathFinder):
def __init__(self, extension="_thrift"):
self.extension = extension

class ThriftImporter(importlib.abc.MetaPathFinder):
def __init__(self, extension="_thrift"):
self.extension = extension
def find_spec(self, fullname, path, target=None):
if not fullname.endswith(self.extension):
return None
return importlib.util.spec_from_loader(fullname,
ThriftLoader(fullname))

def find_spec(self, fullname, path, target=None):
if not fullname.endswith(self.extension):
return None
return importlib.util.spec_from_loader(fullname,
ThriftLoader(fullname))

class ThriftLoader(importlib.abc.Loader):
def __init__(self, fullname):
self.fullname = fullname

class ThriftLoader(importlib.abc.Loader):
def __init__(self, fullname):
self.fullname = fullname
def create_module(self, spec):
return load_module(self.fullname)

def create_module(self, spec):
return load_module(self.fullname)

def exec_module(self, module):
pass
else:
class ThriftImporter(object):
def __init__(self, extension="_thrift"):
self.extension = extension

def find_module(self, fullname, path=None):
if fullname.endswith(self.extension):
return self

def load_module(self, fullname):
return load_module(fullname)
def exec_module(self, module):
pass


_imp = ThriftImporter()
Expand Down
3 changes: 0 additions & 3 deletions thriftpy2/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None,
cached, this is enabled by default. If `module_name`
is provided, use it as cache key, else use the `path`.
"""
if os.name == 'nt' and sys.version_info[0] < 3:
os.path.samefile = lambda f1, f2: os.stat(f1) == os.stat(f2)

# dead include checking on current stack
for thrift in thrift_stack:
if thrift.__thrift_file__ is not None and \
Expand Down

0 comments on commit 79a5117

Please sign in to comment.