Commits

Jason R. Coombs committed 440010a

Re-saved with whitespace cleanup

Comments (0)

Files changed (3)

cherrypy/test/test_static.py

 has_space_filepath = os.path.join(curdir, 'static', 'has space.html')
 bigfile_filepath = os.path.join(curdir, "static", "bigfile.log")
 BIGFILE_SIZE = 1024 * 1024
-import threading
 
 import cherrypy
 from cherrypy.lib import static
             open(has_space_filepath, 'wb').write(ntob('Hello, world\r\n'))
         if not os.path.exists(bigfile_filepath):
             open(bigfile_filepath, 'wb').write(ntob("x" * BIGFILE_SIZE))
-        
+
         class Root:
-            
+
             def bigfile(self):
                 from cherrypy.lib import static
                 self.f = static.serve_file(bigfile_filepath)
                 return self.f
             bigfile.exposed = True
             bigfile._cp_config = {'response.stream': True}
-            
+
             def tell(self):
                 if self.f.input.closed:
                     return ''
                 return repr(self.f.input.tell()).rstrip('L')
             tell.exposed = True
-            
+
             def fileobj(self):
                 f = open(os.path.join(curdir, 'style.css'), 'rb')
                 return static.serve_fileobj(f, content_type='text/css')
             fileobj.exposed = True
-            
+
             def bytesio(self):
                 f = BytesIO(ntob('Fee\nfie\nfo\nfum'))
                 return static.serve_fileobj(f, content_type='text/plain')
             bytesio.exposed = True
-        
+
         class Static:
-            
+
             def index(self):
                 return 'You want the Baron? You can have the Baron!'
             index.exposed = True
-            
+
             def dynamic(self):
                 return "This is a DYNAMIC page"
             dynamic.exposed = True
-        
-        
+
+
         root = Root()
         root.static = Static()
