# Path: gnsq/errors.py
# class NSQSocketError(socket.error, NSQException):
#     pass
# 
# Path: gnsq/stream/defalte.py
# class DefalteSocket(CompressionSocket):
#     def __init__(self, socket, level):
#         wbits = -zlib.MAX_WBITS
#         self._decompressor = zlib.decompressobj(wbits)
#         self._compressor = zlib.compressobj(level, zlib.DEFLATED, wbits)
#         super(DefalteSocket, self).__init__(socket)
# 
#     def compress(self, data):
#         data = self._compressor.compress(data)
#         return data + self._compressor.flush(zlib.Z_SYNC_FLUSH)
# 
#     def decompress(self, data):
#         return self._decompressor.decompress(data)
# 
#     def close(self):
#         self._socket.sendall(self._compressor.flush(zlib.Z_FINISH))
#         self._socket.close()


from mmap import PAGESIZE
from errno import ENOTCONN, EDEADLK, EAGAIN, EWOULDBLOCK
from gevent import socket
from gevent.lock import Semaphore
from gevent.ssl import SSLSocket, PROTOCOL_TLSv1_2, CERT_NONE
from gnsq.errors import NSQSocketError
    from .snappy import SnappySocket
from .defalte import DefalteSocket
import six
import gevent
        keyfile=None,
        certfile=None,
        cert_reqs=CERT_NONE,
        ca_certs=None,
        ssl_version=PROTOCOL_TLSv1_2
    ):
        self.ensure_connection()

        try:
            self.socket = SSLSocket(
                self.socket,
                keyfile=keyfile,
                certfile=certfile,
                cert_reqs=cert_reqs,
                ca_certs=ca_certs,
                ssl_version=ssl_version,
            )
        except socket.error as error:
            six.raise_from(NSQSocketError(*error.args), error)

    def upgrade_to_snappy(self):
        if SnappySocket is None:
            raise RuntimeError('snappy requires the python-snappy package')

        self.ensure_connection()
        self.socket = SnappySocket(self.socket)
        self.socket.bootstrap(self.consume_buffer())

    def upgrade_to_defalte(self, level):
        self.ensure_connection()

# Path: gnsq/errors.py
# class NSQSocketError(socket.error, NSQException):
#     pass
# 
# Path: gnsq/stream/defalte.py
# class DefalteSocket(CompressionSocket):
#     def __init__(self, socket, level):
#         wbits = -zlib.MAX_WBITS
#         self._decompressor = zlib.decompressobj(wbits)
#         self._compressor = zlib.compressobj(level, zlib.DEFLATED, wbits)
#         super(DefalteSocket, self).__init__(socket)
# 
#     def compress(self, data):
#         data = self._compressor.compress(data)
#         return data + self._compressor.flush(zlib.Z_SYNC_FLUSH)
# 
#     def decompress(self, data):
#         return self._decompressor.decompress(data)
# 
#     def close(self):
#         self._socket.sendall(self._compressor.flush(zlib.Z_FINISH))
#         self._socket.close()


# Path: gnsq/stream/stream.py
from mmap import PAGESIZE
from errno import ENOTCONN, EDEADLK, EAGAIN, EWOULDBLOCK
from gevent import socket
from gevent.lock import Semaphore
from gevent.ssl import SSLSocket, PROTOCOL_TLSv1_2, CERT_NONE
from gnsq.errors import NSQSocketError
    from .snappy import SnappySocket
from .defalte import DefalteSocket
import six
import gevent

        keyfile=None,
        certfile=None,
        cert_reqs=CERT_NONE,
        ca_certs=None,
        ssl_version=PROTOCOL_TLSv1_2
    ):
        self.ensure_connection()

        try:
            self.socket = SSLSocket(
                self.socket,
                keyfile=keyfile,
                certfile=certfile,
                cert_reqs=cert_reqs,
                ca_certs=ca_certs,
                ssl_version=ssl_version,
            )
        except socket.error as error:
            six.raise_from(NSQSocketError(*error.args), error)

    def upgrade_to_snappy(self):
        if SnappySocket is None:
            raise RuntimeError('snappy requires the python-snappy package')

        self.ensure_connection()
        self.socket = SnappySocket(self.socket)
        self.socket.bootstrap(self.consume_buffer())

    def upgrade_to_defalte(self, level):
        self.ensure_connection()

        self.socket = DefalteSocket(self.socket, level)