[debian] Break old geocoding
It wants cubicweb.interfaces.
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""HTTP cache managers"""__docformat__="restructuredtext en"fromtimeimportmktimefromdatetimeimportdatetime# time delta usable to convert localized time to GMT time# XXX this become erroneous after a DST transition!!!GMTOFFSET=-(datetime.now()-datetime.utcnow())classNoHTTPCacheManager(object):"""default cache manager: set no-cache cache control policy"""def__init__(self,view):self.view=viewself.req=view._cwself.cw_rset=view.cw_rsetdefset_headers(self):self.req.set_header('Cache-control','no-cache')classMaxAgeHTTPCacheManager(NoHTTPCacheManager):"""max-age cache manager: set max-age cache control policy, with max-age specified with the `cache_max_age` attribute of the view """defset_headers(self):self.req.set_header('Cache-control','max-age=%s'%self.view.cache_max_age)classEtagHTTPCacheManager(NoHTTPCacheManager):"""etag based cache manager for startup views * etag is generated using the view name and the user's groups * set policy to 'must-revalidate' and expires to the current time to force revalidation on each request """defetag(self):ifnotself.req.cnx:# session without established connection to the reporeturnself.view.__regid__returnself.view.__regid__+'/'+','.join(sorted(self.req.user.groups))defmax_age(self):# 0 to actually force revalidationreturn0deflast_modified(self):"""return view's last modified GMT time"""returnself.view.last_modified()defset_headers(self):req=self.reqtry:req.set_header('Etag','"%s"'%self.etag())exceptNoEtag:self.req.set_header('Cache-control','no-cache')returnreq.set_header('Cache-control','must-revalidate;max-age=%s'%self.max_age())mdate=self.last_modified()# use a timestamp, not a formatted raw header, and let# the front-end correctly generate it# ("%a, %d %b %Y %H:%M:%S GMT" return localized date that# twisted don't parse correctly)req.set_header('Last-modified',mktime(mdate.timetuple()),raw=False)classEntityHTTPCacheManager(EtagHTTPCacheManager):"""etag based cache manager for view displaying a single entity * etag is generated using entity's eid, the view name and the user's groups * get last modified time from the entity definition (this may not be the entity's modification time since a view may include some related entities with a modification time to consider) using the `last_modified` method """defetag(self):ifself.cw_rsetisNoneorlen(self.cw_rset)==0:# entity startup view for instancereturnsuper(EntityHTTPCacheManager,self).etag()iflen(self.cw_rset)>1:raiseNoEtag()etag=super(EntityHTTPCacheManager,self).etag()eid=self.cw_rset[0][0]ifself.req.user.owns(eid):etag+=',owners'returnstr(eid)+'/'+etagclassNoEtag(Exception):"""an etag can't be generated"""__all__=('GMTOFFSET','NoHTTPCacheManager','MaxAgeHTTPCacheManager','EtagHTTPCacheManager','EntityHTTPCacheManager')# monkey patching, so view doesn't depends on this module and we have all# http cache related logic herefromcubicwebimportviewasviewmoddefset_http_cache_headers(self):self.http_cache_manager(self).set_headers()viewmod.View.set_http_cache_headers=set_http_cache_headersdeflast_modified(self):"""return the date/time where this view should be considered as modified. Take care of possible related objects modifications. /!\ must return GMT time /!\ """# XXX check view module's file modification time in dev mod ?ctime=datetime.utcnow()ifself.cache_max_age:mtime=self._cw.header_if_modified_since()ifmtime:tdelta=(ctime-mtime)iftdelta.days*24*60*60+tdelta.seconds<=self.cache_max_age:returnmtime# mtime = ctime will force page rerenderingreturnctimeviewmod.View.last_modified=last_modified# configure default cachingviewmod.View.http_cache_manager=NoHTTPCacheManager# max-age=0 to actually force revalidation when neededviewmod.View.cache_max_age=0viewmod.StartupView.http_cache_manager=MaxAgeHTTPCacheManagerviewmod.StartupView.cache_max_age=60*60*2# stay in http cache for 2 hours by default### HTTP Cache validator ############################################defget_validators(headers_in):"""return a list of http condition validator relevant to this request """result=[]forheader,funcinVALIDATORS:value=headers_in.getHeader(header)ifvalueisnotNone:result.append((func,value))returnresultdefif_modified_since(ref_date,headers_out):last_modified=headers_out.getHeader('last-modified')iflast_modifiedisNone:returnTruereturnref_date<last_modifieddefif_none_match(tags,headers_out):etag=headers_out.getHeader('etag')ifetagisNone:returnTruereturnnot((etagintags)or('*'intags))VALIDATORS=[('if-modified-since',if_modified_since),#('if-unmodified-since', if_unmodified_since),('if-none-match',if_none_match),#('if-modified-since', if_modified_since),]