Changeset 338
- Timestamp:
- 06/17/05 11:50:52
- Files:
-
- trunk/cherrypy/_cpdefaults.py (deleted)
- trunk/cherrypy/_cphttptools.py (modified) (2 diffs)
- trunk/cherrypy/_cputil.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttptools.py
r337 r338 34 34 import mimetypes, Cookie, urlparse 35 35 from lib.filter import basefilter 36 import cpg, _cputil, cperror, _cp defaults, _cpcgifs36 import cpg, _cputil, cperror, _cpcgifs 37 37 38 38 # Can't use cStringIO; doesn't support unicode strings … … 395 395 def applyFilters(methodName): 396 396 if methodName in ('beforeRequestBody', 'beforeMain'): 397 filterList = (_cp defaults._cpDefaultInputFilterList +397 filterList = (_cputil._cpDefaultInputFilterList + 398 398 _cputil.getSpecialAttribute('_cpFilterList')) 399 399 elif methodName in ('beforeFinalize',): 400 400 filterList = (_cputil.getSpecialAttribute('_cpFilterList') + 401 _cp defaults._cpDefaultOutputFilterList)401 _cputil._cpDefaultOutputFilterList) 402 402 else: 403 403 # 'onStartResource', 'onEndResource' 404 404 # 'beforeErrorResponse', 'afterErrorResponse' 405 filterList = (_cp defaults._cpDefaultInputFilterList +405 filterList = (_cputil._cpDefaultInputFilterList + 406 406 _cputil.getSpecialAttribute('_cpFilterList') + 407 _cp defaults._cpDefaultOutputFilterList)407 _cputil._cpDefaultOutputFilterList) 408 408 for filter in filterList: 409 409 method = getattr(filter, methodName, None) trunk/cherrypy/_cputil.py
r337 r338 32 32 """ 33 33 34 import time, thread, cpg, _cpdefaults, cperror 34 import time, cpg, cperror 35 35 36 36 37 class EmptyClass: … … 38 39 pass 39 40 41 40 42 def getSpecialAttribute(name): 41 43 """ Return the special function """ 42 44 43 45 # First, we look in the right-most object if this special function is implemented. 44 46 # If not, then we try the previous object and so on until we reach cpg.root 45 # If it's still not there, we use the implementation from the 46 # "_cpdefaults.py" module 47 48 49 moduleList = [_cpdefaults] 47 # If it's still not there, we use the implementation from this module. 48 50 49 root = getattr(cpg, 'root', None) 51 50 if root: 52 moduleList .append(root)51 moduleList = [root] 53 52 # Try object path 54 53 try: 55 54 path = cpg.request.objectPath or cpg.request.path 56 except :55 except AttributeError: 57 56 path = '/' 58 57 if path: 59 58 pathList = path.split('/')[1:] 60 61 obj = cpg.root 62 previousObj = None 59 63 60 # Successively get objects from the path 64 61 for newObj in pathList: 65 previousObj = obj66 62 try: 67 obj = getattr(obj, newObj)68 moduleList.append( obj)63 root = getattr(root, newObj) 64 moduleList.append(root) 69 65 except AttributeError: 70 66 break 71 72 moduleList.reverse() 73 for module in moduleList: 74 func = getattr(module, name, None) 75 if func != None: 76 return func 77 78 raise cperror.InternalError, "Special function %s could not be found" % repr(name) 79 67 68 moduleList.reverse() 69 for module in moduleList: 70 func = getattr(module, name, None) 71 if func != None: 72 return func 73 74 try: 75 return globals()[name] 76 except KeyError: 77 raise cperror.InternalError("Special function %s could not be found" 78 % repr(name)) 79 80 81 def _cpLogMessage(msg, context = '', severity = 0): 82 """ Default method for logging messages """ 83 84 nowTuple = time.localtime(time.time()) 85 nowStr = '%04d/%02d/%02d %02d:%02d:%02d' % (nowTuple[:6]) 86 if severity == 0: 87 level = "INFO" 88 elif severity == 1: 89 level = "WARNING" 90 elif severity == 2: 91 level = "ERROR" 92 else: 93 level = "UNKNOWN" 94 try: 95 logToScreen = cpg.config.get('server.logToScreen') 96 except: 97 logToScreen = True 98 s = nowStr + ' ' + context + ' ' + level + ' ' + msg 99 if logToScreen: 100 print s 101 if cpg.config.get('server.logFile'): 102 f = open(cpg.config.get('server.logFile'), 'ab') 103 f.write(s + '\n') 104 f.close() 105 106 def _cpOnError(): 107 """ Default _cpOnError method """ 108 import sys, traceback 109 content = "".join(traceback.format_exception(*sys.exc_info())) 110 cpg.response.body = [content] 111 cpg.response.headerMap['Content-Type'] = 'text/plain' 112 if cpg.response.headerMap.has_key('Content-Encoding'): 113 del cpg.response.headerMap['Content-Encoding'] 114 115 _cpFilterList = [] 116 117 # Filters that are always included 118 from cherrypy.lib.filter import baseurlfilter, cachefilter, \ 119 decodingfilter, encodingfilter, gzipfilter, logdebuginfofilter, \ 120 staticfilter, nsgmlsfilter, tidyfilter, \ 121 virtualhostfilter, xmlrpcfilter 122 123 from cherrypy.lib.filter.sessionfilter import sessionfilter 124 125 _cachefilter = cachefilter.CacheFilter() 126 _logdebuginfofilter = logdebuginfofilter.LogDebugInfoFilter() 127 _nsgmlsfilter = nsgmlsfilter.NsgmlsFilter() 128 _sessionfilter = sessionfilter.SessionFilter() 129 _tidyfilter = tidyfilter.TidyFilter() 130 _xmlfilter = xmlrpcfilter.XmlRpcFilter() 131 132 # These are in order for a reason! 133 134 _cpDefaultInputFilterList = [ 135 _cachefilter, 136 _logdebuginfofilter, 137 virtualhostfilter.VirtualHostFilter(), 138 baseurlfilter.BaseUrlFilter(), 139 decodingfilter.DecodingFilter(), 140 _sessionfilter, 141 staticfilter.StaticFilter(), 142 _nsgmlsfilter, 143 _tidyfilter, 144 _xmlfilter, 145 ] 146 _cpDefaultOutputFilterList = [ 147 _xmlfilter, 148 encodingfilter.EncodingFilter(), 149 _tidyfilter, 150 _nsgmlsfilter, 151 _logdebuginfofilter, 152 gzipfilter.GzipFilter(), 153 _sessionfilter, 154 _cachefilter, 155 ] 80 156 81 157 # public domain "unrepr" implementation, found on the web and then improved.

