Skip to content

Commit bdf48e0

Browse files
committed
remove six as dependency + pylint
closes gh-89
1 parent 456d7de commit bdf48e0

File tree

9 files changed

+83
-65
lines changed

9 files changed

+83
-65
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
msgpack-python>=0.4.0
22
pyyaml>=3.10
3-
six

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def find_version(*file_paths):
8383
command_options=command_options,
8484
install_requires=[
8585
'msgpack-python>=0.4',
86-
'six',
8786
'PyYAML>=3.10',
8887
]
8988
)

tarantool/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
SOCKET_TIMEOUT,
77
RECONNECT_MAX_ATTEMPTS,
88
RECONNECT_DELAY,
9-
ENCODING_DEFAULT
109
)
1110

1211
from tarantool.error import (
@@ -21,6 +20,9 @@
2120
SchemaError
2221
)
2322

23+
from tarantool.utils import (
24+
ENCODING_DEFAULT
25+
)
2426

2527
__version__ = "0.5.5"
2628

tarantool/connection.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55
'''
66

77
import os
8-
import six
9-
import copy
108
import time
119
import errno
12-
import ctypes
13-
import ctypes.util
1410
import socket
15-
import msgpack
1611

12+
import ctypes
13+
import ctypes.util
1714
try:
1815
from ctypes import c_ssize_t
1916
except ImportError:
2017
from ctypes import c_longlong as c_ssize_t
2118

22-
import tarantool
19+
import msgpack
20+
21+
import tarantool.error
2322
from tarantool.response import Response
2423
from tarantool.request import (
2524
Request,
@@ -45,19 +44,26 @@
4544
REQUEST_TYPE_OK,
4645
REQUEST_TYPE_ERROR,
4746
IPROTO_GREETING_SIZE,
48-
ENCODING_DEFAULT,
4947
ITERATOR_EQ,
5048
ITERATOR_ALL
5149
)
5250
from tarantool.error import (
5351
NetworkError,
54-
# DatabaseError,
52+
DatabaseError,
53+
InterfaceError,
54+
SchemaError,
5555
NetworkWarning,
5656
SchemaReloadException,
5757
warn
5858
)
5959
from tarantool.schema import Schema
60-
from tarantool.utils import check_key, greeting_decode, version_id
60+
from tarantool.utils import (
61+
check_key,
62+
greeting_decode,
63+
version_id,
64+
string_types,
65+
ENCODING_DEFAULT,
66+
)
6167

6268

6369
class Connection(object):
@@ -70,10 +76,10 @@ class Connection(object):
7076
(insert/delete/update/select).
7177
'''
7278
Error = tarantool.error
73-
DatabaseError = tarantool.error.DatabaseError
74-
InterfaceError = tarantool.error.InterfaceError
75-
SchemaError = tarantool.error.SchemaError
76-
NetworkError = tarantool.error.NetworkError
79+
DatabaseError = DatabaseError
80+
InterfaceError = InterfaceError
81+
SchemaError = SchemaError
82+
NetworkError = NetworkError
7783

