# Path: couchbaseConstants.py
# AUDIT_PKT_FMT = ">I"
# 
# INCRDECR_RES_FMT = ">Q"
# 
# MIN_RECV_PACKET = struct.calcsize(REQ_PKT_FMT)
# 
# REQ_MAGIC_BYTE = 0x80
# 
# REQ_PKT_FMT = ">BBHBBHIIQ"
# 
# RES_MAGIC_BYTE = 0x81
# 
# RES_PKT_FMT = ">BBHBBHIIQ"
# 
# SET_PKT_FMT = ">II"


import array
import random
import socket
import ssl
import struct
import couchbaseConstants
from typing import Iterable, List, Optional, Tuple, Union
from couchbaseConstants import (AUDIT_PKT_FMT, INCRDECR_RES_FMT, MIN_RECV_PACKET, REQ_MAGIC_BYTE, REQ_PKT_FMT,
                                RES_MAGIC_BYTE, RES_PKT_FMT, SET_PKT_FMT)
    from cb_version import VERSION  # pylint: disable=import-error
                    sock = ssl.wrap_socket(sock, server_side=False, do_handshake_on_connect=True, cert_reqs=cert_req,
                                           ca_certs=cacert)

                self.s = sock
                self.s.connect_ex(sockaddr)
                break
            except socket.error as e:
                sock_error = e
                # If we get here socket objects will be close()d via
                # garbage collection.
                pass
        else:
            # Didn't break from the loop, re-raise the last error
            raise sock_error

        self.r = random.Random()

    def close(self):
        self.s.close()

    def __del__(self):
        self.close()

    def _send_cmd(self, cmd: int, key: bytes, val: bytes, opaque: int, extra_header: bytes = b'', cas: int = 0,
                  extra_meta: bytes = b''):
        self._send_msg(cmd, key, val, opaque, extra_header=extra_header, cas=cas,
                       vbucket_id=self.vbucket_id, extra_meta=extra_meta)

    def _send_msg(self, cmd: int, key: bytes, val: bytes, opaque: int, extra_header: bytes = b'', cas: int = 0,
                  dtype: int = 0, vbucket_id: int = 0, extra_meta: bytes = b'',

# Path: couchbaseConstants.py
# AUDIT_PKT_FMT = ">I"
# 
# INCRDECR_RES_FMT = ">Q"
# 
# MIN_RECV_PACKET = struct.calcsize(REQ_PKT_FMT)
# 
# REQ_MAGIC_BYTE = 0x80
# 
# REQ_PKT_FMT = ">BBHBBHIIQ"
# 
# RES_MAGIC_BYTE = 0x81
# 
# RES_PKT_FMT = ">BBHBBHIIQ"
# 
# SET_PKT_FMT = ">II"


# Path: cb_bin_client.py
import array
import random
import socket
import ssl
import struct
import couchbaseConstants
from typing import Iterable, List, Optional, Tuple, Union
from couchbaseConstants import (AUDIT_PKT_FMT, INCRDECR_RES_FMT, MIN_RECV_PACKET, REQ_MAGIC_BYTE, REQ_PKT_FMT,
                                RES_MAGIC_BYTE, RES_PKT_FMT, SET_PKT_FMT)
    from cb_version import VERSION  # pylint: disable=import-error

                    sock = ssl.wrap_socket(sock, server_side=False, do_handshake_on_connect=True, cert_reqs=cert_req,
                                           ca_certs=cacert)

                self.s = sock
                self.s.connect_ex(sockaddr)
                break
            except socket.error as e:
                sock_error = e
                # If we get here socket objects will be close()d via
                # garbage collection.
                pass
        else:
            # Didn't break from the loop, re-raise the last error
            raise sock_error

        self.r = random.Random()

    def close(self):
        self.s.close()

    def __del__(self):
        self.close()

    def _send_cmd(self, cmd: int, key: bytes, val: bytes, opaque: int, extra_header: bytes = b'', cas: int = 0,
                  extra_meta: bytes = b''):
        self._send_msg(cmd, key, val, opaque, extra_header=extra_header, cas=cas,
                       vbucket_id=self.vbucket_id, extra_meta=extra_meta)

    def _send_msg(self, cmd: int, key: bytes, val: bytes, opaque: int, extra_header: bytes = b'', cas: int = 0,
                  dtype: int = 0, vbucket_id: int = 0, extra_meta: bytes = b'',

                  fmt: str = REQ_PKT_FMT, magic: int = REQ_MAGIC_BYTE):