gdata.client
index
/usr/local/svn/gdata-python-client-release/src/gdata/client.py

# Copyright (C) 2008 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

 
Modules
       
atom
gdata
urllib
urlparse

 
Classes
       
gdata.service.Error(exceptions.Exception)
AuthorizationRequired
gdata.service.GDataService(atom.service.AtomService)
GDataClient

 
class AuthorizationRequired(gdata.service.Error)
    
Method resolution order:
AuthorizationRequired
gdata.service.Error
exceptions.Exception

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class GDataClient(gdata.service.GDataService)
    This class is deprecated. 
 
All functionality has been migrated to gdata.service.GDataService.
 
 
Method resolution order:
GDataClient
gdata.service.GDataService
atom.service.AtomService
__builtin__.object

Methods defined here:
ClientLogin(self, username, password, service_name, source=None, account_type=None, auth_url=None, login_token=None, login_captcha=None)
Delete(self, url)
Get(self, url, parser)
Simplified interface for Get.
 
Requires a parser function which takes the server response's body as
the only argument.
 
Args:
  url: A string or something that can be converted to a string using str.
      The URL of the requested resource.
  parser: A function which takes the HTTP body from the server as it's
      only result. Common values would include str, 
      gdata.GDataEntryFromString, and gdata.GDataFeedFromString.
 
Returns: The result of calling parser(http_response_body).
Post(self, data, url, parser, media_source=None)
Streamlined version of Post.
 
Requires a parser function which takes the server response's body as
the only argument.
Put(self, data, url, parser, media_source=None)
Streamlined version of Put.
 
Requires a parser function which takes the server response's body as
the only argument.
__init__(self, application_name=None, tokens=None)

Methods inherited from gdata.service.GDataService:
GenerateAuthSubURL(self, next, scope, secure=False, session=True, domain='default')
Generate a URL at which the user will login and be redirected back.
 
Users enter their credentials on a Google login page and a token is sent
to the URL specified in next. See documentation for AuthSub login at:
http://code.google.com/apis/accounts/AuthForWebApps.html
 
Args:
  next: string The URL user will be sent to after logging in.
  scope: string or list of strings. The URLs of the services to be 
         accessed.
  secure: boolean (optional) Determines whether or not the issued token
          is a secure token.
  session: boolean (optional) Determines whether or not the issued token
           can be upgraded to a session token.
GetAuthSubToken(self)
Returns the AuthSub Token after removing the AuthSub Authorization
Label.
 
The AuthSub Authorization Label reads: "AuthSub token"
 
Returns:
  If the AuthSub Token is set AND it begins with the AuthSub 
  Authorization Label, the AuthSub Token is returned minus the AuthSub
  Label. If the AuthSub Token does not start with the AuthSub
  Authorization Label or it is not set, None is returned.
GetClientLoginToken(self)
Returns the token string for the current request scope.
 
The current scope is determined by the service name string member.
The token string is the end of the Authorization header, it doesn not
include the ClientLogin label.
GetEntry(self, uri, extra_headers=None)
Query the GData API with the given URI and receive an Entry.
 
