def extract_bower_zipfile(self, zip_file, dest, expected_version=None):
        bower_json = None
        root = None
        deps_installed = []
        for info in zip_file.infolist():
            if PurePath(info.filename).name == "bower.json":
                with zip_file.open(info) as f:
                    bower_json = json.load(f)
                    root = str(PurePath(info.filename).parent)
                break
        version = bower_json["version"]
        if expected_version is not None:
            expected_version = Bower.clean_semver(expected_version)
            if not semver.match(version, expected_version):
                click.secho("error: versions do not match ({} =/= {})".format(
                    version, expected_version))
                raise InvalidPackageError
        if "dependencies" in bower_json:
            for package, version in bower_json["dependencies"].items():
                url = Bower.get_package_url(package)
                deps_installed.extend(self.get_bower_package(
                    url, dest=dest, version=version))
        ignore_patterns = [GitIgnorePattern(ig) for ig in bower_json["ignore"]]
        path_spec = PathSpec(ignore_patterns)
        namelist = [path for path in zip_file.namelist()
                    if PurePath(path).parts[0] == root]
        ignored = list(path_spec.match_files(namelist))
        for path in namelist:
            dest_path = PurePath(
                bower_json["name"],
                *PurePath(path).parts[1:])

            if path in ignored:
                continue

            for path in ignored:
                for parent in PurePath(path):
                    if parent in ignored:
                        continue

            if path.endswith("/"):
                if list(path_spec.match_files([str(dest_path)])):
                    ignored.append(PurePath(path))
                elif not (dest / dest_path).is_dir():
                    (dest / dest_path).mkdir(parents=True)
            else:
                target_path = dest / dest_path.parent / dest_path.name
                source = zip_file.open(path)
                target = target_path.open("wb")
                with source, target:
                    shutil.copyfileobj(source, target)
        deps_installed.append((bower_json["name"], bower_json["version"]))
        return deps_installed
def deny(self,
             error_msg,
             error_code="",
             reviewing_user=None,
             reviewing_service=""):
        """
        Deny this attempt.

        Valid attempt statuses when calling this method:
            `submitted`, `approved`, `denied`

        Status after method completes: `denied`

        Other fields that will be set by this method:
            `reviewed_by_user_id`, `reviewed_by_service`, `error_msg`,
            `error_code`

        State Transitions:

        `submitted` → `denied`
            This is the usual flow, whether initiated by a staff user or an
            external validation service.
        `approved` → `denied`
            This might happen if a staff member wants to override a decision
            made by an external service or another staff member, or just correct
            a mistake made during the approval process. In this case, the
            previous values of `reviewed_by_user_id` and `reviewed_by_service`
            will be changed to whoever is doing the denying. The only record
            that this record was ever approved would be in our logs. This should
            be a relatively rare occurence.
        `denied` → `denied`
            Update the error message and reviewing_user/reviewing_service. Just
            lets you amend the error message in case there were additional
            details to be made.
        """
        log.info(u"Verification for user '{user_id}' denied by '{reviewer}'.".format(
            user_id=self.user, reviewer=reviewing_user
        ))
        self.error_msg = error_msg
        self.error_code = error_code
        self.reviewing_user = reviewing_user
        self.reviewing_service = reviewing_service
        self.status = "denied"
        self.save()