# Path: muninn/enum.py
# class MetaEnum(type):
#     def __new__(meta, name, bases, dct):
#     def count(cls):
#     def valid(cls, value):
#     def items(cls):
#     def to_string(cls, value):
#     def from_string(cls, value):
# 
# Path: muninn/visitor.py
# class Visitor(object):
#     def visit(self, visitable, *args, **kwargs):
#         for type_ in inspect.getmro(type(visitable)):
#             try:
#                 visit_func = getattr(self, "visit_%s" % type_.__name__)
#             except AttributeError:
#                 pass
#             else:
#                 return visit_func(visitable, *args, **kwargs)
# 
#         try:
#             visit_func = getattr(self, "default")
#         except AttributeError:
#             pass
#         else:
#             return visit_func(visitable, *args, **kwargs)


import codecs
import struct
from muninn.enum import Enum
from muninn.exceptions import *
from muninn.geometry import *
from muninn.visitor import Visitor


def _decode_multi_polygon(stream):
    return MultiPolygon(_decode_geometry_sequence(stream, GeometryType.POLYGON))


def _decode_ewkb(stream, expected_ewkb_type=None):
    ewkb_type = stream.decode("I")
    ewkb_type, ewkb_flags = ewkb_type & 0x00FFFFFF, ewkb_type >> 28

    if expected_ewkb_type is not None and ewkb_type != expected_ewkb_type:
        raise Error("unexpected EWKB type code: %s (expected: %s)" % (ewkb_type, expected_ewkb_type))

    if ewkb_flags == 0x02:
        srid = stream.decode("I")
        if srid != 4326:
            raise Error("unsupported SRID code: %d" % srid)
    elif ewkb_flags != 0x00:
        raise Error("unsupported EWKB type flags: %d" % ewkb_flags)

    if ewkb_type == GeometryType.POINT:
        return _decode_point(stream)
    elif ewkb_type == GeometryType.LINESTRING:
        return _decode_line_string(stream)
    elif ewkb_type == GeometryType.POLYGON:
        return _decode_polygon(stream)
    elif ewkb_type == GeometryType.MULTIPOINT:
        return _decode_multi_point(stream)
    elif ewkb_type == GeometryType.MULTILINESTRING:
        return _decode_multi_line_string(stream)

# Path: muninn/enum.py
# class MetaEnum(type):
#     def __new__(meta, name, bases, dct):
#     def count(cls):
#     def valid(cls, value):
#     def items(cls):
#     def to_string(cls, value):
#     def from_string(cls, value):
# 
# Path: muninn/visitor.py
# class Visitor(object):
#     def visit(self, visitable, *args, **kwargs):
#         for type_ in inspect.getmro(type(visitable)):
#             try:
#                 visit_func = getattr(self, "visit_%s" % type_.__name__)
#             except AttributeError:
#                 pass
#             else:
#                 return visit_func(visitable, *args, **kwargs)
# 
#         try:
#             visit_func = getattr(self, "default")
#         except AttributeError:
#             pass
#         else:
#             return visit_func(visitable, *args, **kwargs)


# Path: muninn/database/ewkb.py
import codecs
import struct
from muninn.enum import Enum
from muninn.exceptions import *
from muninn.geometry import *
from muninn.visitor import Visitor



def _decode_multi_polygon(stream):
    return MultiPolygon(_decode_geometry_sequence(stream, GeometryType.POLYGON))


def _decode_ewkb(stream, expected_ewkb_type=None):
    ewkb_type = stream.decode("I")
    ewkb_type, ewkb_flags = ewkb_type & 0x00FFFFFF, ewkb_type >> 28

    if expected_ewkb_type is not None and ewkb_type != expected_ewkb_type:
        raise Error("unexpected EWKB type code: %s (expected: %s)" % (ewkb_type, expected_ewkb_type))

    if ewkb_flags == 0x02:
        srid = stream.decode("I")
        if srid != 4326:
            raise Error("unsupported SRID code: %d" % srid)
    elif ewkb_flags != 0x00:
        raise Error("unsupported EWKB type flags: %d" % ewkb_flags)

    if ewkb_type == GeometryType.POINT:
        return _decode_point(stream)
    elif ewkb_type == GeometryType.LINESTRING:
        return _decode_line_string(stream)
    elif ewkb_type == GeometryType.POLYGON:
        return _decode_polygon(stream)
    elif ewkb_type == GeometryType.MULTIPOINT:
        return _decode_multi_point(stream)
    elif ewkb_type == GeometryType.MULTILINESTRING:
        return _decode_multi_line_string(stream)

    elif ewkb_type == GeometryType.MULTIPOLYGON: