Example #1
0
 def __init__(self, defaults):
     self.distbase = defaults.distbase
     self.distdefault = defaults.distdefault
     self.aliases = defaults.aliases
     self.servers = defaults.servers
     self.locations = []
     self.urlparser = URLParser()
Example #2
0
 def __init__(self, urlparser=None):
     self.urlparser = urlparser or URLParser()
Example #3
0
 def __init__(self, process=None, urlparser=None):
     self.process = process or Process(env=self.get_env())
     self.urlparser = urlparser or URLParser()
     self.dirstack = ChdirStack()
Example #4
0
    def testHTTPNoPageWithoutProtocol(self):
        url = fetchURL("www.some.com/")
        parser = URLParser(url.url)
        protocol = parser.getPage()

        self.assertEqual(protocol, "")
Example #5
0
    def testHTTPPageWithoutProtocol(self):
        url = fetchURL("www.some.com/someootherfolder/one/two/three/index.html")
        parser = URLParser(url.url)
        protocol = parser.getPage()

        self.assertEqual(protocol, "someootherfolder/one/two/three/index.html")
Example #6
0
    def testHTTPPage2(self):
        url = fetchURL("http://www.some.com/someootherfolder/index.html")
        parser = URLParser(url.url)
        protocol = parser.getPage()

        self.assertEqual(protocol, "someootherfolder/index.html")
Example #7
0
    def testHostNoProtocol(self):
        url = fetchURL("www.someothersite.com/index.html")
        parser = URLParser(url.url)
        host = protocol = parser.getHost()

        self.assertEqual(host, "www.someothersite.com")
Example #8
0
    def testHost1(self):
        url = fetchURL("http://www.some.com/index.html")
        parser = URLParser(url.url)
        host = protocol = parser.getHost()

        self.assertEqual(host, "www.some.com")
Example #9
0
    def testUnknownProtocol(self):
        url = fetchURL("qwery://www.some.com/index.html")
        parser = URLParser(url.url)
        protocol = parser.getProtocol()

        self.assertEqual(protocol, "qwery")
Example #10
0
    def testNoProtocol(self):
        url = fetchURL("www.some.com/index.html")
        parser = URLParser(url.url)
        protocol = parser.getProtocol()

        self.assertEqual(protocol, "")
Example #11
0
    def testHTTPProtocl(self):
        url = fetchURL("http://www.some.com/index.html")
        parser = URLParser(url.url)
        protocol = parser.getProtocol()

        self.assertEqual(protocol, "http")
Example #12
0
class Locations(object):

    def __init__(self, defaults):
        self.distbase = defaults.distbase
        self.distdefault = defaults.distdefault
        self.aliases = defaults.aliases
        self.servers = defaults.servers
        self.locations = []
        self.urlparser = URLParser()

    def __len__(self):
        """Return number of locations.
        """
        return len(self.locations)

    def __iter__(self):
        """Iterate over locations.
        """
        return iter(self.locations)

    def extend(self, location):
        """Extend list of locations.
        """
        self.locations.extend(location)

    def is_server(self, location):
        """Return True if 'location' is an index server.
        """
        return location in self.servers

    def is_dist_url(self, location):
        """Return True if 'location' is an scp or sftp URL.
        """
        return self.urlparser.get_scheme(location) in ('scp', 'sftp')

    def has_host(self, location):
        """Return True if 'location' contains a host part.
        """
        return self.urlparser.is_ssh_url(location)

    def join(self, distbase, location):
        """Join 'distbase' and 'location' in such way that the
        result is a valid scp destination.
        """
        sep = ''
        if distbase and distbase[-1] not in (':', '/'):
            sep = '/'
        return distbase + sep + location

    def get_location(self, location, depth=0):
        """Resolve aliases and apply distbase.
        """
        if not location:
            return []
        if location in self.aliases:
            res = []
            if depth > MAXALIASDEPTH:
                err_exit('Maximum alias depth exceeded: %(location)s' % locals())
            for loc in self.aliases[location]:
                res.extend(self.get_location(loc, depth+1))
            return res
        if self.is_server(location):
            return [location]
        if location == 'pypi':
            err_exit('No configuration found for server: pypi\n'
                     'Please create a ~/.pypirc file')
        if self.urlparser.is_url(location):
            return [location]
        if not self.has_host(location) and self.distbase:
            return [self.join(self.distbase, location)]
        return [location]

    def get_default_location(self):
        """Return the default location.
        """
        res = []
        for location in self.distdefault:
            res.extend(self.get_location(location))
        return res

    def check_valid_locations(self, locations=None):
        """Fail if 'locations' is empty or contains bad destinations.
        """
        if locations is None:
            locations = self.locations
        if not locations:
            err_exit('mkrelease: option -d is required\n%s' % USAGE)
        for location in locations:
            if (not self.is_server(location) and
                not self.is_dist_url(location) and
                not self.has_host(location)):
                err_exit('Unknown location: %(location)s' % locals())