Skip to content

Commit 7823be2

Browse files
wip
1 1
1 parent 6aa89a6 commit 7823be2

File tree

9 files changed

+836
-11
lines changed

9 files changed

+836
-11
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from tarantool.connection import Connection
55
from tarantool.mesh_connection import MeshConnection
6+
from tarantool.connection_pool import ConnectionPool, Mode
67
from tarantool.const import (
78
SOCKET_TIMEOUT,
89
RECONNECT_MAX_ATTEMPTS,
@@ -75,4 +76,5 @@ def connectmesh(addrs=({'host': 'localhost', 'port': 3301},), user=None,
7576

7677
__all__ = ['connect', 'Connection', 'connectmesh', 'MeshConnection', 'Schema',
7778
'Error', 'DatabaseError', 'NetworkError', 'NetworkWarning',
78-
'SchemaError', 'dbapi']
79+
'SchemaError', 'ConnectionPool',
80+
'Mode', 'dbapi']

tarantool/connection.py

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import time
99
import errno
1010
import socket
11+
import abc
1112

1213
import ctypes
1314
import ctypes.util
@@ -76,8 +77,92 @@
7677
ENCODING_DEFAULT,
7778
)
7879

80+
# Based on https://realpython.com/python-interface/
81+
class ConnectionInterface(metaclass=abc.ABCMeta):
82+
@classmethod
83+
def __subclasshook__(cls, subclass):
84+
return (hasattr(subclass, 'close') and
85+
callable(subclass.close) and
86+
hasattr(subclass, 'is_closed') and
87+
callable(subclass.is_closed) and
88+
hasattr(subclass, 'connect') and
89+
callable(subclass.connect) and
90+
hasattr(subclass, 'call') and
91+
callable(subclass.call) and
92+
hasattr(subclass, 'eval') and
93+
callable(subclass.eval) and
94+
hasattr(subclass, 'replace') and
95+
callable(subclass.replace) and
96+
hasattr(subclass, 'insert') and
97+
callable(subclass.insert) and
98+
hasattr(subclass, 'delete') and
99+
callable(subclass.delete) and
100+
hasattr(subclass, 'upsert') and
101+
callable(subclass.upsert) and
102+
hasattr(subclass, 'update') and
103+
callable(subclass.update) and
104+
hasattr(subclass, 'ping') and
105+
callable(subclass.ping) and
106+
hasattr(subclass, 'select') and
107+
callable(subclass.select) and
108+
hasattr(subclass, 'execute') and
109+
callable(subclass.execute) or
110+
NotImplemented)
111+
112+
@abc.abstractmethod
113+
def close(self):
114+
raise NotImplementedError
115+
116+
@abc.abstractmethod
117+
def is_closed(self):
118+
raise NotImplementedError
119+
120+
@abc.abstractmethod
121+
def connect(self):
122+
raise NotImplementedError
123+
124+
@abc.abstractmethod
125+
def call(self, func_name, *args, **kwargs):
126+
raise NotImplementedError
127+
128+
@abc.abstractmethod
129+
def eval(self, expr, *args, **kwargs):
130+
raise NotImplementedError
131+
132+
@abc.abstractmethod
133+
def replace(self, space_name, values):
134+
raise NotImplementedError
135+
136+
@abc.abstractmethod
137+
def insert(self, space_name, values):
138+
raise NotImplementedError
139+
140+
@abc.abstractmethod
141+
def delete(self, space_name, key, **kwargs):
142+
raise NotImplementedError
143+
144+
@abc.abstractmethod
145+
def upsert(self, space_name, tuple_value, op_list, **kwargs):
146+
raise NotImplementedError
147+
148+
@abc.abstractmethod
149+
def update(self, space_name, key, op_list, **kwargs):
150+
raise NotImplementedError
151+
152+
@abc.abstractmethod
153+
def ping(self, notime):
154+
raise NotImplementedError
155+
156+
@abc.abstractmethod
157+
def select(self, space_name, key, **kwargs):
158+
raise NotImplementedError
159+
160+
@abc.abstractmethod
161+
def execute(self, query, params, **kwargs):
162+
raise NotImplementedError
163+
79164

80-
class Connection(object):
165+
class Connection(ConnectionInterface):
81166
'''
82167
Represents connection to the Tarantool server.
83168

0 commit comments

Comments
 (0)