From 191e642b22c3faa5be2762dad49977e787e382be Mon Sep 17 00:00:00 2001 From: obenassy <> Date: Sat, 15 Dec 2007 06:28:32 +0000 Subject: [PATCH] Works with python2.4. --- glasnost-web/code/webhandler.py | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/glasnost-web/code/webhandler.py b/glasnost-web/code/webhandler.py index c4b2e314..e6f85520 100644 --- a/glasnost-web/code/webhandler.py +++ b/glasnost-web/code/webhandler.py @@ -194,7 +194,7 @@ class Application(applications.Application): _req = req._req except AttributeError: _req = req - + # If the file at webFilePath exists and is static (images, # stylesheets...) then return its content directly. if not (_req.filename.endswith('/index') or @@ -621,7 +621,7 @@ class Application(applications.Application): if reqCache is None: # The system caching is not activated when a session is open. - reqCache = Request(req) + reqCache = req reqCache.caching = 0 reqCache.depends = [] reqCache.buffered = 0 @@ -1066,7 +1066,7 @@ class Application(applications.Application): else: module = apache.import_module( moduleName, - context.getVar('req')._req, + context.getVar('req'), context.getVar('webDirectoryPaths')) except ImportError: if context.getVar('debug'): @@ -1314,11 +1314,6 @@ class BufferedRequest: except AttributeError: self.__dict__[attr] = val -class Request(apache.Request): - def write(self, st): - if type(st) is type(u''): - st = st.encode('iso-8859-1') - return self._req.write(st) class RequestCache: buffered = 0 @@ -1332,8 +1327,12 @@ class RequestCache: depends = None def __init__(self, req, language): - for key, value in req.__dict__.items(): - self.__dict__[key] = value + for attr in dir(req): + if hasattr(req, attr) and not attr.startswith('_'): #and type(getattr(req, attr))!=type(str) : + try: + setattr(self, attr, getattr(req, attr)) + except: + pass self.cacheDirectoryPath = os.path.join( context.getVar('varDirectoryPath'), 'webcache', context.getVar('virtualHost').hostName) @@ -1353,7 +1352,12 @@ class RequestCache: self.cacheDirectoryPath, self.getCacheFileName(language) + '.mimetype') self.depends = [] - + if not self.__dict__.has_key('_req') or not self.__dict__[_req_]: + try: + self._req = req._req + except: + self._req = req + def cancel(self): if self.cacheFile is not None: self.cacheFile.close() @@ -1451,12 +1455,20 @@ class RequestCache: fcntl.lockf(self.cacheFile, fcntl.LOCK_UN) def __getattr__(self, attr): + if not hasattr(self, '_req'): + try: + return self.__dict__[attr] + except AttributeError: + raise AttributeError, attr try: return getattr(self._req, attr) except AttributeError: raise AttributeError, attr def __setattr__(self, attr, val): + if not hasattr(self, '_req'): + self.__dict__[attr] = val + return try: if attr != '_req': setattr(self._req, attr, val)