Repository URL to install this package:
|
Version:
2.1.0.jo1 ▾
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.alt.app_engine</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.<a href="gdata.alt.html"><font color="#ffffff">alt</font></a>.app_engine</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/alt/app_engine.py">/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/alt/app_engine.py</a></font></td></tr></table>
<p><tt>Provides functions to persist serialized auth tokens in the datastore.<br>
<br>
The get_token and set_token functions should be used in conjunction with<br>
gdata.gauth's token_from_blob and token_to_blob to allow auth token objects<br>
to be reused across requests. It is up to your own code to ensure that the<br>
token key's are unique.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="google.appengine.ext.db.html">google.appengine.ext.db</a><br>
</td><td width="25%" valign=top><a href="google.appengine.api.memcache.html">google.appengine.api.memcache</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.alt.app_engine.html#Token">Token</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Token">class <strong>Token</strong></a>(<a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Datastore <a href="google.appengine.ext.db.html#Model">Model</a> which stores a serialized auth token.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="gdata.alt.app_engine.html#Token">Token</a></dd>
<dd><a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a></dd>
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
</dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>t</strong></dt>
<dd><tt>A byte string that can be longer than 500 bytes.</tt></dd>
</dl>
<hr>
Methods inherited from <a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>:<br>
<dl><dt><a name="Token-__init__"><strong>__init__</strong></a>(self, parent<font color="#909090">=None</font>, key_name<font color="#909090">=None</font>, _app<font color="#909090">=None</font>, _from_entity<font color="#909090">=False</font>, **kwds)</dt><dd><tt>Creates a new instance of this model.<br>
<br>
To create a new entity, you instantiate a model and then call <a href="#Token-put">put</a>(),<br>
which saves the entity to the datastore:<br>
<br>
person = Person()<br>
person.name = 'Bret'<br>
person.<a href="#Token-put">put</a>()<br>
<br>
You can initialize properties in the model in the constructor with keyword<br>
arguments:<br>
<br>
person = Person(name='Bret')<br>
<br>
We initialize all other properties to the default value (as defined by the<br>
properties in the model definition) if they are not provided in the<br>
constructor.<br>
<br>
Args:<br>
parent: Parent instance for this instance or None, indicating a top-<br>
level instance.<br>
key_name: Name for new model instance.<br>
_from_entity: Intentionally undocumented.<br>
kwds: Keyword arguments mapping to properties of model. Also:<br>
key: Key instance for this instance, if provided makes parent and<br>
key_name redundant (they do not need to be set but if they are<br>
they must match the key).</tt></dd></dl>
<dl><dt><a name="Token-delete"><strong>delete</strong></a>(self, **kwargs)</dt><dd><tt>Deletes this entity from the datastore.<br>
<br>
Args:<br>
config: datastore_rpc.Configuration to use for this request.<br>
<br>
Raises:<br>
TransactionFailedError if the data could not be committed.</tt></dd></dl>
<dl><dt><a name="Token-dynamic_properties"><strong>dynamic_properties</strong></a>(self)</dt><dd><tt>Returns a list of all dynamic properties defined for instance.</tt></dd></dl>
<dl><dt><a name="Token-has_key"><strong>has_key</strong></a>(self)</dt><dd><tt>Determine if this model instance has a complete key.<br>
<br>
When not using a fully self-assigned Key, ids are not assigned until the<br>
data is saved to the Datastore, but instances with a key name always have<br>
a full key.<br>
<br>
Returns:<br>
True if the object has been persisted to the datastore or has a key<br>
or has a key_name, otherwise False.</tt></dd></dl>
<dl><dt><a name="Token-instance_properties"><strong>instance_properties</strong></a>(self)</dt><dd><tt>Alias for dyanmic_properties.</tt></dd></dl>
<dl><dt><a name="Token-is_saved"><strong>is_saved</strong></a>(self)</dt><dd><tt>Determine if entity is persisted in the datastore.<br>
<br>
New instances of <a href="google.appengine.ext.db.html#Model">Model</a> do not start out saved in the data. Objects which<br>
are saved to or loaded from the Datastore will have a True saved state.<br>
<br>
Returns:<br>
True if object has been persisted to the datastore, otherwise False.</tt></dd></dl>
<dl><dt><a name="Token-key"><strong>key</strong></a>(self)</dt><dd><tt>Unique key for this entity.<br>
<br>
This property is only available if this entity is already stored in the<br>
datastore or if it has a full key, so it is available if this entity was<br>
fetched returned from a query, or after <a href="#Token-put">put</a>() is called the first time<br>
for new entities, or if a complete key was given when constructed.<br>
<br>
Returns:<br>
Datastore key of persisted entity.<br>
<br>
Raises:<br>
NotSavedError when entity is not persistent.</tt></dd></dl>
<dl><dt><a name="Token-parent"><strong>parent</strong></a>(self)</dt><dd><tt>Get the parent of the model instance.<br>
<br>
Returns:<br>
Parent of contained entity or parent provided in constructor, None if<br>
instance has no parent.</tt></dd></dl>
<dl><dt><a name="Token-parent_key"><strong>parent_key</strong></a>(self)</dt><dd><tt>Get the parent's key.<br>
<br>
This method is useful for avoiding a potential fetch from the datastore<br>
but still get information about the instances parent.<br>
<br>
Returns:<br>
Parent key of entity, None if there is no parent.</tt></dd></dl>
<dl><dt><a name="Token-put"><strong>put</strong></a>(self, **kwargs)</dt><dd><tt>Writes this model instance to the datastore.<br>
<br>
If this instance is new, we add an entity to the datastore.<br>
Otherwise, we update this instance, and the key will remain the<br>
same.<br>
<br>
Args:<br>
config: datastore_rpc.Configuration to use for this request.<br>
<br>
Returns:<br>
The key of the instance (either the existing key or a new key).<br>
<br>
Raises:<br>
TransactionFailedError if the data could not be committed.</tt></dd></dl>
<dl><dt><a name="Token-save"><strong>save</strong></a> = put(self, **kwargs)</dt><dd><tt>Writes this model instance to the datastore.<br>
<br>
If this instance is new, we add an entity to the datastore.<br>
Otherwise, we update this instance, and the key will remain the<br>
same.<br>
<br>
Args:<br>
config: datastore_rpc.Configuration to use for this request.<br>
<br>
Returns:<br>
The key of the instance (either the existing key or a new key).<br>
<br>
Raises:<br>
TransactionFailedError if the data could not be committed.</tt></dd></dl>
<dl><dt><a name="Token-to_xml"><strong>to_xml</strong></a>(self, _entity_class<font color="#909090">=<class 'google.appengine.api.datastore.Entity'></font>)</dt><dd><tt>Generate an XML representation of this model instance.<br>
<br>
atom and gd:namespace properties are converted to XML according to their<br>
respective schemas. For more information, see:<br>
<br>
<a href="http://www.atomenabled.org/developers/syndication/">http://www.atomenabled.org/developers/syndication/</a><br>
<a href="http://code.google.com/apis/gdata/common-elements.html">http://code.google.com/apis/gdata/common-elements.html</a></tt></dd></dl>
<hr>
Class methods inherited from <a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>:<br>
<dl><dt><a name="Token-all"><strong>all</strong></a>(cls, **kwds)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Returns a query over all instances of this model from the datastore.<br>
<br>
Returns:<br>
Query that will retrieve all instances from entity collection.</tt></dd></dl>
<dl><dt><a name="Token-entity_type"><strong>entity_type</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Soon to be removed alias for kind.</tt></dd></dl>
<dl><dt><a name="Token-fields"><strong>fields</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Soon to be removed alias for properties.</tt></dd></dl>
<dl><dt><a name="Token-from_entity"><strong>from_entity</strong></a>(cls, entity)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Converts the entity representation of this model to an instance.<br>
<br>
Converts datastore.Entity instance to an instance of cls.<br>
<br>
Args:<br>
entity: Entity loaded directly from datastore.<br>
<br>
Raises:<br>
KindError when cls is incorrect model for entity.</tt></dd></dl>
<dl><dt><a name="Token-get"><strong>get</strong></a>(cls, keys, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Fetch instance from the datastore of a specific <a href="google.appengine.ext.db.html#Model">Model</a> type using key.<br>
<br>
We support Key objects and string keys (we convert them to Key objects<br>
automatically).<br>
<br>
Useful for ensuring that specific instance types are retrieved from the<br>
datastore. It also helps that the source code clearly indicates what<br>
kind of object is being retreived. Example:<br>
<br>
story = Story.<a href="#Token-get">get</a>(story_key)<br>
<br>
Args:<br>
keys: Key within datastore entity collection to find; or string key;<br>
or list of Keys or string keys.<br>
config: datastore_rpc.Configuration to use for this request.<br>
<br>
Returns:<br>
If a single key was given: a <a href="google.appengine.ext.db.html#Model">Model</a> instance associated with key<br>
for provided class if it exists in the datastore, otherwise<br>
None; if a list of keys was given: a list whose items are either<br>
a <a href="google.appengine.ext.db.html#Model">Model</a> instance or None.<br>
<br>
Raises:<br>
KindError if any of the retreived objects are not instances of the<br>
type associated with call to 'get'.</tt></dd></dl>
<dl><dt><a name="Token-get_by_id"><strong>get_by_id</strong></a>(cls, ids, parent<font color="#909090">=None</font>, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Get instance of <a href="google.appengine.ext.db.html#Model">Model</a> class by id.<br>
<br>
Args:<br>
key_names: A single id or a list of ids.<br>
parent: Parent of instances to get. Can be a model or key.<br>
config: datastore_rpc.Configuration to use for this request.</tt></dd></dl>
<dl><dt><a name="Token-get_by_key_name"><strong>get_by_key_name</strong></a>(cls, key_names, parent<font color="#909090">=None</font>, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Get instance of <a href="google.appengine.ext.db.html#Model">Model</a> class by its key's name.<br>
<br>
Args:<br>
key_names: A single key-name or a list of key-names.<br>
parent: Parent of instances to get. Can be a model or key.<br>
config: datastore_rpc.Configuration to use for this request.</tt></dd></dl>
<dl><dt><a name="Token-get_or_insert"><strong>get_or_insert</strong></a>(cls, key_name, **kwds)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Transactionally retrieve or create an instance of <a href="google.appengine.ext.db.html#Model">Model</a> class.<br>
<br>
This acts much like the Python dictionary setdefault() method, where we<br>
first try to retrieve a <a href="google.appengine.ext.db.html#Model">Model</a> instance with the given key name and parent.<br>
If it's not present, then we create a new instance (using the *kwds<br>
supplied) and insert that with the supplied key name.<br>
<br>
Subsequent calls to this method with the same key_name and parent will<br>
always yield the same entity (though not the same actual object instance),<br>
regardless of the *kwds supplied. If the specified entity has somehow<br>
been deleted separately, then the next call will create a new entity and<br>
return it.<br>
<br>
If the 'parent' keyword argument is supplied, it must be a <a href="google.appengine.ext.db.html#Model">Model</a> instance.<br>
It will be used as the parent of the new instance of this <a href="google.appengine.ext.db.html#Model">Model</a> class if<br>
one is created.<br>
<br>
This method is especially useful for having just one unique entity for<br>
a specific identifier. Insertion/retrieval is done transactionally, which<br>
guarantees uniqueness.<br>
<br>
Example usage:<br>
<br>
class WikiTopic(db.<a href="google.appengine.ext.db.html#Model">Model</a>):<br>
creation_date = db.DatetimeProperty(auto_now_add=True)<br>
body = db.TextProperty(required=True)<br>
<br>
# The first time through we'll create the new topic.<br>
wiki_word = 'CommonIdioms'<br>
topic = WikiTopic.<a href="#Token-get_or_insert">get_or_insert</a>(wiki_word,<br>
body='This topic is totally new!')<br>
assert topic.<a href="#Token-key">key</a>().name() == 'CommonIdioms'<br>
assert topic.body == 'This topic is totally new!'<br>
<br>
# The second time through will just retrieve the entity.<br>
overwrite_topic = WikiTopic.<a href="#Token-get_or_insert">get_or_insert</a>(wiki_word,<br>
body='A totally different message!')<br>
assert topic.<a href="#Token-key">key</a>().name() == 'CommonIdioms'<br>
assert topic.body == 'This topic is totally new!'<br>
<br>
Args:<br>
key_name: Key name to retrieve or create.<br>
**kwds: Keyword arguments to pass to the constructor of the model class<br>
if an instance for the specified key name does not already exist. If<br>
an instance with the supplied key_name and parent already exists, the<br>
rest of these arguments will be discarded.<br>
<br>
Returns:<br>
Existing instance of <a href="google.appengine.ext.db.html#Model">Model</a> class with the specified key_name and parent<br>
or a new one that has just been created.<br>
<br>
Raises:<br>
TransactionFailedError if the specified <a href="google.appengine.ext.db.html#Model">Model</a> instance could not be<br>
retrieved or created transactionally (due to high contention, etc).</tt></dd></dl>
<dl><dt><a name="Token-gql"><strong>gql</strong></a>(cls, query_string, *args, **kwds)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Returns a query using GQL query string.<br>
<br>
See appengine/ext/gql for more information about GQL.<br>
<br>
Args:<br>
query_string: properly formatted GQL query string with the<br>
'SELECT * FROM <entity>' part omitted<br>
*args: rest of the positional arguments used to bind numeric references<br>
in the query.<br>
**kwds: dictionary-based arguments (for named parameters).</tt></dd></dl>
<dl><dt><a name="Token-kind"><strong>kind</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Returns the datastore kind we use for this model.<br>
<br>
We just use the name of the model for now, ignoring potential collisions.</tt></dd></dl>
<dl><dt><a name="Token-properties"><strong>properties</strong></a>(cls)<font color="#909090"><font face="helvetica, arial"> from <a href="google.appengine.ext.db.html#PropertiedClass">google.appengine.ext.db.PropertiedClass</a></font></font></dt><dd><tt>Returns a dictionary of all the properties defined for this model.</tt></dd></dl>
<hr>
Static methods inherited from <a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>:<br>
<dl><dt><a name="Token-__new__"><strong>__new__</strong></a>(*args, **unused_kwds)</dt><dd><tt>Allow subclasses to call <a href="#Token-__new__">__new__</a>() with arguments.<br>
<br>
Do NOT list 'cls' as the first argument, or in the case when<br>
the 'unused_kwds' dictionary contains the key 'cls', the function<br>
will complain about multiple argument values for 'cls'.<br>
<br>
Raises:<br>
TypeError if there are no positional arguments.</tt></dd></dl>
<hr>
Data descriptors inherited from <a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
<hr>
Data and other attributes inherited from <a href="google.appengine.ext.db.html#Model">google.appengine.ext.db.Model</a>:<br>
<dl><dt><strong>__metaclass__</strong> = <class 'google.appengine.ext.db.PropertiedClass'><dd><tt>Meta-class for initializing <a href="google.appengine.ext.db.html#Model">Model</a> classes properties.<br>
<br>
Used for initializing Properties defined in the context of a model.<br>
By using a meta-class much of the configuration of a Property<br>
descriptor becomes implicit. By using this meta-class, descriptors<br>
that are of class <a href="google.appengine.ext.db.html#Model">Model</a> are notified about which class they<br>
belong to and what attribute they are associated with and can<br>
do appropriate initialization via __property_config__.<br>
<br>
Duplicate properties are not permitted.</tt></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-delete_token"><strong>delete_token</strong></a>(unique_key)</dt></dl>
<dl><dt><a name="-get_token"><strong>get_token</strong></a>(unique_key)</dt><dd><tt>Searches for a stored token with the desired key.<br>
<br>
Checks memcache and then the datastore if required.<br>
<br>
Args:<br>
unique_key: str which uniquely identifies the desired auth token.<br>
<br>
Returns:<br>
A string encoding the auth token data. Use gdata.gauth.token_from_blob to<br>
convert back into a usable token object. None if the token was not found<br>
in memcache or the datastore.</tt></dd></dl>
<dl><dt><a name="-set_token"><strong>set_token</strong></a>(unique_key, token_str)</dt><dd><tt>Saves the serialized auth token in the datastore.<br>
<br>
The token is also stored in memcache to speed up retrieval on a cache hit.<br>
<br>
Args:<br>
unique_key: The unique name for this token as a string. It is up to your<br>
code to ensure that this token value is unique in your application.<br>
Previous values will be silently overwitten.<br>
token_str: A serialized auth token as a string. I expect that this string<br>
will be generated by gdata.gauth.token_to_blob.<br>
<br>
Returns:<br>
True if the token was stored sucessfully, False if the token could not be<br>
safely cached (if an old value could not be cleared). If the token was<br>
set in memcache, but not in the datastore, this function will return None.<br>
However, in that situation an exception will likely be raised.<br>
<br>
Raises:<br>
Datastore exceptions may be raised from the App Engine SDK in the event of<br>
failure.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>__author__</strong> = 'j.s@google.com (Jeff Scudder)'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
<td width="100%">j.s@google.com (Jeff Scudder)</td></tr></table>
</body></html>