gdata.alt.appengine | index /usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/alt/appengine.py

`Provides HTTP functions for gdata.service to use on Google App Engine
AppEngineHttpClient: Provides an HTTP request method which uses App Engine's
urlfetch API. Set the http_client member of a GDataService object to an
instance of an AppEngineHttpClient to allow the gdata library to run on
Google App Engine.
run_on_appengine: Function which will modify an existing GDataService object
to allow it to run on App Engine. It works by creating a new instance of
the AppEngineHttpClient and replacing the GDataService object's
http_client.`

Modules

``

StringIO atom | google.appengine.ext.db google.appengine.api.memcache | pickle google.appengine.api.urlfetch | google.appengine.api.users

Classes

``

__builtin__.object
  HttpResponse
atom.http_interface.GenericHttpClient(__builtin__.object)
  AppEngineHttpClient
atom.token_store.TokenStore(__builtin__.object)
  AppEngineTokenStore
google.appengine.ext.db.Model(__builtin__.object)
  TokenCollection

class AppEngineHttpClient(atom.http_interface.GenericHttpClient)

``

Method resolution order:
  AppEngineHttpClient
  atom.http_interface.GenericHttpClient
  __builtin__.object

Methods defined here:

__init__(self, headers=None, deadline=None)

request(self, operation, url, data=None, headers=None)
  `Performs an HTTP call to the server, supports GET, POST, PUT, and
  DELETE.
  Usage example, perform and HTTP GET on http://www.google.com/:
  import atom.http
  client = atom.http.HttpClient()
  http_response = client.request('GET', 'http://www.google.com/')
  Args:
  operation: str The HTTP operation to be performed. This is usually one
  of 'GET', 'POST', 'PUT', or 'DELETE'
  data: filestream, list of parts, or other object which can be converted
  to a string. Should be set to None when performing a GET or DELETE.
  If data is a file-like object which can be read, this method will
  read a chunk of 100K bytes at a time and send them.
  If the data is a list of parts to be sent, each part will be
  evaluated and sent.
  url: The full URL to which the request should be sent. Can be a string
  or atom.url.Url.
  headers: dict of strings. HTTP headers which should be sent
  in the request.`

Methods inherited from atom.http_interface.GenericHttpClient:

delete(self, url, headers=None)

get(self, url, headers=None)

post(self, url, data, headers=None)

put(self, url, data, headers=None)

Data descriptors inherited from atom.http_interface.GenericHttpClient:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

Data and other attributes inherited from atom.http_interface.GenericHttpClient:

debug = False

class AppEngineTokenStore(atom.token_store.TokenStore)
`` | `Stores the user's auth tokens in the App Engine datastore. Tokens are only written to the datastore if a user is signed in (if users.get_current_user() returns a user object).`

Method resolution order:
  AppEngineTokenStore
  atom.token_store.TokenStore
  __builtin__.object

Methods defined here:

__init__(self)

add_token(self, token)
  `Associates the token with the current user and stores it.
  If there is no current user, the token will not be stored.
  Returns:
  False if the token was not stored.`

find_token(self, url)
  `Searches the current user's collection of token for a token which can
  be used for a request to the url.
  Returns:
  The stored token which belongs to the current user and is valid for the
  desired URL. If there is no current user, or there is no valid user
  token in the datastore, a atom.http_interface.GenericToken is returned.`

remove_all_tokens(self)
  `Removes all of the current user's tokens from the datastore.`

remove_token(self, token)
  `Removes the token from the current user's collection in the datastore.
  Returns:
  False if the token was not removed, this could be because the token was
  not in the datastore, or because there is no current user.`

Data descriptors inherited from atom.token_store.TokenStore:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class HttpResponse(__builtin__.object)
`` | `Translates a urlfetch resoinse to look like an hhtplib resoinse. Used to allow the resoinse from HttpRequest to be usable by gdata.service methods.`

Methods defined here:

__init__(self, urlfetch_response)

getheader(self, name)

read(self, length=None)

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class TokenCollection(google.appengine.ext.db.Model)
`` | `Datastore Model which associates auth tokens with the current user.`

Method resolution order:
  TokenCollection
  google.appengine.ext.db.Model
  __builtin__.object

Data descriptors defined here:

pickled_tokens
  `A byte string that can be longer than 500 bytes.`

user
  `A user property.`

Methods inherited from google.appengine.ext.db.Model:

__init__(self, parent=None, key_name=None, _app=None, _from_entity=False, **kwds)
  `Creates a new instance of this model.
  To create a new entity, you instantiate a model and then call put(),
  which saves the entity to the datastore:
  person = Person()
  person.name = 'Bret'
  person.put()
  You can initialize properties in the model in the constructor with keyword
  arguments:
  person = Person(name='Bret')
  We initialize all other properties to the default value (as defined by the
  properties in the model definition) if they are not provided in the
  constructor.
  Args:
  parent: Parent instance for this instance or None, indicating a top-
  level instance.
  key_name: Name for new model instance.
  _from_entity: Intentionally undocumented.
  kwds: Keyword arguments mapping to properties of model. Also:
  key: Key instance for this instance, if provided makes parent and
  key_name redundant (they do not need to be set but if they are
  they must match the key).`

delete(self, **kwargs)
  `Deletes this entity from the datastore.
  Args:
  config: datastore_rpc.Configuration to use for this request.
  Raises:
  TransactionFailedError if the data could not be committed.`

dynamic_properties(self)
  `Returns a list of all dynamic properties defined for instance.`

has_key(self)
  `Determine if this model instance has a complete key.
  When not using a fully self-assigned Key, ids are not assigned until the
  data is saved to the Datastore, but instances with a key name always have
  a full key.
  Returns:
  True if the object has been persisted to the datastore or has a key
  or has a key_name, otherwise False.`

instance_properties(self)
  `Alias for dyanmic_properties.`

is_saved(self)
  `Determine if entity is persisted in the datastore.
  New instances of Model do not start out saved in the data. Objects which
  are saved to or loaded from the Datastore will have a True saved state.
  Returns:
  True if object has been persisted to the datastore, otherwise False.`

key(self)
  `Unique key for this entity.
  This property is only available if this entity is already stored in the
  datastore or if it has a full key, so it is available if this entity was
  fetched returned from a query, or after put() is called the first time
  for new entities, or if a complete key was given when constructed.
  Returns:
  Datastore key of persisted entity.
  Raises:
  NotSavedError when entity is not persistent.`

parent(self)
  `Get the parent of the model instance.
  Returns:
  Parent of contained entity or parent provided in constructor, None if
  instance has no parent.`

parent_key(self)
  `Get the parent's key.
  This method is useful for avoiding a potential fetch from the datastore
  but still get information about the instances parent.
  Returns:
  Parent key of entity, None if there is no parent.`

put(self, **kwargs)
  `Writes this model instance to the datastore.
  If this instance is new, we add an entity to the datastore.
  Otherwise, we update this instance, and the key will remain the
  same.
  Args:
  config: datastore_rpc.Configuration to use for this request.
  Returns:
  The key of the instance (either the existing key or a new key).
  Raises:
  TransactionFailedError if the data could not be committed.`

save = put(self, **kwargs)
  `Writes this model instance to the datastore.
  If this instance is new, we add an entity to the datastore.
  Otherwise, we update this instance, and the key will remain the
  same.
  Args:
  config: datastore_rpc.Configuration to use for this request.
  Returns:
  The key of the instance (either the existing key or a new key).
  Raises:
  TransactionFailedError if the data could not be committed.`

to_xml(self, _entity_class=<class 'google.appengine.api.datastore.Entity'>)
  `Generate an XML representation of this model instance.
  atom and gd:namespace properties are converted to XML according to their
  respective schemas. For more information, see:
  http://www.atomenabled.org/developers/syndication/
  http://code.google.com/apis/gdata/common-elements.html`

