Monero
Loading...
Searching...
No Matches
upload.AbstractRpcServer Class Reference
Inheritance diagram for upload.AbstractRpcServer:
Collaboration diagram for upload.AbstractRpcServer:

Public Member Functions

 __init__ (self, host, auth_function, host_override=None, extra_headers={}, save_cookies=False)
 Send (self, request_path, payload=None, content_type="application/octet-stream", timeout=None, **kwargs)
 __init__ (self, host, auth_function, host_override=None, extra_headers={}, save_cookies=False)
 Send (self, request_path, payload=None, content_type="application/octet-stream", timeout=None, **kwargs)

Public Attributes

 host = host
 host_override = host_override
 auth_function = auth_function
bool authenticated = False
 extra_headers = extra_headers
 save_cookies = save_cookies
 opener = self._GetOpener()

Protected Member Functions

 _GetOpener (self)
 _CreateRequest (self, url, data=None)
 _GetAuthToken (self, email, password)
 _GetAuthCookie (self, auth_token)
 _Authenticate (self)
 _GetOpener (self)
 _CreateRequest (self, url, data=None)
 _GetAuthToken (self, email, password)
 _GetAuthCookie (self, auth_token)
 _Authenticate (self)

Detailed Description

Provides a common interface for a simple RPC server.

Constructor & Destructor Documentation

◆ __init__() [1/2]

upload.AbstractRpcServer.__init__ ( self,
host,
auth_function,
host_override = None,
extra_headers = {},
save_cookies = False )
Creates a new HttpRpcServer.

Args:
  host: The host to send requests to.
  auth_function: A function that takes no arguments and returns an
    (email, password) tuple when called. Will be called if authentication
    is required.
  host_override: The host header to send to the server (defaults to host).
  extra_headers: A dict of extra headers to append to every request.
  save_cookies: If True, save the authentication cookies to local disk.
    If False, use an in-memory cookiejar instead.  Subclasses must
    implement this functionality.  Defaults to False.

◆ __init__() [2/2]

upload.AbstractRpcServer.__init__ ( self,
host,
auth_function,
host_override = None,
extra_headers = {},
save_cookies = False )
Creates a new HttpRpcServer.

Args:
  host: The host to send requests to.
  auth_function: A function that takes no arguments and returns an
    (email, password) tuple when called. Will be called if authentication
    is required.
  host_override: The host header to send to the server (defaults to host).
  extra_headers: A dict of extra headers to append to every request.
  save_cookies: If True, save the authentication cookies to local disk.
    If False, use an in-memory cookiejar instead.  Subclasses must
    implement this functionality.  Defaults to False.

Member Function Documentation

◆ _Authenticate() [1/2]

upload.AbstractRpcServer._Authenticate ( self)
protected
Authenticates the user.

The authentication process works as follows:
 1) We get a username and password from the user
 2) We use ClientLogin to obtain an AUTH token for the user
    (see http://code.google.com/apis/accounts/AuthForInstalledApps.html).
 3) We pass the auth token to /_ah/login on the server to obtain an
    authentication cookie. If login was successful, it tries to redirect
    us to the URL we provided.

If we attempt to access the upload API without first obtaining an
authentication cookie, it returns a 401 response and directs us to
authenticate ourselves with ClientLogin.

Reimplemented in upload.HttpRpcServer, and upload.HttpRpcServer.

◆ _Authenticate() [2/2]

upload.AbstractRpcServer._Authenticate ( self)
protected
Authenticates the user.

The authentication process works as follows:
 1) We get a username and password from the user
 2) We use ClientLogin to obtain an AUTH token for the user
    (see http://code.google.com/apis/accounts/AuthForInstalledApps.html).
 3) We pass the auth token to /_ah/login on the server to obtain an
    authentication cookie. If login was successful, it tries to redirect
    us to the URL we provided.

If we attempt to access the upload API without first obtaining an
authentication cookie, it returns a 401 response and directs us to
authenticate ourselves with ClientLogin.

Reimplemented in upload.HttpRpcServer, and upload.HttpRpcServer.

◆ _CreateRequest() [1/2]