-        
+
         rootconf = {
             '/static': {
                 'tools.staticdir.on': True,
             }
         rootApp = cherrypy.Application(root)
         rootApp.merge(rootconf)
-        
+
         test_app_conf = {
             '/test': {
                 'tools.staticdir.index': 'index.html',
             }
         testApp = cherrypy.Application(Static())
         testApp.merge(test_app_conf)
-        
+
         vhost = cherrypy._cpwsgi.VirtualHost(rootApp, {'virt.net': testApp})
         cherrypy.tree.graft(vhost)
     setup_server = staticmethod(setup_server)
                     pass
     teardown_server = staticmethod(teardown_server)
 
-    
+
     def testStatic(self):
         self.getPage("/static/index.html")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/html')
         self.assertBody('Hello, world\r\n')
-        
+
         # Using a staticdir.root value in a subdir...
         self.getPage("/docroot/index.html")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/html')
         self.assertBody('Hello, world\r\n')
-        
+
         # Check a filename with spaces in it
         self.getPage("/static/has%20space.html")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/html')
         self.assertBody('Hello, world\r\n')
-        
+
         self.getPage("/style.css")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/css')
         #   into \r\n on Windows when extracting the CherryPy tarball so
         #   we just check the content
         self.assertMatchesBody('^Dummy stylesheet')
-    
+
     def test_fallthrough(self):
         # Test that NotFound will then try dynamic handlers (see [878]).
         self.getPage("/static/dynamic")
         self.assertBody("This is a DYNAMIC page")
-        
+
         # Check a directory via fall-through to dynamic handler.
         self.getPage("/static/")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/html;charset=utf-8')
         self.assertBody('You want the Baron? You can have the Baron!')
-    
+
     def test_index(self):
         # Check a directory via "staticdir.index".
         self.getPage("/docroot/")
         self.assertHeader('Location', '%s/docroot/' % self.base())
         self.assertMatchesBody("This resource .* <a href='%s/docroot/'>"
                                "%s/docroot/</a>." % (self.base(), self.base()))
-    
+
     def test_config_errors(self):
         # Check that we get an error if no .file or .dir
         self.getPage("/error/thing.html")
         self.assertErrorPage(500)
         self.assertMatchesBody(ntob("TypeError: staticdir\(\) takes at least 2 "
                                     "(positional )?arguments \(0 given\)"))
-    
+
     def test_security(self):
         # Test up-level security
         self.getPage("/static/../../test/style.css")
         self.assertStatus((400, 403))
-    
+
     def test_modif(self):
         # Test modified-since on a reasonably-large file
         self.getPage("/static/dirback.jpg")
         self.assertNoHeader("Content-Length")
         self.assertNoHeader("Content-Disposition")
         self.assertBody("")
-    
+
     def test_755_vhost(self):
         self.getPage("/test/", [('Host', 'virt.net')])
         self.assertStatus(200)
         self.getPage("/test", [('Host', 'virt.net')])
         self.assertStatus(301)
         self.assertHeader('Location', self.scheme + '://virt.net/test/')
-    
+
     def test_serve_fileobj(self):
         self.getPage("/fileobj")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/css;charset=utf-8')
         self.assertMatchesBody('^Dummy stylesheet')
-    
+
     def test_serve_bytesio(self):
         self.getPage("/bytesio")
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/plain;charset=utf-8')
         self.assertHeader('Content-Length', 14)
         self.assertMatchesBody('Fee\nfie\nfo\nfum')
-    
+
     def test_file_stream(self):
         if cherrypy.server.protocol_version != "HTTP/1.1":
             return self.skip()
-        
+
         self.PROTOCOL = "HTTP/1.1"
-        
+
         # Make an initial request
         self.persistent = True
         conn = self.HTTP_CONN
         response = conn.response_class(conn.sock, method="GET")
         response.begin()
         self.assertEqual(response.status, 200)
-        
+
         body = ntob('')
         remaining = BIGFILE_SIZE
         while remaining > 0:
                 break
             body += data
             remaining -= len(data)
-            
+
             if self.scheme == "https":
                 newconn = HTTPSConnection
             else:
                 tell_position = BIGFILE_SIZE
             else:
                 tell_position = int(b)
-            
+
             expected = len(body)
             if tell_position >= BIGFILE_SIZE:
                 # We can't exactly control how much content the server asks for.
                     "only advanced to position %r. It may not be streamed "
                     "as intended, or at the wrong chunk size (65536)" %
                     (expected, tell_position))
-        
+
         if body != ntob("x" * BIGFILE_SIZE):
             self.fail("Body != 'x' * %d. Got %r instead (%d bytes)." %
                       (BIGFILE_SIZE, body[:50], len(body)))
         conn.close()
-    
+
     def test_file_stream_deadlock(self):
         if cherrypy.server.protocol_version != "HTTP/1.1":
             return self.skip()
-        
+
         self.PROTOCOL = "HTTP/1.1"
-        
+
         # Make an initial request but abort early.
         self.persistent = True
         conn = self.HTTP_CONN
                       (65536, body[:50], len(body)))
         response.close()
         conn.close()
-        
+
         # Make a second request, which should fetch the whole file.
         self.persistent = False
         self.getPage("/bigfile")
         if self.body != ntob("x" * BIGFILE_SIZE):
             self.fail("Body != 'x' * %d. Got %r instead (%d bytes)." %
                       (BIGFILE_SIZE, self.body[:50], len(body)))
-

cherrypy/test/test_virtualhost.py

             def index(self):
                 return "Hello, world"
             index.exposed = True
-            
+
             def dom4(self):
                 return "Under construction"
             dom4.exposed = True
-            
+
             def method(self, value):
                 return "You sent %s" % value
             method.exposed = True
-        
+
         class VHost:
             def __init__(self, sitename):
                 self.sitename = sitename
-            
+
             def index(self):
                 return "Welcome to %s" % self.sitename
             index.exposed = True
