def getMetaserverURL(eventLoop, callback): """Contact the meta-meta-server to find the URL for the metaserver. call the provided callback with the URL once we find it. """ global metaMetaURL, metaURL if metaURL: callback(metaURL) else: # Stick together an HTTP request, with responseHandler called when it comes back. def responseHandler(response): lines = [line.strip() for line in response.strip().split("\n")] if lines[0] != "HTTP/1.1 200 OK": raise Errors.NetworkException("Meta-meta-server returned status '%s'" % lines[0]) metaURL = lines[-1] callback(metaURL) parsed = urlparse.urlparse(metaMetaURL) Network.asyncRequest(eventLoop, parsed[1], 80, "GET %s HTTP/1.1\nHost: %s\nUser-Agent: %s/%s\n\n" % (parsed[2], parsed[1], BZFlag.name, BZFlag.version), responseHandler)
def performRequest(url): # Normally we'd use urlparse for this, but it has wacky defaults # for URL schemes it doesn't recognize. host = url.split("/")[2] Network.asyncRequest(self.eventLoop, host, 5156, line, callback)