示例#1
0
def fix_parameters(parameters):
    if not parameters:
        return {}
    dehydrator = DataDehydrator()
    try:
        dehydrated, = dehydrator.dehydrate([parameters])
    except TypeError as error:
        value = error.args[0]
        raise TypeError("Parameters of type {} are not supported".format(type(value).__name__))
    else:
        return dehydrated
示例#2
0
    def test_dehydration_2d(self):
        coordinates = (.1, 0)
        p = CartesianPoint(coordinates)

        dehydrator = DataDehydrator()
        buffer = io.BytesIO()
        packer = Packer(buffer)
        packer.pack(dehydrator.dehydrate((p, ))[0])
        self.assertEqual(
            buffer.getvalue(),
            b"\xB3X" + b"\xC9" + struct.pack(">h", 7203) + b"".join(
                map(lambda c: b"\xC1" + struct.pack(">d", c), coordinates)))
    def test_dehydration_3d(self):
        coordinates = (1, -2, 3.1)
        p = WGS84Point(coordinates)

        dehydrator = DataDehydrator()
        buffer = io.BytesIO()
        packer = Packer(buffer)
        packer.pack(dehydrator.dehydrate((p, ))[0])
        self.assertEqual(
            buffer.getvalue(),
            b"\xB4Y" + b"\xC9" + struct.pack(">h", 4979) + b"".join(
                map(lambda c: b"\xC1" + struct.pack(">d", c), coordinates)))
示例#4
0
    def test_dehydration(self):
        MyPoint = point_type("MyPoint", ["x", "y"], {2: 1234})
        coordinates = (.1, 0)
        p = MyPoint(coordinates)

        dehydrator = DataDehydrator()
        buffer = io.BytesIO()
        packer = Packer(buffer)
        packer.pack(dehydrator.dehydrate((p, ))[0])
        self.assertEqual(
            buffer.getvalue(),
            b"\xB3X" + b"\xC9" + struct.pack(">h", 1234) + b"".join(
                map(lambda c: b"\xC1" + struct.pack(">d", c), coordinates)))