File: pipe_client.py

package info (click to toggle)
siridb-server 2.0.53-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,612 kB
  • sloc: ansic: 47,501; python: 6,263; sh: 254; makefile: 149
file content (27 lines) | stat: -rw-r--r-- 893 bytes parent folder | download | duplicates (4)
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
import logging
import asyncio
from siridb.connector import SiriDBProtocol
from siridb.connector.lib.connection import SiriDBAsyncConnection


class PipeClient(SiriDBAsyncConnection):
    def __init__(self, pipe_name, loop=None):
        self._pipe_name = pipe_name
        self._protocol = None

    async def connect(self, username, password, dbname, loop=None):
        loop = loop or asyncio.get_event_loop()

        transport, self._protocol = await loop.create_unix_connection(
            path=self._pipe_name,
            protocol_factory=lambda: SiriDBProtocol(
                username, password, dbname))

        try:
            res = await self._protocol.auth_future
        except Exception as exc:
            logging.debug('Authentication failed: {}'.format(exc))
            transport.close()
            raise exc
        else:
            self._protocol.on_authenticated()