/usr/lib/python2.6/site-packages/openstack
Edit: /usr/lib/python2.6/site-packages/openstack/resource.pyc (38240B)
Ñò
5
Wc @ s d Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d k
l Z d d k
l Z d d k
l
Z
d e f d „ ƒ YZ d Z d
e f d „ ƒ YZ e i e i ƒ d e i f d
„ ƒ Yƒ Z d „ Z d „ Z d S( så
The :class:`~openstack.resource.Resource` class is a base
class that represent a remote resource. Attributes of the resource
are defined by the responses from the server rather than in code so
that we don't have to try and keep up with all possible attributes
and extensions. This may be changed in the future.
The :class:`~openstack.resource.prop` class is a helper for
definiting properties in a resource.
For update management, :class:`~openstack.resource.Resource`
maintains a dirty list so when updating an object only the attributes
that have actually been changed are sent to the server.
There is also some support here for lazy loading that needs improvement.
There are plenty of examples of use of this class in the SDK code.
iÿÿÿÿN( t parse( t
exceptions( t format( t utilst propc B s; e Z d Z d d d d „ Z d „ Z d „ Z d „ Z RS( så A helper for defining properties in a resource.
A prop defines some known attributes within a resource's values.
For example we know a User resource will have a name:
>>> class User(Resource):
... name = prop('name')
...
>>> u = User()
>>> u.name = 'John Doe'
>>> print u['name']
John Doe
User objects can now be accessed via the User().name attribute. The 'name'
value we pass as an attribute is the name of the attribute in the message.
This means that you don't need to use the same name for your attribute as
will be set within the object. For example:
>>> class User(Resource):
... name = prop('userName')
...
>>> u = User()
>>> u.name = 'John Doe'
>>> print u['userName']
John Doe
There is limited validation ability in props.
You can validate the type of values that are set:
>>> class User(Resource):
... name = prop('userName')
... age = prop('age', type=int)
...
>>> u = User()
>>> u.age = 'thirty'
TypeError: Invalid type for attr age
By specifying an alias attribute name, that alias will be read when the
primary attribute name does not appear within the resource:
>>> class User(Resource):
... name = prop('address', alias='location')
...
>>> u = User(location='Far Away')
>>> print u['address']
Far Away
c C s( | | _ | | _ | | _ | | _ d S( N( t namet typet aliast default( t selfR R R R ( ( s8 /tmp/pip-build-wCUybK/openstacksdk/openstack/resource.pyt __init__a s c C s6 | d j o d Sy# | | i } | d j o d SWnD t j
o8 y | | i } Wq| t t f j
o | i SXn X| i o¬ t | | i ƒ o˜ t | i t ƒ oF t | t
i ƒ o | i h | | i i 6ƒ } q.| i | ƒ } q2t | i t
i ƒ o | i i | ƒ } q2| i | ƒ } n | S( N( t NoneR t KeyErrorR t AttributeErrorR R t
isinstancet
issubclasst Resourcet sixt string_typest id_attributeR t Formattert deserialize( R t instancet ownert value( ( s8 /tmp/pip-build-wCUybK/openstacksdk/openstack/resource.pyt __get__g s(
c C s | i o t | | i ƒ o® | | i j ož t | i t ƒ oF t | t i ƒ o | i h | | i i 6ƒ } qÈ | i | ƒ } qÌ t | i t i ƒ o | i i
| ƒ } qÌ t | i | ƒ ƒ } n | i | i
j o | i
i | i ƒ n | | | i