コード例 #1
0
ファイル: fbcore.py プロジェクト: gzip4/pyfirebirdsql
    def __init__(self, conn, names, timeout):
        self.sock = None
        self.connection = conn
        self.event_names = {}
        for name in names:
            self.event_names[name] = 0
        self.timeout = timeout
        self.connection._op_connect_request()
        (h, oid, buf) = self.connection._op_response()
        family = buf[:2]
        port = bytes_to_bint(buf[2:4], u=True)
        if family == b'\x02\x00':  # IPv4
            ip_address = '.'.join([str(byte_to_int(c)) for c in buf[4:8]])
        elif family == b'\x0a\x00':  # IPv6
            address = bytes_to_hex(buf[8:24])
            if not isinstance(address, str):  # Py3
                address = address.decode('ascii')
            ip_address = ':'.join(
                [address[i:i + 4] for i in range(0, len(address), 4)])
        self.sock = SocketStream(ip_address, port, timeout)
        self.connection.last_event_id += 1
        self.event_id = self.connection.last_event_id

        self.connection._op_que_events(self.event_names, self.event_id)
        (h, oid, buf) = self.connection._op_response()

        (event_id, event_names) = self._wait_for_event(timeout=timeout)
        assert event_id == self.event_id  # treat only one event_id
        self.event_names.update(event_names)
コード例 #2
0
ファイル: fbcore.py プロジェクト: yuhisern7/pyfirebirdsql
    def __init__(
        self, dsn=None, user=None, password=None, role=None, host=None,
        database=None, charset=DEFAULT_CHARSET, port=None,
        page_size=4096, is_services=False, cloexec=False,
        timeout=None, isolation_level=None, use_unicode=None,
        auth_plugin_name=None, wire_crypt=True, create_new=False,
        timezone=None
    ):
        DEBUG_OUTPUT("Connection::__init__()")
        if auth_plugin_name is None:
            auth_plugin_name = 'Srp256'
        WireProtocol.__init__(self)
        self.sock = None
        self.db_handle = None
        (self.hostname, self.port, self.filename, self.user, self.password) = parse_dsn(dsn, host, port, database, user, password)
        self.role = role
        self.charset = charset
        self.timeout = float(timeout) if timeout is not None else None
        self.auth_plugin_name = auth_plugin_name
        self.wire_crypt = wire_crypt
        self.page_size = page_size
        self.is_services = is_services
        if isolation_level is None:
            self.isolation_level = ISOLATION_LEVEL_READ_COMMITED
        else:
            self.isolation_level = int(isolation_level)
        self.use_unicode = use_unicode
        self.timezone = timezone
        self.last_event_id = 0

        self._autocommit = False
        self._transaction = None
        self.sock = SocketStream(self.hostname, self.port, self.timeout, cloexec)

        self._op_connect(auth_plugin_name, wire_crypt)
        try:
            self._parse_connect_response()
        except OperationalError as e:
            self.sock.close()
            self.sock = None
            raise e
        if create_new:                      # create database
            self._op_create(self.page_size)
        elif self.is_services:                  # service api
            self._op_service_attach()
        else:                                   # connect
            self._op_attach()
        (h, oid, buf) = self._op_response()
        self.db_handle = h
コード例 #3
0
ファイル: fbcore.py プロジェクト: tuksik/pyfirebirdsql
    def __init__(self, conn, names, timeout):
        self.sock = None
        self.connection = conn
        self.event_names = {}
        for name in names:
            self.event_names[name] = 0
        self.timeout = timeout
        (h, port, family, ip_address) = self.connection._op_connect_request()
        self.sock = SocketStream(ip_address, port, timeout)
        self.connection.last_event_id += 1
        self.event_id = self.connection.last_event_id

        self.connection._op_que_events(self.event_names, 0, 0, self.event_id)
        (h, oid, buf) = self.connection._op_response()

        (event_id, event_names) = self._wait_for_event(timeout=timeout)
        assert event_id == self.event_id   # treat only one event_id
        self.event_names.update(event_names)
コード例 #4
0
    def __init__(self, conn, names, timeout):
        self.sock = None
        self.connection = conn
        self.event_names = {}
        for name in names:
            self.event_names[name] = 0
        self.timeout = timeout
        self.connection._op_connect_request()
        (h, oid, buf) = self.connection._op_response()
        family = bytes_to_bint(buf[:2])
        port = bytes_to_bint(buf[2:4], u=True)
        ip_address = '.'.join([str(byte_to_int(c)) for c in buf[4:8]])

        self.sock = SocketStream(ip_address, port, timeout)
        self.connection.last_event_id += 1
        self.event_id = self.connection.last_event_id

        self.connection._op_que_events(self.event_names, self.event_id)
        (h, oid, buf) = self.connection._op_response()

        (event_id, event_names) = self._wait_for_event(timeout=timeout)
        assert event_id == self.event_id  # treat only one event_id
        self.event_names.update(event_names)