--- a/web/request.py Wed Apr 22 16:56:03 2009 +0200
+++ b/web/request.py Wed Apr 22 16:56:19 2009 +0200
@@ -73,7 +73,7 @@
self.data = {}
# search state: 'normal' or 'linksearch' (eg searching for an object
# to create a relation with another)
- self.search_state = ('normal',)
+ self.search_state = ('normal',)
# tabindex generator
self.tabindexgen = count()
self.next_tabindex = self.tabindexgen.next
@@ -106,27 +106,27 @@
return
# 3. default language
self.set_default_language(vreg)
-
+
def set_language(self, lang):
self._ = self.__ = self.translations[lang]
self.lang = lang
self.debug('request language: %s', lang)
-
+
# input form parameters management ########################################
-
+
# common form parameters which should be protected against html values
# XXX can't add 'eid' for instance since it may be multivalued
# dont put rql as well, if query contains < and > it will be corrupted!
- no_script_form_params = set(('vid',
- 'etype',
+ no_script_form_params = set(('vid',
+ 'etype',
'vtitle', 'title',
'__message',
'__redirectvid', '__redirectrql'))
-
+
def setup_params(self, params):
"""WARNING: we're intentionaly leaving INTERNAL_FIELD_VALUE here
- subclasses should overrides to
+ subclasses should overrides to
"""
if params is None:
params = {}
@@ -146,7 +146,7 @@
del self.form[k]
else:
self.form[k] = v
-
+
def no_script_form_param(self, param, default=None, value=None):
"""ensure there is no script in a user form param
@@ -167,11 +167,11 @@
value = value[0]
return remove_html_tags(value)
return value
-
+
def list_form_param(self, param, form=None, pop=False):
"""get param from form parameters and return its value as a list,
skipping internal markers if any
-
+
* if the parameter isn't defined, return an empty list
* if the parameter is a single (unicode) value, return a list
containing that value
@@ -182,8 +182,8 @@
"""
if form is None:
form = self.form
- return list_form_param(form, param, pop)
-
+ return list_form_param(form, param, pop)
+
def reset_headers(self):
"""used by AutomaticWebTest to clear html headers between tests on
@@ -193,11 +193,11 @@
return self
# web state helpers #######################################################
-
+
def set_message(self, msg):
assert isinstance(msg, unicode)
self.message = msg
-
+
def update_search_state(self):
"""update the current search state"""
searchstate = self.form.get('__mode')
@@ -247,7 +247,7 @@
def register_onetime_callback(self, func, *args):
cbname = 'cb_%s' % (
sha.sha('%s%s%s%s' % (time.time(), func.__name__,
- random.random(),
+ random.random(),
self.user.login)).hexdigest())
def _cb(req):
try:
@@ -255,12 +255,12 @@
except TypeError:
from warnings import warn
warn('user callback should now take request as argument')
- ret = func(*args)
+ ret = func(*args)
self.unregister_callback(self.pageid, cbname)
return ret
self.set_page_data(cbname, _cb)
return cbname
-
+
def unregister_callback(self, pageid, cbname):
assert pageid is not None
assert cbname.startswith('cb_')
@@ -273,9 +273,9 @@
callbacks = [key for key in sessdata if key.startswith('cb_')]
for callback in callbacks:
self.del_session_data(callback)
-
+
# web edition helpers #####################################################
-
+
@cached # so it's writed only once
def fckeditor_config(self):
self.add_js('fckeditor/fckeditor.js')
@@ -330,7 +330,7 @@
print eid, params
raise RequestError(self._('missing parameters for entity %s') % eid)
return params
-
+
def get_pending_operations(self, entity, relname, role):
operations = {'insert' : [], 'delete' : []}
for optype in ('insert', 'delete'):
@@ -342,7 +342,7 @@
if role == 'object' and entity.eid == eidto:
operations[optype].append(eidfrom)
return operations
-
+
def get_pending_inserts(self, eid=None):
"""shortcut to access req's pending_insert entry
@@ -377,7 +377,7 @@
"""
self.del_session_data(errorurl)
self.remove_pending_operations()
-
+
# high level methods for HTTP headers management ##########################
# must be cached since login/password are popped from the form dictionary
@@ -395,7 +395,7 @@
return None, None
else:
return self.header_authorization()
-
+
def get_cookie(self):
"""retrieve request cookies, returns an empty cookie if not found"""
try:
@@ -423,7 +423,7 @@
morsel['Max-Age'] = 0
# The only way to set up cookie age for IE is to use an old "expired"
# syntax. IE doesn't support Max-Age there is no library support for
- # managing
+ # managing
# ===> Do _NOT_ comment this line :
morsel['expires'] = 'Thu, 01-Jan-1970 00:00:00 GMT'
self.add_header('Set-Cookie', morsel.OutputString())
@@ -476,9 +476,9 @@
if localfile:
cssfile = self.datadir_url + cssfile
add_css(cssfile, media)
-
+
# urls/path management ####################################################
-
+
def url(self, includeparams=True):
"""return currently accessed url"""
return self.base_url() + self.relative_path(includeparams)
@@ -486,7 +486,7 @@
def _datadir_url(self):
"""return url of the application's data directory"""
return self.base_url() + 'data%s/' % self.vreg.config.instance_md5_version()
-
+
def selected(self, url):
"""return True if the url is equivalent to currently accessed url"""
reqpath = self.relative_path().lower()
@@ -502,7 +502,7 @@
def base_url_path(self):
"""returns the absolute path of the base url"""
return urlsplit(self.base_url())[2]
-
+
@cached
def from_controller(self):
"""return the id (string) of the controller issuing the request"""
@@ -512,7 +512,7 @@
if controller in registered_controllers:
return controller
return 'view'
-
+
def external_resource(self, rid, default=_MARKER):
"""return a path to an external resource, using its identifier
@@ -541,9 +541,9 @@
self._validate_cache()
if self.http_method() == 'HEAD':
raise StatusResponse(200, '')
-
+
# abstract methods to override according to the web front-end #############
-
+
def http_method(self):
"""returns 'POST', 'GET', 'HEAD', etc."""
raise NotImplementedError()
@@ -553,7 +553,7 @@
exists and is still usable
"""
raise NotImplementedError()
-
+
def relative_path(self, includeparams=True):
"""return the normalized path of the request (ie at least relative
to the application's root, but some other normalization may be needed
@@ -577,11 +577,11 @@
def add_header(self, header, value):
"""add an output HTTP header"""
raise NotImplementedError()
-
+
def remove_header(self, header):
"""remove an output HTTP header"""
raise NotImplementedError()
-
+
def header_authorization(self):
"""returns a couple (auth-type, auth-value)"""
auth = self.get_header("Authorization", None)
@@ -619,21 +619,21 @@
mx date time value (GMT), else return None
"""
raise NotImplementedError()
-
+
# page data management ####################################################
def get_page_data(self, key, default=None):
"""return value associated to `key` in curernt page data"""
page_data = self.cnx.get_session_data(self.pageid, {})
return page_data.get(key, default)
-
+
def set_page_data(self, key, value):
"""set value associated to `key` in current page data"""
self.html_headers.add_unload_pagedata()
page_data = self.cnx.get_session_data(self.pageid, {})
page_data[key] = value
return self.cnx.set_session_data(self.pageid, page_data)
-
+
def del_page_data(self, key=None):
"""remove value associated to `key` in current page data
if `key` is None, all page data will be cleared
@@ -654,7 +654,7 @@
def ie_browser(self):
useragent = self.useragent()
return useragent and 'MSIE' in useragent
-
+
def xhtml_browser(self):
useragent = self.useragent()
# * MSIE/Konqueror does not support xml content-type