Class methods inherited from google.appengine.ext.db.Model:

all(cls, **kwds) from google.appengine.ext.db.PropertiedClass
  `Returns a query over all instances of this model from the datastore.
  Returns:
  Query that will retrieve all instances from entity collection.`

entity_type(cls) from google.appengine.ext.db.PropertiedClass
  `Soon to be removed alias for kind.`

fields(cls) from google.appengine.ext.db.PropertiedClass
  `Soon to be removed alias for properties.`

from_entity(cls, entity) from google.appengine.ext.db.PropertiedClass
  `Converts the entity representation of this model to an instance.
  Converts datastore.Entity instance to an instance of cls.
  Args:
  entity: Entity loaded directly from datastore.
  Raises:
  KindError when cls is incorrect model for entity.`

get(cls, keys, **kwargs) from google.appengine.ext.db.PropertiedClass
  `Fetch instance from the datastore of a specific Model type using key.
  We support Key objects and string keys (we convert them to Key objects
  automatically).
  Useful for ensuring that specific instance types are retrieved from the
  datastore. It also helps that the source code clearly indicates what
  kind of object is being retreived. Example:
  story = Story.get(story_key)
  Args:
  keys: Key within datastore entity collection to find; or string key;
  or list of Keys or string keys.
  config: datastore_rpc.Configuration to use for this request.
  Returns:
  If a single key was given: a Model instance associated with key
  for provided class if it exists in the datastore, otherwise
  None; if a list of keys was given: a list whose items are either
  a Model instance or None.
  Raises:
  KindError if any of the retreived objects are not instances of the
  type associated with call to 'get'.`

get_by_id(cls, ids, parent=None, **kwargs) from google.appengine.ext.db.PropertiedClass
  `Get instance of Model class by id.
  Args:
  key_names: A single id or a list of ids.
  parent: Parent of instances to get. Can be a model or key.
  config: datastore_rpc.Configuration to use for this request.`

get_by_key_name(cls, key_names, parent=None, **kwargs) from google.appengine.ext.db.PropertiedClass
  `Get instance of Model class by its key's name.
  Args:
  key_names: A single key-name or a list of key-names.
  parent: Parent of instances to get. Can be a model or key.
  config: datastore_rpc.Configuration to use for this request.`

get_or_insert(cls, key_name, **kwds) from google.appengine.ext.db.PropertiedClass
  `Transactionally retrieve or create an instance of Model class.
  This acts much like the Python dictionary setdefault() method, where we
  first try to retrieve a Model instance with the given key name and parent.
  If it's not present, then we create a new instance (using the *kwds
  supplied) and insert that with the supplied key name.
  Subsequent calls to this method with the same key_name and parent will
  always yield the same entity (though not the same actual object instance),
  regardless of the *kwds supplied. If the specified entity has somehow
  been deleted separately, then the next call will create a new entity and
  return it.
  If the 'parent' keyword argument is supplied, it must be a Model instance.
  It will be used as the parent of the new instance of this Model class if
  one is created.
  This method is especially useful for having just one unique entity for
  a specific identifier. Insertion/retrieval is done transactionally, which
  guarantees uniqueness.
  Example usage:
  class WikiTopic(db.Model):
  creation_date = db.DatetimeProperty(auto_now_add=True)
  body = db.TextProperty(required=True)
  # The first time through we'll create the new topic.
  wiki_word = 'CommonIdioms'
  topic = WikiTopic.get_or_insert(wiki_word,
  body='This topic is totally new!')
  assert topic.key().name() == 'CommonIdioms'
  assert topic.body == 'This topic is totally new!'
  # The second time through will just retrieve the entity.
  overwrite_topic = WikiTopic.get_or_insert(wiki_word,
  body='A totally different message!')
  assert topic.key().name() == 'CommonIdioms'
  assert topic.body == 'This topic is totally new!'
  Args:
  key_name: Key name to retrieve or create.
  **kwds: Keyword arguments to pass to the constructor of the model class
  if an instance for the specified key name does not already exist. If
  an instance with the supplied key_name and parent already exists, the
  rest of these arguments will be discarded.
  Returns:
  Existing instance of Model class with the specified key_name and parent
  or a new one that has just been created.
  Raises:
  TransactionFailedError if the specified Model instance could not be
  retrieved or created transactionally (due to high contention, etc).`

