当前位置: 首页>>代码示例>>Python>>正文


Python Storage.clear方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:Viper525,项目名称:sonospy,代码行数:103,代码来源:html.py

示例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
开发者ID:yekeqiang,项目名称:web2py,代码行数:7,代码来源:globals.py

示例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)
开发者ID:wangking,项目名称:formbuilder,代码行数:91,代码来源:html.py

示例4: clear

# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import clear [as 别名]
 def clear(self):
     Storage.clear(self)
开发者ID:hungl,项目名称:web2py,代码行数:4,代码来源:globals.py


注:本文中的storage.Storage.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。