Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 2433

Show
Ignore:
Timestamp:
06/14/09 14:28:31
Author:
fumanchu
Message:

python3: More synchro with trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/python3/cherrypy/_cprequest.py

    r2430 r2433  
    11 
    2 import http.cookies 
     2from http.cookies import SimpleCookie, CookieError 
    33import io 
    44import os 
     
    267267    httputil.HeaderMap, httputil.HeaderElement.""" 
    268268     
    269     cookie = http.cookies.SimpleCookie() 
     269    cookie = SimpleCookie() 
    270270    cookie__doc = """See help(Cookie).""" 
    271271     
     
    508508            from the Request-Line (e.g. "GET /path?key=val HTTP/1.0"). 
    509509        path should be %XX-unquoted, but query_string should not be. 
    510             They both MUST be unicode strings, not bytestrings. 
     510            They both MUST be unicode strings, not byte strings. 
    511511        headers should be a list of (name, value) tuples. 
    512512        rfile should be a file-like object containing the HTTP request entity. 
     
    559559            self.body = None 
    560560             
    561             self.cookie = http.cookies.SimpleCookie() 
     561            self.cookie = SimpleCookie() 
    562562            self.handler = None 
    563563             
     
    700700            # cookies come on different lines with the same key 
    701701            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) 
    703707         
    704708        if not dict.__contains__(headers, 'Host'): 
     
    773777     
    774778    Deprecated in 3.2, will be removed for 3.3""") 
     779 
    775780 
    776781class ResponseBody(object): 
     
    840845    httputil.HeaderMap, httputil.HeaderElement.""" 
    841846     
    842     cookie = http.cookies.SimpleCookie() 
     847    cookie = SimpleCookie() 
    843848    cookie__doc = """See help(Cookie).""" 
    844849     
     
    874879            "Date": httputil.HTTPDate(self.time), 
    875880        }) 
    876         self.cookie = http.cookies.SimpleCookie() 
     881        self.cookie = SimpleCookie() 
    877882     
    878883    def collapse_body(self): 
  • branches/python3/cherrypy/_cpwsgi.py

    r2430 r2433  
    202202                raise 
    203203             
    204             return ("".join(b)).encode('ISO-8859-1'
     204            return (b"".join(b)
    205205     
    206206    def close(self): 
  • branches/python3/cherrypy/wsgiserver/__init__.py

    r2430 r2433  
    7777""" 
    7878 
    79  
     79CRLF = b'\r\n' 
    8080import os 
    8181import queue 
     
    327327            return 
    328328         
    329         if request_line == b"\r\n"
     329        if request_line == CRLF
    330330            # RFC 2616 sec 4.1: "...if the server is reading the protocol 
    331331            # stream at the beginning of a message and receives a CRLF 
     
    337337                return 
    338338         
    339         if not request_line.endswith(b'\r\n'): 
     339        if not request_line.endswith(CRLF): 
    340340            self.simple_response(400, "HTTP requires CRLF terminators") 
    341341            return 
     
    544544                raise ValueError("Illegal end of headers.") 
    545545             
    546             if line == b'\r\n'
     546            if line == CRLF
    547547                # Normal end of headers 
    548548                break 
    549             if not line.endswith(b'\r\n'): 
     549            if not line.endswith(CRLF): 
    550550                raise ValueError("HTTP requires CRLF terminators") 
    551551             
     
    585585            data.write(self.rfile.read(chunk_size)) 
    586586            crlf = self.rfile.read(2) 
    587             if crlf != b"\r\n"
     587            if crlf != CRLF
    588588                self.simple_response("400 Bad Request", 
    589589                                     b"Bad chunked transfer coding " 
    590                                      b"(expected '\\r\\n', got " + crlf + ")") 
     590                                     b"(expected '\\r\\n', got " + repr(crlf) + ")") 
    591591                return 
    592592         
     
    654654        """Write a simple response back to the client.""" 
    655655        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"), 
    658658               b"Content-Type: text/plain\r\n"] 
    659659         
     
    663663            buf.append(b"Connection: close\r\n") 
    664664         
    665         buf.append(b"\r\n"
     665        buf.append(CRLF
    666666        if msg: 
    667667            if isinstance(msg, str): 
     
    711711         
    712712        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
    714714            self.wfile.write(b"".join(buf)) 
    715715        else: 
     
    774774         
    775775        buf = [self.environ['ACTUAL_SERVER_PROTOCOL'].encode('ISO-8859-1') + 
    776                b" " + self.status + b"\r\n"
     776               b" " + self.status + CRLF
    777777        try: 
    778778            for k, v in self.outheaders: 
     
    785785            else: 
    786786                raise 
    787         buf.append(b"\r\n"
     787        buf.append(CRLF
    788788        self.wfile.write(b"".join(buf)) 
    789789 
     
    931931            raw = socket.SocketIO(sock, "w") 
    932932            self.wfile = CP_BufferedWriter(raw) 
     933         
    933934        # Wrap wsgi.input but not HTTPConnection.rfile itself. 
    934935        # We're also not setting maxlen yet; we'll do that separately 
     
    15231524                    host, port = sock.getsockname()[:2] 
    15241525                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. 
    15261529                        raise 
    15271530                else: 

Hosted by WebFaction

Log in as guest/cpguest to create tickets