Robert Brewer avatar Robert Brewer committed b901d2d

Even more sync

Comments (0)

Files changed (6)

py3/cherrypy/lib/reprconf.py

     """Return a Python object compiled from a string."""
     if not s:
         return s
-    if sys.version_info <= (3, 0):
+    if sys.version_info < (3, 0):
         b = _Builder2()
     else:
         b = _Builder3()

py3/cherrypy/test/fcgi.conf

 
 # Apache2 server conf file for testing CherryPy with mod_fcgid.
 
-DocumentRoot "/usr/lib/python2.5/site-packages/cproot/branches/python3/cherrypy/test"
+DocumentRoot "/usr/lib/python2.6/site-packages/cproot/trunk/cherrypy/test"
 ServerName 127.0.0.1
 Listen 8080
 LoadModule fastcgi_module modules/mod_fastcgi.dll
 SetHandler fastcgi-script
 RewriteEngine On
 RewriteRule ^(.*)$ /fastcgi.pyc [L]
-FastCgiExternalServer "/usr/lib/python2.5/site-packages/cproot/branches/python3/cherrypy/test/fastcgi.pyc" -host 127.0.0.1:4000
+FastCgiExternalServer "/usr/lib/python2.6/site-packages/cproot/trunk/cherrypy/test/fastcgi.pyc" -host 127.0.0.1:4000

py3/cherrypy/test/logtest.py

 import time
 
 import cherrypy
-from cherrypy._cpcompat import ntob
+from cherrypy._cpcompat import basestring, ntob, unicodestr
 
 
 try:
         if marker is None:
             return open(logfile, 'rb').readlines()
         
-        if isinstance(marker, str):
-            marker = bytes(marker, 'utf-8')
+        if isinstance(marker, unicodestr):
+            marker = marker.encode('utf-8')
         data = []
         in_region = False
         for line in open(logfile, 'rb'):
             # Single arg. Use __getitem__ and allow lines to be str or list.
             if isinstance(lines, (tuple, list)):
                 lines = lines[0]
-            if isinstance(lines, str):
-                lines = bytes(lines, 'utf-8')
+            if isinstance(lines, unicodestr):
+                lines = lines.encode('utf-8')
             if lines not in data[sliceargs]:
                 msg = "%r not found on log line %r" % (lines, sliceargs)
                 self._handleLogError(msg, [data[sliceargs],"--EXTRA CONTEXT--"] + data[sliceargs+1:sliceargs+6], marker, lines)
             # Multiple args. Use __getslice__ and require lines to be list.
             if isinstance(lines, tuple):
                 lines = list(lines)
-            elif isinstance(lines, str):
+            elif isinstance(lines, basestring):
                 raise TypeError("The 'lines' arg must be a list when "
                                 "'sliceargs' is a tuple.")
             
             start, stop = sliceargs
             for line, logline in zip(lines, data[start:stop]):
-                if isinstance(line, str):
-                    line = bytes(line, 'utf-8')
+                if isinstance(line, unicodestr):
+                    line = line.encode('utf-8')
                 if line not in logline:
                     msg = "%r not found in log" % line
                     self._handleLogError(msg, data[start:stop], marker, line)

py3/cherrypy/test/test_caching.py

         for t in ts:
             t.join()
         self.assertEqualDates(start, datetime.datetime.now(),
-                              # Allow a second for our thread/TCP overhead etc.
-                              seconds=SECONDS + 1.1)
+                              # Allow a second (two, for slow hosts)
+                              # for our thread/TCP overhead etc.
+                              seconds=SECONDS + 2)
     
     def test_cache_control(self):
         self.getPage("/control")

py3/cherrypy/test/test_config.py

         silly._cp_config = {'response.headers.X-silly': 'sillyval'}
         
         # Test the expose and config decorators
-        @cherrypy.expose
-        @cherrypy.config(foo='this3', **{'bax': 'this4'})
+        #@cherrypy.expose
+        #@cherrypy.config(foo='this3', **{'bax': 'this4'})
         def bar(self, key):
             return repr(cherrypy.request.config.get(key, None))
-    
+        bar.exposed = True
+        bar._cp_config = {'foo': 'this3', 'bax': 'this4'}
+
     class Another:
 
         def index(self, key):

py3/cherrypy/test/test_core.py

                     if isinstance(value, types.FunctionType):
                         value.exposed = True
                 setattr(root, name.lower(), cls())
