예제 #1
0
파일: connection.py 프로젝트: willp/kazoo
 def _submit(self, request, timeout, xid=None):
     """Submit a request object with a timeout value and optional
     xid"""
     b = bytearray()
     b.extend(int_struct.pack(xid))
     if request.type:
         b.extend(int_struct.pack(request.type))
     b += request.serialize()
     self._write(int_struct.pack(len(b)) + b, timeout)
예제 #2
0
 def _submit(self, request, timeout, xid=None):
     """Submit a request object with a timeout value and optional
     xid"""
     b = bytearray()
     b.extend(int_struct.pack(xid))
     if request.type:
         b.extend(int_struct.pack(request.type))
     b += request.serialize()
     self._write(int_struct.pack(len(b)) + b, timeout)
예제 #3
0
파일: connection.py 프로젝트: mrtheb/kazoo
 def _submit(self, request, timeout, xid=None):
     """Submit a request object with a timeout value and optional
     xid"""
     b = bytearray()
     if xid:
         b.extend(int_struct.pack(xid))
     if request.type:
         b.extend(int_struct.pack(request.type))
     b += request.serialize()
     self.logger.log((logging.DEBUG if isinstance(request, Ping) else logging.INFO),
                     "Sending request(xid=%s): %s", xid, request)
     self._write(int_struct.pack(len(b)) + b, timeout)
예제 #4
0
 def _submit(self, request, timeout, xid=None):
     """Submit a request object with a timeout value and optional
     xid"""
     b = bytearray()
     if xid:
         b.extend(int_struct.pack(xid))
     if request.type:
         b.extend(int_struct.pack(request.type))
     b += request.serialize()
     self.logger.log(
         (BLATHER if isinstance(request, Ping) else logging.DEBUG),
         "Sending request(xid=%s): %s", xid, request)
     self._write(int_struct.pack(len(b)) + b, timeout)
예제 #5
0
파일: connection.py 프로젝트: willp/kazoo
    def _invoke(self, timeout, request, xid=None):
        """A special writer used during connection establishment
        only"""
        b = bytearray()
        if xid:
            b.extend(int_struct.pack(xid))
        if request.type:
            b.extend(int_struct.pack(request.type))
        b.extend(request.serialize())

        if self.log_debug:
            log.debug("Sending request: %s", request)
        self._write(int_struct.pack(len(b)) + b, timeout)

        zxid = None
        if xid:
            header, buffer, offset = self._read_header(timeout)
            if header.xid != xid:
                raise RuntimeError('xids do not match, expected %r received %r',
                                   xid, header.xid)
            if header.zxid > 0:
                zxid = header.zxid
            if header.err:
                callback_exception = EXCEPTIONS[header.err]()
                log.debug('Received error %r', callback_exception)
                raise callback_exception
            return zxid

        msg = self._read(4, timeout)
        length = int_struct.unpack(msg)[0]
        msg = self._read(length, timeout)

        if hasattr(request, 'deserialize'):
            obj, _ = request.deserialize(msg, 0)
            log.debug('Read response %s', obj)
            return obj, zxid

        return zxid
예제 #6
0
    def _invoke(self, timeout, request, xid=None):
        """A special writer used during connection establishment
        only"""
        b = bytearray()
        if xid:
            b.extend(int_struct.pack(xid))
        if request.type:
            b.extend(int_struct.pack(request.type))
        b.extend(request.serialize())

        if self.log_debug:
            log.debug("Sending request: %s", request)
        self._write(int_struct.pack(len(b)) + b, timeout)

        zxid = None
        if xid:
            header, buffer, offset = self._read_header(timeout)
            if header.xid != xid:
                raise RuntimeError('xids do not match, expected %r received %r',
                                   xid, header.xid)
            if header.zxid > 0:
                zxid = header.zxid
            if header.err:
                callback_exception = EXCEPTIONS[header.err]()
                log.debug('Received error %r', callback_exception)
                raise callback_exception
            return zxid

        msg = self._read(4, timeout)
        length = int_struct.unpack(msg)[0]
        msg = self._read(length, timeout)

        if hasattr(request, 'deserialize'):
            obj, _ = request.deserialize(msg, 0)
            log.debug('Read response %s', obj)
            return obj, zxid

        return zxid
예제 #7
0
 def serialize(self):
     b = bytearray()
     b.extend(write_string(self.path))
     b.extend(int_struct.pack(self.version))
     return b
예제 #8
0
 def serialize(self):
     b = bytearray()
     b.extend(write_string(self.path))
     b.extend(int_struct.pack(self.version))
     return b