Commits

Robert Brewer committed 24e2267

trunk: some merges from python3.

Comments (0)

Files changed (4)

cherrypy/_cpconfig.py

         if isinstance(config, basestring):
             # Filename
             cherrypy.engine.autoreload.files.add(config)
-
         reprconf.Config.update(self, config)
 
     def _apply(self, config):
             config = config["global"]
         if 'tools.staticdir.dir' in config:
             config['tools.staticdir.section'] = "global"
-
         reprconf.Config._apply(self, config)
+    
+    def __call__(self, *args, **kwargs):
+        """Decorator for page handlers to set _cp_config."""
+        if args:
+            raise TypeError(
+                "The cherrypy.config decorator does not accept positional "
+                "arguments; you must use keyword arguments.")
+        def tool_decorator(f):
+            if not hasattr(f, "_cp_config"):
+                f._cp_config = {}
+            for k, v in kwargs.items():
+                f._cp_config[k] = v
+            return f
+        return tool_decorator
 
 
 Config.environments = environments = {
     cherrypy.engine.log("Mounted: %s on %s" % (v, v.script_name or "/"))
 Config.namespaces["tree"] = _tree_namespace_handler
 
+

cherrypy/_cpreqbody.py

         
     # Now that all values have been successfully parsed and decoded,
     # apply them to the entity.params dict.
-    for key, value in params.iteritems():
+    for key, value in params.items():
         if key in entity.params:
             if not isinstance(entity.params[key], list):
                 entity.params[key] = [entity.params[key]]

cherrypy/lib/auth.py

     cherrypy.serving.response.headers['www-authenticate'] = httpauth.digestAuth(realm)
     
     raise cherrypy.HTTPError(401, "You are not authorized to access that resource")
-

cherrypy/test/test_encoding.py

         utf8._cp_config = {'tools.encode.encoding': 'utf-8'}
         
         def reqparams(self, *args, **kwargs):
-            return repr(cherrypy.request.params)
+            return ', '.join([": ".join((k, v)).encode('utf8')
+                             for k, v in cherrypy.request.params.items()])
         reqparams.exposed = True
     
     class GZIP:
     
     class Decode:
         def extra_charset(self, *args, **kwargs):
-            return repr(cherrypy.request.params)
+            return ', '.join([": ".join((k, v)).encode('utf8')
+                             for k, v in cherrypy.request.params.items()])
         extra_charset.exposed = True
         extra_charset._cp_config = {
             'tools.decode.on': True,
             }
         
         def force_charset(self, *args, **kwargs):
-            return repr(cherrypy.request.params)
+            return ', '.join([": ".join((k, v)).encode('utf8')
+                             for k, v in cherrypy.request.params.items()])
         force_charset.exposed = True
         force_charset._cp_config = {
             'tools.decode.on': True,
         # Encoded utf8 query strings MUST be parsed correctly.
         # Here, q is the POUND SIGN U+00A3 encoded in utf8 and then %HEX
         self.getPage("/reqparams?q=%C2%A3")
-        self.assertBody(r"{'q': u'\xa3'}")
+        self.assertBody("q: \xc2\xa3")
         
         # Query strings that are incorrectly encoded MUST raise 404.
         # Here, q is the POUND SIGN U+00A3 encoded in latin1 and then %HEX
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'q': u'\xa3'}")
+        self.assertBody("q: \xc2\xa3")
         
         # ...and in utf16, which is not in the default attempt_charsets list:
         body = "\xff\xfeq\x00=\xff\xfe\xa3\x00"
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'q': u'\xa3'}")
+        self.assertBody("q: \xc2\xa3")
         
         # Entities that are incorrectly encoded MUST raise 400.
         # Here, q is the POUND SIGN U+00A3 encoded in utf16, but
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'q': u'\xa3'}")
+        self.assertBody("q: \xc2\xa3")
         
         # An extra charset should be tried first, and continue to other default
         # charsets if it doesn't match.
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'q': u'\xa3'}")
+        self.assertBody("q: \xc2\xa3")
         
         # An extra charset should error if force is True and it doesn't match.
         # Here, we force utf-16 as a charset but still pass a utf-8 body.
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'text': u'ab\u201cc', 'submit': u'Create'}")
+        self.assertBody("text: ab\xe2\x80\x9cc, submit: Create")
     
     def test_multipart_decoding_no_charset(self):
         # Test the decoding of a multipart entity when the charset (utf8) is
                               ("Content-Length", str(len(body))),
                               ],
                      body=body),
-        self.assertBody(r"{'text': u'\u201c', 'submit': u'Create'}")
+        self.assertBody("text: \xe2\x80\x9c, submit: Create")
     
     def test_multipart_decoding_no_successful_charset(self):
         # Test the decoding of a multipart entity when the charset (utf16) is