Changeset 2433
- Timestamp:
- 06/14/09 14:28:31
- Files:
-
- branches/python3/cherrypy/_cprequest.py (modified) (8 diffs)
- branches/python3/cherrypy/_cpwsgi.py (modified) (1 diff)
- branches/python3/cherrypy/wsgiserver/__init__.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/python3/cherrypy/_cprequest.py
r2430 r2433 1 1 2 import http.cookies 2 from http.cookies import SimpleCookie, CookieError 3 3 import io 4 4 import os … … 267 267 httputil.HeaderMap, httputil.HeaderElement.""" 268 268 269 cookie = http.cookies.SimpleCookie()269 cookie = SimpleCookie() 270 270 cookie__doc = """See help(Cookie).""" 271 271 … … 508 508 from the Request-Line (e.g. "GET /path?key=val HTTP/1.0"). 509 509 path should be %XX-unquoted, but query_string should not be. 510 They both MUST be unicode strings, not byte strings.510 They both MUST be unicode strings, not byte strings. 511 511 headers should be a list of (name, value) tuples. 512 512 rfile should be a file-like object containing the HTTP request entity. … … 559 559 self.body = None 560 560 561 self.cookie = http.cookies.SimpleCookie()561 self.cookie = SimpleCookie() 562 562 self.handler = None 563 563 … … 700 700 # cookies come on different lines with the same key 701 701 if name == 'Cookie': 702 self.cookie.load(value) 702 try: 703 self.cookie.load(value) 704 except CookieError: 705 msg = "Illegal cookie name %s" % value.split('=')[0] 706 raise cherrypy.HTTPError(400, msg) 703 707 704 708 if not dict.__contains__(headers, 'Host'): … … 773 777 774 778 Deprecated in 3.2, will be removed for 3.3""") 779 775 780 776 781 class ResponseBody(object): … … 840 845 httputil.HeaderMap, httputil.HeaderElement.""" 841 846 842 cookie = http.cookies.SimpleCookie()847 cookie = SimpleCookie() 843 848 cookie__doc = """See help(Cookie).""" 844 849 … … 874 879 "Date": httputil.HTTPDate(self.time), 875 880 }) 876 self.cookie = http.cookies.SimpleCookie()881 self.cookie = SimpleCookie() 877 882 878 883 def collapse_body(self): branches/python3/cherrypy/_cpwsgi.py
r2430 r2433 202 202 raise 203 203 204 return ( "".join(b)).encode('ISO-8859-1')204 return (b"".join(b)) 205 205 206 206 def close(self): branches/python3/cherrypy/wsgiserver/__init__.py
r2430 r2433 77 77 """ 78 78 79 79 CRLF = b'\r\n' 80 80 import os 81 81 import queue … … 327 327 return 328 328 329 if request_line == b"\r\n":329 if request_line == CRLF: 330 330 # RFC 2616 sec 4.1: "...if the server is reading the protocol 331 331 # stream at the beginning of a message and receives a CRLF … … 337 337 return 338 338 339 if not request_line.endswith( b'\r\n'):339 if not request_line.endswith(CRLF): 340 340 self.simple_response(400, "HTTP requires CRLF terminators") 341 341 return … … 544 544 raise ValueError("Illegal end of headers.") 545 545 546 if line == b'\r\n':546 if line == CRLF: 547 547 # Normal end of headers 548 548 break 549 if not line.endswith( b'\r\n'):549 if not line.endswith(CRLF): 550 550 raise ValueError("HTTP requires CRLF terminators") 551 551 … … 585 585 data.write(self.rfile.read(chunk_size)) 586 586 crlf = self.rfile.read(2) 587 if crlf != b"\r\n":587 if crlf != CRLF: 588 588 self.simple_response("400 Bad Request", 589 589 b"Bad chunked transfer coding " 590 b"(expected '\\r\\n', got " + crlf+ ")")590 b"(expected '\\r\\n', got " + repr(crlf) + ")") 591 591 return 592 592 … … 654 654 """Write a simple response back to the client.""" 655 655 status = str(status) 656 buf = [bytes("%s %s\r\n" % (self.environ['ACTUAL_SERVER_PROTOCOL'], status), " Latin-1"),657 bytes("Content-Length: %s\r\n" % len(msg), " Latin-1"),656 buf = [bytes("%s %s\r\n" % (self.environ['ACTUAL_SERVER_PROTOCOL'], status), "ISO-8859-1"), 657 bytes("Content-Length: %s\r\n" % len(msg), "ISO-8859-1"), 658 658 b"Content-Type: text/plain\r\n"] 659 659 … … 663 663 buf.append(b"Connection: close\r\n") 664 664 665 buf.append( b"\r\n")665 buf.append(CRLF) 666 666 if msg: 667 667 if isinstance(msg, str): … … 711 711 712 712 if self.chunked_write and chunk: 713 buf = [bytes(hex(len(chunk)), 'ASCII')[2:], b"\r\n", chunk, b"\r\n"]713 buf = [bytes(hex(len(chunk)), 'ASCII')[2:], CRLF, chunk, CRLF] 714 714 self.wfile.write(b"".join(buf)) 715 715 else: … … 774 774 775 775 buf = [self.environ['ACTUAL_SERVER_PROTOCOL'].encode('ISO-8859-1') + 776 b" " + self.status + b"\r\n"]776 b" " + self.status + CRLF] 777 777 try: 778 778 for k, v in self.outheaders: … … 785 785 else: 786 786 raise 787 buf.append( b"\r\n")787 buf.append(CRLF) 788 788 self.wfile.write(b"".join(buf)) 789 789 … … 931 931 raw = socket.SocketIO(sock, "w") 932 932 self.wfile = CP_BufferedWriter(raw) 933 933 934 # Wrap wsgi.input but not HTTPConnection.rfile itself. 934 935 # We're also not setting maxlen yet; we'll do that separately … … 1523 1524 host, port = sock.getsockname()[:2] 1524 1525 except socket.error as x: 1525 if x.args[1] != "Bad file descriptor": 1526 if x.args[0] not in socket_errors_to_ignore: 1527 # Changed to use error code and not message 1528 # See http://www.cherrypy.org/ticket/860. 1526 1529 raise 1527 1530 else:

