def prepare_url(self, url, params):
<EOL>if isinstance(url, bytes):<EOL><INDENT>url = url.decode('<STR_LIT:utf8>')<EOL><DEDENT>else:<EOL><INDENT>url = unicode(url) if is_py2 else str(url)<EOL><DEDENT>url = url.lstrip()<EOL>if '<STR_LIT::>' in url and not url.lower().startswith('<STR_LIT:http>'):<EOL><INDENT>self.url = url<EOL>return<EOL><DEDENT>try:<EOL><INDENT>scheme, auth, host, port, path, query, fragment = parse_url(url)<EOL><DEDENT>except LocationParseError as e:<EOL><INDENT>raise InvalidURL(*e.args)<EOL><DEDENT>if not scheme:<EOL><INDENT>error = ("<STR_LIT>")<EOL>error = error.format(to_native_string(url, '<STR_LIT:utf8>'))<EOL>raise MissingSchema(error)<EOL><DEDENT>if not host:<EOL><INDENT>raise InvalidURL("<STR_LIT>" % url)<EOL><DEDENT>if not unicode_is_ascii(host):<EOL><INDENT>try:<EOL><INDENT>host = self._get_idna_encoded_host(host)<EOL><DEDENT>except UnicodeError:<EOL><INDENT>raise InvalidURL('<STR_LIT>')<EOL><DEDENT><DEDENT>elif host.startswith(u'<STR_LIT:*>'):<EOL><INDENT>raise InvalidURL('<STR_LIT>')<EOL><DEDENT>netloc = auth or '<STR_LIT>'<EOL>if netloc:<EOL><INDENT>netloc += '<STR_LIT:@>'<EOL><DEDENT>netloc += host<EOL>if port:<EOL><INDENT>netloc += '<STR_LIT::>' + str(port)<EOL><DEDENT>if not path:<EOL><INDENT>path = '<STR_LIT:/>'<EOL><DEDENT>if is_py2:<EOL><INDENT>if isinstance(scheme, str):<EOL><INDENT>scheme = scheme.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if isinstance(netloc, str):<EOL><INDENT>netloc = netloc.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if isinstance(path, str):<EOL><INDENT>path = path.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if isinstance(query, str):<EOL><INDENT>query = query.encode('<STR_LIT:utf-8>')<EOL><DEDENT>if isinstance(fragment, str):<EOL><INDENT>fragment = fragment.encode('<STR_LIT:utf-8>')<EOL><DEDENT><DEDENT>if isinstance(params, (str, bytes)):<EOL><INDENT>params = to_native_string(params)<EOL><DEDENT>enc_params = self._encode_params(params)<EOL>if enc_params:<EOL><INDENT>if query:<EOL><INDENT>query = '<STR_LIT>' % (query, enc_params)<EOL><DEDENT>else:<EOL><INDENT>query = enc_params<EOL><DEDENT><DEDENT>url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment]))<EOL>self.url = url<EOL>
Prepares the given HTTP URL.