atom.mock_http_core | index /usr/local/svn/gdata-python-client/src/atom/mock_http_core.py

`# Copyright (C) 2009 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
`` |  |
StringIO atom | os pickle | tempfile |

Classes
`` |  | __builtin__.object EchoHttpClient MockHttpClient SettableHttpClient atom.http_core.HttpResponse(__builtin__.object) MockHttpResponse exceptions.Exception(exceptions.BaseException) Error NoRecordingFound
class EchoHttpClient(__builtin__.object)
`` | `Sends the request data back in the response. Used to check the formatting of the request as it was sent. Always responds with a 200 OK, and some information from the HTTP request is returned in special Echo-X headers in the response. The following headers are added in the response: 'Echo-Host': The host name and port number to which the HTTP connection is made. If no port was passed in, the header will contain host:None. 'Echo-Uri': The path portion of the URL being requested. /example?x=1&y=2 'Echo-Scheme': The beginning of the URL, usually 'http' or 'https' 'Echo-Method': The HTTP method being used, 'GET', 'POST', 'PUT', etc.`
| Methods defined here: request(self, http_request) Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`
class Error(exceptions.Exception)
`` |  | Method resolution order: Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors defined here: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x74d100> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` __unicode__(...) Data descriptors inherited from exceptions.BaseException: __dict__ args message
class MockHttpClient(__builtin__.object)
`` |  | Methods defined here: AddResponse = add_response(self, http_request, status, reason, headers=None, body=None) Request = request(self, http_request) __init__(self, recordings=None, real_client=None) add_response(self, http_request, status, reason, headers=None, body=None) close_session(self) `Saves recordings in the temporary file named in use_cached_session.` delete_session(self, name=None) `Removes recordings from a previous live request.` get_cache_file_name(self) request(self, http_request) `Provide a recorded response, or record a response for replay. If the real_client is set, the request will be made using the real_client, and the response from the server will be recorded. If the real_client is None (the default), this method will examine the recordings and find the first which matches.` use_cached_session(self, name=None, real_http_client=None) `Attempts to load recordings from a previous live request. If a temp file with the recordings exists, then it is used to fulfill requests. If the file does not exist, then a real client is used to actually make the desired HTTP requests. Requests and responses are recorded and will be written to the desired temprary cache file when close_session is called. Args: name: str (optional) The file name of session file to be used. The file is loaded from the temporary directory of this machine. If no name is passed in, a default name will be constructed using the cache_name_prefix, cache_case_name, and cache_test_name of this object. real_http_client: atom.http_core.HttpClient the real client to be used if the cached recordings are not found. If the default value is used, this will be an atom.http_core.HttpClient.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Data and other attributes defined here: cache_case_name = '' cache_name_prefix = 'gdata_live_test' cache_test_name = '' debug = None last_request_was_live = False real_client = None
class MockHttpResponse(atom.http_core.HttpResponse)
`` |  | Method resolution order: MockHttpResponse atom.http_core.HttpResponse __builtin__.object Methods defined here: __init__(self, status=None, reason=None, headers=None, body=None) read(self) Methods inherited from atom.http_core.HttpResponse: getheader(self, name, default=None) getheaders(self) Data descriptors inherited from atom.http_core.HttpResponse: __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_core.HttpResponse: reason = None status = None
class NoRecordingFound(Error)
`` |  | Method resolution order: NoRecordingFound Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors inherited from Error: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x74d100> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` __unicode__(...) Data descriptors inherited from exceptions.BaseException: __dict__ args message
class SettableHttpClient(__builtin__.object)
`` | `An HTTP Client which responds with the data given in set_response.`
| Methods defined here: __init__(self, status, reason, body, headers) `Configures the response for the server. See set_response for details on the arguments to the constructor.` request(self, http_request) set_response(self, status, reason, body, headers) `Determines the response which will be sent for each request. Args: status: An int for the HTTP status code, example: 200, 404, etc. reason: String for the HTTP reason, example: OK, NOT FOUND, etc. body: The body of the HTTP response as a string or a file-like object (something with a read method). headers: dict of strings containing the HTTP headers in the response.` Data descriptors defined here: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)`

Data
`` |  | __author__ = 'j.s@google.com (Jeff Scudder)'

Author
`` |  | j.s@google.com (Jeff Scudder)