7884
def __init__(self, host, port,
7985
user=None,
@@ -376,7 +382,7 @@ def replace(self, space_name, values):
376382
377383
:rtype: `Response` instance
378384
'''
379-
if isinstance(space_name, six.string_types):
385+
if isinstance(space_name, string_types):
380386
space_name = self.schema.get_space(space_name).sid
381387
request = RequestReplace(self, space_name, values)
382388
return self._send_request(request)
@@ -433,7 +439,7 @@ class JoinState:
433439
def _ops_process(self, space, update_ops):
434440
new_ops = []
435441
for op in update_ops:
436-
if isinstance(op[1], six.string_types):
442+
if isinstance(op[1], string_types):
437443
op = list(op)
438444
op[1] = self.schema.get_field(space, op[1])['id']
439445
new_ops.append(op)
@@ -469,7 +475,7 @@ def insert(self, space_name, values):
469475
470476
:rtype: `Response` instance
471477
'''
472-
if isinstance(space_name, six.string_types):
478+
if isinstance(space_name, string_types):
473479
space_name = self.schema.get_space(space_name).sid
474480
request = RequestInsert(self, space_name, values)
475481
return self._send_request(request)
@@ -490,9 +496,9 @@ def delete(self, space_name, key, **kwargs):
490496
index_name = kwargs.get("index", 0)
491497

492498
key = check_key(key)
493-
if isinstance(space_name, six.string_types):
499+
if isinstance(space_name, string_types):
494500
space_name = self.schema.get_space(space_name).sid
495-
if isinstance(index_name, six.string_types):
501+
if isinstance(index_name, string_types):
496502
index_name = self.schema.get_index(space_name, index_name).iid
497503
request = RequestDelete(self, space_name, index_name, key)
498504
return self._send_request(request)
@@ -561,9 +567,9 @@ def upsert(self, space_name, tuple_value, op_list, **kwargs):
561567
'''
562568
index_name = kwargs.get("index", 0)
563569

564-
if isinstance(space_name, six.string_types):
570+
if isinstance(space_name, string_types):
565571
space_name = self.schema.get_space(space_name).sid
566-
if isinstance(index_name, six.string_types):
572+
if isinstance(index_name, string_types):
567573
index_name = self.schema.get_index(space_name, index_name).iid
568574
op_list = self._ops_process(space_name, op_list)
569575
request = RequestUpsert(self, space_name, index_name, tuple_value,
@@ -636,9 +642,9 @@ def update(self, space_name, key, op_list, **kwargs):
636642
index_name = kwargs.get("index", 0)
637643

638644
key = check_key(key)
639-
if isinstance(space_name, six.string_types):
645+
if isinstance(space_name, string_types):
640646
space_name = self.schema.get_space(space_name).sid
641-
if isinstance(index_name, six.string_types):
647+
if isinstance(index_name, string_types):
642648
index_name = self.schema.get_index(space_name, index_name).iid
643649
op_list = self._ops_process(space_name, op_list)
644650
request = RequestUpdate(self, space_name, index_name, key, op_list)
@@ -719,9 +725,9 @@ def select(self, space_name, key=None, **kwargs):
719725
# tuples)
720726
key = check_key(key, select=True)
721727

722-
if isinstance(space_name, six.string_types):
728+
if isinstance(space_name, string_types):
723729
space_name = self.schema.get_space(space_name).sid
724-
if isinstance(index_name, six.string_types):
730+
if isinstance(index_name, string_types):
725731
index_name = self.schema.get_index(space_name, index_name).iid
726732
request = RequestSelect(self, space_name, index_name, key, offset,
727733
limit, iterator_type)

tarantool/const.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# pylint: disable=C0301,W0105,W0401,W0614
33

4-
import sys
5-
6-
#
74
IPROTO_CODE = 0x00
85
IPROTO_SYNC = 0x01
96
# replication keys (header)
@@ -86,8 +83,3 @@
8683
RECONNECT_MAX_ATTEMPTS = 10
8784
# Default delay between attempts to reconnect (seconds)
8885
RECONNECT_DELAY = 0.1
89-
90-
if sys.version_info.major == 2:
91-
ENCODING_DEFAULT = None
92-
else:
93-
ENCODING_DEFAULT = "utf-8"

tarantool/request.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
Request types definitions
55
'''
66

7-
import six
8-
import sys
97
import msgpack
108
import hashlib
119

10+
1211
from tarantool.const import (
1312
IPROTO_CODE,
1413
IPROTO_SYNC,
@@ -42,7 +41,10 @@
4241
REQUEST_TYPE_JOIN,
4342
REQUEST_TYPE_SUBSCRIBE
4443
)
45-
44+
from tarantool.utils import (
45+
strxor,
46+
binary_types
47+
)
4648

4749
class Request(object):
4850
'''
@@ -60,6 +62,7 @@ def __init__(self, conn):
6062
self._bytes = None
6163
self.conn = conn
6264
self._sync = None
65+
self._body = ''
6366

6467
def __bytes__(self):
6568
return self.header(len(self._body)) + self._body
@@ -117,18 +120,12 @@ def sha1(values):
117120
sha = hashlib.sha1()
118121
for i in values:
119122
if i is not None:
120-
if isinstance(i, six.binary_type):
123+
if isinstance(i, binary_types):
121124
sha.update(i)
122125
else:
123126
sha.update(i.encode())
124127
return sha.digest()
125128

126-
def strxor(rhs, lhs):
127-
if sys.version_info.major == 2:
128-
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(rhs, lhs))
129-
130-
return bytes([x ^ y for x, y in zip(rhs, lhs)])
131-
132129
hash1 = sha1((password,))
133130
hash2 = sha1((hash1,))
134131
scramble = sha1((salt, hash2))

tarantool/response.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
22
# pylint: disable=C0301,W0105,W0401,W0614
33

4-
import sys
4+
import collections
5+
56
import yaml
67
import msgpack
7-
import collections
88

99
from tarantool.const import (
1010
IPROTO_CODE,
@@ -22,10 +22,6 @@
2222
)
2323

2424

25-
if sys.version_info < (2, 6):
26-
bytes = str # pylint: disable=W0622
27-
28-
2925
class Response(collections.Sequence):
3026
'''
3127
Represents a single response from the server in compliance with the
@@ -46,8 +42,8 @@ def __init__(self, conn, response):
4642
'''
4743

4844
# This is not necessary, because underlying list data structures are
49-
# created in the __new__(). But let it be.
50-
super(Response, self).__init__()
45+
# created in the __new__().
46+
# super(Response, self).__init__()
5147

5248
if conn.encoding is not None:
5349
unpacker = msgpack.Unpacker(use_list=True, encoding=conn.encoding)

tarantool/schema.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
It is a Tarantool schema description.
66
'''
77

8-
import six
9-
10-
from tarantool.error import SchemaError, DatabaseError
8+
from tarantool.utils import (
9+
string_types,
10+
integer_types,
11+
)
12+
from tarantool.error import (
13+
SchemaError,
14+
DatabaseError
15+
)
1116
import tarantool.const as const
1217

1318

@@ -87,7 +92,7 @@ def fetch_space(self, space):
8792
)
8893
elif len(space_row) == 0 or not len(space_row[0]):
8994
# We can't find space with this name or id
90-
temp_name = 'name' if isinstance(space, six.string_types) else 'id'
95+
temp_name = 'name' if isinstance(space, string_types) else 'id'
9196
errmsg = "There's no space with {1} '{0}'".format(space, temp_name)
9297
raise SchemaError(errmsg)
9398

