# Path: distance/bytes.py
# UTF_16_DECODE = codecs.getdecoder('utf-16-le')
# UTF_16_ENCODE = codecs.getencoder('utf-16-le')
# S_COLOR_RGBA = Struct("<4f")
# S_FLOAT = Struct("<f")
# S_DOUBLE = Struct("<d")
# S_FLOAT3 = Struct("<fff")
# S_FLOAT4 = Struct("<ffff")
# S_BYTE = Struct('b')
# S_INT = Struct('<i')
# S_LONG = Struct('<q')
# S_UINT = Struct('<I')
# S_ULONG = Struct('<Q')
# S_UINT2 = Struct("<II")
# S_UINT3 = Struct("<III")
# SKIP_BYTES = b'\xFD\xFF\xFF\x7F'
# MAGIC_1 = 11111111
# MAGIC_2 = 22222222
# MAGIC_3 = 33333333
# MAGIC_5 = 55555555
# MAGIC_6 = 66666666
# MAGIC_7 = 77777777
# MAGIC_8 = 88888888
# MAGIC_9 = 99999999
# MAGIC_12 = 12121212
# MAGIC_32 = 32323232
# CATCH_EXCEPTIONS = (ValueError, EOFError)
# S_SEC_BASE = Struct("<IQ")
#     MIN_SIZE = 12 # 4b (magic) + 8b (data_size)
# class ErrorPosition(namedtuple('_ErrorPosition', ['start', 'error'])):
# class BytesModel(object):
# class Section(BytesModel):
# class DstBytes(object):
#     def __repr__(self):
#     def get(cls, ex):
#     def first(cls, ex):
#     def maybe(cls, dbytes, **kw):
#     def iter_n_maybe(cls, dbytes, n, **kw):
#     def lazy_n_maybe(cls, dbytes, n, *, start_pos=None, **kw):
#     def __init__(self, dbytes=None, **kw):
#     def read(self, dbytes, *, seek_end=True, **kw):
#     def _read(self, dbytes):
#     def _init_defaults(self):
#     def _after_init(self):
#     def write(self, dbytes, **kw):
#     def visit_write(self, dbytes):
#     def __repr__(self):
#     def _repr_detail(self):
#     def print(self, file=None, flags=(), p=None):
#     def visit_print(self, p):
#     def _print_type(self, p):
#     def _print_offset(self, p):
#     def _visit_print_data(self, p):
#     def _visit_print_children(self, p):
#     def base(cls, *args, **kw):
#     def __init__(self, *args, **kw):
#     def _init_from_args(self, *args, any_version=False, base=None, **kw):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def to_key(self, noversion=False):
#     def from_key(cls, key):
#     def has_version(self):
#     def _read(self, dbytes):
#     def _write_header(self, dbytes):
#     def _print_type(self, p):
#     def _print_offset(self, p):
#     def __init__(self, file):
#     def __repr__(self):
#     def in_memory(cls):
#     def from_data(cls, data):
#     def from_arg(cls, arg):
#     def _write_arg(cls, obj, arg, write_mode='wb'):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, exc_traceback):
#     def read_bytes(self, n):
#     def read_byte(self):
#     def read_var_int(self):
#     def read_uint(self):
#     def read_int(self):
#     def read_ulong(self):
#     def read_long(self):
#     def read_struct(self, st):
#     def read_str(self):
#     def read_id(self):
#     def write_bytes(self, data):
#     def write_uint(self, value):
#     def write_int(self, value):
#     def write_ulong(self, value):
#     def write_long(self, value):
#     def write_var_int(self, value):
#     def require_equal_uint4(self, expect):
#     def write_str(self, s):
#     def write_id(self, id_):
#     def stable_iter(self, source, *, start_pos=None):
#         def gen():
#     def write_size(self):
#     def write_num_subsections(self):
#     def write_section(self, *args, **kw):
# 
# Path: distance/printing.py
# def format_bytes(data, fmt='02x'):
#     if isinstance(data, (tuple, list)):
#         return ', '.join(format_bytes(d) for d in data)
#     else:
#         return ' '.join(format(b, fmt) for b in data)


from collections import OrderedDict
from .bytes import Magic, S_FLOAT4
from .printing import format_bytes
    def _write_property(self, dbytes, propname, value):
        dbytes.write_str(propname)
        if not self.old_format:
            dbytes.write_ulong(dbytes.tell() + len(value) + 8)
            dbytes.write_bytes(value)
        else:
            # Assume value is of correct length. Usually
            # only 4b values are found.
            dbytes.write_bytes(value)

    def print(self, p):
        p(f"Properties: {len(self)}")
        with p.tree_children(len(self)):
            for k, v in self.items():
                p.tree_next_child()
                p(f"Property: {k!r} = {format_bytes(v)}")


class ColorSet(OrderedDict):

    def read(self, dbytes):
        if dbytes.read_uint() != Magic[1]:
            raise ValueError(f"expected {Magic[1]}")
        num_colors = dbytes.read_uint()
        for _ in range(num_colors):
            colname, colors = self.read_color(dbytes)
            self[colname] = colors

    def read_color(self, dbytes):
        colname = dbytes.read_str()

