diff --git a/thriftpy/hook.py b/thriftpy/hook.py index d11b631..434f70b 100644 --- a/thriftpy/hook.py +++ b/thriftpy/hook.py @@ -12,16 +12,19 @@ def __init__(self, extension="_thrift"): self.extension = extension def __eq__(self, other): - return self.__class__.__module__ == other.__class__.__module__ and \ - self.__class__.__name__ == other.__class__.__name__ and \ - self.extension == other.extension + if not other or not isinstance(other, self.__class__): + return False + return self.extension == other.extension def find_module(self, fullname, path=None): if fullname.endswith(self.extension): return self - def load_module(self, fullname): + @classmethod + def load_module(cls, fullname): return load_module(fullname) + + _imp = ThriftImporter() diff --git a/thriftpy/parser/lexer.py b/thriftpy/parser/lexer.py index bde1cb7..2f40dec 100644 --- a/thriftpy/parser/lexer.py +++ b/thriftpy/parser/lexer.py @@ -8,7 +8,7 @@ literals = ':;,=*{}()<>[]' -thrift_reserved_keywords = ( +thrift_reserved_keywords = set([ 'BEGIN', 'END', '__CLASS__', @@ -113,7 +113,7 @@ 'with', 'xor', 'yield' -) +]) keywords = ( @@ -159,7 +159,7 @@ def t_error(t): - raise ThriftLexerError('Illegal characher %r at line %d' % + raise ThriftLexerError('Illegal character %r at line %d' % (t.value[0], t.lineno)) @@ -236,7 +236,7 @@ def t_LITERAL(t): if s[i] in maps: val += maps[s[i]] else: - msg = 'Unexcepted escaping characher: %s' % s[i] + msg = 'Unexpected escaping character: %s' % s[i] raise ThriftLexerError(msg) else: val += s[i] diff --git a/thriftpy/parser/parser.py b/thriftpy/parser/parser.py index f65320a..cdbba1c 100644 --- a/thriftpy/parser/parser.py +++ b/thriftpy/parser/parser.py @@ -48,7 +48,7 @@ def p_include(p): '''include : INCLUDE LITERAL''' thrift = thrift_stack[-1] if thrift.__thrift_file__ is None: - raise ThriftParserError('Unexcepted include statement while loading' + raise ThriftParserError('Unexpected include statement while loading' 'from file like object.') replace_include_dirs = [os.path.dirname(thrift.__thrift_file__)] \ + include_dirs_ @@ -593,7 +593,7 @@ def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True): return thrift_cache[module_name] if not hasattr(source, 'read'): - raise ThriftParserError('Except `source` to be a file-like object with' + raise ThriftParserError('Expect `source` to be a file-like object with' 'a method named \'read\'') if lexer is None: diff --git a/thriftpy/tornado.py b/thriftpy/tornado.py index fd53ebf..185e9d7 100644 --- a/thriftpy/tornado.py +++ b/thriftpy/tornado.py @@ -17,11 +17,18 @@ from __future__ import absolute_import +import logging +import socket +import struct + from contextlib import contextmanager -from tornado import tcpserver, ioloop, iostream, gen from io import BytesIO from datetime import timedelta +import toro + +from tornado import tcpserver, ioloop, iostream, gen + from .transport import TTransportException, TTransportBase from .transport.memory import TMemoryBuffer from .thrift import TApplicationException, TProcessor, TClient @@ -29,11 +36,6 @@ # TODO need TCyTornadoStreamTransport to work with cython binary protocol from .protocol.binary import TBinaryProtocolFactory -import logging -import socket -import struct -import toro - logger = logging.getLogger(__name__) diff --git a/thriftpy/utils.py b/thriftpy/utils.py index f089dbf..e7135c2 100644 --- a/thriftpy/utils.py +++ b/thriftpy/utils.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import +from __future__ import absolute_import, print_function import binascii @@ -34,4 +34,4 @@ def hexprint(byte_array, delimeter=' ', count=10): print("\nHex:") g = hexlify(byte_array, delimeter).split(delimeter) - print('\n'.join(' '.join(g[i:i+10]) for i in range(0, len(g), 10))) + print('\n'.join(' '.join(g[i:i+count]) for i in range(0, len(g), count)))