code: def prepare_url(self, url, params):
          
          url = to_native_string(url)
  
          # Don't do any URL preparation for non-HTTP schemes like `mailto`,
          # `data` etc to work around exceptions from `url_parse`, which
          # handles RFC 3986 only.
          if ':' in url and not url.lower().startswith('http'):
              self.url = url
              return
  
          # Support for unicode domain names and paths.
          scheme, auth, host, port, path, query, fragment = parse_url(url)
  
          if not scheme:
              raise MissingSchema("Invalid URL {0!r}: No schema supplied. "
                                  "Perhaps you meant http://{0}?".format(url))
  
          if not host:
              raise InvalidURL("Invalid URL %r: No host supplied" % url)
  
          # Only want to apply IDNA to the hostname
          try:
              host = host.encode('idna').decode('utf-8')
          except UnicodeError:
              raise InvalidURL('URL has an invalid label.')
  
          # Carefully reconstruct the network location
          netloc = auth or ''
          if netloc:
              netloc += '@'
          netloc += host
          if port:
              netloc += ':' + str(port)
  
          # Bare domains aren't valid URLs.
          if not path:
              path = '/'
  
          if is_py2:
              if isinstance(scheme, str):
                  scheme = scheme.encode('utf-8')
              if isinstance(netloc, str):
                  netloc = netloc.encode('utf-8')
              if isinstance(path, str):
                  path = path.encode('utf-8')
              if isinstance(query, str):
                  query = query.encode('utf-8')
              if isinstance(fragment, str):
                  fragment = fragment.encode('utf-8')
  
          enc_params = self._encode_params(params)
          if enc_params:
              if query:
                  query = '%s&%s' % (query, enc_params)
              else:
                  query = enc_params
  
          url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))
          self.url = url
docs: Prepares the given HTTP URL.