-        class Test(object, metaclass=TestType):
-            pass
+        Test = TestType('Test', (object, ), {})
         
         
         class URL(Test):
                 raise cherrypy.HTTPRedirect(url, code)
             
             def by_code(self, code):
-                raise cherrypy.HTTPRedirect("somewhere else", code)
+                raise cherrypy.HTTPRedirect("somewhere%20else", code)
             by_code._cp_config = {'tools.trailing_slash.extra': True}
             
             def nomodify(self):
                     cherrypy.response.cookie[str(name)] = cookie.value
 
 
+        def append_headers(header_list, debug=False):
+            if debug:
+                cherrypy.log(
+                    "Extending response headers with %s" % repr(header_list),
+                    "TOOLS.APPEND_HEADERS")
+            cherrypy.serving.response.header_list.extend(header_list)
+        cherrypy.tools.append_headers = cherrypy.Tool('on_end_resource', append_headers)
+        
+        class MultiHeader(Test):
+            
+            @cherrypy.tools.append_headers(header_list=[
+                ('WWW-Authenticate', 'Negotiate'),
+                ('WWW-Authenticate', 'Basic realm="foo"'),
+                ])
+            def header_list(self):
+                pass
+            
+            def commas(self):
+                cherrypy.response.headers['WWW-Authenticate'] = 'Negotiate,Basic realm="foo"'
+
+
         cherrypy.tree.mount(root)
     setup_server = staticmethod(setup_server)
 
         self.assertStatus(200)
         
         self.getPage("/redirect/by_code?code=300")
-        self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")
+        self.assertMatchesBody(r"<a href='(.*)somewhere%20else'>\1somewhere%20else</a>")
         self.assertStatus(300)
         
         self.getPage("/redirect/by_code?code=301")
-        self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")
+        self.assertMatchesBody(r"<a href='(.*)somewhere%20else'>\1somewhere%20else</a>")
         self.assertStatus(301)
         
         self.getPage("/redirect/by_code?code=302")
-        self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")
+        self.assertMatchesBody(r"<a href='(.*)somewhere%20else'>\1somewhere%20else</a>")
         self.assertStatus(302)
         
         self.getPage("/redirect/by_code?code=303")
-        self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")
+        self.assertMatchesBody(r"<a href='(.*)somewhere%20else'>\1somewhere%20else</a>")
         self.assertStatus(303)
         
         self.getPage("/redirect/by_code?code=307")
-        self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")
+        self.assertMatchesBody(r"<a href='(.*)somewhere%20else'>\1somewhere%20else</a>")
         self.assertStatus(307)
         
         self.getPage("/redirect/nomodify")
         self.assertBody(data)
     
     def testCookies(self):
+        if sys.version_info >= (2, 5):
+            header_value = lambda x: x
+        else:
+            header_value = lambda x: x+';'
+        
         self.getPage("/cookies/single?name=First",
                      [('Cookie', 'First=Dinsdale;')])
-        self.assertHeader('Set-Cookie', 'First=Dinsdale')
+        self.assertHeader('Set-Cookie', header_value('First=Dinsdale'))
         
         self.getPage("/cookies/multiple?names=First&names=Last",
                      [('Cookie', 'First=Dinsdale; Last=Piranha;'),
                       ])
-        self.assertHeader('Set-Cookie', 'First=Dinsdale')
-        self.assertHeader('Set-Cookie', 'Last=Piranha')
+        self.assertHeader('Set-Cookie', header_value('First=Dinsdale'))
+        self.assertHeader('Set-Cookie', header_value('Last=Piranha'))
         
         self.getPage("/cookies/single?name=Something-With:Colon",
             [('Cookie', 'Something-With:Colon=some-value')])
         self.assertHeader('Content-Type', 'text/plain;charset=utf-8')
         self.getPage('/defct/html')
     
+    def test_multiple_headers(self):
+        self.getPage('/multiheader/header_list')
+        self.assertEqual([(k, v) for k, v in self.headers if k == 'WWW-Authenticate'],
+                         [('WWW-Authenticate', 'Negotiate'),
+                          ('WWW-Authenticate', 'Basic realm="foo"'),
+                          ])
+        self.getPage('/multiheader/commas')
+        self.assertHeader('WWW-Authenticate', 'Negotiate,Basic realm="foo"')
+    
     def test_cherrypy_url(self):
         # Input relative to current
         self.getPage('/url/leaf?path_info=page1')
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.