# Path: distance/bytes.py
# UTF_16_DECODE = codecs.getdecoder('utf-16-le')
# UTF_16_ENCODE = codecs.getencoder('utf-16-le')
# S_COLOR_RGBA = Struct("<4f")
# S_FLOAT = Struct("<f")
# S_DOUBLE = Struct("<d")
# S_FLOAT3 = Struct("<fff")
# S_FLOAT4 = Struct("<ffff")
# S_BYTE = Struct('b')
# S_INT = Struct('<i')
# S_LONG = Struct('<q')
# S_UINT = Struct('<I')
# S_ULONG = Struct('<Q')
# S_UINT2 = Struct("<II")
# S_UINT3 = Struct("<III")
# SKIP_BYTES = b'\xFD\xFF\xFF\x7F'
# MAGIC_1 = 11111111
# MAGIC_2 = 22222222
# MAGIC_3 = 33333333
# MAGIC_5 = 55555555
# MAGIC_6 = 66666666
# MAGIC_7 = 77777777
# MAGIC_8 = 88888888
# MAGIC_9 = 99999999
# MAGIC_12 = 12121212
# MAGIC_32 = 32323232
# CATCH_EXCEPTIONS = (ValueError, EOFError)
# S_SEC_BASE = Struct("<IQ")
#     MIN_SIZE = 12 # 4b (magic) + 8b (data_size)
# class ErrorPosition(namedtuple('_ErrorPosition', ['start', 'error'])):
# class BytesModel(object):
# class Section(BytesModel):
# class DstBytes(object):
#     def __repr__(self):
#     def get(cls, ex):
#     def first(cls, ex):
#     def maybe(cls, dbytes, **kw):
#     def iter_n_maybe(cls, dbytes, n, **kw):
#     def lazy_n_maybe(cls, dbytes, n, *, start_pos=None, **kw):
#     def __init__(self, dbytes=None, **kw):
#     def read(self, dbytes, *, seek_end=True, **kw):
#     def _read(self, dbytes):
#     def _init_defaults(self):
#     def _after_init(self):
#     def write(self, dbytes, **kw):
#     def visit_write(self, dbytes):
#     def __repr__(self):
#     def _repr_detail(self):
#     def print(self, file=None, flags=(), p=None):
#     def visit_print(self, p):
#     def _print_type(self, p):
#     def _print_offset(self, p):
#     def _visit_print_data(self, p):
#     def _visit_print_children(self, p):
#     def base(cls, *args, **kw):
#     def __init__(self, *args, **kw):
#     def _init_from_args(self, *args, any_version=False, base=None, **kw):
#     def __repr__(self):
#     def __getitem__(self, key):
#     def to_key(self, noversion=False):
#     def from_key(cls, key):
#     def has_version(self):
#     def _read(self, dbytes):
#     def _write_header(self, dbytes):
#     def _print_type(self, p):
#     def _print_offset(self, p):
#     def __init__(self, file):
#     def __repr__(self):
#     def in_memory(cls):
#     def from_data(cls, data):
#     def from_arg(cls, arg):
#     def _write_arg(cls, obj, arg, write_mode='wb'):
#     def __enter__(self):
#     def __exit__(self, exc_type, exc_value, exc_traceback):
#     def read_bytes(self, n):
#     def read_byte(self):
#     def read_var_int(self):
#     def read_uint(self):
#     def read_int(self):
#     def read_ulong(self):
#     def read_long(self):
#     def read_struct(self, st):
#     def read_str(self):
#     def read_id(self):
#     def write_bytes(self, data):
#     def write_uint(self, value):
#     def write_int(self, value):
#     def write_ulong(self, value):
#     def write_long(self, value):
#     def write_var_int(self, value):
#     def require_equal_uint4(self, expect):
#     def write_str(self, s):
#     def write_id(self, id_):
#     def stable_iter(self, source, *, start_pos=None):
#         def gen():
#     def write_size(self):
#     def write_num_subsections(self):
#     def write_section(self, *args, **kw):
# 
# Path: distance/printing.py
# def format_bytes(data, fmt='02x'):
#     if isinstance(data, (tuple, list)):
#         return ', '.join(format_bytes(d) for d in data)
#     else:
#         return ' '.join(format(b, fmt) for b in data)


# Path: distance/_data.py
from collections import OrderedDict
from .bytes import Magic, S_FLOAT4
from .printing import format_bytes

    def _write_property(self, dbytes, propname, value):
        dbytes.write_str(propname)
        if not self.old_format:
            dbytes.write_ulong(dbytes.tell() + len(value) + 8)
            dbytes.write_bytes(value)
        else:
            # Assume value is of correct length. Usually
            # only 4b values are found.
            dbytes.write_bytes(value)

    def print(self, p):
        p(f"Properties: {len(self)}")
        with p.tree_children(len(self)):
            for k, v in self.items():
                p.tree_next_child()
                p(f"Property: {k!r} = {format_bytes(v)}")


class ColorSet(OrderedDict):

    def read(self, dbytes):
        if dbytes.read_uint() != Magic[1]:
            raise ValueError(f"expected {Magic[1]}")
        num_colors = dbytes.read_uint()
        for _ in range(num_colors):
            colname, colors = self.read_color(dbytes)
            self[colname] = colors

    def read_color(self, dbytes):
        colname = dbytes.read_str()

        colors = dbytes.read_struct(S_FLOAT4)