Skip to content

Cleanup: fix errors, mistypes and PEP8 violations #80

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

Merged
merged 1 commit into from
Aug 15, 2016
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
10 changes: 6 additions & 4 deletions tarantool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# pylint: disable=C0301,W0105,W0401,W0614

__version__ = "0.5.4"

from tarantool.connection import Connection
from tarantool.const import (
SOCKET_TIMEOUT,
Expand All @@ -24,8 +22,12 @@
)


def connect(host="localhost", port=33013, user=None, password=None, encoding=ENCODING_DEFAULT):
'''\
__version__ = "0.5.4"


def connect(host="localhost", port=33013, user=None, password=None,
encoding=ENCODING_DEFAULT):
'''
Create a connection to the Tarantool server.

:param str host: Server hostname or IP-address
Expand Down
62 changes: 38 additions & 24 deletions tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from tarantool.response import Response
from tarantool.request import (
Request,
RequestOK,
# RequestOK,
RequestCall,
RequestDelete,
RequestEval,
Expand All @@ -34,8 +34,8 @@
RequestSubscribe,
RequestUpdate,
RequestUpsert,
RequestAuthenticate)

RequestAuthenticate
)
from tarantool.space import Space
from tarantool.const import (
SOCKET_TIMEOUT,
Expand All @@ -46,16 +46,17 @@
IPROTO_GREETING_SIZE,
ENCODING_DEFAULT,
ITERATOR_EQ,
ITERATOR_ALL)

ITERATOR_ALL
)
from tarantool.error import (
NetworkError,
DatabaseError,
# DatabaseError,
NetworkWarning,
SchemaReloadException)

from .schema import Schema
from .utils import check_key, greeting_decode, version_id
SchemaReloadException,
warn
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!

)
from tarantool.schema import Schema
from tarantool.utils import check_key, greeting_decode, version_id


class Connection(object):
Expand Down Expand Up @@ -91,7 +92,9 @@ def __init__(self, host, port,
if False than you have to call connect() manualy.
'''
if os.name == 'nt':
libc = ctypes.windll.LoadLibrary(ctypes.util.find_library('Ws2_32'))
libc = ctypes.windll.LoadLibrary(
ctypes.util.find_library('Ws2_32')
)
else:
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
recv = self._sys_recv = libc.recv
Expand Down Expand Up @@ -177,15 +180,24 @@ def _recv(self, to_read):
tmp = self._socket.recv(to_read)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

socker!!!

except OverflowError:
self._socket.close()
raise NetworkError(socker.error(errno.ECONNRESET,
"Too big packet. Closing connection to server"))
err = socket.error(
errno.ECONNRESET,
"Too big packet. Closing connection to server"
)
raise NetworkError(err)
except socket.error:
raise NetworkError(socket.error(errno.ECONNRESET,
"Lost connection to server during query"))
err = socket.error(
errno.ECONNRESET,
"Lost connection to server during query"
)
raise NetworkError(err)
else:
if len(tmp) == 0:
raise NetworkError(socket.error(errno.ECONNRESET,
"Lost connection to server during query"))
err = socket.error(
errno.ECONNRESET,
"Lost connection to server during query"
)
raise NetworkError(err)
to_read -= len(tmp)
buf += tmp
return buf
Expand Down Expand Up @@ -261,7 +273,7 @@ def check(): # Check that connection is alive
time.sleep(self.reconnect_delay)
try:
self.connect_basic()
except NetworkError as e:
except NetworkError:
pass
else:
if self.connected:
Expand Down Expand Up @@ -394,7 +406,7 @@ def _join_v16(self, server_uuid):
self._socket.sendall(bytes(request))

while True:
resp = Response(self, self._read_response());
resp = Response(self, self._read_response())
yield resp
if resp.code == REQUEST_TYPE_OK or resp.code >= REQUEST_TYPE_ERROR:
return
Expand Down Expand Up @@ -543,7 +555,8 @@ def upsert(self, space_name, tuple_value, op_list, **kwargs):
space_name = self.schema.get_space(space_name).sid
if isinstance(index_name, six.string_types):
index_name = self.schema.get_index(space_name, index_name).iid
request = RequestUpsert(self, space_name, index_name, tuple_value, op_list)
request = RequestUpsert(self, space_name, index_name, tuple_value,
op_list)
return self._send_request(request)

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

if iterator_type == None:
if iterator_type is None:
iterator_type = ITERATOR_EQ
if (key == None or (isinstance(key, (list, tuple)) and len(key) == 0)):
if key is None or (isinstance(key, (list, tuple)) and
len(key) == 0):
iterator_type = ITERATOR_ALL

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

def generate_sync(self):
"""\
'''
Need override for async io connection
"""
'''
return 0
2 changes: 1 addition & 1 deletion tarantool/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
IPROTO_ERROR = 0x31

IPROTO_GREETING_SIZE = 128
IPROTO_BODY_MAX_LEN = 2147483648
IPROTO_BODY_MAX_LEN = 2147483648

REQUEST_TYPE_OK = 0
REQUEST_TYPE_SELECT = 1
Expand Down
Loading