Skip to content

Commit 93b5d3d

Browse files
author
Vladimir Rudnyh
committed
Cleanup: fix errors, mistypes and PEP8 violations
1 parent 0237373 commit 93b5d3d

File tree

9 files changed

+273
-175
lines changed

9 files changed

+273
-175
lines changed

tarantool/__init__.py

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

4-
__version__ = "0.5.4"
5-
64
from tarantool.connection import Connection
75
from tarantool.const import (
86
SOCKET_TIMEOUT,
@@ -24,8 +22,12 @@
2422
)
2523

2624

27-
def connect(host="localhost", port=33013, user=None, password=None, encoding=ENCODING_DEFAULT):
28-
'''\
25+
__version__ = "0.5.4"
26+
27+
28+
def connect(host="localhost", port=33013, user=None, password=None,
29+
encoding=ENCODING_DEFAULT):
30+
'''
2931
Create a connection to the Tarantool server.
3032
3133
:param str host: Server hostname or IP-address

tarantool/connection.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from tarantool.response import Response
2323
from tarantool.request import (
2424
Request,
25-
RequestOK,
25+
# RequestOK,
2626
RequestCall,
2727
RequestDelete,
2828
RequestEval,
@@ -34,8 +34,8 @@
3434
RequestSubscribe,
3535
RequestUpdate,
3636
RequestUpsert,
37-
RequestAuthenticate)
38-
37+
RequestAuthenticate
38+
)
3939
from tarantool.space import Space
4040
from tarantool.const import (
4141
SOCKET_TIMEOUT,
@@ -46,16 +46,17 @@
4646
IPROTO_GREETING_SIZE,
4747
ENCODING_DEFAULT,
4848
ITERATOR_EQ,
49-
ITERATOR_ALL)
50-
49+
ITERATOR_ALL
50+
)
5151
from tarantool.error import (
5252
NetworkError,
53-
DatabaseError,
53+
# DatabaseError,
5454
NetworkWarning,
55-
SchemaReloadException)
56-
57-
from .schema import Schema
58-
from .utils import check_key, greeting_decode, version_id
55+
SchemaReloadException,
56+
warn
57+
)
58+
from tarantool.schema import Schema
59+
from tarantool.utils import check_key, greeting_decode, version_id
5960

6061

6162
class Connection(object):
@@ -91,7 +92,9 @@ def __init__(self, host, port,
9192
if False than you have to call connect() manualy.
9293
'''
9394
if os.name == 'nt':
94-
libc = ctypes.windll.LoadLibrary(ctypes.util.find_library('Ws2_32'))
95+
libc = ctypes.windll.LoadLibrary(
96+
ctypes.util.find_library('Ws2_32')
97+
)
9598
else:
9699
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
97100
recv = self._sys_recv = libc.recv
@@ -177,15 +180,24 @@ def _recv(self, to_read):
177180
tmp = self._socket.recv(to_read)
178181
except OverflowError:
179182
self._socket.close()
180-
raise NetworkError(socker.error(errno.ECONNRESET,
181-
"Too big packet. Closing connection to server"))
183+
err = socket.error(
184+
errno.ECONNRESET,
185+
"Too big packet. Closing connection to server"
186+
)
187+
raise NetworkError(err)
182188
except socket.error:
183-
raise NetworkError(socket.error(errno.ECONNRESET,
184-
"Lost connection to server during query"))
189+
err = socket.error(
190+
errno.ECONNRESET,
191+
"Lost connection to server during query"
192+
)
193+
raise NetworkError(err)
185194
else:
186195
if len(tmp) == 0:
187-
raise NetworkError(socket.error(errno.ECONNRESET,
188-
"Lost connection to server during query"))
196+
err = socket.error(
197+
errno.ECONNRESET,
198+
"Lost connection to server during query"
199+
)
200+
raise NetworkError(err)
189201
to_read -= len(tmp)
190202
buf += tmp
191203
return buf
@@ -261,7 +273,7 @@ def check(): # Check that connection is alive
261273
time.sleep(self.reconnect_delay)
262274
try:
263275
self.connect_basic()
264-
except NetworkError as e:
276+
except NetworkError:
265277
pass
266278
else:
267279
if self.connected:
@@ -394,7 +406,7 @@ def _join_v16(self, server_uuid):
394406
self._socket.sendall(bytes(request))
395407

396408
while True:
397-
resp = Response(self, self._read_response());
409+
resp = Response(self, self._read_response())
398410
yield resp
399411
if resp.code == REQUEST_TYPE_OK or resp.code >= REQUEST_TYPE_ERROR:
400412
return
@@ -543,7 +555,8 @@ def upsert(self, space_name, tuple_value, op_list, **kwargs):
543555
space_name = self.schema.get_space(space_name).sid
544556
if isinstance(index_name, six.string_types):
545557
index_name = self.schema.get_index(space_name, index_name).iid
546-
request = RequestUpsert(self, space_name, index_name, tuple_value, op_list)
558+
request = RequestUpsert(self, space_name, index_name, tuple_value,
559+
op_list)
547560
return self._send_request(request)
548561

549562
def update(self, space_name, key, op_list, **kwargs):
@@ -684,9 +697,10 @@ def select(self, space_name, key=None, **kwargs):
684697
index_name = kwargs.get("index", 0)
685698
iterator_type = kwargs.get("iterator")
686699

687-
if iterator_type == None:
700+
if iterator_type is None:
688701
iterator_type = ITERATOR_EQ
689-
if (key == None or (isinstance(key, (list, tuple)) and len(key) == 0)):
702+
if key is None or (isinstance(key, (list, tuple)) and
703+
len(key) == 0):
690704
iterator_type = ITERATOR_ALL
691705

692706
# Perform smart type checking (scalar / list of scalars / list of
@@ -717,7 +731,7 @@ def space(self, space_name):
717731
return Space(self, space_name)
718732

719733
def generate_sync(self):
720-
"""\
734+
'''
721735
Need override for async io connection
722-
"""
736+
'''
723737
return 0

tarantool/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
IPROTO_ERROR = 0x31
3535

3636
IPROTO_GREETING_SIZE = 128
37-
IPROTO_BODY_MAX_LEN = 2147483648
37+
IPROTO_BODY_MAX_LEN = 2147483648
3838

3939
REQUEST_TYPE_OK = 0
4040
REQUEST_TYPE_SELECT = 1

0 commit comments

Comments
 (0)