Changeset 521
- Timestamp:
- 08/08/05 13:35:03
- Files:
-
- trunk/cherrypy/_cputil.py (modified) (6 diffs)
- trunk/cherrypy/lib/cptools.py (modified) (previous)
- trunk/cherrypy/lib/filter/cachefilter.py (modified) (previous)
- trunk/cherrypy/server.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cputil.py
r517 r521 250 250 sys.path.remove(path) 251 251 252 252 253 # public domain "unrepr" implementation, found on the web and then improved. 253 254 import compiler … … 258 259 return p.getChildren()[1].getChildren()[0].getChildren()[1] 259 260 261 260 262 class UnknownType(Exception): 261 pass262 # initi lize the builtin filters263 264 # initialize the built-in filters 263 265 for n in xrange(len(_cpDefaultInputFilterList)): 264 266 try: … … 272 274 except: 273 275 pass 274 276 277 275 278 class Builder: 276 279 277 280 def build(self, o): 278 m = getattr(self, 'build_' +o.__class__.__name__, None)281 m = getattr(self, 'build_' + o.__class__.__name__, None) 279 282 if m is None: 280 283 raise UnknownType(o.__class__.__name__) 281 284 return m(o) 282 285 283 286 def build_List(self, o): 284 287 return map(self.build, o.getChildren()) 285 288 286 289 def build_Const(self, o): 287 290 return o.value 288 291 289 292 def build_Dict(self, o): 290 293 d = {} … … 293 296 d[el] = i.next() 294 297 return d 295 298 296 299 def build_Tuple(self, o): 297 300 return tuple(self.build_List(o)) 298 301 299 302 def build_Name(self, o): 300 303 if o.name == 'None': 301 304 return None 302 elif o.name == 'True':305 if o.name == 'True': 303 306 return True 304 elif o.name == 'False':307 if o.name == 'False': 305 308 return False 309 310 # See if the Name is a package or module 311 try: 312 return modules(o.name) 313 except ImportError: 314 pass 315 306 316 raise UnknownType(o.name) 307 317 308 318 def build_Add(self, o): 309 319 real, imag = map(self.build_Const, o.getChildren()) … … 315 325 raise UnknownType('Add') 316 326 return real+imag 327 328 def build_Getattr(self, o): 329 parent = self.build(o.expr) 330 return getattr(parent, o.attrname) 331 317 332 318 333 def unrepr(s): … … 322 337 return Builder().build(getObj(s)) 323 338 except: 324 raise cherrypy.WrongUnreprValue, repr(s) 339 raise #cherrypy.WrongUnreprValue, repr(s) 340 341 def modules(modulePath): 342 """Load a module and retrieve a reference to that module.""" 343 try: 344 mod = sys.modules[modulePath] 345 if mod is None: 346 raise KeyError 347 except KeyError: 348 # The last [''] is important. 349 mod = __import__(modulePath, globals(), locals(), ['']) 350 return mod 351 352 def attributes(fullAttributeName): 353 """Load a module and retrieve an attribute of that module.""" 354 355 # Parse out the path, module, and attribute 356 lastDot = fullAttributeName.rfind(u".") 357 attrName = fullAttributeName[lastDot + 1:] 358 modPath = fullAttributeName[:lastDot] 359 360 aMod = modules(modPath) 361 # Let an AttributeError propagate outward. 362 try: 363 attr = getattr(aMod, attrName) 364 except AttributeError: 365 raise AttributeError("'%s' object has no attribute '%s'" 366 % (modPath, attrName)) 367 368 # Return a reference to the attribute. 369 return attr trunk/cherrypy/server.py
r517 r521 143 143 serverClass = cherrypy.config.get("server.class", None) 144 144 if serverClass and isinstance(serverClass, basestring): 145 serverClass = attributes(serverClass)145 serverClass = cherrypy._cputil.attributes(serverClass) 146 146 if serverClass is None: 147 147 import _cpwsgi … … 172 172 stop() 173 173 174 def modules(modulePath):175 """Load a module and retrieve a reference to that module."""176 try:177 aMod = sys.modules[modulePath]178 if aMod is None:179 raise KeyError180 except KeyError:181 # The last [''] is important.182 aMod = __import__(modulePath, globals(), locals(), [''])183 return aMod184 185 def attributes(fullAttributeName):186 """Load a module and retrieve an attribute of that module."""187 188 # Parse out the path, module, and attribute189 lastDot = fullAttributeName.rfind(u".")190 attrName = fullAttributeName[lastDot + 1:]191 modPath = fullAttributeName[:lastDot]192 193 aMod = modules(modPath)194 # Let an AttributeError propagate outward.195 try:196 anAttr = getattr(aMod, attrName)197 except AttributeError:198 raise AttributeError("'%s' object has no attribute '%s'"199 % (modPath, attrName))200 201 # Return a reference to the attribute.202 return anAttr203 204 174 205 175 seen_threads = {}

