From: Ben Darnell Date: Sun, 1 May 2011 21:06:00 +0000 (-0700) Subject: Merge branch 'master' into python3 X-Git-Tag: v2.0.0~85^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b7cbcf87b86890c80b51f57f345fc4724c80ab6e;p=thirdparty%2Ftornado.git Merge branch 'master' into python3 Conflicts: tornado/simple_httpclient.py tornado/web.py --- b7cbcf87b86890c80b51f57f345fc4724c80ab6e diff --cc tornado/simple_httpclient.py index ac4fb5265,906461bb5..2efe7e445 --- a/tornado/simple_httpclient.py +++ b/tornado/simple_httpclient.py @@@ -133,13 -127,12 +133,12 @@@ class _HTTPConnection(object) # Timeout handle returned by IOLoop.add_timeout self._timeout = None with stack_context.StackContext(self.cleanup): - parsed = urlparse.urlsplit(self.request.url) + parsed = urlparse.urlsplit(_unicode(self.request.url)) - if ":" in parsed.netloc: - host, _, port = parsed.netloc.partition(":") - port = int(port) - else: - host = parsed.netloc + host = parsed.hostname + if parsed.port is None: port = 443 if parsed.scheme == "https" else 80 + else: + port = parsed.port if self.client.hostname_mapping is not None: host = self.client.hostname_mapping.get(host, host) @@@ -196,11 -189,16 +195,16 @@@ raise NotImplementedError('%s not supported' % key) if "Host" not in self.request.headers: self.request.headers["Host"] = parsed.netloc - if self.request.auth_username: - auth = utf8(self.request.auth_username) + b(":") + \ - utf8(self.request.auth_password) - self.request.headers["Authorization"] = \ - b("Basic ") + base64.b64encode(auth) + username, password = None, None + if parsed.username is not None: + username, password = parsed.username, parsed.password + elif self.request.auth_username is not None: + username = self.request.auth_username + password = self.request.auth_password + if username is not None: - auth = "%s:%s" % (username, password) - self.request.headers["Authorization"] = ("Basic %s" % ++ auth = utf8(username) + b(":") + utf8(password) ++ self.request.headers["Authorization"] = (b("Basic ") + + base64.b64encode(auth)) if self.request.user_agent: self.request.headers["User-Agent"] = self.request.user_agent has_body = self.request.method in ("POST", "PUT") @@@ -217,14 -215,17 +221,17 @@@ self.request.headers["Accept-Encoding"] = "gzip" req_path = ((parsed.path or '/') + (('?' + parsed.query) if parsed.query else '')) - request_lines = ["%s %s HTTP/1.1" % (self.request.method, - req_path)] + request_lines = [utf8("%s %s HTTP/1.1" % (self.request.method, + req_path))] for k, v in self.request.headers.get_all(): - request_lines.append(utf8(k) + b(": ") + utf8(v)) - line = "%s: %s" % (k, v) - if '\n' in line: ++ line = utf8(k) + b(": ") + utf8(v) ++ if b('\n') in line: + raise ValueError('Newline in header: ' + repr(line)) + request_lines.append(line) - self.stream.write("\r\n".join(request_lines) + "\r\n\r\n") + self.stream.write(b("\r\n").join(request_lines) + b("\r\n\r\n")) if has_body: - self.stream.write(self.request.body) - self.stream.read_until("\r\n\r\n", self._on_headers) + self.stream.write(utf8(self.request.body)) + self.stream.read_until(b("\r\n\r\n"), self._on_headers) @contextlib.contextmanager def cleanup(self): diff --cc tornado/web.py index 9608908aa,c30c9851f..5a021f334 --- a/tornado/web.py +++ b/tornado/web.py @@@ -450,9 -443,11 +450,11 @@@ class RequestHandler(object) else: css_files.extend(file_part) head_part = module.html_head() - if head_part: html_heads.append(_utf8(head_part)) + if head_part: html_heads.append(utf8(head_part)) body_part = module.html_body() - if body_part: html_bodies.append(_utf8(body_part)) + if body_part: html_bodies.append(utf8(body_part)) + def is_absolute(path): + return any(path.startswith(x) for x in ["/", "http:", "https:"]) if js_files: # Maintain order of JavaScript files given by modules paths = []