Skip to content

Commit 3f9ed0a

Browse files
wip
1 parent 0f95f28 commit 3f9ed0a

10 files changed

+854
-130
lines changed

appveyor.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
environment:
22
matrix:
3-
- PYTHON: "C:\\Python27"
4-
- PYTHON: "C:\\Python27-x64"
5-
- PYTHON: "C:\\Python34"
6-
- PYTHON: "C:\\Python34-x64"
7-
- PYTHON: "C:\\Python35"
8-
- PYTHON: "C:\\Python35-x64"
9-
- PYTHON: "C:\\Python36"
10-
- PYTHON: "C:\\Python36-x64"
113
- PYTHON: "C:\\Python37"
124
- PYTHON: "C:\\Python37-x64"
135
- PYTHON: "C:\\Python38"

tarantool/__init__.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,13 @@
22
# pylint: disable=C0301,W0105,W0401,W0614
33

44
from tarantool.connection import Connection
5+
from tarantool.connection_pool import ConnectionPool, Mode
6+
from tarantool.const import (RECONNECT_DELAY, RECONNECT_MAX_ATTEMPTS,
7+
SOCKET_TIMEOUT)
8+
from tarantool.error import DatabaseError, Error, NetworkError, NetworkWarning
59
from tarantool.mesh_connection import MeshConnection
6-
from tarantool.const import (
7-
SOCKET_TIMEOUT,
8-
RECONNECT_MAX_ATTEMPTS,
9-
RECONNECT_DELAY,
10-
)
11-
12-
from tarantool.error import (
13-
Error,
14-
DatabaseError,
15-
NetworkError,
16-
NetworkWarning,
17-
)
18-
19-
from tarantool.schema import (
20-
Schema,
21-
SchemaError
22-
)
23-
24-
from tarantool.utils import (
25-
ENCODING_DEFAULT
26-
)
10+
from tarantool.schema import Schema, SchemaError
11+
from tarantool.utils import ENCODING_DEFAULT
2712

2813
__version__ = "0.7.1"
2914

@@ -75,4 +60,5 @@ def connectmesh(addrs=({'host': 'localhost', 'port': 3301},), user=None,
7560

7661
__all__ = ['connect', 'Connection', 'connectmesh', 'MeshConnection', 'Schema',
7762
'Error', 'DatabaseError', 'NetworkError', 'NetworkWarning',
78-
'SchemaError', 'dbapi']
63+
'SchemaError', 'ConnectionPool',
64+
'Mode', 'dbapi']

tarantool/connection.py

