# Path: ethronsoft/gcspypi/utilities/queries.py
# def get_package_type(path):
#     if ".zip" in path:
#         return "SOURCE"
#     elif ".tar" in path:
#         return "SOURCE"
#     elif ".whl" in path:
#         return "WHEEL"
#     else:
#         raise InvalidParameter("Unrecognized file extension. expected {.zip|.tar*|.whl}")
# 
# Path: ethronsoft/gcspypi/package/package.py
# class Package(object):
# 
#     def __init__(self, name, version="", requirements=set([]), type=""):
#         self.name = name.replace("_", "-")
#         self.version = complete_version(version) if version else None
#         self.requirements = set([])
#         self.type = type
#         for r in requirements:
#             self.requirements.add(r.replace("_","-"))
# 
#     @staticmethod
#     def repo_name(pkg, filename):
#         if not pkg.version:
#             raise InvalidState("cannot formulate package repository-name for a package without version")
#         return "{name}/{version}/{filename}".format(
#             name=pkg.name,
#             version=pkg.version,
#             filename=os.path.split(filename)[1]
#         )
# 
#     @staticmethod
#     def from_text(text):
#         if ">" in text or "<" in text:
#             raise InvalidParameter("Cannot create a package with non deterministic version")
#         if "==" in text:
#             name, version = text.split("==")
#             return Package(name.strip(), version.strip())
#         else:
#             return Package(text)
# 
#     def __str__(self):
#         return self.full_name
# 
#     def __repr__(self): # pragma: no cover
#         return "<Package {}>".format(str(self))
# 
#     def __eq__(self, o):
#         if not o: return False
#         return (self.name, self.version, self.type) == (o.name, o.version, o.type)
# 
#     def __ne__(self, o):
#         return not self.__eq__(o)
# 
#     def __hash__(self):
#         return hash((self.name, str(self.version), self.type))
# 
#     @property
#     def full_name(self):
#         return self.name + ":" + self.version if self.version else self.name
# 
# Path: ethronsoft/gcspypi/exceptions/state_errors.py
# class InvalidState(Exception):
#     pass


from ethronsoft.gcspypi.utilities.queries import get_package_type
from ethronsoft.gcspypi.package.package import Package
from ethronsoft.gcspypi.exceptions import InvalidState
import json
import os
import shutil
import tarfile
import tempfile
import zipfile
                for line in target.readlines():
                    k, v = line.split(":")
                    m[k.upper().strip()] = v.strip()
                self.metadata["name"] = m["name".upper()]
                self.metadata["version"] = m["version".upper()]

        cmd = InfoCmd()
        self.__seek_and_apply(zpfile, "PKG-INFO", cmd)
        if not cmd.metadata:
            raise InvalidState("Could not find PKG-INFO")
        return {"name": cmd.metadata["name"],
                "version": cmd.metadata["version"],
                "requirements": self.__read_requirements(zpfile)}

    def __extract_wheel(self, zpfile):
        class InfoCmd(object):
            def __init__(self):
                self.metadata = {}

            def __call__(self, target):
                m = json.loads(target.read())
                self.metadata["name"] = m["name"]
                self.metadata["version"] = m["version"]
                self.metadata["requirements"] = set([])
                for reqs in m["run_requires"]:
                    self.metadata["requirements"].update(reqs["requires"])

        cmd = InfoCmd()
        self.__seek_and_apply(zpfile, "metadata.json", cmd)
        if not cmd.metadata:

# Path: ethronsoft/gcspypi/utilities/queries.py
# def get_package_type(path):
#     if ".zip" in path:
#         return "SOURCE"
#     elif ".tar" in path:
#         return "SOURCE"
#     elif ".whl" in path:
#         return "WHEEL"
#     else:
#         raise InvalidParameter("Unrecognized file extension. expected {.zip|.tar*|.whl}")
# 
# Path: ethronsoft/gcspypi/package/package.py
# class Package(object):
# 
#     def __init__(self, name, version="", requirements=set([]), type=""):
#         self.name = name.replace("_", "-")
#         self.version = complete_version(version) if version else None
#         self.requirements = set([])
#         self.type = type
#         for r in requirements:
#             self.requirements.add(r.replace("_","-"))
# 
#     @staticmethod
#     def repo_name(pkg, filename):
#         if not pkg.version:
#             raise InvalidState("cannot formulate package repository-name for a package without version")
#         return "{name}/{version}/{filename}".format(
#             name=pkg.name,
#             version=pkg.version,
#             filename=os.path.split(filename)[1]
#         )
# 
#     @staticmethod
#     def from_text(text):
#         if ">" in text or "<" in text:
#             raise InvalidParameter("Cannot create a package with non deterministic version")
#         if "==" in text:
#             name, version = text.split("==")
#             return Package(name.strip(), version.strip())
#         else:
#             return Package(text)
# 
#     def __str__(self):
#         return self.full_name
# 
#     def __repr__(self): # pragma: no cover
#         return "<Package {}>".format(str(self))
# 
#     def __eq__(self, o):
#         if not o: return False
#         return (self.name, self.version, self.type) == (o.name, o.version, o.type)
# 
#     def __ne__(self, o):
#         return not self.__eq__(o)
# 
#     def __hash__(self):
#         return hash((self.name, str(self.version), self.type))
# 
#     @property
#     def full_name(self):
#         return self.name + ":" + self.version if self.version else self.name
# 
# Path: ethronsoft/gcspypi/exceptions/state_errors.py
# class InvalidState(Exception):
#     pass


# Path: ethronsoft/gcspypi/package/package_builder.py
from ethronsoft.gcspypi.utilities.queries import get_package_type
from ethronsoft.gcspypi.package.package import Package
from ethronsoft.gcspypi.exceptions import InvalidState
import json
import os
import shutil
import tarfile
import tempfile
import zipfile

                for line in target.readlines():
                    k, v = line.split(":")
                    m[k.upper().strip()] = v.strip()
                self.metadata["name"] = m["name".upper()]
                self.metadata["version"] = m["version".upper()]

        cmd = InfoCmd()
        self.__seek_and_apply(zpfile, "PKG-INFO", cmd)
        if not cmd.metadata:
            raise InvalidState("Could not find PKG-INFO")
        return {"name": cmd.metadata["name"],
                "version": cmd.metadata["version"],
                "requirements": self.__read_requirements(zpfile)}

    def __extract_wheel(self, zpfile):
        class InfoCmd(object):
            def __init__(self):
                self.metadata = {}

            def __call__(self, target):
                m = json.loads(target.read())
                self.metadata["name"] = m["name"]
                self.metadata["version"] = m["version"]
                self.metadata["requirements"] = set([])
                for reqs in m["run_requires"]:
                    self.metadata["requirements"].update(reqs["requires"])

        cmd = InfoCmd()
        self.__seek_and_apply(zpfile, "metadata.json", cmd)
        if not cmd.metadata:

            raise InvalidState("Could not find metadata.json")