How to use quarry - 10 common examples

To help you get started, we’ve selected a few quarry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github barneygale / quarry / quarry / types / nbt.py View on Github external
def to_bytes(self):
        data = self.value.to_bytes()
        data = Buffer.pack('i', len(data) // (self.width // 8)) + data
        return data
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_read():
    buffer = Buffer()
    buffer.add(b"spam")
    assert buffer.read(2) == b"sp"
    assert buffer.read(2) == b"am"
    buffer.add(b"eggs")
    assert buffer.read() == b"eggs"
    with pytest.raises(BufferUnderrun):
        buffer.read(1)
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_string():
    buffer = Buffer()
    buffer.add(b"\x04spam")
    assert buffer.unpack_string() == "spam"
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_chat():
    buffer = Buffer()
    buffer.add(b'\x11["spam", " eggs"]')
    assert buffer.unpack_chat().to_string() == "spam eggs"
    buffer.add(b'\x22{"text": "spam", "extra": " eggs"}')
    assert buffer.unpack_chat().to_string() == "spam eggs"
    buffer.add(b'\x14{"translate": "foo"}')
    assert buffer.unpack_chat().to_string() == "foo"
    buffer.add(b'\x2E{"translate": "foo", "with": ["spam", "eggs"]}')
    assert buffer.unpack_chat().to_string() == "foo{spam, eggs}"
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_unpack_uuid():
    buffer = Buffer()
    buffer.add(uuid_vector)
    assert buffer.unpack_uuid().to_bytes() == uuid_vector
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_add():
    buffer = Buffer()
    buffer.add(b"spam")
    assert len(buffer) == 4
    assert buffer.read() == b"spam"
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_pack():
    for fmt, data, values in pack_unpack_vectors:
        if not isinstance(values, tuple):
            values = (values,)
        assert Buffer.pack(fmt, *values) == data
github barneygale / quarry / tests / types / test_buffer.py View on Github external
]
entity_metadata_vectors = [
    (OrderedDict((
        ((0, 0), 0),
        ((1, 1), 1),
        ((2, 2), 2.0),
        ((3, 3), u'three'),
        ((4, 4), Message({'text': u'four'})),
        ((5, 5), Message({'text': u'five'})),
        ((6, 6), {'count': 1, 'item': 267, 'tag': TagRoot({})}),
        ((7, 7), True),
        ((8, 8), (8, 8, 8)),
        ((9, 9), (9, 9, 9)),
        ((10, 10), (10, 10, 10)),
        ((11, 11), 'north'),
        ((12, 12), UUID.from_bytes(uuid_vector)),
        ((13, 13), 13),
        ((14, 14), TagRoot({u'foo': TagString(u'bar')})))),

        b'\x00\x00\x00'
        b'\x01\x01\x01'
        b'\x02\x02\x40\x00\x00\x00'
        b'\x03\x03\x05three'
        b'\x04\x04\x10{"text": "four"}'
        b'\x05\x05\x01\x10{"text": "five"}'
        b'\x06\x06\x01\x8b\x02\x01\x00'
        b'\x07\x07\x01'
        b'\x08\x08\x41\x00\x00\x00\x41\x00\x00\x00\x41\x00\x00\x00'
        b'\x09\x09\x00\x00\x02\x40\x00\x00\x90\x09'
        b'\x0a\x0a\x01\x00\x00\x02\x80\x00\x00\xa0\x0a'
        b'\x0b\x0b\x02'
        b'\x0c\x0c\x01' + uuid_vector +
github barneygale / quarry / tests / types / test_types.py View on Github external
def test_uuid_from_offline_player():
    uuid = UUID.from_offline_player("Notch")
    assert isinstance(uuid, UUID)
    assert uuid.to_bytes() == bytes_vector
github barneygale / quarry / tests / types / test_buffer.py View on Github external
def test_pack_uuid():
    assert Buffer.pack_uuid(UUID.from_bytes(uuid_vector)) == uuid_vector