-            
+
             def vmethod(self, value):
                 return "You sent %s" % value
             vmethod.exposed = True
-            
+
             def url(self):
                 return cherrypy.url("nextpage")
             url.exposed = True
-            
+
             # Test static as a handler (section must NOT include vhost prefix)
             static = cherrypy.tools.staticdir.handler(section='/static', dir=curdir)
-        
+
         root = Root()
         root.mydom2 = VHost("Domain 2")
         root.mydom3 = VHost("Domain 3")
                                 },
             })
     setup_server = staticmethod(setup_server)
-    
+
     def testVirtualHost(self):
         self.getPage("/", [('Host', 'www.mydom1.com')])
         self.assertBody('Hello, world')
         self.getPage("/mydom2/", [('Host', 'www.mydom1.com')])
         self.assertBody('Welcome to Domain 2')
-        
+
         self.getPage("/", [('Host', 'www.mydom2.com')])
         self.assertBody('Welcome to Domain 2')
         self.getPage("/", [('Host', 'www.mydom3.com')])
         self.assertBody('Welcome to Domain 3')
         self.getPage("/", [('Host', 'www.mydom4.com')])
         self.assertBody('Under construction')
-        
+
         # Test GET, POST, and positional params
         self.getPage("/method?value=root")
         self.assertBody("You sent root")
         self.assertBody("You sent dom3 POST")
         self.getPage("/vmethod/pos", [('Host', 'www.mydom3.com')])
         self.assertBody("You sent pos")
-        
+
         # Test that cherrypy.url uses the browser url, not the virtual url
         self.getPage("/url", [('Host', 'www.mydom2.com')])
         self.assertBody("%s://www.mydom2.com/nextpage" % self.scheme)
-    
+
     def test_VHost_plus_Static(self):
         # Test static as a handler
         self.getPage("/static/style.css", [('Host', 'www.mydom2.com')])
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'text/css;charset=utf-8')
-        
+
         # Test static in config
         self.getPage("/static2/dirback.jpg", [('Host', 'www.mydom2.com')])
         self.assertStatus('200 OK')
         self.assertHeader('Content-Type', 'image/jpeg')
-        
+
         # Test static config with "index" arg
         self.getPage("/static2/", [('Host', 'www.mydom2.com')])
         self.assertStatus('200 OK')
         # Since tools.trailing_slash is on by default, this should redirect
         self.getPage("/static2", [('Host', 'www.mydom2.com')])
         self.assertStatus(301)
-

cherrypy/test/webtest.py

 be of further significance to your tests).
 """
 
-import os
 import pprint
 import re
 import socket
     status = None
     headers = None
     body = None
-    
+
     encoding = 'utf-8'
-    
+
     time = None
 
     def get_conn(self, auto_open=False):
     def getPage(self, url, headers=None, method="GET", body=None, protocol=None):
         """Open the url with debugging support. Return status, headers, body."""
         ServerError.on = False
-        
+
         if isinstance(url, unicodestr):
             url = url.encode('utf-8')
         if isinstance(body, unicodestr):
             body = body.encode('utf-8')
-        
+
         self.url = url
         self.time = None
         start = time.time()
                 def putrequest(self, method, url):
                     if self._HTTPConnection__response and self._HTTPConnection__response.isclosed():
                         self._HTTPConnection__response = None
-                    
+
                     if self._HTTPConnection__state == http.client._CS_IDLE:
                         self._HTTPConnection__state = http.client._CS_REQ_STARTED
                     else:
                         raise http.client.CannotSendRequest()
-                    
+
                     self._method = method
                     if not url:
                         url = ntob('/')
                     self._output(request)
                 import types
                 conn.putrequest = types.MethodType(putrequest, conn)
-                
+
                 conn.putrequest(method.upper(), url)
 
             for key, value in headers:
         print("")
         print("".join(traceback.format_exception(*exc)))
         return True
-
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.