gql(cls, query_string, *args, **kwds) from google.appengine.ext.db.PropertiedClass
  `Returns a query using GQL query string.
  See appengine/ext/gql for more information about GQL.
  Args:
  query_string: properly formatted GQL query string with the
  'SELECT * FROM <entity>' part omitted
  *args: rest of the positional arguments used to bind numeric references
  in the query.
  **kwds: dictionary-based arguments (for named parameters).`

kind(cls) from google.appengine.ext.db.PropertiedClass
  `Returns the datastore kind we use for this model.
  We just use the name of the model for now, ignoring potential collisions.`

properties(cls) from google.appengine.ext.db.PropertiedClass
  `Returns a dictionary of all the properties defined for this model.`

Static methods inherited from google.appengine.ext.db.Model:

__new__(*args, **unused_kwds)
  `Allow subclasses to call __new__() with arguments.
  Do NOT list 'cls' as the first argument, or in the case when
  the 'unused_kwds' dictionary contains the key 'cls', the function
  will complain about multiple argument values for 'cls'.
  Raises:
  TypeError if there are no positional arguments.`

Data descriptors inherited from google.appengine.ext.db.Model:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

Data and other attributes inherited from google.appengine.ext.db.Model:

__metaclass__ = <class 'google.appengine.ext.db.PropertiedClass'>
  `Meta-class for initializing Model classes properties.
  Used for initializing Properties defined in the context of a model.
  By using a meta-class much of the configuration of a Property
  descriptor becomes implicit. By using this meta-class, descriptors
  that are of class Model are notified about which class they
  belong to and what attribute they are associated with and can
  do appropriate initialization via __property_config__.
  Duplicate properties are not permitted.`

Functions

``

load_auth_tokens(user=None)
  `Reads a dictionary of the current user's tokens from the datastore.
  If there is no current user (a user is not signed in to the app) or the user
  does not have any tokens, an empty dictionary is returned.`

run_on_appengine(gdata_service, store_tokens=True, single_user_mode=False, deadline=None)
  `Modifies a GDataService object to allow it to run on App Engine.
  Args:
  gdata_service: An instance of AtomService, GDataService, or any
  of their subclasses which has an http_client member and a
  token_store member.
  store_tokens: Boolean, defaults to True. If True, the gdata_service
  will attempt to add each token to it's token_store when
  SetClientLoginToken or SetAuthSubToken is called. If False
  the tokens will not automatically be added to the
  token_store.
  single_user_mode: Boolean, defaults to False. If True, the current_token
  member of gdata_service will be set when
  SetClientLoginToken or SetAuthTubToken is called. If set
  to True, the current_token is set in the gdata_service
  and anyone who accesses the object will use the same
  token.
  Note: If store_tokens is set to False and
  single_user_mode is set to False, all tokens will be
  ignored, since the library assumes: the tokens should not
  be stored in the datastore and they should not be stored
  in the gdata_service object. This will make it
  impossible to make requests which require authorization.
  deadline: int (optional) The number of seconds to wait for a response
  before timing out on the HTTP request. If no deadline is
  specified, the deafault deadline for HTTP requests from App
  Engine is used. The maximum is currently 10 (for 10 seconds).
  The default deadline for App Engine is 5 seconds.`

save_auth_tokens(token_dict, user=None)
  `Associates the tokens with the current user and writes to the datastore.
  If there us no current user, the tokens are not written and this function
  returns None.
  Returns:
  The key of the datastore entity containing the user's tokens, or None if
  there was no current user.`

Data
`` |  | __author__ = 'api.jscudder (Jeff Scudder)'

Author
`` |  | api.jscudder (Jeff Scudder)