Exemplo n.º 1
0
    def _send(self,command_str):
        command = command_str.split(",")
        debug('command %r,buffer.pointerC %r, clock %r' % (command,buffer.pointerC , clock()))

        if len(command[0]) == 0:
            msg_out =msgpack_packb([-1], default=m.encode)
        elif command[0] == "1":
            frame.live_checkbox.SetValue(False)
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "2":
            frame.live_checkbox.SetValue(False)
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "3":
            if len(commmand) >=2:
                msg_out = msgpack_packb([int(command[0]),int(command[1])], default=m.encode)
            else:
                msg_out = msgpack_packb([int(command[0]),int(1)], default=m.encode)
        elif command[0] == "4":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "5":
            msg_out = msgpack_packb([int(command[0]),int(buffer.pointerC)], default=m.encode)
            debug('msg_out %r' % msg_out)
        elif command[0] == "6":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "7":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        else:
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        self.server.sendall(msg_out)
Exemplo n.º 2
0
    def _send(self, command_str):
        command = command_str.split(",")
        print 'command', command, 'buffer.pointerC', buffer.pointerC

        if len(command[0]) == 0:
            msg_out = msgpack_packb([-1], default=m.encode)
        elif command[0] == "1":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "2":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "3":
            if len(commmand) >= 2:
                msg_out = msgpack_packb(
                    [int(command[0]), int(command[1])], default=m.encode)
            else:
                msg_out = msgpack_packb(
                    [int(command[0]), int(1)], default=m.encode)
        elif command[0] == "4":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "5":
            msg_out = msgpack_packb(
                [int(command[0]), int(buffer.pointerC)], default=m.encode)
            debug('msg_out %r' % msg_out)
        elif command[0] == "6":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        elif command[0] == "7":
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        else:
            msg_out = msgpack_packb([int(command[0])], default=m.encode)
        self.server.sendall(msg_out)
Exemplo n.º 3
0
    def get_db_prep_value ( self, value, connection=None, prepared=False ) :
        """Overrides the parent method to encode data before storing it \
        in the database."""

        if not prepared :
            value = msgpack_packb( value )
        if value is not None :
            return connection.Database.Binary( value )
        return None
Exemplo n.º 4
0
def packb(data: dict, exc_cls=SerdePackingError) -> bytes:
    """
    Raises:
        SerdePackingError
    """
    def _default(obj):
        # TODO: we should be only testing against pendulum.Pendulum, but
        # asyncpg returns datetime
        if isinstance(obj, datetime):
            return ExtType(1, struct_pack("!d", obj.timestamp()))
        elif isinstance(obj, UUID):
            return ExtType(2, obj.bytes)

        raise TypeError("Unknown type: %r" % (obj, ))

    try:
        return msgpack_packb(data, default=_default, use_bin_type=True)

    except (ExtraData, ValueError, FormatError, StackError) as exc:
        raise exc_cls(f"Invalid msgpack data: {exc}") from exc
Exemplo n.º 5
0
        return self.storage.db(self.db, write)

    @contextmanager
    def cursor(self, write=False):
        with self.ctx(write) as txn:
            cursor = txn.cursor()
            try:
                yield cursor
            finally:
                cursor.close()

    def close(self):
        self.sock.close()


mpackb = lambda o: msgpack_packb(o, use_bin_type=True)
munpackb = lambda b: msgpack_unpackb(b, raw=False)


def mpackdict(d):
    for key, value in d.items():
        yield (encode(key), mpackb(value))


def encodedict(d):
    for key, value in d.items():
        yield (encode(key), encode(value))


def requires_dupsort(meth):
    @wraps(meth)
Exemplo n.º 6
0
def serialize(value):
    return msgpack_packb(value, use_bin_type=True)