See also documentation for gdata.service.Get
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dictionary (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.
 
Returns:
  A GDataEntry built from the XML in the server's response.
GetFeed(self, uri, extra_headers=None, converter=<function GDataFeedFromString>)
Query the GData API with the given URI and receive a Feed.
 
See also documentation for gdata.service.Get
 
Args:
  uri: string The query in the form of a URI. Example:
       '/base/feeds/snippets?bq=digital+camera'.
  extra_headers: dictionary (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.
 
Returns:
  A GDataFeed built from the XML in the server's response.
GetMedia(self, uri, extra_headers=None)
Returns a MediaSource containing media and its metadata from the given
URI string.
GetNext(self, feed)
Requests the next 'page' of results in the feed.
 
This method uses the feed's next link to request an additional feed
and uses the class of the feed to convert the results of the GET request.
 
Args:
  feed: atom.Feed or a subclass. The feed should contain a next link and
      the type of the feed will be applied to the results from the 
      server. The new feed which is returned will be of the same class
      as this feed which was passed in.
 
Returns:
  A new feed representing the next set of results in the server's feed.
  The type of this feed will match that of the feed argument.
PostOrPut(self, verb, data, uri, extra_headers=None, url_params=None, escape_params=True, redirects_remaining=4, media_source=None, converter=None)
Insert data into a GData service at the given URI.
 
Args:
  verb: string, either 'POST' or 'PUT'
  data: string, ElementTree._Element, atom.Entry, or gdata.GDataEntry 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.
  media_source: MediaSource (optional) Container for the media to be sent
      along with the entry, if provided.
  converter: func (optional) A function which will be executed on the 
      server's response. Often this is a function like 
      GDataEntryFromString which will parse the body of the server's 
      response and return a GDataEntry.
 
Returns:
  If the post succeeded, this method will return a GDataFeed, GDataEntry,
  or the results of running converter on the server's result body (if
  converter was specified).
ProgrammaticLogin(self, captcha_token=None, captcha_response=None)
Authenticates the user and sets the GData Auth token.
 
Login retreives a temporary auth token which must be used with all
requests to GData services. The auth token is stored in the GData client
object.
 
Login is also used to respond to a captcha challenge. If the user's login
attempt failed with a CaptchaRequired error, the user can respond by
calling Login with the captcha token and the answer to the challenge.
 
Args:
  captcha_token: string (optional) The identifier for the captcha challenge
                 which was presented to the user.
  captcha_response: string (optional) The user's answer to the captch 
                    challenge.
 
Raises:
  CaptchaRequired if the login service will require a captcha response
  BadAuthentication if the login service rejected the username or password
  Error if the login service responded with a 403 different from the above
RevokeAuthSubToken(self)
Revokes an existing AuthSub token.
 
Raises:
  NonAuthSubToken if the user's auth token is not an AuthSub token
SetAuthSubToken(self, token, scopes=None)
Sets the token sent in requests to an AuthSub token.
 
Only use this method if you have received a token from the AuthSub
service. The authi token is set automatically when UpgradeToSessionToken()
is used. See documentation for Google AuthSub here:
http://code.google.com/apis/accounts/AuthForWebApps.html 
 
Args:
 token: gdata.auth.AuthSubToken or string The token returned by the
        AuthSub service. If the token is an AuthSubToken, the scope
        information stored in the AuthSubToken is used. If the token
        is a string, the scopes parameter is used to determine the
        valid scopes.
 scopes: list of URLs for which the token is valid. This is only used
         if the token parameter is a string.
SetClientLoginToken(self, token, scopes=None)
Sets the token sent in requests to an ClientLogin token.
 
Only use this method if you have received a token from the ClientLogin
service. The auth_token is set automatically when ProgrammaticLogin()
is used. See documentation for Google ClientLogin here:
http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
 
Args:
  token: string The token returned by the ClientLogin service.
UpgradeToSessionToken(self, token=None)
Upgrades a single use AuthSub token to a session token.
 
Args:
  token: A gdata.auth.AuthSubToken (optional) which is good for a single
         use but can be upgraded to a session token. If no token is 
         passed in, the AuthSubToken is found by looking in the 
         token_store by looking for a token for the current scope.
 
Raises:
  NonAuthSubToken if the user's auth token is not an AuthSub token
  TokenUpgradeFailed if the server responded to the request with an 
  error.
upgrade_to_session_token(self, token)
Upgrades a single use AuthSub token to a session token.
 
Args:
  token: A gdata.auth.AuthSubToken (optional) which is good for a single
         use but can be upgraded to a session token.
 
Returns:
  The upgraded token as a gdata.auth.AuthSubToken object.
 
Raises:
  TokenUpgradeFailed if the server responded to the request with an 
  error.

Properties inherited from gdata.service.GDataService:
captcha_token
Get the captcha token for a login request.
get = __GetCaptchaToken(self)
captcha_url
Get the captcha URL for a login request.
get = __GetCaptchaURL(self)
source
The source is the name of the application making the request. 
It should be in the form company_id-app_name-app_version
get = __GetSource(self)
# Private methods to create the source property.
set = __SetSource(self, new_source)

Data and other attributes inherited from gdata.service.GDataService:
auth_token = None
handler = None
tokens = None

Methods inherited from atom.service.AtomService:
UseBasicAuth(self, username, password, for_proxy=False)
Sets an Authenticaiton: Basic HTTP header containing plaintext.
 
Deprecated, use use_basic_auth instead.
 
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
request(self, operation, url, data=None, headers=None, url_params=None)
use_basic_auth(self, username, password, scopes=None)

Properties inherited from atom.service.AtomService:
debug
If True, HTTP debug information is printed.
get = _get_debug(self)
set = _set_debug(self, value)

Data and other attributes inherited from atom.service.AtomService:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'AtomService' objects>
list of weak references to the object (if defined)
override_token = None
port = 80
ssl = False

 
Data
        CLIENT_LOGIN_SCOPES = {'apps': ['http://www.google.com/a/feeds/', 'https://www.google.com/a/feeds/'], 'blogger': ['http://www.blogger.com/feeds/'], 'cl': ['https://www.google.com/calendar/feeds/', 'http://www.google.com/calendar/feeds/'], 'codesearch': ['http://www.google.com/codesearch/feeds/'], 'cp': ['https://www.google.com/m8/feeds/', 'http://www.google.com/m8/feeds/'], 'finance': ['http://finance.google.com/finance/feeds/'], 'gbase': ['http://base.google.com/base/feeds/', 'http://www.google.com/base/feeds/'], 'health': ['https://www.google.com/health/feeds/'], 'lh2': ['http://picasaweb.google.com/data/'], 'sitemaps': ['https://www.google.com/webmasters/tools/feeds/'], ...}
SCOPE_URL_PARAM_NAME = 'authsub_token_scope'
__author__ = 'api.jscudder (Jeff Scudder)'

 
Author
        api.jscudder (Jeff Scudder)