def get(self, serverurl, path=''): if self.url is not None: raise AssertionError('Already doing a get') self.url = serverurl + path scheme, host, path_ignored, params, query, fragment = urlparse.urlparse( self.url) if not scheme in ("http", "unix"): raise NotImplementedError self.host = host if ":" in host: hostname, port = host.split(":", 1) port = int(port) else: hostname = host port = 80 self.path = path self.port = port if scheme == "http": ip = hostname self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((ip, self.port)) elif scheme == "unix": socketname = serverurl[7:] self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.connect(socketname)
def get_server_url(self): """ Functionality that medusa's http request doesn't have; set an attribute named 'server_url' on the request based on the Host: header """ default_port = {'http': '80', 'https': '443'} environ = self.cgi_environment() if (environ.get('HTTPS') in ('on', 'ON') or environ.get('SERVER_PORT_SECURE') == "1"): # XXX this will currently never be true protocol = 'https' else: protocol = 'http' if 'HTTP_HOST' in environ: host = environ['HTTP_HOST'].strip() parsed = urlparse.urlparse(host) hostname, port = parsed.hostname, str(parsed.port) else: hostname = environ['SERVER_NAME'].strip() port = environ['SERVER_PORT'] if port is None or default_port[protocol] == port: host = hostname else: host = hostname + ':' + port server_url = '%s://%s' % (protocol, host) if server_url[-1:] == '/': server_url = server_url[:-1] return server_url
def get(self, serverurl, path=''): if self.url is not None: raise AssertionError('Already doing a get') self.url = serverurl + path scheme, host, path_ignored, params, query, fragment = urlparse.urlparse( self.url) if not scheme in ("http", "unix"): raise NotImplementedError self.host = host if ":" in host: hostname, port = host.split(":", 1) port = int(port) else: hostname = host port = 80 self.path = path self.port = port if scheme == "http": ip = hostname self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((ip, self.port)) elif scheme == "unix": socketname = serverurl[7:] self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM) self.connect(socketname)
def url(value): # earlier Python 2.6 urlparse (2.6.4 and under) can't parse unix:// URLs, # later ones can but we need to straddle uri = value.replace('unix://', 'http://', 1).strip() scheme, netloc, path, params, query, fragment = urlparse.urlparse(uri) if scheme and (netloc or path): return value raise ValueError("value %r is not a URL" % value)
def do_open(self, arg): url = arg.strip() parts = urlparse.urlparse(url) if parts[0] not in ('unix', 'http'): self.ctl.output('ERROR: url must be http:// or unix://') return self.ctl.options.serverurl = url self.do_status('')
def url(value): # earlier Python 2.6 urlparse (2.6.4 and under) can't parse unix:// URLs, # later ones can but we need to straddle uri = value.replace('unix://', 'http://', 1).strip() scheme, netloc, path, params, query, fragment = urlparse.urlparse(uri) if scheme and (netloc or path): return value raise ValueError("value %s is not a URL" % value)
def do_open(self, arg): url = arg.strip() parts = urlparse.urlparse(url) if parts[0] not in ('unix', 'http'): self.ctl.output('ERROR: url must be http:// or unix://') return self.ctl.options.serverurl = url self.do_status('')
def __init__(self, username=None, password=None, serverurl=None): xmlrpclib.Transport.__init__(self) self.username = username self.password = password self.verbose = False self.serverurl = serverurl if serverurl.startswith('http://'): parsed = urlparse.urlparse(serverurl) host, port = parsed.hostname, parsed.port if port is None: port = 80 def get_connection(host=host, port=port): return httplib.HTTPConnection(host, port) self._get_connection = get_connection elif serverurl.startswith('unix://'): def get_connection(serverurl=serverurl): # we use 'localhost' here because domain names must be # < 64 chars (or we'd use the serverurl filename) conn = UnixStreamHTTPConnection('localhost') conn.socketfile = serverurl[7:] return conn self._get_connection = get_connection else: raise ValueError('Unknown protocol for serverurl %s' % serverurl)
def url(value): scheme, netloc, path, params, query, fragment = urlparse.urlparse(value) if scheme and (netloc or path): return value raise ValueError("value %r is not a URL" % value)