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

Class Storage

source code

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

A Storage object is like a dictionary except `obj.foo` can be used in addition to `obj['foo']`, and setting obj.foo = None deletes item 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]
 
__copy__(self) source code
 
__delattr__(x, y)
del x[y]
 
__getattr__(D, k, d=...)
d defaults to None.
 
__getitem__(D, k, d=...)
d defaults to None.
 
__getstate__(self) source code
 
__repr__(self)
<Storage %s>
source code
 
__setattr__(x, i, y)
x[i]=y
 
getfirst(self, key, default=threading.local())
Return the first or only value when given a request.vars-style key.
source code
 
getlast(self, key, default=threading.local())
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__, __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__(x, y)

 
del x[y]
Overrides: object.__delattr__

__getattr__(D, k, d=...)
(Qualification operator)

 
d defaults to None.
Returns:
D[k] if k in D, else d

__getitem__(D, k, d=...)
(Indexing operator)

 
d defaults to None.
Returns:
D[k] if k in D, else d

Overrides: dict.__getitem__

__repr__(self)
(Representation operator)

source code 
<Storage %s>
Overrides: dict.__repr__

__setattr__(x, i, y)

 
x[i]=y
Overrides: object.__setattr__

getfirst(self, key, default=threading.local())

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, default=threading.local())

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') []