atom.service
index
/home/jscudder/svn/gdata-python-client/src/atom/service.py

AtomService provides CRUD ops. in line with the Atom Publishing Protocol.
 
AtomService: Encapsulates the ability to perform insert, update and delete
             operations with the Atom Publishing Protocol on which GData is
             based. An instance can perform query, insertion, deletion, and
             update.

 
Modules
       
cElementTree
base64
httplib
os
re
socket
urllib

 
Classes
       
__builtin__.object
AtomService

 
class AtomService(__builtin__.object)
    Performs Atom Publishing Protocol CRUD operations.
 
The AtomService contains methods to perform HTTP CRUD operations.
 
  Methods defined here:
Delete(self, uri, extra_headers=None, url_params=None, escape_params=True)
Deletes the entry at the given URI.
 
Args:
  uri: string The URI of the entry to be deleted. Example: 
       '/base/feeds/items/ITEM-ID'
  extra_headers: dict (optional) HTTP headers which are to be included.
                 The client automatically sets the Content-Type and
                 Authorization headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  httplib.HTTPResponse Server's response to the DELETE request.
Get(self, uri, extra_headers=None, url_params=None, escape_params=True)
Query the APP server with the given URI
 
The uri is the portion of the URI after the server value 
(server example: 'www.google.com').
 
Example use:
To perform a query against Google Base, set the server to 
'base.google.com' and set the uri to '/base/feeds/...', where ... is 
your query. For example, to find snippets for all digital cameras uri 
should be set to: '/base/feeds/snippets?bq=digital+camera'
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dicty (optional) Extra HTTP headers to be included
                 in the GET request. These headers are in addition to 
                 those stored in the client's additional_headers property.
                 The client automatically sets the Content-Type and 
                 Authorization headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the query. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  httplib.HTTPResponse The server's response to the GET request.
Post(self, data, uri, extra_headers=None, url_params=None, escape_params=True, content_type='application/atom+xml')
Insert data into an APP server at the given URI.
 
Args:
  data: string, ElementTree._Element, or something with a __str__ method 
        The XML to be sent to the uri. 
  uri: string The location (feed) to which the data should be inserted. 
       Example: '/base/feeds/items'. 
  extra_headers: dict (optional) HTTP headers which are to be included. 
                 The client automatically sets the Content-Type,
                 Authorization, and Content-Length headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  httplib.HTTPResponse Server's response to the POST request.
Put(self, data, uri, extra_headers=None, url_params=None, escape_params=True, content_type='application/atom+xml')
Updates an entry at the given URI.
 
Args:
  data: string, ElementTree._Element, or xml_wrapper.ElementWrapper The 
        XML containing the updated data.
  uri: string A URI indicating entry to which the update will be applied.
       Example: '/base/feeds/items/ITEM-ID'
  extra_headers: dict (optional) HTTP headers which are to be included.
                 The client automatically sets the Content-Type,
                 Authorization, and Content-Length headers.
  url_params: dict (optional) Additional URL parameters to be included
              in the URI. These are translated into query arguments
              in the form '&dict_key=value&...'.
              Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  httplib.HTTPResponse Server's response to the PUT request.
UseBasicAuth(self, username, password, for_proxy=False)
Sets an Authenticaiton: Basic HTTP header containing plaintext.
 
The username and password are base64 encoded and added to an HTTP header
which will be included in each request. Note that your username and 
password are sent in plaintext.
 
Args:
  username: str
  password: str
__init__(self, server=None, additional_headers=None)
Creates a new AtomService client.
 
Args:
  server: string (optional) The start of a URL for the server
          to which all operations should be directed. Example: 
          'www.google.com'
  additional_headers: dict (optional) Any additional HTTP headers which
                      should be included with CRUD operations.

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'AtomService' objects>
list of weak references to the object (if defined)
debug = False
port = 80
ssl = False

 
Functions
       
BuildUri(uri, url_params=None, escape_params=True)
Converts a uri string and a collection of parameters into a URI.
 
Args:
  uri: string
  url_params: dict (optional)
  escape_params: boolean (optional)
  uri: string The start of the desired URI. This string can alrady contain
       URL parameters. Examples: '/base/feeds/snippets', 
       '/base/feeds/snippets?bq=digital+camera'
  url_parameters: dict (optional) Additional URL parameters to be included
                  in the query. These are translated into query arguments
                  in the form '&dict_key=value&...'.
                  Example: {'max-results': '250'} becomes &max-results=250
  escape_params: boolean (optional) If false, the calling code has already
                 ensured that the query will form a valid URL (all
                 reserved characters have been escaped). If true, this
                 method will escape the query and any URL parameters
                 provided.
 
Returns:
  string The URI consisting of the escaped URL parameters appended to the
  initial uri string.
DictionaryToParamList(url_parameters, escape_params=True)
Convert a dictionary of URL arguments into a URL parameter string.
 
Args:
  url_parameters: The dictionaty of key-value pairs which will be converted
                  into URL parameters. For example,
                  {'dry-run': 'true', 'foo': 'bar'}
                  will become ['dry-run=true', 'foo=bar'].
 
Returns:
  A list which contains a string for each key-value pair. The strings are
  ready to be incorporated into a URL by using '&'.join([] + parameter_list)

 
Data
        URL_REGEX = <_sre.SRE_Pattern object>
__author__ = 'api.jscudder (Jeffrey Scudder)'

 
Author
        api.jscudder (Jeffrey Scudder)