Lines changed: 113 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,130 @@
44
This module provides low-level API for Tarantool
55
'''
66

7-
import os
8-
import time
7+
import abc
8+
import ctypes
9+
import ctypes.util
910
import errno
11+
import os
1012
import socket
13+
import time
14+
15+
import msgpack
16+
import tarantool.error
17+
from tarantool.const import (CONNECTION_TIMEOUT, IPROTO_GREETING_SIZE,
18+
ITERATOR_ALL, ITERATOR_EQ, RECONNECT_DELAY,
19+
RECONNECT_MAX_ATTEMPTS, REQUEST_TYPE_ERROR,
20+
REQUEST_TYPE_OK, SOCKET_TIMEOUT)
21+
from tarantool.error import (ConfigurationError, DatabaseError, DataError,
22+
Error, IntegrityError, InterfaceError,
23+
InternalError, NetworkError, NetworkWarning,
24+
NotSupportedError, OperationalError,
25+
ProgrammingError, SchemaError,
26+
SchemaReloadException, Warning, warn)
27+
from tarantool.request import (Request, RequestAuthenticate, # RequestOK,
28+
RequestCall, RequestDelete, RequestEval,
29+
RequestExecute, RequestInsert, RequestJoin,
30+
RequestPing, RequestReplace, RequestSelect,
31+
RequestSubscribe, RequestUpdate, RequestUpsert)
32+
from tarantool.response import Response
33+
from tarantool.schema import Schema
34+
from tarantool.space import Space
35+
from tarantool.utils import (ENCODING_DEFAULT, check_key, greeting_decode,
36+
string_types, version_id)
1137

12-
import ctypes
13-
import ctypes.util
1438
try:
1539
from ctypes import c_ssize_t
1640
except ImportError:
1741
from ctypes import c_longlong as c_ssize_t
1842

19-
import msgpack
2043

21-
import tarantool.error
22-
from tarantool.response import Response
23-
from tarantool.request import (
24-
Request,
25-
# RequestOK,
26-
RequestCall,
27-
RequestDelete,
28-
RequestEval,
29-
RequestInsert,
30-
RequestJoin,
31-
RequestReplace,
32-
RequestPing,
33-
RequestSelect,
34-
RequestSubscribe,
35-
RequestUpdate,
36-
RequestUpsert,
37-
RequestAuthenticate,
38-
RequestExecute
39-
)
40-
from tarantool.space import Space
41-
from tarantool.const import (
42-
CONNECTION_TIMEOUT,
43-
SOCKET_TIMEOUT,
44-
RECONNECT_MAX_ATTEMPTS,
45-
RECONNECT_DELAY,
46-
REQUEST_TYPE_OK,
47-
REQUEST_TYPE_ERROR,
48-
IPROTO_GREETING_SIZE,
49-
ITERATOR_EQ,
50-
ITERATOR_ALL
51-
)
52-
from tarantool.error import (
53-
Error,
54-
NetworkError,
55-
DatabaseError,
56-
InterfaceError,
57-
ConfigurationError,
58-
SchemaError,
59-
NetworkWarning,
60-
OperationalError,
61-
DataError,
62-
IntegrityError,
63-
InternalError,
64-
ProgrammingError,
65-
NotSupportedError,
66-
SchemaReloadException,
67-
Warning,
68-
warn
69-
)
70-
from tarantool.schema import Schema
71-
from tarantool.utils import (
72-
check_key,
73-
greeting_decode,
74-
version_id,
75-
string_types,
76-
ENCODING_DEFAULT,
77-
)
44+
45+
# Based on https://realpython.com/python-interface/
46+
class ConnectionInterface(metaclass=abc.ABCMeta):
47+
@classmethod
48+
def __subclasshook__(cls, subclass):
49+
return (hasattr(subclass, 'close') and
50+
callable(subclass.close) and
51+
hasattr(subclass, 'is_closed') and
52+
callable(subclass.is_closed) and
53+
hasattr(subclass, 'connect') and
54+
callable(subclass.connect) and
55+
hasattr(subclass, 'call') and
56+
callable(subclass.call) and
57+
hasattr(subclass, 'eval') and
58+
callable(subclass.eval) and
59+
hasattr(subclass, 'replace') and
60+
callable(subclass.replace) and
61+
hasattr(subclass, 'insert') and
62+
callable(subclass.insert) and
63+
hasattr(subclass, 'delete') and
64+
callable(subclass.delete) and
65+
hasattr(subclass, 'upsert') and
66+
callable(subclass.upsert) and
67+
hasattr(subclass, 'update') and
68+
callable(subclass.update) and
69+
hasattr(subclass, 'ping') and
70+
callable(subclass.ping) and
71+
hasattr(subclass, 'select') and
72+
callable(subclass.select) and
73+
hasattr(subclass, 'execute') and
74+
callable(subclass.execute) or
75+
NotImplemented)
76+
77+
@abc.abstractmethod
78+
def close(self):
79+
raise NotImplementedError
80+
81+
@abc.abstractmethod
82+
def is_closed(self):
83+
raise NotImplementedError
84+
85+
@abc.abstractmethod
86+
def connect(self):
87+
raise NotImplementedError
88+
89+
@abc.abstractmethod
90+
def call(self, func_name, *args, **kwargs):
91+
raise NotImplementedError
92+
93+
@abc.abstractmethod
94+
def eval(self, expr, *args, **kwargs):
95+
raise NotImplementedError
96+
97+
@abc.abstractmethod
98+
def replace(self, space_name, values):
99+
raise NotImplementedError
100+
101+
@abc.abstractmethod
102+
def insert(self, space_name, values):
103+
raise NotImplementedError
104+
105+
@abc.abstractmethod
106+
def delete(self, space_name, key, **kwargs):
107+
raise NotImplementedError
108+
109+
@abc.abstractmethod
110+
def upsert(self, space_name, tuple_value, op_list, **kwargs):
111+
raise NotImplementedError
112+
113+
@abc.abstractmethod
114+
def update(self, space_name, key, op_list, **kwargs):
115+
raise NotImplementedError
116+
117+
@abc.abstractmethod
118+
def ping(self, notime):
119+
raise NotImplementedError
120+
121+
@abc.abstractmethod
122+
def select(self, space_name, key, **kwargs):
123+
raise NotImplementedError
124+
125+
@abc.abstractmethod
126+
def execute(self, query, params, **kwargs):
127+
raise NotImplementedError
78128

79129

80-
class Connection(object):
130+
class Connection(ConnectionInterface):
81131
'''
82132
Represents connection to the Tarantool server.
83133

0 commit comments

Comments
 (0)