1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
import os
import sys
import asyncio
from .lib.protocol import _SiriDBProtocol
from .lib.protocol import _SiriDBInfoProtocol
from .lib.connection import SiriDBConnection
from .lib.defaults import DEFAULT_CLIENT_PORT
from .lib.client import SiriDBClient
__version_info__ = (2, 0, 5)
__version__ = '.'.join(map(str, __version_info__))
__maintainer__ = 'Jeroen van der Heijden'
__email__ = 'jeroen@transceptor.technology'
__all__ = [
'async_connect',
'async_server_info',
'connect',
'SiriDBClient',
'SiriDBProtocol',
]
class SiriDBProtocol(_SiriDBProtocol):
def on_connection_made(self):
pass
def on_authenticated(self):
pass
def on_connection_lost(self, exc):
pass
def connect(username,
password,
dbname,
host='127.0.0.1',
port=DEFAULT_CLIENT_PORT,
loop=None,
timeout=10,
protocol=SiriDBProtocol):
return SiriDBConnection(
username,
password,
dbname,
host=host,
port=port,
loop=loop,
timeout=timeout,
protocol=protocol)
async def async_connect(username,
password,
dbname,
host='127.0.0.1',
port=DEFAULT_CLIENT_PORT,
loop=None,
timeout=10,
keepalive=False,
protocol=SiriDBProtocol):
connection = SiriDBAsyncConnection()
await connection.connect(
username,
password,
dbname,
host=host,
port=port,
loop=loop,
timeout=timeout,
keepalive=keepalive,
protocol=protocol)
return connection
async def async_server_info(host='127.0.0.1',
port=DEFAULT_CLIENT_PORT,
loop=None,
timeout=10):
loop = loop or asyncio.get_event_loop()
client = loop.create_connection(
lambda: _SiriDBInfoProtocol(None, None, None),
host=host,
port=port)
transport, protocol = \
await asyncio.wait_for(client, timeout=timeout)
result = await protocol.future
transport.close()
return result
|