upload.AbstractRpcServer._CreateRequest ( self,
url,
data = None )
protected
Creates a new urllib request.

◆ _CreateRequest() [2/2]

upload.AbstractRpcServer._CreateRequest ( self,
url,
data = None )
protected
Creates a new urllib request.

◆ _GetAuthCookie() [1/2]

upload.AbstractRpcServer._GetAuthCookie ( self,
auth_token )
protected
Fetches authentication cookies for an authentication token.

Args:
  auth_token: The authentication token returned by ClientLogin.

Raises:
  HTTPError: If there was an error fetching the authentication cookies.

◆ _GetAuthCookie() [2/2]

upload.AbstractRpcServer._GetAuthCookie ( self,
auth_token )
protected
Fetches authentication cookies for an authentication token.

Args:
  auth_token: The authentication token returned by ClientLogin.

Raises:
  HTTPError: If there was an error fetching the authentication cookies.

◆ _GetAuthToken() [1/2]

upload.AbstractRpcServer._GetAuthToken ( self,
email,
password )
protected
Uses ClientLogin to authenticate the user, returning an auth token.

Args:
  email:    The user's email address
  password: The user's password

Raises:
  ClientLoginError: If there was an error authenticating with ClientLogin.
  HTTPError: If there was some other form of HTTP error.

Returns:
  The authentication token returned by ClientLogin.

◆ _GetAuthToken() [2/2]

upload.AbstractRpcServer._GetAuthToken ( self,
email,
password )
protected
Uses ClientLogin to authenticate the user, returning an auth token.

Args:
  email:    The user's email address
  password: The user's password

Raises:
  ClientLoginError: If there was an error authenticating with ClientLogin.
  HTTPError: If there was some other form of HTTP error.

Returns:
  The authentication token returned by ClientLogin.

◆ _GetOpener() [1/2]

upload.AbstractRpcServer._GetOpener ( self)
protected
Returns an OpenerDirector for making HTTP requests.

Returns:
  A urllib2.OpenerDirector object.

Reimplemented in upload.HttpRpcServer, and upload.HttpRpcServer.

◆ _GetOpener() [2/2]

upload.AbstractRpcServer._GetOpener ( self)
protected
Returns an OpenerDirector for making HTTP requests.

Returns:
  A urllib2.OpenerDirector object.

Reimplemented in upload.HttpRpcServer, and upload.HttpRpcServer.

◆ Send() [1/2]

upload.AbstractRpcServer.Send ( self,
request_path,
payload = None,
content_type = "application/octet-stream",
timeout = None,
** kwargs )
Sends an RPC and returns the response.

Args:
  request_path: The path to send the request to, eg /api/appversion/create.
  payload: The body of the request, or None to send an empty request.
  content_type: The Content-Type header to use.
  timeout: timeout in seconds; default None i.e. no timeout.
    (Note: for large requests on OS X, the timeout doesn't work right.)
  kwargs: Any keyword arguments are converted into query string parameters.

Returns:
  The response body, as a string.

◆ Send() [2/2]

upload.AbstractRpcServer.Send ( self,
request_path,
payload = None,
content_type = "application/octet-stream",
timeout = None,
** kwargs )
Sends an RPC and returns the response.

Args:
  request_path: The path to send the request to, eg /api/appversion/create.
  payload: The body of the request, or None to send an empty request.
  content_type: The Content-Type header to use.
  timeout: timeout in seconds; default None i.e. no timeout.
    (Note: for large requests on OS X, the timeout doesn't work right.)
  kwargs: Any keyword arguments are converted into query string parameters.

Returns:
  The response body, as a string.

Member Data Documentation

◆ auth_function

upload.AbstractRpcServer.auth_function = auth_function

◆ authenticated

bool upload.AbstractRpcServer.authenticated = False

◆ extra_headers

upload.AbstractRpcServer.extra_headers = extra_headers

◆ host

upload.AbstractRpcServer.host = host

◆ host_override

upload.AbstractRpcServer.host_override = host_override

◆ opener

upload.AbstractRpcServer.opener = self._GetOpener()

◆ save_cookies

upload.AbstractRpcServer.save_cookies = save_cookies

The documentation for this class was generated from the following files: