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

Changeset 1920

Show
Ignore:
Timestamp:
03/14/08 10:14:57
Author:
fumanchu
Message:

Replaced HTTPRequest.send with .wfile, as it should have been in the first place.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/wsgiserver/__init__.py

    r1915 r1920  
    274274    max_request_body_size = 0 
    275275     
    276     def __init__(self, send, environ, wsgi_app): 
     276    def __init__(self, wfile, environ, wsgi_app): 
    277277        self.rfile = environ['wsgi.input'] 
    278         self.send = send 
     278        self.wfile = wfile 
    279279        self.environ = environ.copy() 
    280280        self.wsgi_app = wsgi_app 
     
    554554            self.send_headers() 
    555555        if self.chunked_write: 
    556             self.sendall("0\r\n\r\n") 
     556            self.wfile.sendall("0\r\n\r\n") 
    557557     
    558558    def simple_response(self, status, msg=""): 
     
    571571        if msg: 
    572572            buf.append(msg) 
    573         self.sendall("".join(buf)) 
     573        self.wfile.sendall("".join(buf)) 
    574574     
    575575    def start_response(self, status, headers, exc_info = None): 
     
    604604        if self.chunked_write and chunk: 
    605605            buf = [hex(len(chunk))[2:], "\r\n", chunk, "\r\n"] 
    606             self.sendall("".join(buf)) 
     606            self.wfile.sendall("".join(buf)) 
    607607        else: 
    608             self.sendall(chunk) 
    609      
    610     def sendall(self, data): 
    611         """Sendall for non-blocking sockets.""" 
    612         while data: 
    613             try: 
    614                 bytes_sent = self.send(data) 
    615                 data = data[bytes_sent:] 
    616             except socket.error, e: 
    617                 if e.args[0] not in socket_errors_nonblocking: 
    618                     raise 
     608            self.wfile.sendall(chunk) 
    619609     
    620610    def send_headers(self): 
     
    683673                raise 
    684674        buf.append("\r\n") 
    685         self.sendall("".join(buf)) 
     675        self.wfile.sendall("".join(buf)) 
    686676 
    687677 
     
    701691        while data: 
    702692            try: 
    703                 bytes_sent = self._sock.send(data) 
     693                bytes_sent = self.send(data) 
    704694                data = data[bytes_sent:] 
    705695            except socket.error, e: 
     
    872862                 
    873863                if is_reader and thirdarg == 'ssl handshake failure': 
     864                    # Return "" to simulate EOF which will close the conn. 
    874865                    return "" 
    875866                if thirdarg == 'http request': 
    876867                    # The client is talking HTTP to an HTTPS server. 
    877868                    raise NoSSLError() 
    878                 raise 
     869                if is_reader and thirdarg == 'decryption failed or bad record mac': 
     870                    # Return "" to simulate EOF which will close the conn. 
     871                    return "" 
     872                else: 
     873                    raise 
    879874            except: 
    880875                raise 
     876             
    881877            if time.time() - start > self.ssl_timeout: 
    882878                raise socket.timeout("timed out") 
     
    923919        if SSL and isinstance(sock, SSL.ConnectionType): 
    924920            timeout = sock.gettimeout() 
    925             self.rfile = SSL_fileobject(sock, "r", self.rbufsize) 
     921            self.rfile = SSL_fileobject(sock, "rb", self.rbufsize) 
    926922            self.rfile.ssl_timeout = timeout 
    927             self.send = self.rfile.send 
     923            self.wfile = SSL_fileobject(sock, "wb", -1) 
     924            self.wfile.ssl_timeout = timeout 
    928925        else: 
    929926            self.rfile = CP_fileobject(sock, "rb", self.rbufsize) 
    930             self.send = sock.send 
     927            self.wfile = CP_fileobject(sock, "wb", -1) 
    931928         
    932929        # Wrap wsgi.input but not HTTPConnection.rfile itself. 
     
    944941                # get written to the previous request. 
    945942                req = None 
    946                 req = self.RequestHandlerClass(self.send, self.environ, 
     943                req = self.RequestHandlerClass(self.wfile, self.environ, 
    947944                                               self.wsgi_app) 
    948945                 
     
    971968            raise 
    972969        except NoSSLError: 
    973             # Unwrap our send 
    974             req.send = self.socket._sock.send 
     970            # Unwrap our wfile 
     971            req.wfile = CP_fileobject(self.socket, "wb", -1) 
    975972            req.simple_response("400 Bad Request", 
    976973                                "The client sent a plain HTTP request, but " 
    977974                                "this server only speaks HTTPS on this port.") 
    978975        except Exception, e: 
     976            fd = open("ssl_errors.txt", "a") 
     977            fd.write("2" * 80) 
     978            fd.write("\n") 
     979            fd.write(format_exc()) 
    979980            if req: 
    980                 fd = open("ssl_errors.txt", "a") 
    981                 fd.write("2" * 80) 
    982                 fd.write("\n") 
    983                 fd.write(format_exc()) 
    984981                req.simple_response("500 Internal Server Error", format_exc()) 
    985982     

Hosted by WebFaction

Log in as guest/cpguest to create tickets