예제 #1
0
def get_uri(uri):
    """Request the given URI and return the response

    Checks for 200 response and raises appropriate exceptions otherwise.

    """
    response = requests.get(uri)
    if response.status_code == 404:
        raise exceptions.NotFound("Can't locate {a}: {b}".format(a=uri,
                                                                 b=response))
    elif response.status_code != 200:
        raise exceptions.RemoteError(
            "Unexpected response from {a}: {b}".format(a=uri, b=response))
    return response
예제 #2
0
 def get_file(self, package, filename):
     path = self.get_file_path(package, filename)
     try:
         return open(path, "rb")
     except IOError:
         self.log.info("Fishing for package file matching {a}: {b}".format(a = package, b = filename))
         # Try fishing for the file with different cases
         for my_package in self.list_packages():
             if package.lower() == my_package.lower():
                 for fileinfo in self.list_files(my_package):
                     my_filename = fileinfo["filename"]
                     if my_filename.lower() == filename.lower():
                         return self.get_file(my_package, my_filename)
         raise exceptions.NotFound("Package {a}: {b} not found in {c}".format(a = package, b = filename, c = path))
예제 #3
0
 def fail(*args, **kwargs):
     raise exceptions.NotFound("Unknown package")