# Path: zarr/errors.py
# class MetadataError(Exception):
#     pass
# 
# Path: zarr/util.py
# def json_dumps(o: Any) -> bytes:
#     """Write JSON in a consistent, human-readable way."""
#     return json.dumps(o, indent=4, sort_keys=True, ensure_ascii=True,
#                       separators=(',', ': ')).encode('ascii')
# 
# def json_loads(s: str) -> Dict[str, Any]:
#     """Read JSON in a consistent way."""
#     return json.loads(ensure_text(s, 'ascii'))


import base64
import numpy as np
                import numcodecs
            import numcodecs
from collections.abc import Mapping
from zarr.errors import MetadataError
from zarr.util import json_dumps, json_loads
from typing import cast, Union, Any, List, Mapping as MappingType


class Metadata2:
    ZARR_FORMAT = ZARR_FORMAT

    @classmethod
    def parse_metadata(cls, s: Union[MappingType, str]) -> MappingType[str, Any]:

        # Here we allow that a store may return an already-parsed metadata object,
        # or a string of JSON that we will parse here. We allow for an already-parsed
        # object to accommodate a consolidated metadata store, where all the metadata for
        # all groups and arrays will already have been parsed from JSON.

        if isinstance(s, Mapping):
            # assume metadata has already been parsed into a mapping object
            meta = s

        else:
            # assume metadata needs to be parsed as JSON
            meta = json_loads(s)

        return meta

    @classmethod
    def decode_array_metadata(cls, s: Union[MappingType, str]) -> MappingType[str, Any]:
        meta = cls.parse_metadata(s)

        # check metadata format
        zarr_format = meta.get("zarr_format", None)
        if zarr_format != cls.ZARR_FORMAT:

# Path: zarr/errors.py
# class MetadataError(Exception):
#     pass
# 
# Path: zarr/util.py
# def json_dumps(o: Any) -> bytes:
#     """Write JSON in a consistent, human-readable way."""
#     return json.dumps(o, indent=4, sort_keys=True, ensure_ascii=True,
#                       separators=(',', ': ')).encode('ascii')
# 
# def json_loads(s: str) -> Dict[str, Any]:
#     """Read JSON in a consistent way."""
#     return json.loads(ensure_text(s, 'ascii'))


# Path: zarr/meta.py
import base64
import numpy as np
                import numcodecs
            import numcodecs
from collections.abc import Mapping
from zarr.errors import MetadataError
from zarr.util import json_dumps, json_loads
from typing import cast, Union, Any, List, Mapping as MappingType



class Metadata2:
    ZARR_FORMAT = ZARR_FORMAT

    @classmethod
    def parse_metadata(cls, s: Union[MappingType, str]) -> MappingType[str, Any]:

        # Here we allow that a store may return an already-parsed metadata object,
        # or a string of JSON that we will parse here. We allow for an already-parsed
        # object to accommodate a consolidated metadata store, where all the metadata for
        # all groups and arrays will already have been parsed from JSON.

        if isinstance(s, Mapping):
            # assume metadata has already been parsed into a mapping object
            meta = s

        else:
            # assume metadata needs to be parsed as JSON
            meta = json_loads(s)

        return meta

    @classmethod
    def decode_array_metadata(cls, s: Union[MappingType, str]) -> MappingType[str, Any]:
        meta = cls.parse_metadata(s)

        # check metadata format
        zarr_format = meta.get("zarr_format", None)
        if zarr_format != cls.ZARR_FORMAT:

            raise MetadataError("unsupported zarr format: %s" % zarr_format)