Changeset 2029
- Timestamp:
- 07/25/08 12:16:43
- Files:
-
- branches/py3k/cherrypy/__init__.py (modified) (4 diffs)
- branches/py3k/cherrypy/_cpcgifs.py (modified) (1 diff)
- branches/py3k/cherrypy/_cpchecker.py (modified) (10 diffs)
- branches/py3k/cherrypy/_cpconfig.py (modified) (11 diffs)
- branches/py3k/cherrypy/_cperror.py (modified) (4 diffs)
- branches/py3k/cherrypy/_cplogging.py (modified) (3 diffs)
- branches/py3k/cherrypy/_cpmodpy.py (modified) (5 diffs)
- branches/py3k/cherrypy/_cprequest.py (modified) (14 diffs)
- branches/py3k/cherrypy/_cpserver.py (modified) (1 diff)
- branches/py3k/cherrypy/_cptools.py (modified) (5 diffs)
- branches/py3k/cherrypy/_cptree.py (modified) (1 diff)
- branches/py3k/cherrypy/_cpwsgi.py (modified) (4 diffs)
- branches/py3k/cherrypy/lib/__init__.py (modified) (2 diffs)
- branches/py3k/cherrypy/lib/auth.py (modified) (2 diffs)
- branches/py3k/cherrypy/lib/caching.py (modified) (3 diffs)
- branches/py3k/cherrypy/lib/covercp.py (modified) (3 diffs)
- branches/py3k/cherrypy/lib/cptools.py (modified) (4 diffs)
- branches/py3k/cherrypy/lib/encoding.py (modified) (2 diffs)
- branches/py3k/cherrypy/lib/http.py (modified) (7 diffs)
- branches/py3k/cherrypy/lib/httpauth.py (modified) (4 diffs)
- branches/py3k/cherrypy/lib/profiler.py (modified) (2 diffs)
- branches/py3k/cherrypy/lib/sessions.py (modified) (7 diffs)
- branches/py3k/cherrypy/lib/tidy.py (modified) (2 diffs)
- branches/py3k/cherrypy/lib/wsgiapp.py (modified) (1 diff)
- branches/py3k/cherrypy/process/plugins.py (modified) (11 diffs)
- branches/py3k/cherrypy/process/servers.py (modified) (2 diffs)
- branches/py3k/cherrypy/process/win32.py (modified) (2 diffs)
- branches/py3k/cherrypy/process/wspbus.py (modified) (4 diffs)
- branches/py3k/cherrypy/test/benchmark.py (modified) (6 diffs)
- branches/py3k/cherrypy/test/helper.py (modified) (3 diffs)
- branches/py3k/cherrypy/test/logtest.py (modified) (4 diffs)
- branches/py3k/cherrypy/test/modfcgid.py (modified) (1 diff)
- branches/py3k/cherrypy/test/modpy.py (modified) (2 diffs)
- branches/py3k/cherrypy/test/modwsgi.py (modified) (2 diffs)
- branches/py3k/cherrypy/test/test.py (modified) (10 diffs)
- branches/py3k/cherrypy/test/test_caching.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_config.py (modified) (4 diffs)
- branches/py3k/cherrypy/test/test_conn.py (modified) (15 diffs)
- branches/py3k/cherrypy/test/test_core.py (modified) (4 diffs)
- branches/py3k/cherrypy/test/test_encoding.py (modified) (3 diffs)
- branches/py3k/cherrypy/test/test_etags.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_http.py (modified) (4 diffs)
- branches/py3k/cherrypy/test/test_httpauth.py (modified) (3 diffs)
- branches/py3k/cherrypy/test/test_logging.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_refleaks.py (modified) (3 diffs)
- branches/py3k/cherrypy/test/test_session.py (modified) (6 diffs)
- branches/py3k/cherrypy/test/test_sessionauthenticate.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_states.py (modified) (18 diffs)
- branches/py3k/cherrypy/test/test_tidy.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_tools.py (modified) (10 diffs)
- branches/py3k/cherrypy/test/test_wsgi_ns.py (modified) (2 diffs)
- branches/py3k/cherrypy/test/test_wsgiapps.py (modified) (1 diff)
- branches/py3k/cherrypy/test/test_xmlrpc.py (modified) (3 diffs)
- branches/py3k/cherrypy/test/webtest.py (modified) (11 diffs)
- branches/py3k/cherrypy/tutorial/bonus-sqlobject.py (modified) (1 diff)
- branches/py3k/cherrypy/wsgiserver/__init__.py (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/py3k/cherrypy/__init__.py
r2007 r2029 60 60 __version__ = "3.1.0" 61 61 62 from url parse import urljoin as _urljoin62 from urllib.parse import urljoin as _urljoin 63 63 64 64 … … 94 94 Help on class Thing in module pkg.mod: 95 95 96 class Thing( __builtin__.object)96 class Thing(builtins.object) 97 97 | A thing and its properties. 98 98 | … … 127 127 newdoc = [cls.__doc__ or ""] 128 128 129 dctnames = dct.keys() 130 dctnames.sort() 131 132 for name in dctnames: 129 for name in sorted(dct.keys()): 133 130 if name.endswith("__doc"): 134 131 # Remove the magic doc attribute. … … 407 404 func.exposed = True 408 405 if alias is not None: 409 if isinstance(alias, basestring):406 if isinstance(alias, (str, bytes)): 410 407 parents[alias.replace(".", "_")] = func 411 408 else: branches/py3k/cherrypy/_cpcgifs.py
r762 r2029 7 7 try: 8 8 cgi.FieldStorage.__init__(self, *args, **kwds) 9 except ValueError ,ex:9 except ValueError as ex: 10 10 if str(ex) == 'Maximum content length exceeded': 11 11 raise cherrypy.HTTPError(status=413) branches/py3k/cherrypy/_cpchecker.py
r1841 r2029 48 48 49 49 def check_skipped_app_config(self): 50 for sn, app in cherrypy.tree.apps.ite ritems():50 for sn, app in cherrypy.tree.apps.items(): 51 51 if not isinstance(app, cherrypy.Application): 52 52 continue … … 65 65 # Use the dummy Request object in the main thread. 66 66 request = cherrypy.request 67 for sn, app in cherrypy.tree.apps.ite ritems():67 for sn, app in cherrypy.tree.apps.items(): 68 68 if not isinstance(app, cherrypy.Application): 69 69 continue … … 131 131 def _compat(self, config): 132 132 """Process config and warn on each obsolete or deprecated entry.""" 133 for section, conf in config.ite ritems():133 for section, conf in config.items(): 134 134 if isinstance(conf, dict): 135 for k, v in conf.ite ritems():135 for k, v in conf.items(): 136 136 if k in self.obsolete: 137 137 warnings.warn("%r is obsolete. Use %r instead.\n" … … 153 153 """Process config and warn on each obsolete or deprecated entry.""" 154 154 self._compat(cherrypy.config) 155 for sn, app in cherrypy.tree.apps.ite ritems():155 for sn, app in cherrypy.tree.apps.items(): 156 156 if not isinstance(app, cherrypy.Application): 157 157 continue … … 171 171 ns += self.extra_config_namespaces 172 172 173 for section, conf in app.config.ite ritems():173 for section, conf in app.config.items(): 174 174 is_path_section = section.startswith("/") 175 175 if is_path_section and isinstance(conf, dict): 176 for k, v in conf.ite ritems():176 for k, v in conf.items(): 177 177 atoms = k.split(".") 178 178 if len(atoms) > 1: … … 198 198 def check_config_namespaces(self): 199 199 """Process config and warn on each unknown config namespace.""" 200 for sn, app in cherrypy.tree.apps.ite ritems():200 for sn, app in cherrypy.tree.apps.items(): 201 201 if not isinstance(app, cherrypy.Application): 202 202 continue … … 211 211 212 212 def _populate_known_types(self): 213 import __builtin__214 builtins = [x for x in vars( __builtin__).values()213 import builtins 214 builtins = [x for x in vars(builtins).values() 215 215 if type(x) is type(str)] 216 216 … … 231 231 "which does not match the expected type %r.") 232 232 233 for section, conf in config.ite ritems():233 for section, conf in config.items(): 234 234 if isinstance(conf, dict): 235 for k, v in conf.ite ritems():235 for k, v in conf.items(): 236 236 if v is not None: 237 237 expected_type = self.known_config_types.get(k, None) … … 252 252 """Assert that config values are of the same type as default values.""" 253 253 self._known_types(cherrypy.config) 254 for sn, app in cherrypy.tree.apps.ite ritems():254 for sn, app in cherrypy.tree.apps.items(): 255 255 if not isinstance(app, cherrypy.Application): 256 256 continue … … 262 262 def check_localhost(self): 263 263 """Warn if any socket_host is 'localhost'. See #711.""" 264 for k, v in cherrypy.config.ite ritems():264 for k, v in cherrypy.config.items(): 265 265 if k == 'server.socket_host' and v == 'localhost': 266 266 warnings.warn("The use of 'localhost' as a socket host can " branches/py3k/cherrypy/_cpconfig.py
r1989 r2029 94 94 """ 95 95 96 import ConfigParser96 import configparser 97 97 try: 98 98 set … … 139 139 def as_dict(config): 140 140 """Return a dict from 'config' whether it is a dict, file, or filename.""" 141 if isinstance(config, basestring):141 if isinstance(config, (str, bytes)): 142 142 config = _Parser().dict_from_file(config) 143 143 elif hasattr(config, 'read'): … … 151 151 the list of files to monitor for "autoreload" changes. 152 152 """ 153 if isinstance(other, basestring):153 if isinstance(other, (str, bytes)): 154 154 cherrypy.engine.autoreload.files.add(other) 155 155 156 156 # Load other into base 157 for section, value_map in as_dict(other).ite ritems():157 for section, value_map in as_dict(other).items(): 158 158 base.setdefault(section, {}).update(value_map) 159 159 … … 193 193 # I chose __enter__ and __exit__ so someday this could be 194 194 # rewritten using Python 2.5's 'with' statement: 195 # for ns, handler in self.ite ritems():195 # for ns, handler in self.items(): 196 196 # with handler as callable: 197 # for k, v in ns_confs.get(ns, {}).ite ritems():197 # for k, v in ns_confs.get(ns, {}).items(): 198 198 # callable(k, v) 199 for ns, handler in self.ite ritems():199 for ns, handler in self.items(): 200 200 exit = getattr(handler, "__exit__", None) 201 201 if exit: … … 204 204 try: 205 205 try: 206 for k, v in ns_confs.get(ns, {}).ite ritems():206 for k, v in ns_confs.get(ns, {}).items(): 207 207 callable(k, v) 208 208 except: … … 219 219 exit(None, None, None) 220 220 else: 221 for k, v in ns_confs.get(ns, {}).ite ritems():221 for k, v in ns_confs.get(ns, {}).items(): 222 222 handler(k, v) 223 223 … … 258 258 def update(self, config): 259 259 """Update self from a dict, file or filename.""" 260 if isinstance(config, basestring):260 if isinstance(config, (str, bytes)): 261 261 # Filename 262 262 cherrypy.engine.autoreload.files.add(config) … … 321 321 322 322 323 class _Parser( ConfigParser.ConfigParser):323 class _Parser(configparser.ConfigParser): 324 324 """Sub-class of ConfigParser that keeps the case of options and that raises 325 325 an exception if the file cannot be read. … … 330 330 331 331 def read(self, filenames): 332 if isinstance(filenames, basestring):332 if isinstance(filenames, (str, bytes)): 333 333 filenames = [filenames] 334 334 for filename in filenames: … … 355 355 try: 356 356 value = unrepr(value) 357 except Exception ,x:357 except Exception as x: 358 358 msg = ("Config error in section: %r, option: %r, " 359 359 "value: %r. Config values must be valid Python." % … … 370 370 return self.as_dict() 371 371 372 del ConfigParser372 del configparser branches/py3k/cherrypy/_cperror.py
r1949 r2029 4 4 from sys import exc_info as _exc_info 5 5 from traceback import format_exception as _format_exception 6 from url parse import urljoin as _urljoin6 from urllib.parse import urljoin as _urljoin 7 7 from cherrypy.lib import http as _http 8 8 … … 58 58 request = cherrypy.request 59 59 60 if isinstance(urls, basestring):60 if isinstance(urls, (str, bytes)): 61 61 urls = [urls] 62 62 … … 276 276 try: 277 277 code, reason, message = _http.valid_status(status) 278 except ValueError ,x:278 except ValueError as x: 279 279 raise cherrypy.HTTPError(500, x.args[0]) 280 280 … … 290 290 kwargs['version'] = cherrypy.__version__ 291 291 292 for k, v in kwargs.ite ritems():292 for k, v in kwargs.items(): 293 293 if v is None: 294 294 kwargs[k] = "" branches/py3k/cherrypy/_cplogging.py
r1984 r2029 7 7 logfmt = logging.Formatter("%(message)s") 8 8 import os 9 import rfc822 9 from email._parseaddr import _monthnames 10 10 import sys 11 11 … … 89 89 'a': inheaders.get('User-Agent', ''), 90 90 } 91 for k, v in atoms.items():91 for k, v in list(atoms.items()): 92 92 if isinstance(v, unicode): 93 93 v = v.encode('utf8') … … 108 108 """Return now() in Apache Common Log Format (no timezone).""" 109 109 now = datetime.datetime.now() 110 month = rfc822._monthnames[now.month - 1].capitalize()110 month = _monthnames[now.month - 1].capitalize() 111 111 return ('[%02d/%s/%04d:%02d:%02d:%02d]' % 112 112 (now.day, month, now.year, now.hour, now.minute, now.second)) branches/py3k/cherrypy/_cpmodpy.py
r1989 r2029 57 57 58 58 import logging 59 import StringIO59 import io 60 60 61 61 import cherrypy … … 184 184 qs = req.args or "" 185 185 reqproto = req.protocol 186 headers = req.headers_in.items()186 headers = list(req.headers_in.items()) 187 187 rfile = _ReadOnlyRequest(req) 188 188 prev = None … … 203 203 request.run(method, path, qs, reqproto, headers, rfile) 204 204 break 205 except cherrypy.InternalRedirect ,ir:205 except cherrypy.InternalRedirect as ir: 206 206 app.release_serving() 207 207 prev = request … … 221 221 path = ir.path 222 222 qs = ir.query_string 223 rfile = StringIO.StringIO()223 rfile = io.StringIO() 224 224 225 225 send_response(req, response.status, response.header_list, … … 252 252 253 253 # Set response body 254 if isinstance(body, basestring):254 if isinstance(body, (str, bytes)): 255 255 req.write(body) 256 256 else: branches/py3k/cherrypy/_cprequest.py
r1994 r2029 1 1 2 import Cookie 2 from http import cookies 3 3 import os 4 4 import sys … … 64 64 self.failsafe, self.priority, 65 65 ", ".join(['%s=%r' % (k, v) 66 for k, v in self.kwargs.ite ritems()])))66 for k, v in self.kwargs.items()]))) 67 67 68 68 … … 112 112 # We can't just use 'update' because we want copies of the 113 113 # mutable values (each is a list) as well. 114 for k, v in self.ite ritems():114 for k, v in self.items(): 115 115 newmap[k] = v[:] 116 116 return newmap … … 130 130 # Little-known fact you only get from reading source ;) 131 131 hookpoint = k.split(".", 1)[0] 132 if isinstance(v, basestring):132 if isinstance(v, (str, bytes)): 133 133 v = cherrypy.lib.attributes(v) 134 134 if not isinstance(v, Hook): … … 252 252 http.HeaderMap, http.HeaderElement.""" 253 253 254 cookie = Cookie.SimpleCookie()255 cookie__doc = """See help( Cookie)."""254 cookie = cookies.SimpleCookie() 255 cookie__doc = """See help(http.cookies).""" 256 256 257 257 rfile = None … … 530 530 self.rfile = rfile 531 531 self.headers = http.HeaderMap() 532 self.cookie = Cookie.SimpleCookie()532 self.cookie = cookies.SimpleCookie() 533 533 self.handler = None 534 534 … … 609 609 self.hooks.run('before_finalize') 610 610 cherrypy.response.finalize() 611 except (cherrypy.HTTPRedirect, cherrypy.HTTPError) ,inst:611 except (cherrypy.HTTPRedirect, cherrypy.HTTPError) as inst: 612 612 inst.set_response() 613 613 self.stage = 'before_finalize (HTTPError)' … … 706 706 # didn't provide a "Content-Type" header. 707 707 if 'Content-Type' not in self.headers: 708 h = http.HeaderMap( self.headers.items())708 h = http.HeaderMap(list(self.headers.items())) 709 709 h['Content-Type'] = '' 710 710 else: … … 717 717 environ={'REQUEST_METHOD': "POST"}, 718 718 keep_blank_values=1) 719 except Exception ,e:719 except Exception as e: 720 720 if e.__class__.__name__ == 'MaxSizeExceeded': 721 721 # Post data is too big … … 743 743 self.hooks.run("after_error_response") 744 744 cherrypy.response.finalize() 745 except cherrypy.HTTPRedirect ,inst:745 except cherrypy.HTTPRedirect as inst: 746 746 inst.set_response() 747 747 cherrypy.response.finalize() … … 769 769 def __set__(self, obj, value): 770 770 # Convert the given value to an iterable object. 771 if isinstance(value, basestring):771 if isinstance(value, (str, bytes)): 772 772 # strings get wrapped in a list because iterating over a single 773 773 # item list is much faster than iterating over every character … … 814 814 http.HeaderMap, http.HeaderElement.""" 815 815 816 cookie = Cookie.SimpleCookie()817 cookie__doc = """See help( Cookie)."""816 cookie = cookies.SimpleCookie() 817 cookie__doc = """See help(http.cookies).""" 818 818 819 819 body = Body() … … 848 848 "Date": http.HTTPDate(self.time), 849 849 }) 850 self.cookie = Cookie.SimpleCookie()850 self.cookie = cookies.SimpleCookie() 851 851 852 852 def collapse_body(self): … … 860 860 try: 861 861 code, reason, _ = http.valid_status(self.status) 862 except ValueError ,x:862 except ValueError as x: 863 863 raise cherrypy.HTTPError(500, x.args[0]) 864 864 branches/py3k/cherrypy/_cpserver.py
r1994 r2029 73 73 from cherrypy import _cpwsgi_server 74 74 httpserver = _cpwsgi_server.CPWSGIServer() 75 if isinstance(httpserver, basestring):75 if isinstance(httpserver, (str, bytes)): 76 76 httpserver = attributes(httpserver)() 77 77 branches/py3k/cherrypy/_cptools.py
r2013 r2029 32 32 if isinstance(func, types.MethodType): 33 33 func = func.im_func 34 co = func. func_code34 co = func.__code__ 35 35 return co.co_varnames[:co.co_argcount] 36 36 … … 106 106 subspace = self.namespace + "." + self._name + "." 107 107 f._cp_config[subspace + "on"] = True 108 for k, v in kwargs.ite ritems():108 for k, v in kwargs.items(): 109 109 f._cp_config[subspace + k] = v 110 110 return f … … 287 287 288 288 # Grab cookie-relevant tool args 289 conf = dict([(k, v) for k, v in self._merged_args().ite ritems()289 conf = dict([(k, v) for k, v in self._merged_args().items() 290 290 if k in ('path', 'path_header', 'name', 'timeout', 291 291 'domain', 'secure')]) … … 347 347 # raising an exception here will do that; see 348 348 # cherrypy.lib.xmlrpc.on_error 349 raise Exception , 'method "%s" is not supported' % attr349 raise Exception('method "%s" is not supported' % attr) 350 350 351 351 conf = cherrypy.request.toolmaps['tools'].get("xmlrpc", {}) … … 400 400 401 401 # Take all remaining kwargs and set them on the Cache object. 402 for k, v in kwargs.ite ritems():402 for k, v in kwargs.items(): 403 403 setattr(cherrypy._cache, k, v) 404 404 branches/py3k/cherrypy/_cptree.py
r1989 r2029 104 104 req.app = self 105 105 106 for name, toolbox in self.toolboxes.ite ritems():106 for name, toolbox in self.toolboxes.items(): 107 107 req.namespaces[name] = toolbox 108 108 branches/py3k/cherrypy/_cpwsgi.py
r1994 r2029 1 1 """WSGI interface (see PEP 333).""" 2 2 3 import StringIO as _StringIO3 import io as _io 4 4 import sys as _sys 5 5 … … 83 83 self.close() 84 84 raise 85 except _cherrypy.InternalRedirect ,ir:85 except _cherrypy.InternalRedirect as ir: 86 86 self.environ['cherrypy.previous_request'] = _cherrypy.serving.request 87 87 self.close() … … 151 151 env['PATH_INFO'] = path 152 152 env['QUERY_STRING'] = query_string 153 env['wsgi.input'] = _ StringIO.StringIO()153 env['wsgi.input'] = _io.StringIO() 154 154 env['CONTENT_LENGTH'] = "0" 155 155 … … 171 171 self.close() 172 172 raise 173 except _cherrypy.InternalRedirect ,ir:173 except _cherrypy.InternalRedirect as ir: 174 174 self.environ['cherrypy.previous_request'] = _cherrypy.serving.request 175 175 self.close() branches/py3k/cherrypy/lib/__init__.py
r1794 r2029 19 19 20 20 # Parse out the path, module, and attribute 21 last_dot = full_attribute_name.rfind( u".")21 last_dot = full_attribute_name.rfind(".") 22 22 attr_name = full_attribute_name[last_dot + 1:] 23 23 mod_path = full_attribute_name[:last_dot] … … 90 90 pass 91 91 92 # See if the Name is in __builtin__.92 # See if the Name is in builtins. 93 93 try: 94 import __builtin__95 return getattr( __builtin__, o.name)94 import builtins 95 return getattr(builtins, o.name) 96 96 except AttributeError: 97 97 pass branches/py3k/cherrypy/lib/auth.py
r1931 r2029 20 20 21 21 if not isinstance(users, dict): 22 raise ValueError , "Authentication users must be a dictionary"22 raise ValueError("Authentication users must be a dictionary") 23 23 24 24 # fetch the user password … … 29 29 else: 30 30 if not isinstance(users, dict): 31 raise ValueError , "Authentication users must be a dictionary"31 raise ValueError("Authentication users must be a dictionary") 32 32 33 33 # fetch the user password branches/py3k/cherrypy/lib/caching.py
r1798 r2029 42 42 while time: 43 43 now = time.time() 44 for expiration_time, objects in self.expirations.items():44 for expiration_time, objects in list(self.expirations.items()): 45 45 if expiration_time <= now: 46 46 for obj_size, obj_key in objects: … … 158 158 # resurrected just above (response.headers = cache_data[1]). 159 159 cptools.validate_since() 160 except cherrypy.HTTPRedirect ,x:160 except cherrypy.HTTPRedirect as x: 161 161 if x.status == 304: 162 162 cherrypy._cache.tot_non_modified += 1 … … 185 185 if vary: 186 186 sel_headers = dict([(k, v) for k, v 187 in cherrypy.request.headers.ite ritems()187 in cherrypy.request.headers.items() 188 188 if k in vary]) 189 189 else: branches/py3k/cherrypy/lib/covercp.py
r1814 r2029 26 26 localFile = os.path.join(os.path.dirname(__file__), "coverage.cache") 27 27 28 try:29 import cStringIO as StringIO30 except ImportError:31 import StringIO32 28 33 29 try: … … 191 187 192 188 # Show the directory name and any of our children 193 dirs = [k for k, v in root.ite ritems() if v]189 dirs = [k for k, v in root.items() if v] 194 190 dirs.sort() 195 191 for name in dirs: … … 208 204 if path.lower().startswith(base): 209 205 relpath = path[len(base):] 210 files = [k for k, v in root.ite ritems() if not v]206 files = [k for k, v in root.items() if not v] 211 207 files.sort() 212 208 for name in files: branches/py3k/cherrypy/lib/cptools.py
r2016 r2029 2 2 3 3 import logging 4 import md54 from hashlib import md5 5 5 import re 6 6 … … 41 41 if status == 200: 42 42 etag = response.collapse_body() 43 etag = '"%s"' % md5 .new(etag).hexdigest()43 etag = '"%s"' % md5(etag).hexdigest() 44 44 response.headers['ETag'] = etag 45 45 … … 282 282 def session_auth(**kwargs): 283 283 sa = SessionAuth() 284 for k, v in kwargs.ite ritems():284 for k, v in kwargs.items(): 285 285 setattr(sa, k, v) 286 286 return sa.run() … … 390 390 if not media: 391 391 return 392 if isinstance(media, basestring):392 if isinstance(media, (str, bytes)): 393 393 media = [media] 394 394 branches/py3k/cherrypy/lib/encoding.py
r1993 r2029 106 106 # Encoded strings may be of different lengths from their 107 107 # unicode equivalents, and even from each other. For example: 108 # >>> t = u"\u7007\u3040"108 # >>> t = "\u7007\u3040" 109 109 # >>> len(t) 110 110 # 2 … … 195 195 yield zobj.flush() 196 196 yield struct.pack("<l", crc) 197 yield struct.pack("<L", size & 0xFFFFFFFF L)197 yield struct.pack("<L", size & 0xFFFFFFFF) 198 198 199 199 def decompress(body): 200 import gzip, StringIO201 202 zbuf = StringIO.StringIO()200 import gzip, io 201 202 zbuf = io.StringIO() 203 203 zbuf.write(body) 204 204 zbuf.seek(0) branches/py3k/cherrypy/lib/http.py
r2026 r2029 7 7 # to a public caning. 8 8 9 from BaseHTTPServer import BaseHTTPRequestHandler9 from http.server import BaseHTTPRequestHandler 10 10 response_codes = BaseHTTPRequestHandler.responses.copy() 11 11 … … 22 22 import cgi 23 23 import re 24 from rfc822import formatdate as HTTPDate24 from email.utils import formatdate as HTTPDate 25 25 26 26 … … 102 102 103 103 def __unicode__(self): 104 p = [";%s=%s" % (k, v) for k, v in self.params.ite ritems()]105 return u"%s%s" % (self.value, "".join(p))104 p = [";%s=%s" % (k, v) for k, v in self.params.items()] 105 return "%s%s" % (self.value, "".join(p)) 106 106 107 107 def __str__(self): … … 195 195 196 196 def decode_TEXT(value): 197 """Decode RFC-2047 TEXT (e.g. "=?utf-8?q?f=C3=BCr?=" -> u"f\xfcr")."""197 """Decode RFC-2047 TEXT (e.g. "=?utf-8?q?f=C3=BCr?=" -> "f\xfcr").""" 198 198 from email.Header import decode_header 199 199 atoms = decode_header(value) … … 265 265 else: 266 266 pm = cgi.parse_qs(query_string, keep_blank_values) 267 for key, val in pm.items():267 for key, val in list(pm.items()): 268 268 if len(val) == 1: 269 269 pm[key] = val[0] … … 358 358 """Transform self into a list of (name, value) tuples.""" 359 359 header_list = [] 360 for key, v in self.ite ritems():360 for key, v in self.items(): 361 361 if isinstance(v, unicode): 362 362 # HTTP/1.0 says, "Words of *TEXT may contain octets … … 370 370 if protocol >= (1, 1): 371 371 # Encode RFC-2047 TEXT 372 # (e.g. u"\u8200" -> "=?utf-8?b?6IiA?=").372 # (e.g. "\u8200" -> "=?utf-8?b?6IiA?="). 373 373 from email.Header import Header 374 374 v = Header(v, 'utf-8').encode() branches/py3k/cherrypy/lib/httpauth.py
r1891 r2029 7 7 8 8 First use 'doAuth' to request the client authentication for a 9 certain resource. You should send an http lib.UNAUTHORIZED response to the10 client so he knows he has to authenticate itself.9 certain resource. You should send an http.client.UNAUTHORIZED 10 response to the client so he knows he has to authenticate itself. 11 11 12 12 Then use 'parseAuthorization' to retrieve the 'auth_map' used in … … 60 60 61 61 ################################################################################ 62 import md562 from hashlib import md5 63 63 import time 64 64 import base64 65 import urllib 265 import urllib 66 66 67 67 MD5 = "MD5" … … 77 77 # 78 78 DIGEST_AUTH_ENCODERS = { 79 MD5: lambda val: md5 .new(val).hexdigest (),80 MD5_SESS: lambda val: md5 .new(val).hexdigest (),81 # SHA: lambda val: sha .new(val).hexdigest (),79 MD5: lambda val: md5(val).hexdigest (), 80 MD5_SESS: lambda val: md5(val).hexdigest (), 81 # SHA: lambda val: sha1(val).hexdigest (), 82 82 } 83 83 … … 131 131 def _parseDigestAuthorization (auth_params): 132 132 # Convert the auth params to a dict 133 items = urllib 2.parse_http_list(auth_params)134 params = urllib 2.parse_keqv_list(items)133 items = urllib.parse_http_list(auth_params) 134 params = urllib.parse_keqv_list(items) 135 135 136 136 # Now validate the params branches/py3k/cherrypy/lib/profiler.py
r2012 r2029 61 61 import sys 62 62 63 try: 64 import cStringIO as StringIO 65 except ImportError: 66 import StringIO 63 import io 67 64 68 65 … … 95 92 def s
