Robert Brewer avatar Robert Brewer committed 062f6bd

A couple syncs with python3.

Comments (0)

Files changed (7)

cherrypy/_cpreqbody.py

             chunksize = min(remaining, self.bufsize)
             try:
                 data = self.fp.read(chunksize)
-            except IOError:
-                raise cherrypy.HTTPError(413)
+            except Exception, e:
+                if e.__class__.__name__ == 'MaxSizeExceeded':
+                    # Post data is too big
+                    raise cherrypy.HTTPError(
+                        413, "Maximum request length: %r" % e.args[1])
+                else:
+                    raise
             if not data:
                 self.finish()
                 break
                         if existing:
                             v = ", ".join((existing, v))
                     self.trailers[k] = v
-            except IOError:
-                raise cherrypy.HTTPError(413)
+            except Exception, e:
+                if e.__class__.__name__ == 'MaxSizeExceeded':
+                    # Post data is too big
+                    raise cherrypy.HTTPError(
+                        413, "Maximum request length: %r" % e.args[1])
+                else:
+                    raise
 
 
 class RequestBody(Entity):

cherrypy/lib/profiler.py

 
 import os, os.path
 import sys
+import warnings
 
 try:
     from cStringIO import StringIO

cherrypy/test/test_http.py

 from cherrypy.test import test
 test.prefer_parent_path()
 
-import httplib
+from httplib import HTTPConnection, HTTPSConnection
 import cherrypy
 import mimetypes
 
         # the request is of method POST, this should be OK because we set
         # request.process_request_body to False for our handler.
         if self.scheme == "https":
-            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
         else:
-            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c.request("POST", "/no_body")
         response = c.getresponse()
         self.body = response.fp.read()
         # Verify that CP times out the socket and responds
         # with 411 Length Required.
         if self.scheme == "https":
-            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
         else:
-            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c.request("POST", "/")
         response = c.getresponse()
         self.body = response.fp.read()
         
         # post file
         if self.scheme == 'https':
-            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
         else:
-            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c.putrequest('POST', '/post_multipart')
         c.putheader('Content-Type', content_type)
         c.putheader('Content-Length', str(len(body)))
         
         # Test missing version in Request-Line
         if self.scheme == 'https':
-            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
         else:
-            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c._output('GET /')
         c._send_output()
         response = c.response_class(c.sock, strict=c.strict, method='GET')
     
     def test_malformed_header(self):
         if self.scheme == 'https':
-            c = httplib.HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPSConnection('%s:%s' % (self.interface(), self.PORT))
         else:
-            c = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+            c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         c.putrequest('GET', '/')
         c.putheader('Content-Type', 'text/plain')
         # See http://www.cherrypy.org/ticket/941 
         c.endheaders()
         
         response = c.getresponse()
-        self.body = response.fp.read()
         self.status = str(response.status)
         self.assertStatus(400)
+        self.body = response.fp.read()
         self.assertBody("Illegal header line.")
     
     def test_http_over_https(self):
             return self.skip("skipped (not running HTTPS)... ")
         
         # Try connecting without SSL.
-        conn = httplib.HTTPConnection('%s:%s' % (self.interface(), self.PORT))
+        conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
         conn.putrequest("GET", "/", skip_host=True)
         conn.putheader("Host", self.HOST)
         conn.endheaders()

cherrypy/test/test_refleaks.py

 test.prefer_parent_path()
 
 import gc
-import httplib
+from httplib import HTTPConnection, HTTPSConnection
 import threading
 
 import cherrypy
         def getpage():
             host = '%s:%s' % (self.interface(), self.PORT)
             if self.scheme == 'https':
-                c = httplib.HTTPSConnection(host)
+                c = HTTPSConnection(host)
             else:
-                c = httplib.HTTPConnection(host)
+                c = HTTPConnection(host)
             try:
                 c.putrequest('GET', '/')
                 c.endheaders()

cherrypy/test/test_states.py

-import httplib
 from httplib import BadStatusLine
 
 import os

cherrypy/test/webtest.py

 be of further significance to your tests).
 """
 
-import httplib
+from httplib import HTTPConnection, HTTPSConnection
 import os
 import pprint
 import re
 class WebCase(TestCase):
     HOST = "127.0.0.1"
     PORT = 8000
-    HTTP_CONN = httplib.HTTPConnection
+    HTTP_CONN = HTTPConnection
     PROTOCOL = "HTTP/1.1"
     
     scheme = "http"
     def get_conn(self, auto_open=False):
         """Return a connection to our HTTP server."""
         if self.scheme == "https":
-            cls = httplib.HTTPSConnection
+            cls = HTTPSConnection
         else:
-            cls = httplib.HTTPConnection
+            cls = HTTPConnection
         conn = cls(self.interface(), self.PORT)
         # Automatically re-connect?
         conn.auto_open = auto_open
         """Make our HTTP_CONN persistent (or not).
         
         If the 'on' argument is True (the default), then self.HTTP_CONN
-        will be set to an instance of httplib.HTTPConnection (or HTTPS
+        will be set to an instance of HTTPConnection (or HTTPS
         if self.scheme is "https"). This will then persist across requests.
         
         We only allow for a single open connection, so if you call this
             self.HTTP_CONN = self.get_conn(auto_open=auto_open)
         else:
             if self.scheme == "https":
-                self.HTTP_CONN = httplib.HTTPSConnection
+                self.HTTP_CONN = HTTPSConnection
             else:
-                self.HTTP_CONN = httplib.HTTPConnection
+                self.HTTP_CONN = HTTPConnection
     
     def _get_persistent(self):
         return hasattr(self.HTTP_CONN, "__class__")
 
 
 def openURL(url, headers=None, method="GET", body=None,
-            host="127.0.0.1", port=8000, http_conn=httplib.HTTPConnection,
+            host="127.0.0.1", port=8000, http_conn=HTTPConnection,
             protocol="HTTP/1.1"):
     """Open the given HTTP resource and return status, headers, and body."""
     

cherrypy/wsgiserver/__init__.py

         return data
 
 
+class MaxSizeExceeded(Exception):
+    pass
+
+
 class ChunkedRFile(object):
     """Wraps a file-like object, returning an empty string when exhausted.
     
         self.bytes_read += len(line)
         
         if self.maxlen and self.bytes_read > self.maxlen:
-            raise IOError("Request Entity Too Large")
+            raise MaxSizeExceeded("Request Entity Too Large", self.maxlen)
         
         line = line.strip().split(";", 1)
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.