gam7 7.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gam7 might be problematic. Click here for more details.

Files changed (72) hide show
  1. gam/__init__.py +77555 -0
  2. gam/__main__.py +40 -0
  3. gam/atom/__init__.py +1460 -0
  4. gam/atom/auth.py +41 -0
  5. gam/atom/client.py +214 -0
  6. gam/atom/core.py +535 -0
  7. gam/atom/data.py +327 -0
  8. gam/atom/http.py +354 -0
  9. gam/atom/http_core.py +599 -0
  10. gam/atom/http_interface.py +144 -0
  11. gam/atom/mock_http.py +123 -0
  12. gam/atom/mock_http_core.py +313 -0
  13. gam/atom/mock_service.py +235 -0
  14. gam/atom/service.py +723 -0
  15. gam/atom/token_store.py +105 -0
  16. gam/atom/url.py +130 -0
  17. gam/cacerts.pem +1130 -0
  18. gam/cbcm-v1.1beta1.json +593 -0
  19. gam/contactdelegation-v1.json +249 -0
  20. gam/datastudio-v1.json +486 -0
  21. gam/gamlib/__init__.py +17 -0
  22. gam/gamlib/glaction.py +308 -0
  23. gam/gamlib/glapi.py +837 -0
  24. gam/gamlib/glcfg.py +616 -0
  25. gam/gamlib/glclargs.py +1184 -0
  26. gam/gamlib/glentity.py +831 -0
  27. gam/gamlib/glgapi.py +817 -0
  28. gam/gamlib/glgdata.py +98 -0
  29. gam/gamlib/glglobals.py +307 -0
  30. gam/gamlib/glindent.py +46 -0
  31. gam/gamlib/glmsgs.py +547 -0
  32. gam/gamlib/glskus.py +246 -0
  33. gam/gamlib/gluprop.py +279 -0
  34. gam/gamlib/glverlibs.py +33 -0
  35. gam/gamlib/yubikey.py +202 -0
  36. gam/gdata/__init__.py +825 -0
  37. gam/gdata/alt/__init__.py +20 -0
  38. gam/gdata/alt/app_engine.py +101 -0
  39. gam/gdata/alt/appengine.py +321 -0
  40. gam/gdata/apps/__init__.py +526 -0
  41. gam/gdata/apps/audit/__init__.py +1 -0
  42. gam/gdata/apps/audit/service.py +278 -0
  43. gam/gdata/apps/contacts/__init__.py +874 -0
  44. gam/gdata/apps/contacts/service.py +355 -0
  45. gam/gdata/apps/service.py +544 -0
  46. gam/gdata/apps/sites/__init__.py +283 -0
  47. gam/gdata/apps/sites/service.py +246 -0
  48. gam/gdata/service.py +1714 -0
  49. gam/gdata/urlfetch.py +247 -0
  50. gam/googleapiclient/__init__.py +27 -0
  51. gam/googleapiclient/_auth.py +167 -0
  52. gam/googleapiclient/_helpers.py +207 -0
  53. gam/googleapiclient/channel.py +315 -0
  54. gam/googleapiclient/discovery.py +1662 -0
  55. gam/googleapiclient/discovery_cache/__init__.py +78 -0
  56. gam/googleapiclient/discovery_cache/appengine_memcache.py +55 -0
  57. gam/googleapiclient/discovery_cache/base.py +46 -0
  58. gam/googleapiclient/discovery_cache/file_cache.py +145 -0
  59. gam/googleapiclient/errors.py +197 -0
  60. gam/googleapiclient/http.py +1962 -0
  61. gam/googleapiclient/mimeparse.py +183 -0
  62. gam/googleapiclient/model.py +429 -0
  63. gam/googleapiclient/schema.py +317 -0
  64. gam/googleapiclient/version.py +15 -0
  65. gam/iso8601/__init__.py +28 -0
  66. gam/iso8601/iso8601.py +160 -0
  67. gam/serviceaccountlookup-v1.json +141 -0
  68. gam/six.py +982 -0
  69. gam7-7.3.4.dist-info/METADATA +69 -0
  70. gam7-7.3.4.dist-info/RECORD +72 -0
  71. gam7-7.3.4.dist-info/WHEEL +4 -0
  72. gam7-7.3.4.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,144 @@
