本文整理汇总了Python中storage.Storage.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.clear方法的具体用法?Python Storage.clear怎么用?Python Storage.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storage.Storage
的用法示例。
在下文中一共展示了Storage.clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FORM
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import clear [as 别名]
class FORM(DIV):
"""
example::
>>> form=FORM(INPUT(_name=\"test\", requires=IS_NOT_EMPTY()))
>>> form.xml()
'<form action=\"\" enctype=\"multipart/form-data\" method=\"post\"><input name=\"test\" type=\"text\" /></form>'
a FORM is container for INPUT, TEXTAREA, SELECT and other helpers
form has one important method::
form.accepts(request.vars, session)
if form is accepted (and all validators pass) form.vars contains the
accepted vars, otherwise form.errors contains the errors.
in case of errors the form is modified to present the errors to the user.
"""
tag = 'form'
def __init__(self, *components, **attributes):
if self.tag[-1:] == '/' and components:
raise SyntaxError, '<%s> tags cannot have components' % self.tag
if len(components) == 1 and isinstance(components[0], (list,
tuple)):
self.components = list(components[0])
else:
self.components = list(components)
self.attributes = attributes
self._fixup()
# converts special attributes in components attributes
self._postprocessing()
self.vars = Storage()
self.errors = Storage()
self.latest = Storage()
def accepts(
self,
vars,
session=None,
formname='default',
keepvalues=False,
onvalidation=None,
):
self.errors.clear()
self.request_vars = Storage()
self.request_vars.update(vars)
self.session = session
self.formname = formname
self.keepvalues = keepvalues
# if this tag is a form and we are in accepting mode (status=True)
# check formname and formkey
status = True
if self.session and self.session.get('_formkey[%s]'
% self.formname, None) != self.request_vars._formkey:
status = False
if self.formname != self.request_vars._formname:
status = False
status = self._traverse(status)
if status and onvalidation:
onvalidation(self)
if self.errors:
status = False
if session != None:
self.formkey = session['_formkey[%s]' % formname] = web2py_uuid()
if status and not keepvalues:
self._traverse(False)
return status
def _postprocessing(self):
if not '_action' in self.attributes:
self['_action'] = ''
if not '_method' in self.attributes:
self['_method'] = 'post'
if not '_enctype' in self.attributes:
self['_enctype'] = 'multipart/form-data'
def hidden_fields(self):
c = []
if 'hidden' in self.attributes:
for (key, value) in self.attributes.get('hidden',
{}).items():
c.append(INPUT(_type='hidden', _name=key, _value=value))
if hasattr(self, 'formkey') and self.formkey:
c.append(INPUT(_type='hidden', _name='_formkey',
_value=self.formkey))
if hasattr(self, 'formname') and self.formname:
c.append(INPUT(_type='hidden', _name='_formname',
_value=self.formname))
return DIV(c, _class="hidden")
def xml(self):
newform = FORM(*self.components, **self.attributes)
hidden_fields = self.hidden_fields()
if hidden_fields.components:
newform.append(hidden_fields)
#.........这里部分代码省略.........
示例2: clear
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import clear [as 别名]
def clear(self):
previous_session_hash = self.pop('_session_hash', None)
Storage.clear(self)
if previous_session_hash:
self._session_hash = previous_session_hash
示例3: FORM
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import clear [as 别名]
class FORM(DIV):
"""
example::
>>> from validators import IS_NOT_EMPTY
>>> form=FORM(INPUT(_name=\"test\", requires=IS_NOT_EMPTY()))
>>> form.xml()
'<form action=\"\" enctype=\"multipart/form-data\" method=\"post\"><input name=\"test\" type=\"text\" /></form>'
a FORM is container for INPUT, TEXTAREA, SELECT and other helpers
form has one important method::
form.accepts(request.vars, session)
if form is accepted (and all validators pass) form.vars contains the
accepted vars, otherwise form.errors contains the errors.
in case of errors the form is modified to present the errors to the user.
"""
tag = "form"
def __init__(self, *components, **attributes):
DIV.__init__(self, *components, **attributes)
self.vars = Storage()
self.errors = Storage()
self.latest = Storage()
def accepts(self, vars, formname="default", keepvalues=False, onvalidation=None, hideerror=False):
if vars.__class__.__name__ == "Request":
vars = vars.post_vars
self.errors.clear()
self.request_vars = Storage()
self.request_vars.update(vars)
self.formname = formname
self.keepvalues = keepvalues
# if this tag is a form and we are in accepting mode (status=True)
# check formname and formkey
status = True
status = self._traverse(status, hideerror)
if onvalidation:
if isinstance(onvalidation, dict):
onsuccess = onvalidation.get("onsuccess", None)
onfailure = onvalidation.get("onfailure", None)
if onsuccess and status:
onsuccess(self)
if onfailure and vars and not status:
onfailure(self)
status = len(self.errors) == 0
elif status:
if isinstance(onvalidation, (list, tuple)):
[f(self) for f in onvalidation]
else:
onvalidation(self)
if self.errors:
status = False
if status and not keepvalues:
self._traverse(False, hideerror)
return status
def _postprocessing(self):
if not "_action" in self.attributes:
self["_action"] = ""
if not "_method" in self.attributes:
self["_method"] = "post"
if not "_enctype" in self.attributes:
self["_enctype"] = "multipart/form-data"
def hidden_fields(self):
c = []
if "hidden" in self.attributes:
for (key, value) in self.attributes.get("hidden", {}).items():
c.append(INPUT(_type="hidden", _name=key, _value=value))
if hasattr(self, "formkey") and self.formkey:
c.append(INPUT(_type="hidden", _name="_formkey", _value=self.formkey))
if hasattr(self, "formname") and self.formname:
c.append(INPUT(_type="hidden", _name="_formname", _value=self.formname))
return DIV(c, _class="hidden")
def xml(self):
newform = FORM(*self.components, **self.attributes)
hidden_fields = self.hidden_fields()
if hidden_fields.components:
newform.append(hidden_fields)
return DIV.xml(newform)
示例4: clear
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import clear [as 别名]
def clear(self):
Storage.clear(self)