Skip to content

Commit 3f9983c

Browse files
connection: introduce common interface
Introduce connection interface to be used in connection pool implementation. Only CRUD and base connect/close API is required by the interface. Part of #196
1 parent 1e71500 commit 3f9983c

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

tarantool/connection.py

+86-1
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)