@@ -97,7 +102,7 @@ def fetch_space(self, space):
97102

98103
def fetch_space_from(self, space):
99104
_index = None
100-
if isinstance(space, six.string_types):
105+
if isinstance(space, string_types):
101106
_index = const.INDEX_SPACE_NAME
102107
else:
103108
_index = const.INDEX_SPACE_PRIMARY
@@ -145,7 +150,7 @@ def fetch_index(self, space_object, index):
145150
)
146151
elif len(index_row) == 0 or not len(index_row[0]):
147152
# We can't find index with this name or id
148-
temp_name = 'name' if isinstance(index, six.string_types) else 'id'
153+
temp_name = 'name' if isinstance(index, string_types) else 'id'
149154
errmsg = ("There's no index with {2} '{0}'"
150155
" in space '{1}'").format(index, space_object.name,
151156
temp_name)
@@ -162,7 +167,7 @@ def fetch_index_all(self):
162167

163168
def fetch_index_from(self, space, index):
164169
_index = None
165-
if isinstance(index, six.string_types):
170+
if isinstance(index, string_types):
166171
_index = const.INDEX_INDEX_NAME
167172
else:
168173
_index = const.INDEX_INDEX_PRIMARY
@@ -199,7 +204,7 @@ def get_field(self, space, field):
199204
try:
200205
return _space.format[field]
201206
except:
202-
tp = 'name' if isinstance(field, six.string_types) else 'id'
207+
tp = 'name' if isinstance(field, string_types) else 'id'
203208
errmsg = "There's no field with {2} '{0}' in space '{1}'".format(
204209
field, _space.name, tp
205210
)

tarantool/utils.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
# -*- coding: utf-8 -*-
2-
3-
import six
2+
import sys
43
import base64
54
import uuid
65

6+
# Compatibility layer for Python2/Python3
7+
if sys.version_info.major == 2:
8+
string_types = (basestring, )
9+
integer_types = (int, long)
10+
ENCODING_DEFAULT = None
11+
if sys.version_info.minor < 6:
12+
binary_types = (str, )
13+
else:
14+
binary_types = (bytes, )
15+
16+
def strxor(rhs, lhs):
17+
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(rhs, lhs))
18+
19+
elif sys.version_info.major == 3:
20+
binary_types = (bytes, )
21+
string_types = (str, )
22+
integer_types = (int, )
23+
ENCODING_DEFAULT = "utf-8"
24+
25+
def strxor(rhs, lhs):
26+
return bytes([x ^ y for x, y in zip(rhs, lhs)])
27+
28+
else:
29+
pass # unreachable
730

831
def check_key(*args, **kwargs):
932
if 'first' not in kwargs:
@@ -19,14 +42,13 @@ def check_key(*args, **kwargs):
1942
elif args[0] is None and kwargs['select']:
2043
return []
2144
for key in args:
22-
assert isinstance(key, six.integer_types + six.string_types + (float,))
45+
assert isinstance(key, integer_types + string_types + (float,))
2346
return list(args)
2447

2548

2649
def version_id(major, minor, patch):
2750
return (((major << 8) | minor) << 8) | patch
2851

29-
3052
def greeting_decode(greeting_buf):
3153
class Greeting:
3254
version_id = 0

0 commit comments

Comments
 (0)