[facets] duhh, necessary fromformfilter hidden was missing
"""Twisted request handler for CubicWeb:organization: Logilab:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses"""__docformat__="restructuredtext en"fromdatetimeimportdatetimefromtwisted.web2importhttp,http_headersfromcubicweb.webimportDirectResponsefromcubicweb.web.requestimportCubicWebRequestBasefromcubicweb.web.httpcacheimportGMTOFFSETdefcleanup_files(dct,encoding):d={}fork,infosindct.items():for(filename,mt,stream)ininfos:iffilename:# XXX: suppose that no file submitted <-> no filenamefilename=unicode(filename,encoding)mt=u'%s/%s'%(mt.mediaType,mt.mediaSubtype)d[k]=(filename,mt,stream)returndclassCubicWebTwistedRequestAdapter(CubicWebRequestBase):def__init__(self,req,vreg,https,base_url):self._twreq=reqself._base_url=base_urlsuper(CubicWebTwistedRequestAdapter,self).__init__(vreg,https,req.args)self.form.update(cleanup_files(req.files,self.encoding))# prepare output headersself.headers_out=http_headers.Headers()self._headers=req.headersdefbase_url(self):"""return the root url of the instance"""returnself._base_urldefhttp_method(self):"""returns 'POST', 'GET', 'HEAD', etc."""returnself._twreq.methoddefrelative_path(self,includeparams=True):"""return the normalized path of the request (ie at least relative to the instance's root, but some other normalization may be needed so that the returned path may be used to compare to generated urls :param includeparams: boolean indicating if GET form parameters should be kept in the path """path=self._twreq.uri[1:]# remove the root '/'ifnotincludeparams:path=path.split('?',1)[0]returnpathdefget_header(self,header,default=None,raw=True):"""return the value associated with the given input header, raise KeyError if the header is not set """ifraw:returnself._twreq.headers.getRawHeaders(header,[default])[0]returnself._twreq.headers.getHeader(header,default)defset_header(self,header,value,raw=True):"""set an output HTTP header"""ifraw:# adding encoded header is important, else page content# will be reconverted back to unicode and apart unefficiency, this# may cause decoding problem (e.g. when downloading a file)self.headers_out.setRawHeaders(header,[str(value)])else:self.headers_out.setHeader(header,value)defadd_header(self,header,value):"""add an output HTTP header"""# adding encoded header is important, else page content# will be reconverted back to unicode and apart unefficiency, this# may cause decoding problem (e.g. when downloading a file)self.headers_out.addRawHeader(header,str(value))defremove_header(self,header):"""remove an output HTTP header"""self.headers_out.removeHeader(header)def_validate_cache(self):"""raise a `DirectResponse` exception if a cached page along the way exists and is still usable """ifself.get_header('Cache-Control')in('max-age=0','no-cache'):# Expires header seems to be required by IE7self.add_header('Expires','Sat, 01 Jan 2000 00:00:00 GMT')returntry:http.checkPreconditions(self._twreq,_PreResponse(self))excepthttp.HTTPError,ex:self.info('valid http cache, no actual rendering')raiseDirectResponse(ex.response)# Expires header seems to be required by IE7self.add_header('Expires','Sat, 01 Jan 2000 00:00:00 GMT')defheader_accept_language(self):"""returns an ordered list of preferred languages"""acceptedlangs=self.get_header('Accept-Language',raw=False)or{}forlang,_insorted(acceptedlangs.iteritems(),key=lambdax:x[1],reverse=True):lang=lang.split('-')[0]yieldlangdefheader_if_modified_since(self):"""If the HTTP header If-modified-since is set, return the equivalent mx date time value (GMT), else return None """mtime=self.get_header('If-modified-since',raw=False)ifmtime:# :/ twisted is returned a localized time stampreturndatetime.fromtimestamp(mtime)+GMTOFFSETreturnNoneclass_PreResponse(object):def__init__(self,request):self.headers=request.headers_outself.code=200