1
+ #
2
+ # Copyright (C) 2008 Google Inc.
3
+ #
4
+ # Licensed under the Apache License 2.0;
5
+
6
+
7
+ """This module provides a common interface for all HTTP requests.
8
+
9
+ HttpResponse: Represents the server's response to an HTTP request. Provides
10
+ an interface identical to httplib.HTTPResponse which is the response
11
+ expected from higher level classes which use HttpClient.request.
12
+
13
+ GenericHttpClient: Provides an interface (superclass) for an object
14
+ responsible for making HTTP requests. Subclasses of this object are
15
+ used in AtomService and GDataService to make requests to the server. By
16
+ changing the http_client member object, the AtomService is able to make
17
+ HTTP requests using different logic (for example, when running on
18
+ Google App Engine, the http_client makes requests using the App Engine
19
+ urlfetch API).
20
+ """
21
+
22
+ # __author__ = 'api.jscudder (Jeff Scudder)'
23
+
24
+ import io
25
+
26
+ USER_AGENT = '%s GData-Python/2.0.18'
27
+
28
+
29
+ class Error(Exception):
30
+ pass
31
+
32
+
33
+ class UnparsableUrlObject(Error):
34
+ pass
35
+
36
+
37
+ class ContentLengthRequired(Error):
38
+ pass
39
+
40
+
41
+ class HttpResponse(object):
42
+ def __init__(self, body=None, status=None, reason=None, headers=None):
43
+ """Constructor for an HttpResponse object.
44
+
45
+ HttpResponse represents the server's response to an HTTP request from
46
+ the client. The HttpClient.request method returns a httplib.HTTPResponse
47
+ object and this HttpResponse class is designed to mirror the interface
48
+ exposed by httplib.HTTPResponse.
49
+
50
+ Args:
51
+ body: A file like object, with a read() method. The body could also
52
+ be a string, and the constructor will wrap it so that
53
+ HttpResponse.read(self) will return the full string.
54
+ status: The HTTP status code as an int. Example: 200, 201, 404.
55
+ reason: The HTTP status message which follows the code. Example:
56
+ OK, Created, Not Found
57
+ headers: A dictionary containing the HTTP headers in the server's
58
+ response. A common header in the response is Content-Length.
59
+ """
60
+ if body:
61
+ if hasattr(body, 'read'):
62
+ self._body = body
63
+ else:
64
+ self._body = io.StringIO(body)
65
+ else:
66
+ self._body = None
67
+ if status is not None:
68
+ self.status = int(status)
69
+ else:
70
+ self.status = None
71
+ self.reason = reason
72
+ self._headers = headers or {}
73
+
74
+ def getheader(self, name, default=None):
75
+ if name in self._headers:
76
+ return self._headers[name]
77
+ else:
78
+ return default
79
+
80
+ def read(self, amt=None):
81
+ if not amt:
82
+ return self._body.read()
83
+ else:
84
+ return self._body.read(amt)
85
+
86
+
87
+ class GenericHttpClient(object):
88
+ debug = False
89
+
90
+ def __init__(self, http_client, headers=None):
91
+ """
92
+
93
+ Args:
94
+ http_client: An object which provides a request method to make an HTTP
95
+ request. The request method in GenericHttpClient performs a
96
+ call-through to the contained HTTP client object.
97
+ headers: A dictionary containing HTTP headers which should be included
98
+ in every HTTP request. Common persistent headers include
99
+ 'User-Agent'.
100
+ """
101
+ self.http_client = http_client
102
+ self.headers = headers or {}
103
+
104
+ def request(self, operation, url, data=None, headers=None):
105
+ all_headers = self.headers.copy()
106
+ if headers:
107
+ all_headers.update(headers)
108
+ return self.http_client.request(operation, url, data=data,
109
+ headers=all_headers)
110
+
111
+ def get(self, url, headers=None):
112
+ return self.request('GET', url, headers=headers)
113
+
114
+ def post(self, url, data, headers=None):
115
+ return self.request('POST', url, data=data, headers=headers)
116
+
117
+ def put(self, url, data, headers=None):
118
+ return self.request('PUT', url, data=data, headers=headers)
119
+
120
+ def delete(self, url, headers=None):
121
+ return self.request('DELETE', url, headers=headers)
122
+
123
+
124
+ class GenericToken(object):
125
+ """Represents an Authorization token to be added to HTTP requests.
126
+
127
+ Some Authorization headers included calculated fields (digital
128
+ signatures for example) which are based on the parameters of the HTTP
129
+ request. Therefore the token is responsible for signing the request
130
+ and adding the Authorization header.
131
+ """
132
+
133
+ def perform_request(self, http_client, operation, url, data=None,
134
+ headers=None):
135
+ """For the GenericToken, no Authorization token is set."""
136
+ return http_client.request(operation, url, data=data, headers=headers)
137
+
138
+ def valid_for_scope(self, url):
139
+ """Tells the caller if the token authorizes access to the desired URL.
140
+
141
+ Since the generic token doesn't add an auth header, it is not valid for
142
+ any scope.
143
+ """
144
+ return False
gam/atom/mock_http.py ADDED
@@ -0,0 +1,123 @@
1
+ #
2
+ # Copyright (C) 2008 Google Inc.
3
+ #
4
+ # Licensed under the Apache License 2.0;
5
+
6
+
7
+
8
+ # __author__ = 'api.jscudder (Jeff Scudder)'
9
+
10
+ import atom.http_interface
11
+ import atom.url
12
+
13
+
14
+ class Error(Exception):
15
+ pass
16
+
17
+
18
+ class NoRecordingFound(Error):
19
+ pass
20
+
21
+
22
+ class MockRequest(object):
23
+ """Holds parameters of an HTTP request for matching against future requests.
24
+ """
25
+
26
+ def __init__(self, operation, url, data=None, headers=None):
27
+ self.operation = operation
28
+ if isinstance(url, str):
29
+ url = atom.url.parse_url(url)
30
+ self.url = url
31
+ self.data = data
32
+ self.headers = headers
33
+
34
+
35
+ class MockResponse(atom.http_interface.HttpResponse):
36
+ """Simulates an httplib.HTTPResponse object."""
37
+
38
+ def __init__(self, body=None, status=None, reason=None, headers=None):
39
+ if body and hasattr(body, 'read'):
40
+ self.body = body.read()
41
+ else:
42
+ self.body = body
43
+ if status is not None:
44
+ self.status = int(status)
45
+ else:
46
+ self.status = None
47
+ self.reason = reason
48
+ self._headers = headers or {}
49
+
50
+ def read(self):
51
+ return self.body
52
+
53
+
54
+ class MockHttpClient(atom.http_interface.GenericHttpClient):
55
+ def __init__(self, headers=None, recordings=None, real_client=None):
56
+ """An HttpClient which responds to request with stored data.
57
+
58
+ The request-response pairs are stored as tuples in a member list named
59
+ recordings.
60
+
61
+ The MockHttpClient can be switched from replay mode to record mode by
62
+ setting the real_client member to an instance of an HttpClient which will
63
+ make real HTTP requests and store the server's response in list of
64
+ recordings.
65
+
66
+ Args:
67
+ headers: dict containing HTTP headers which should be included in all
68
+ HTTP requests.
69
+ recordings: The initial recordings to be used for responses. This list
70
+ contains tuples in the form: (MockRequest, MockResponse)
71
+ real_client: An HttpClient which will make a real HTTP request. The
72
+ response will be converted into a MockResponse and stored in
73
+ recordings.
74
+ """
75
+ self.recordings = recordings or []
76
+ self.real_client = real_client
77
+ self.headers = headers or {}
78
+
79
+ def add_response(self, response, operation, url, data=None, headers=None):
80
+ """Adds a request-response pair to the recordings list.
81
+
82
+ After the recording is added, future matching requests will receive the
83
+ response.
84
+
85
+ Args:
86
+ response: MockResponse
87
+ operation: str
88
+ url: str
89
+ data: str, Currently the data is ignored when looking for matching
90
+ requests.
91
+ headers: dict of strings: Currently the headers are ignored when
92
+ looking for matching requests.
93
+ """
94
+ request = MockRequest(operation, url, data=data, headers=headers)
95
+ self.recordings.append((request, response))
96
+
97
+ def request(self, operation, url, data=None, headers=None):
98
+ """Returns a matching MockResponse from the recordings.
99
+
100
+ If the real_client is set, the request will be passed along and the
101
+ server's response will be added to the recordings and also returned.
102
+
103
+ If there is no match, a NoRecordingFound error will be raised.
104
+ """
105
+ if self.real_client is None:
106
+ if isinstance(url, str):
107
+ url = atom.url.parse_url(url)
108
+ for recording in self.recordings:
109
+ if recording[0].operation == operation and recording[0].url == url:
110
+ return recording[1]
111
+ raise NoRecordingFound('No recodings found for %s %s' % (
112
+ operation, url))
113
+ else:
114
+ # There is a real HTTP client, so make the request, and record the
115
+ # response.
116
+ response = self.real_client.request(operation, url, data=data,
117
+ headers=headers)
118
+ # TODO: copy the headers
119
+ stored_response = MockResponse(body=response, status=response.status,
120
+ reason=response.reason)
121
+ self.add_response(stored_response, operation, url, data=data,
122
+ headers=headers)
123
+ return stored_response
@@ -0,0 +1,313 @@
1
+ #!/usr/bin/env python
2
+ #
3
+ # Copyright (C) 2009 Google Inc.
4
+ #
5
+ # Licensed under the Apache License 2.0;
6
+
7
+
8
+
9
+ # This module is used for version 2 of the Google Data APIs.
10
+
11
+
12
+ # __author__ = 'j.s@google.com (Jeff Scudder)'
13
+
14
+ import io
15
+ import os.path
16
+ import pickle
17
+ import tempfile
18
+
19
+ import atom.http_core
20
+
21
+
22
+ class Error(Exception):
23
+ pass
24
+
25
+
26
+ class NoRecordingFound(Error):
27
+ pass
28
+
29
+
30
+ class MockHttpClient(object):
31
+ debug = None
32
+ real_client = None
33
+ last_request_was_live = False
34
+
35
+ # The following members are used to construct the session cache temp file
36
+ # name.
37
+ # These are combined to form the file name
38
+ # /tmp/cache_prefix.cache_case_name.cache_test_name
39
+ cache_name_prefix = 'gdata_live_test'
40
+ cache_case_name = ''
41
+ cache_test_name = ''
42
+
43
+ def __init__(self, recordings=None, real_client=None):
44
+ self._recordings = recordings or []
45
+ if real_client is not None:
46
+ self.real_client = real_client
47
+
48
+ def add_response(self, http_request, status, reason, headers=None,
49
+ body=None):
50
+ response = MockHttpResponse(status, reason, headers, body)
51
+ # TODO Scrub the request and the response.
52
+ self._recordings.append((http_request._copy(), response))
53
+
54
+ AddResponse = add_response
55
+
56
+ def request(self, http_request):
57
+ """Provide a recorded response, or record a response for replay.
58
+
59
+ If the real_client is set, the request will be made using the
60
+ real_client, and the response from the server will be recorded.
61
+ If the real_client is None (the default), this method will examine
62
+ the recordings and find the first which matches.
63
+ """
64
+ request = http_request._copy()
65
+ _scrub_request(request)
66
+ if self.real_client is None:
67
+ self.last_request_was_live = False
68
+ for recording in self._recordings:
69
+ if _match_request(recording[0], request):
70
+ return recording[1]
71
+ else:
72
+ # Pass along the debug settings to the real client.
73
+ self.real_client.debug = self.debug
74
+ # Make an actual request since we can use the real HTTP client.
75
+ self.last_request_was_live = True
76
+ response = self.real_client.request(http_request)
77
+ scrubbed_response = _scrub_response(response)
78
+ self.add_response(request, scrubbed_response.status,
79
+ scrubbed_response.reason,
80
+ dict(atom.http_core.get_headers(scrubbed_response)),
81
+ scrubbed_response.read())
82
+ # Return the recording which we just added.
83
+ return self._recordings[-1][1]
84
+ raise NoRecordingFound('No recoding was found for request: %s %s' % (
85
+ request.method, str(request.uri)))
86
+
87
+ Request = request
88
+
89
+ def _save_recordings(self, filename):
90
+ recording_file = open(os.path.join(tempfile.gettempdir(), filename),
91
+ 'wb')
92
+ pickle.dump(self._recordings, recording_file)
93
+ recording_file.close()
94
+
95
+ def _load_recordings(self, filename):
96
+ recording_file = open(os.path.join(tempfile.gettempdir(), filename),
97
+ 'rb')
98
+ self._recordings = pickle.load(recording_file)
99
+ recording_file.close()
100
+
101
+ def _delete_recordings(self, filename):
102
+ full_path = os.path.join(tempfile.gettempdir(), filename)
103
+ if os.path.exists(full_path):
104
+ os.remove(full_path)
105
+
106
+ def _load_or_use_client(self, filename, http_client):
107
+ if os.path.exists(os.path.join(tempfile.gettempdir(), filename)):
108
+ self._load_recordings(filename)
109
+ else:
110
+ self.real_client = http_client
111
+
112
+ def use_cached_session(self, name=None, real_http_client=None):
113
+ """Attempts to load recordings from a previous live request.
114
+
115
+ If a temp file with the recordings exists, then it is used to fulfill
116
+ requests. If the file does not exist, then a real client is used to
117
+ actually make the desired HTTP requests. Requests and responses are
118
+ recorded and will be written to the desired temprary cache file when
119
+ close_session is called.
120
+
121
+ Args:
122
+ name: str (optional) The file name of session file to be used. The file
123
+ is loaded from the temporary directory of this machine. If no name
124
+ is passed in, a default name will be constructed using the
125
+ cache_name_prefix, cache_case_name, and cache_test_name of this
126
+ object.
127
+ real_http_client: atom.http_core.HttpClient the real client to be used
128
+ if the cached recordings are not found. If the default
129
+ value is used, this will be an
130
+ atom.http_core.HttpClient.
131
+ """
132
+ if real_http_client is None:
133
+ real_http_client = atom.http_core.HttpClient()
134
+ if name is None:
135
+ self._recordings_cache_name = self.get_cache_file_name()
136
+ else:
137
+ self._recordings_cache_name = name
138
+ self._load_or_use_client(self._recordings_cache_name, real_http_client)
139
+
140
+ def close_session(self):
141
+ """Saves recordings in the temporary file named in use_cached_session."""
142
+ if self.real_client is not None:
143
+ self._save_recordings(self._recordings_cache_name)
144
+
145
+ def delete_session(self, name=None):
146
+ """Removes recordings from a previous live request."""
147
+ if name is None:
148
+ self._delete_recordings(self._recordings_cache_name)
149
+ else:
150
+ self._delete_recordings(name)
151
+
152
+ def get_cache_file_name(self):
153
+ return '%s.%s.%s' % (self.cache_name_prefix, self.cache_case_name,
154
+ self.cache_test_name)
155
+
156
+ def _dump(self):
157
+ """Provides debug information in a string."""
158
+ output = 'MockHttpClient\n real_client: %s\n cache file name: %s\n' % (
159
+ self.real_client, self.get_cache_file_name())
160
+ output += ' recordings:\n'
161
+ i = 0
162
+ for recording in self._recordings:
163
+ output += ' recording %i is for: %s %s\n' % (
164
+ i, recording[0].method, str(recording[0].uri))
165
+ i += 1
166
+ return output
167
+
168
+
169
+ def _match_request(http_request, stored_request):
170
+ """Determines whether a request is similar enough to a stored request
171
+ to cause the stored response to be returned."""
172
+ # Check to see if the host names match.
173
+ if (http_request.uri.host is not None
174
+ and http_request.uri.host != stored_request.uri.host):
175
+ return False
176
+ # Check the request path in the URL (/feeds/private/full/x)
177
+ elif http_request.uri.path != stored_request.uri.path:
178
+ return False
179
+ # Check the method used in the request (GET, POST, etc.)
180
+ elif http_request.method != stored_request.method:
181
+ return False
182
+ # If there is a gsession ID in either request, make sure that it is matched
183
+ # exactly.
184
+ elif ('gsessionid' in http_request.uri.query
185
+ or 'gsessionid' in stored_request.uri.query):
186
+ if 'gsessionid' not in stored_request.uri.query:
187
+ return False
188
+ elif 'gsessionid' not in http_request.uri.query:
189
+ return False
190
+ elif (http_request.uri.query['gsessionid']
191
+ != stored_request.uri.query['gsessionid']):
192
+ return False
193
+ # Ignores differences in the query params (?start-index=5&max-results=20),
194
+ # the body of the request, the port number, HTTP headers, just to name a
195
+ # few.
196
+ return True
197
+
198
+
199
+ def _scrub_request(http_request):
200
+ """ Removes email address and password from a client login request.
201
+
202
+ Since the mock server saves the request and response in plantext, sensitive
203
+ information like the password should be removed before saving the
204
+ recordings. At the moment only requests sent to a ClientLogin url are
205
+ scrubbed.
206
+ """
207
+ if (http_request and http_request.uri and http_request.uri.path and
208
+ http_request.uri.path.endswith('ClientLogin')):
209
+ # Remove the email and password from a ClientLogin request.
210
+ http_request._body_parts = []
211
+ http_request.add_form_inputs(
212
+ {'form_data': 'client login request has been scrubbed'})
213
+ else:
214
+ # We can remove the body of the post from the recorded request, since
215
+ # the request body is not used when finding a matching recording.
216
+ http_request._body_parts = []
217
+ return http_request
218
+
219
+
220
+ def _scrub_response(http_response):
221
+ return http_response
222
+
223
+
224
+ class EchoHttpClient(object):
225
+ """Sends the request data back in the response.
226
+
227
+ Used to check the formatting of the request as it was sent. Always responds
228
+ with a 200 OK, and some information from the HTTP request is returned in
229
+ special Echo-X headers in the response. The following headers are added
230
+ in the response:
231
+ 'Echo-Host': The host name and port number to which the HTTP connection is
232
+ made. If no port was passed in, the header will contain
233
+ host:None.
234
+ 'Echo-Uri': The path portion of the URL being requested. /example?x=1&y=2
235
+ 'Echo-Scheme': The beginning of the URL, usually 'http' or 'https'
236
+ 'Echo-Method': The HTTP method being used, 'GET', 'POST', 'PUT', etc.
237
+ """
238
+
239
+ def request(self, http_request):
240
+ return self._http_request(http_request.uri, http_request.method,
241
+ http_request.headers, http_request._body_parts)
242
+
243
+ def _http_request(self, uri, method, headers=None, body_parts=None):
244
+ body = io.StringIO()
245
+ response = atom.http_core.HttpResponse(status=200, reason='OK', body=body)
246
+ if headers is None:
247
+ response._headers = {}
248
+ else:
249
+ # Copy headers from the request to the response but convert values to
250
+ # strings. Server response headers always come in as strings, so an int
251
+ # should be converted to a corresponding string when echoing.
252
+ for header, value in headers.items():
253
+ response._headers[header] = str(value)
254
+ response._headers['Echo-Host'] = '%s:%s' % (uri.host, str(uri.port))
255
+ response._headers['Echo-Uri'] = uri._get_relative_path()
256
+ response._headers['Echo-Scheme'] = uri.scheme
257
+ response._headers['Echo-Method'] = method
258
+ for part in body_parts:
259
+ if isinstance(part, str):
260
+ body.write(part)
261
+ elif hasattr(part, 'read'):
262
+ body.write(part.read())
263
+ body.seek(0)
264
+ return response
265
+
266
+
267
+ class SettableHttpClient(object):
268
+ """An HTTP Client which responds with the data given in set_response."""
269
+
270
+ def __init__(self, status, reason, body, headers):
271
+ """Configures the response for the server.
272
+
273
+ See set_response for details on the arguments to the constructor.
274
+ """
275
+ self.set_response(status, reason, body, headers)
276
+ self.last_request = None
277
+
278
+ def set_response(self, status, reason, body, headers):
279
+ """Determines the response which will be sent for each request.
280
+
281
+ Args:
282
+ status: An int for the HTTP status code, example: 200, 404, etc.
283
+ reason: String for the HTTP reason, example: OK, NOT FOUND, etc.
284
+ body: The body of the HTTP response as a string or a file-like
285
+ object (something with a read method).
286
+ headers: dict of strings containing the HTTP headers in the response.
287
+ """
288
+ self.response = atom.http_core.HttpResponse(status=status, reason=reason,
289
+ body=body)
290
+ self.response._headers = headers.copy()
291
+
292
+ def request(self, http_request):
293
+ self.last_request = http_request
294
+ return self.response
295
+
296
+
297
+ class MockHttpResponse(atom.http_core.HttpResponse):
298
+ def __init__(self, status=None, reason=None, headers=None, body=None):
299
+ self._headers = headers or {}
300
+ if status is not None:
301
+ self.status = status
302
+ if reason is not None:
303
+ self.reason = reason
304
+ if body is not None:
305
+ # Instead of using a file-like object for the body, store as a string
306
+ # so that reads can be repeated.
307
+ if hasattr(body, 'read'):
308
+ self._body = body.read()
309
+ else:
310
+ self._body = body
311
+
312
+ def read(self):
313
+ return self._body