Submit
Path:
~
/
/
usr
/
lib
/
python2.7
/
site-packages
/
boto
/
dynamodb2
/
File Content:
items.pyo
� �vWc @ s@ d d l m Z d e f d � � YZ d e f d � � YZ d S( i����( t deepcopyt NEWVALUEc B s e Z RS( ( t __name__t __module__( ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyR s t Itemc B s e Z d Z d e d � Z d � Z d � Z d � Z d � Z d � Z d � Z d d � Z d � Z d � Z d � Z e Z d � Z d d � Z d � Z d � Z d � Z d � Z d � Z d d � Z d � Z d � Z d � Z d � Z e d � Z d � Z RS( s An object representing the item data within a DynamoDB table. An item is largely schema-free, meaning it can contain any data. The only limitation is that it must have data for the fields in the ``Table``'s schema. This object presents a dictionary-like interface for accessing/storing data. It also tries to intelligently track how data has changed throughout the life of the instance, to be as efficient as possible about updates. Empty items, or items that have no data, are considered falsey. c C s� | | _ | | _ i | _ | | _ | j | _ t | j t � rT | j j | _ n | j d k ro i | _ n | j r� t | j � | _ n d S( s Constructs an (unsaved) ``Item`` instance. To persist the data in DynamoDB, you'll need to call the ``Item.save`` (or ``Item.partial_save``) on the instance. Requires a ``table`` parameter, which should be a ``Table`` instance. This is required, as DynamoDB's API is focus around all operations being table-level. It's also for persisting schema around many objects. Optionally accepts a ``data`` parameter, which should be a dictionary of the fields & values of the item. Alternatively, an ``Item`` instance may be provided from which to extract the data. Optionally accepts a ``loaded`` parameter, which should be a boolean. ``True`` if it was preexisting data loaded from DynamoDB, ``False`` if it's new data from the user. Default is ``False``. Example:: >>> users = Table('users') >>> user = Item(users, data={ ... 'username': 'johndoe', ... 'first_name': 'John', ... 'date_joined': 1248o61592, ... }) # Change existing data. >>> user['first_name'] = 'Johann' # Add more data. >>> user['last_name'] = 'Doe' # Delete data. >>> del user['date_joined'] # Iterate over all the data. >>> for field, val in user.items(): ... print "%s: %s" % (field, val) username: johndoe first_name: John date_joined: 1248o61592 N( t tablet _loadedt _orig_datat _datat _dynamizert isinstanceR t NoneR ( t selfR t datat loaded( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __init__ s + c C s | j j | d � S( N( R t getR ( R t key( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __getitem__Q s c C s | | j | <d S( N( R ( R R t value( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __setitem__T s c C s! | | j k r d S| j | =d S( N( R ( R R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __delitem__W s c C s | j j � S( N( R t keys( R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyR ] s c C s | j j � S( N( R t values( R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyR ` s c C s | j j � S( N( R t items( R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyR c s c C s | j j | | � S( N( R R ( R R t default( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyR f s c c s$ x | j D] } | j | Vq Wd S( N( R ( R R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __iter__i s c C s | | j k S( N( R ( R R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __contains__m s c C s t | j � S( N( t boolR ( R ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt __bool__p s c C s2 i i d 6i d 6g d 6} t | j j � � } t | j j � � } xs | j | � D]b } | j | | j | k rU | j | j | � r� | j | | d | <q� | d j | � qU qU WxE | j | � D]4 } | j | j | � r� | j | | d | <q� q� Wx( | j | � D] } | d j | � qW| S( s� Checks the ``-orig_data`` against the ``_data`` to determine what changes to the data are present. Returns a dictionary containing the keys ``adds``, ``changes`` & ``deletes``, containing the updated data. t addst changest deletes( t setR R R t intersectiont _is_storablet appendt difference( R t alterationst orig_keyst data_keysR ( ( s8 /usr/lib/python2.7/site-packages/boto/dynamodb2/items.pyt _determine_alterationsu s"