Package web2py :: Package gluon :: Module storage :: Class Storage
[hide private]
[frames] | no frames]

Class Storage

source code

object --+    
         |    
      dict --+
             |
            Storage
Known Subclasses:
globals.Request, globals.Response, globals.Session, Messages, Settings, StorageList, restricted.TicketStorage

A Storage object is like a dictionary except `obj.foo` can be used in addition to `obj['foo']`.
>>> o = Storage(a=1)
>>> print o.a
1
>>> o['a']
1
>>> o.a = 2
>>> print o['a']
2
>>> del o.a
>>> print o.a
None


Instance Methods [hide private]
 
__delattr__(self, key)
x.__delattr__('name') <==> del x.name
source code
 
__getattr__(self, key) source code
 
__getstate__(self) source code
 
__repr__(self)
repr(x)
source code
 
__setattr__(self, key, value)
x.__setattr__('name', value) <==> x.name = value
source code
 
__setstate__(self, value) source code
 
getfirst(self, key)
Return the first or only value when given a request.vars-style key.
source code
 
getlast(self, key)
Returns the last or only single value when given a request.vars-style key.
source code
 
getlist(self, key)
Return a Storage value as a list.
source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __init__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __setitem__, clear, copy, fromkeys, get, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __reduce__, __reduce_ex__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__delattr__(self, key)

source code 
x.__delattr__('name') <==> del x.name
Overrides: object.__delattr__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: dict.__repr__
(inherited documentation)

__setattr__(self, key, value)

source code 
x.__setattr__('name', value) <==> x.name = value
Overrides: object.__setattr__
(inherited documentation)

getfirst(self, key)

source code 

Return the first or only value when given a request.vars-style key.

If the value is a list, its first item will be returned; otherwise, the value will be returned as-is.

Example output for a query string of ?x=abc&y=abc&y=def >>> request = Storage() >>> request.vars = Storage() >>> request.vars.x = 'abc' >>> request.vars.y = ['abc', 'def'] >>> request.vars.getfirst('x') 'abc' >>> request.vars.getfirst('y') 'abc' >>> request.vars.getfirst('z')

getlast(self, key)

source code 

Returns the last or only single value when given a request.vars-style key.

If the value is a list, the last item will be returned; otherwise, the value will be returned as-is.

Simulated output with a query string of ?x=abc&y=abc&y=def >>> request = Storage() >>> request.vars = Storage() >>> request.vars.x = 'abc' >>> request.vars.y = ['abc', 'def'] >>> request.vars.getlast('x') 'abc' >>> request.vars.getlast('y') 'def' >>> request.vars.getlast('z')

getlist(self, key)

source code 

Return a Storage value as a list.

If the value is a list it will be returned as-is. If object is None, an empty list will be returned. Otherwise, [value] will be returned.

Example output for a query string of ?x=abc&y=abc&y=def >>> request = Storage() >>> request.vars = Storage() >>> request.vars.x = 'abc' >>> request.vars.y = ['abc', 'def'] >>> request.vars.getlist('x') ['abc'] >>> request.vars.getlist('y') ['abc', 'def'] >>> request.vars.getlist('z') []