# mcedit2.resourceloader — mceditlib 0.1 documentation

### Navigation

- index
- modules |
- mceditlib 0.1 documentation »
- Module code »

# Source code for mcedit2.resourceloader

    """
        ${NAME}
    """
    from __future__ import absolute_import, division, print_function, unicode_literals
    import logging
    import zipfile

    log = logging.getLogger(__name__)

    class ResourceNotFound(KeyError):
        pass

    class ResourceLoader(object):
        def __init__(self):
            super(ResourceLoader, self).__init__()
            self.zipFiles = []

        def addZipFile(self, zipPath):
            self.zipFiles.append(zipfile.ZipFile(zipPath))

        def openStream(self, path):
            path = "assets/minecraft/%s" % path

            for zipFile in self.zipFiles:
                try:
                    stream = zipFile.open(path)
                    break
                except KeyError:  # Not found in zip file
                    continue
            else:
                raise ResourceNotFound("Resource %s not found in search path" % path)

            return stream

### Navigation

- index
- modules |
- mceditlib 0.1 documentation »
- Module code »