def __init__(self, fd, hostname=None, port=None, use_ssl=False):
    """Create a request. fd should be either a socket descriptor
       or a string. In both case, it should contain a full request.
       To generate a request from a URL, see c()"""
    if isinstance(fd, basestring):
      fd = StringIO(fd)
    try:
      banner = read_banner(fd)
      # ASSUMPTION: The request line contains three elements seperated by
      #             a space.
      self.method, url, self.http_version = banner
    except __HOLE__:
      raise NotConnected(' '.join(banner))
    if self.method.upper() == "CONNECT":
      # ASSUMPTION: CONNECT method needs a hostname and port
      self.hostname, self.port = url.rsplit(":", 1)
      self.port = int(self.port)
      self.url = ""
      self.use_ssl = False
    elif hostname:
      self.hostname = hostname
      self.port = port if port else 80
      self.use_ssl = use_ssl
      self.url = url
    else:
      p_url = urlparse.urlparse(url)
      self.url = urlparse.urlunparse(("", "") + p_url[2:])
      if p_url.scheme:
        self.hostname = p_url.hostname
        if not self.hostname:
          raise BurstException("No hostname: " + str(url))
        if p_url.scheme == 'https':
          self.use_ssl = True
          self.port = int(p_url.port) if p_url.port else 443
        else:
          self.port = int(p_url.port) if p_url.port else 80
          self.use_ssl = use_ssl
    self.raw_headers = read_headers(fd)
    if not hasattr(self, "hostname"): # Last chance, try the Host header
      hosts = self.get_header('Host')
      if not hosts:
        raise BurstException("Unable to find the host for the request")
      else:
        host = hosts[0]
      self.hostname = host.split(":")[0]
      self.port = int(host.split(":")[1]) if ":" in host else 80
      self.use_ssl = False
    self.raw_content = read_content(fd, parse_headers(self.raw_headers), method=self.method)
    if self.raw_content:
      self.content = _clear_content(parse_headers(self.raw_headers), self.raw_content)
    else:
      self.content = ""
    self.response = None
dataset/ETHPy150Open tweksteen/burst/burst/http.py/Request.__init__