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.
- gam/__init__.py +77555 -0
- gam/__main__.py +40 -0
- gam/atom/__init__.py +1460 -0
- gam/atom/auth.py +41 -0
- gam/atom/client.py +214 -0
- gam/atom/core.py +535 -0
- gam/atom/data.py +327 -0
- gam/atom/http.py +354 -0
- gam/atom/http_core.py +599 -0
- gam/atom/http_interface.py +144 -0
- gam/atom/mock_http.py +123 -0
- gam/atom/mock_http_core.py +313 -0
- gam/atom/mock_service.py +235 -0
- gam/atom/service.py +723 -0
- gam/atom/token_store.py +105 -0
- gam/atom/url.py +130 -0
- gam/cacerts.pem +1130 -0
- gam/cbcm-v1.1beta1.json +593 -0
- gam/contactdelegation-v1.json +249 -0
- gam/datastudio-v1.json +486 -0
- gam/gamlib/__init__.py +17 -0
- gam/gamlib/glaction.py +308 -0
- gam/gamlib/glapi.py +837 -0
- gam/gamlib/glcfg.py +616 -0
- gam/gamlib/glclargs.py +1184 -0
- gam/gamlib/glentity.py +831 -0
- gam/gamlib/glgapi.py +817 -0
- gam/gamlib/glgdata.py +98 -0
- gam/gamlib/glglobals.py +307 -0
- gam/gamlib/glindent.py +46 -0
- gam/gamlib/glmsgs.py +547 -0
- gam/gamlib/glskus.py +246 -0
- gam/gamlib/gluprop.py +279 -0
- gam/gamlib/glverlibs.py +33 -0
- gam/gamlib/yubikey.py +202 -0
- gam/gdata/__init__.py +825 -0
- gam/gdata/alt/__init__.py +20 -0
- gam/gdata/alt/app_engine.py +101 -0
- gam/gdata/alt/appengine.py +321 -0
- gam/gdata/apps/__init__.py +526 -0
- gam/gdata/apps/audit/__init__.py +1 -0
- gam/gdata/apps/audit/service.py +278 -0
- gam/gdata/apps/contacts/__init__.py +874 -0
- gam/gdata/apps/contacts/service.py +355 -0
- gam/gdata/apps/service.py +544 -0
- gam/gdata/apps/sites/__init__.py +283 -0
- gam/gdata/apps/sites/service.py +246 -0
- gam/gdata/service.py +1714 -0
- gam/gdata/urlfetch.py +247 -0
- gam/googleapiclient/__init__.py +27 -0
- gam/googleapiclient/_auth.py +167 -0
- gam/googleapiclient/_helpers.py +207 -0
- gam/googleapiclient/channel.py +315 -0
- gam/googleapiclient/discovery.py +1662 -0
- gam/googleapiclient/discovery_cache/__init__.py +78 -0
- gam/googleapiclient/discovery_cache/appengine_memcache.py +55 -0
- gam/googleapiclient/discovery_cache/base.py +46 -0
- gam/googleapiclient/discovery_cache/file_cache.py +145 -0
- gam/googleapiclient/errors.py +197 -0
- gam/googleapiclient/http.py +1962 -0
- gam/googleapiclient/mimeparse.py +183 -0
- gam/googleapiclient/model.py +429 -0
- gam/googleapiclient/schema.py +317 -0
- gam/googleapiclient/version.py +15 -0
- gam/iso8601/__init__.py +28 -0
- gam/iso8601/iso8601.py +160 -0
- gam/serviceaccountlookup-v1.json +141 -0
- gam/six.py +982 -0
- gam7-7.3.4.dist-info/METADATA +69 -0
- gam7-7.3.4.dist-info/RECORD +72 -0
- gam7-7.3.4.dist-info/WHEEL +4 -0
- gam7-7.3.4.dist-info/licenses/LICENSE +201 -0
gam/atom/mock_service.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2008 Google Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License 2.0;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
"""MockService provides CRUD ops. for mocking calls to AtomPub services.
|
|
9
|
+
|
|
10
|
+
MockService: Exposes the publicly used methods of AtomService to provide
|
|
11
|
+
a mock interface which can be used in unit tests.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import pickle
|
|
15
|
+
|
|
16
|
+
import atom.service
|
|
17
|
+
|
|
18
|
+
# __author__ = 'api.jscudder (Jeffrey Scudder)'
|
|
19
|
+
|
|
20
|
+
# Recordings contains pairings of HTTP MockRequest objects with MockHttpResponse objects.
|
|
21
|
+
recordings = []
|
|
22
|
+
# If set, the mock service HttpRequest are actually made through this object.
|
|
23
|
+
real_request_handler = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def ConcealValueWithSha(source):
|
|
27
|
+
import sha
|
|
28
|
+
return sha.new(source[:-5]).hexdigest()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def DumpRecordings(conceal_func=ConcealValueWithSha):
|
|
32
|
+
if conceal_func:
|
|
33
|
+
for recording_pair in recordings:
|
|
34
|
+
recording_pair[0].ConcealSecrets(conceal_func)
|
|
35
|
+
return pickle.dumps(recordings)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def LoadRecordings(recordings_file_or_string):
|
|
39
|
+
if isinstance(recordings_file_or_string, str):
|
|
40
|
+
atom.mock_service.recordings = pickle.loads(recordings_file_or_string)
|
|
41
|
+
elif hasattr(recordings_file_or_string, 'read'):
|
|
42
|
+
atom.mock_service.recordings = pickle.loads(
|
|
43
|
+
recordings_file_or_string.read())
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def HttpRequest(service, operation, data, uri, extra_headers=None,
|
|
47
|
+
url_params=None, escape_params=True, content_type='application/atom+xml'):
|
|
48
|
+
"""Simulates an HTTP call to the server, makes an actual HTTP request if
|
|
49
|
+
real_request_handler is set.
|
|
50
|
+
|
|
51
|
+
This function operates in two different modes depending on if
|
|
52
|
+
real_request_handler is set or not. If real_request_handler is not set,
|
|
53
|
+
HttpRequest will look in this module's recordings list to find a response
|
|
54
|
+
which matches the parameters in the function call. If real_request_handler
|
|
55
|
+
is set, this function will call real_request_handler.HttpRequest, add the
|
|
56
|
+
response to the recordings list, and respond with the actual response.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
service: atom.AtomService object which contains some of the parameters
|
|
60
|
+
needed to make the request. The following members are used to
|
|
61
|
+
construct the HTTP call: server (str), additional_headers (dict),
|
|
62
|
+
port (int), and ssl (bool).
|
|
63
|
+
operation: str The HTTP operation to be performed. This is usually one of
|
|
64
|
+
'GET', 'POST', 'PUT', or 'DELETE'
|
|
65
|
+
data: ElementTree, filestream, list of parts, or other object which can be
|
|
66
|
+
converted to a string.
|
|
67
|
+
Should be set to None when performing a GET or PUT.
|
|
68
|
+
If data is a file-like object which can be read, this method will read
|
|
69
|
+
a chunk of 100K bytes at a time and send them.
|
|
70
|
+
If the data is a list of parts to be sent, each part will be evaluated
|
|
71
|
+
and sent.
|
|
72
|
+
uri: The beginning of the URL to which the request should be sent.
|
|
73
|
+
Examples: '/', '/base/feeds/snippets',
|
|
74
|
+
'/m8/feeds/contacts/default/base'
|
|
75
|
+
extra_headers: dict of strings. HTTP headers which should be sent
|
|
76
|
+
in the request. These headers are in addition to those stored in
|
|
77
|
+
service.additional_headers.
|
|
78
|
+
url_params: dict of strings. Key value pairs to be added to the URL as
|
|
79
|
+
URL parameters. For example {'foo':'bar', 'test':'param'} will
|
|
80
|
+
become ?foo=bar&test=param.
|
|
81
|
+
escape_params: bool default True. If true, the keys and values in
|
|
82
|
+
url_params will be URL escaped when the form is constructed
|
|
83
|
+
(Special characters converted to %XX form.)
|
|
84
|
+
content_type: str The MIME type for the data being sent. Defaults to
|
|
85
|
+
'application/atom+xml', this is only used if data is set.
|
|
86
|
+
"""
|
|
87
|
+
full_uri = atom.service.BuildUri(uri, url_params, escape_params)
|
|
88
|
+
(server, port, ssl, uri) = atom.service.ProcessUrl(service, uri)
|
|
89
|
+
current_request = MockRequest(operation, full_uri, host=server, ssl=ssl,
|
|
90
|
+
data=data, extra_headers=extra_headers, url_params=url_params,
|
|
91
|
+
escape_params=escape_params, content_type=content_type)
|
|
92
|
+
# If the request handler is set, we should actually make the request using
|
|
93
|
+
# the request handler and record the response to replay later.
|
|
94
|
+
if real_request_handler:
|
|
95
|
+
response = real_request_handler.HttpRequest(service, operation, data, uri,
|
|
96
|
+
extra_headers=extra_headers, url_params=url_params,
|
|
97
|
+
escape_params=escape_params, content_type=content_type)
|
|
98
|
+
# TODO: need to copy the HTTP headers from the real response into the
|
|
99
|
+
# recorded_response.
|
|
100
|
+
recorded_response = MockHttpResponse(body=response.read(),
|
|
101
|
+
status=response.status, reason=response.reason)
|
|
102
|
+
# Insert a tuple which maps the request to the response object returned
|
|
103
|
+
# when making an HTTP call using the real_request_handler.
|
|
104
|
+
recordings.append((current_request, recorded_response))
|
|
105
|
+
return recorded_response
|
|
106
|
+
else:
|
|
107
|
+
# Look through available recordings to see if one matches the current
|
|
108
|
+
# request.
|
|
109
|
+
for request_response_pair in recordings:
|
|
110
|
+
if request_response_pair[0].IsMatch(current_request):
|
|
111
|
+
return request_response_pair[1]
|
|
112
|
+
return None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class MockRequest(object):
|
|
116
|
+
"""Represents a request made to an AtomPub server.
|
|
117
|
+
|
|
118
|
+
These objects are used to determine if a client request matches a recorded
|
|
119
|
+
HTTP request to determine what the mock server's response will be.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
def __init__(self, operation, uri, host=None, ssl=False, port=None,
|
|
123
|
+
data=None, extra_headers=None, url_params=None, escape_params=True,
|
|
124
|
+
content_type='application/atom+xml'):
|
|
125
|
+
"""Constructor for a MockRequest
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
operation: str One of 'GET', 'POST', 'PUT', or 'DELETE' this is the
|
|
129
|
+
HTTP operation requested on the resource.
|
|
130
|
+
uri: str The URL describing the resource to be modified or feed to be
|
|
131
|
+
retrieved. This should include the protocol (http/https) and the host
|
|
132
|
+
(aka domain). For example, these are some valud full_uris:
|
|
133
|
+
'http://example.com', 'https://www.google.com/accounts/ClientLogin'
|
|
134
|
+
host: str (optional) The server name which will be placed at the
|
|
135
|
+
beginning of the URL if the uri parameter does not begin with 'http'.
|
|
136
|
+
Examples include 'example.com', 'www.google.com', 'www.blogger.com'.
|
|
137
|
+
ssl: boolean (optional) If true, the request URL will begin with https
|
|
138
|
+
instead of http.
|
|
139
|
+
data: ElementTree, filestream, list of parts, or other object which can be
|
|
140
|
+
converted to a string. (optional)
|
|
141
|
+
Should be set to None when performing a GET or PUT.
|
|
142
|
+
If data is a file-like object which can be read, the constructor
|
|
143
|
+
will read the entire file into memory. If the data is a list of
|
|
144
|
+
parts to be sent, each part will be evaluated and stored.
|
|
145
|
+
extra_headers: dict (optional) HTTP headers included in the request.
|
|
146
|
+
url_params: dict (optional) Key value pairs which should be added to
|
|
147
|
+
the URL as URL parameters in the request. For example uri='/',
|
|
148
|
+
url_parameters={'foo':'1','bar':'2'} could become '/?foo=1&bar=2'.
|
|
149
|
+
escape_params: boolean (optional) Perform URL escaping on the keys and
|
|
150
|
+
values specified in url_params. Defaults to True.
|
|
151
|
+
content_type: str (optional) Provides the MIME type of the data being
|
|
152
|
+
sent.
|
|
153
|
+
"""
|
|
154
|
+
self.operation = operation
|
|
155
|
+
self.uri = _ConstructFullUrlBase(uri, host=host, ssl=ssl)
|
|
156
|
+
self.data = data
|
|
157
|
+
self.extra_headers = extra_headers
|
|
158
|
+
self.url_params = url_params or {}
|
|
159
|
+
self.escape_params = escape_params
|
|
160
|
+
self.content_type = content_type
|
|
161
|
+
|
|
162
|
+
def ConcealSecrets(self, conceal_func):
|
|
163
|
+
"""Conceal secret data in this request."""
|
|
164
|
+
if 'Authorization' in self.extra_headers:
|
|
165
|
+
self.extra_headers['Authorization'] = conceal_func(
|
|
166
|
+
self.extra_headers['Authorization'])
|
|
167
|
+
|
|
168
|
+
def IsMatch(self, other_request):
|
|
169
|
+
"""Check to see if the other_request is equivalent to this request.
|
|
170
|
+
|
|
171
|
+
Used to determine if a recording matches an incoming request so that a
|
|
172
|
+
recorded response should be sent to the client.
|
|
173
|
+
|
|
174
|
+
The matching is not exact, only the operation and URL are examined
|
|
175
|
+
currently.
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
other_request: MockRequest The request which we want to check this
|
|
179
|
+
(self) MockRequest against to see if they are equivalent.
|
|
180
|
+
"""
|
|
181
|
+
# More accurate matching logic will likely be required.
|
|
182
|
+
return (self.operation == other_request.operation and self.uri ==
|
|
183
|
+
other_request.uri)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _ConstructFullUrlBase(uri, host=None, ssl=False):
|
|
187
|
+
"""Puts URL components into the form http(s)://full.host.strinf/uri/path
|
|
188
|
+
|
|
189
|
+
Used to construct a roughly canonical URL so that URLs which begin with
|
|
190
|
+
'http://example.com/' can be compared to a uri of '/' when the host is
|
|
191
|
+
set to 'example.com'
|
|
192
|
+
|
|
193
|
+
If the uri contains 'http://host' already, the host and ssl parameters
|
|
194
|
+
are ignored.
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
uri: str The path component of the URL, examples include '/'
|
|
198
|
+
host: str (optional) The host name which should prepend the URL. Example:
|
|
199
|
+
'example.com'
|
|
200
|
+
ssl: boolean (optional) If true, the returned URL will begin with https
|
|
201
|
+
instead of http.
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
String which has the form http(s)://example.com/uri/string/contents
|
|
205
|
+
"""
|
|
206
|
+
if uri.startswith('http'):
|
|
207
|
+
return uri
|
|
208
|
+
if ssl:
|
|
209
|
+
return 'https://%s%s' % (host, uri)
|
|
210
|
+
else:
|
|
211
|
+
return 'http://%s%s' % (host, uri)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
class MockHttpResponse(object):
|
|
215
|
+
"""Returned from MockService crud methods as the server's response."""
|
|
216
|
+
|
|
217
|
+
def __init__(self, body=None, status=None, reason=None, headers=None):
|
|
218
|
+
"""Construct a mock HTTPResponse and set members.
|
|
219
|
+
|
|
220
|
+
Args:
|
|
221
|
+
body: str (optional) The HTTP body of the server's response.
|
|
222
|
+
status: int (optional)
|
|
223
|
+
reason: str (optional)
|
|
224
|
+
headers: dict (optional)
|
|
225
|
+
"""
|
|
226
|
+
self.body = body
|
|
227
|
+
self.status = status
|
|
228
|
+
self.reason = reason
|
|
229
|
+
self.headers = headers or {}
|
|
230
|
+
|
|
231
|
+
def read(self):
|
|
232
|
+
return self.body
|
|
233
|
+
|
|
234
|
+
def getheader(self, header_name):
|
|
235
|
+
return self.headers[header_name]
|