gam7 7.19.3__py3-none-any.whl → 7.28.2__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.
- gam/__init__.py +1836 -700
- gam/__main__.py +6 -1
- gam/gamlib/glapi.py +35 -19
- gam/gamlib/glcfg.py +16 -0
- gam/gamlib/glclargs.py +294 -5
- gam/gamlib/glentity.py +15 -3
- gam/gamlib/glglobals.py +6 -0
- gam/gamlib/glmsgs.py +5 -2
- gam/gamlib/glskus.py +1 -1
- gam/gamlib/glverlibs.py +1 -1
- gam/gamlib/yubikey.py +13 -12
- {gam7-7.19.3.dist-info → gam7-7.28.2.dist-info}/METADATA +10 -4
- {gam7-7.19.3.dist-info → gam7-7.28.2.dist-info}/RECORD +16 -34
- gam/googleapiclient/__init__.py +0 -27
- gam/googleapiclient/_auth.py +0 -167
- gam/googleapiclient/_helpers.py +0 -207
- gam/googleapiclient/channel.py +0 -315
- gam/googleapiclient/discovery.py +0 -1662
- gam/googleapiclient/discovery_cache/__init__.py +0 -78
- gam/googleapiclient/discovery_cache/appengine_memcache.py +0 -55
- gam/googleapiclient/discovery_cache/base.py +0 -46
- gam/googleapiclient/discovery_cache/file_cache.py +0 -145
- gam/googleapiclient/errors.py +0 -197
- gam/googleapiclient/http.py +0 -1962
- gam/googleapiclient/mimeparse.py +0 -183
- gam/googleapiclient/model.py +0 -429
- gam/googleapiclient/schema.py +0 -317
- gam/googleapiclient/version.py +0 -15
- gam/iso8601/__init__.py +0 -28
- gam/iso8601/iso8601.py +0 -160
- gam/six.py +0 -982
- {gam7-7.19.3.dist-info → gam7-7.28.2.dist-info}/WHEEL +0 -0
- {gam7-7.19.3.dist-info → gam7-7.28.2.dist-info}/entry_points.txt +0 -0
- {gam7-7.19.3.dist-info → gam7-7.28.2.dist-info}/licenses/LICENSE +0 -0
gam/googleapiclient/schema.py
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
# Copyright 2014 Google Inc. All Rights Reserved.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
"""Schema processing for discovery based APIs
|
|
16
|
-
|
|
17
|
-
Schemas holds an APIs discovery schemas. It can return those schema as
|
|
18
|
-
deserialized JSON objects, or pretty print them as prototype objects that
|
|
19
|
-
conform to the schema.
|
|
20
|
-
|
|
21
|
-
For example, given the schema:
|
|
22
|
-
|
|
23
|
-
schema = \"\"\"{
|
|
24
|
-
"Foo": {
|
|
25
|
-
"type": "object",
|
|
26
|
-
"properties": {
|
|
27
|
-
"etag": {
|
|
28
|
-
"type": "string",
|
|
29
|
-
"description": "ETag of the collection."
|
|
30
|
-
},
|
|
31
|
-
"kind": {
|
|
32
|
-
"type": "string",
|
|
33
|
-
"description": "Type of the collection ('calendar#acl').",
|
|
34
|
-
"default": "calendar#acl"
|
|
35
|
-
},
|
|
36
|
-
"nextPageToken": {
|
|
37
|
-
"type": "string",
|
|
38
|
-
"description": "Token used to access the next
|
|
39
|
-
page of this result. Omitted if no further results are available."
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}\"\"\"
|
|
44
|
-
|
|
45
|
-
s = Schemas(schema)
|
|
46
|
-
print s.prettyPrintByName('Foo')
|
|
47
|
-
|
|
48
|
-
Produces the following output:
|
|
49
|
-
|
|
50
|
-
{
|
|
51
|
-
"nextPageToken": "A String", # Token used to access the
|
|
52
|
-
# next page of this result. Omitted if no further results are available.
|
|
53
|
-
"kind": "A String", # Type of the collection ('calendar#acl').
|
|
54
|
-
"etag": "A String", # ETag of the collection.
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
The constructor takes a discovery document in which to look up named schema.
|
|
58
|
-
"""
|
|
59
|
-
from __future__ import absolute_import
|
|
60
|
-
|
|
61
|
-
# TODO(jcgregorio) support format, enum, minimum, maximum
|
|
62
|
-
|
|
63
|
-
__author__ = "jcgregorio@google.com (Joe Gregorio)"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
from collections import OrderedDict
|
|
67
|
-
|
|
68
|
-
from googleapiclient import _helpers as util
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class Schemas(object):
|
|
72
|
-
"""Schemas for an API."""
|
|
73
|
-
|
|
74
|
-
def __init__(self, discovery):
|
|
75
|
-
"""Constructor.
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
discovery: object, Deserialized discovery document from which we pull
|
|
79
|
-
out the named schema.
|
|
80
|
-
"""
|
|
81
|
-
self.schemas = discovery.get("schemas", {})
|
|
82
|
-
|
|
83
|
-
# Cache of pretty printed schemas.
|
|
84
|
-
self.pretty = {}
|
|
85
|
-
|
|
86
|
-
@util.positional(2)
|
|
87
|
-
def _prettyPrintByName(self, name, seen=None, dent=0):
|
|
88
|
-
"""Get pretty printed object prototype from the schema name.
|
|
89
|
-
|
|
90
|
-
Args:
|
|
91
|
-
name: string, Name of schema in the discovery document.
|
|
92
|
-
seen: list of string, Names of schema already seen. Used to handle
|
|
93
|
-
recursive definitions.
|
|
94
|
-
|
|
95
|
-
Returns:
|
|
96
|
-
string, A string that contains a prototype object with
|
|
97
|
-
comments that conforms to the given schema.
|
|
98
|
-
"""
|
|
99
|
-
if seen is None:
|
|
100
|
-
seen = []
|
|
101
|
-
|
|
102
|
-
if name in seen:
|
|
103
|
-
# Do not fall into an infinite loop over recursive definitions.
|
|
104
|
-
return "# Object with schema name: %s" % name
|
|
105
|
-
seen.append(name)
|
|
106
|
-
|
|
107
|
-
if name not in self.pretty:
|
|
108
|
-
self.pretty[name] = _SchemaToStruct(
|
|
109
|
-
self.schemas[name], seen, dent=dent
|
|
110
|
-
).to_str(self._prettyPrintByName)
|
|
111
|
-
|
|
112
|
-
seen.pop()
|
|
113
|
-
|
|
114
|
-
return self.pretty[name]
|
|
115
|
-
|
|
116
|
-
def prettyPrintByName(self, name):
|
|
117
|
-
"""Get pretty printed object prototype from the schema name.
|
|
118
|
-
|
|
119
|
-
Args:
|
|
120
|
-
name: string, Name of schema in the discovery document.
|
|
121
|
-
|
|
122
|
-
Returns:
|
|
123
|
-
string, A string that contains a prototype object with
|
|
124
|
-
comments that conforms to the given schema.
|
|
125
|
-
"""
|
|
126
|
-
# Return with trailing comma and newline removed.
|
|
127
|
-
return self._prettyPrintByName(name, seen=[], dent=0)[:-2]
|
|
128
|
-
|
|
129
|
-
@util.positional(2)
|
|
130
|
-
def _prettyPrintSchema(self, schema, seen=None, dent=0):
|
|
131
|
-
"""Get pretty printed object prototype of schema.
|
|
132
|
-
|
|
133
|
-
Args:
|
|
134
|
-
schema: object, Parsed JSON schema.
|
|
135
|
-
seen: list of string, Names of schema already seen. Used to handle
|
|
136
|
-
recursive definitions.
|
|
137
|
-
|
|
138
|
-
Returns:
|
|
139
|
-
string, A string that contains a prototype object with
|
|
140
|
-
comments that conforms to the given schema.
|
|
141
|
-
"""
|
|
142
|
-
if seen is None:
|
|
143
|
-
seen = []
|
|
144
|
-
|
|
145
|
-
return _SchemaToStruct(schema, seen, dent=dent).to_str(self._prettyPrintByName)
|
|
146
|
-
|
|
147
|
-
def prettyPrintSchema(self, schema):
|
|
148
|
-
"""Get pretty printed object prototype of schema.
|
|
149
|
-
|
|
150
|
-
Args:
|
|
151
|
-
schema: object, Parsed JSON schema.
|
|
152
|
-
|
|
153
|
-
Returns:
|
|
154
|
-
string, A string that contains a prototype object with
|
|
155
|
-
comments that conforms to the given schema.
|
|
156
|
-
"""
|
|
157
|
-
# Return with trailing comma and newline removed.
|
|
158
|
-
return self._prettyPrintSchema(schema, dent=0)[:-2]
|
|
159
|
-
|
|
160
|
-
def get(self, name, default=None):
|
|
161
|
-
"""Get deserialized JSON schema from the schema name.
|
|
162
|
-
|
|
163
|
-
Args:
|
|
164
|
-
name: string, Schema name.
|
|
165
|
-
default: object, return value if name not found.
|
|
166
|
-
"""
|
|
167
|
-
return self.schemas.get(name, default)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
class _SchemaToStruct(object):
|
|
171
|
-
"""Convert schema to a prototype object."""
|
|
172
|
-
|
|
173
|
-
@util.positional(3)
|
|
174
|
-
def __init__(self, schema, seen, dent=0):
|
|
175
|
-
"""Constructor.
|
|
176
|
-
|
|
177
|
-
Args:
|
|
178
|
-
schema: object, Parsed JSON schema.
|
|
179
|
-
seen: list, List of names of schema already seen while parsing. Used to
|
|
180
|
-
handle recursive definitions.
|
|
181
|
-
dent: int, Initial indentation depth.
|
|
182
|
-
"""
|
|
183
|
-
# The result of this parsing kept as list of strings.
|
|
184
|
-
self.value = []
|
|
185
|
-
|
|
186
|
-
# The final value of the parsing.
|
|
187
|
-
self.string = None
|
|
188
|
-
|
|
189
|
-
# The parsed JSON schema.
|
|
190
|
-
self.schema = schema
|
|
191
|
-
|
|
192
|
-
# Indentation level.
|
|
193
|
-
self.dent = dent
|
|
194
|
-
|
|
195
|
-
# Method that when called returns a prototype object for the schema with
|
|
196
|
-
# the given name.
|
|
197
|
-
self.from_cache = None
|
|
198
|
-
|
|
199
|
-
# List of names of schema already seen while parsing.
|
|
200
|
-
self.seen = seen
|
|
201
|
-
|
|
202
|
-
def emit(self, text):
|
|
203
|
-
"""Add text as a line to the output.
|
|
204
|
-
|
|
205
|
-
Args:
|
|
206
|
-
text: string, Text to output.
|
|
207
|
-
"""
|
|
208
|
-
self.value.extend([" " * self.dent, text, "\n"])
|
|
209
|
-
|
|
210
|
-
def emitBegin(self, text):
|
|
211
|
-
"""Add text to the output, but with no line terminator.
|
|
212
|
-
|
|
213
|
-
Args:
|
|
214
|
-
text: string, Text to output.
|
|
215
|
-
"""
|
|
216
|
-
self.value.extend([" " * self.dent, text])
|
|
217
|
-
|
|
218
|
-
def emitEnd(self, text, comment):
|
|
219
|
-
"""Add text and comment to the output with line terminator.
|
|
220
|
-
|
|
221
|
-
Args:
|
|
222
|
-
text: string, Text to output.
|
|
223
|
-
comment: string, Python comment.
|
|
224
|
-
"""
|
|
225
|
-
if comment:
|
|
226
|
-
divider = "\n" + " " * (self.dent + 2) + "# "
|
|
227
|
-
lines = comment.splitlines()
|
|
228
|
-
lines = [x.rstrip() for x in lines]
|
|
229
|
-
comment = divider.join(lines)
|
|
230
|
-
self.value.extend([text, " # ", comment, "\n"])
|
|
231
|
-
else:
|
|
232
|
-
self.value.extend([text, "\n"])
|
|
233
|
-
|
|
234
|
-
def indent(self):
|
|
235
|
-
"""Increase indentation level."""
|
|
236
|
-
self.dent += 1
|
|
237
|
-
|
|
238
|
-
def undent(self):
|
|
239
|
-
"""Decrease indentation level."""
|
|
240
|
-
self.dent -= 1
|
|
241
|
-
|
|
242
|
-
def _to_str_impl(self, schema):
|
|
243
|
-
"""Prototype object based on the schema, in Python code with comments.
|
|
244
|
-
|
|
245
|
-
Args:
|
|
246
|
-
schema: object, Parsed JSON schema file.
|
|
247
|
-
|
|
248
|
-
Returns:
|
|
249
|
-
Prototype object based on the schema, in Python code with comments.
|
|
250
|
-
"""
|
|
251
|
-
stype = schema.get("type")
|
|
252
|
-
if stype == "object":
|
|
253
|
-
self.emitEnd("{", schema.get("description", ""))
|
|
254
|
-
self.indent()
|
|
255
|
-
if "properties" in schema:
|
|
256
|
-
properties = schema.get("properties", {})
|
|
257
|
-
sorted_properties = OrderedDict(sorted(properties.items()))
|
|
258
|
-
for pname, pschema in sorted_properties.items():
|
|
259
|
-
self.emitBegin('"%s": ' % pname)
|
|
260
|
-
self._to_str_impl(pschema)
|
|
261
|
-
elif "additionalProperties" in schema:
|
|
262
|
-
self.emitBegin('"a_key": ')
|
|
263
|
-
self._to_str_impl(schema["additionalProperties"])
|
|
264
|
-
self.undent()
|
|
265
|
-
self.emit("},")
|
|
266
|
-
elif "$ref" in schema:
|
|
267
|
-
schemaName = schema["$ref"]
|
|
268
|
-
description = schema.get("description", "")
|
|
269
|
-
s = self.from_cache(schemaName, seen=self.seen)
|
|
270
|
-
parts = s.splitlines()
|
|
271
|
-
self.emitEnd(parts[0], description)
|
|
272
|
-
for line in parts[1:]:
|
|
273
|
-
self.emit(line.rstrip())
|
|
274
|
-
elif stype == "boolean":
|
|
275
|
-
value = schema.get("default", "True or False")
|
|
276
|
-
self.emitEnd("%s," % str(value), schema.get("description", ""))
|
|
277
|
-
elif stype == "string":
|
|
278
|
-
value = schema.get("default", "A String")
|
|
279
|
-
self.emitEnd('"%s",' % str(value), schema.get("description", ""))
|
|
280
|
-
elif stype == "integer":
|
|
281
|
-
value = schema.get("default", "42")
|
|
282
|
-
self.emitEnd("%s," % str(value), schema.get("description", ""))
|
|
283
|
-
elif stype == "number":
|
|
284
|
-
value = schema.get("default", "3.14")
|
|
285
|
-
self.emitEnd("%s," % str(value), schema.get("description", ""))
|
|
286
|
-
elif stype == "null":
|
|
287
|
-
self.emitEnd("None,", schema.get("description", ""))
|
|
288
|
-
elif stype == "any":
|
|
289
|
-
self.emitEnd('"",', schema.get("description", ""))
|
|
290
|
-
elif stype == "array":
|
|
291
|
-
self.emitEnd("[", schema.get("description"))
|
|
292
|
-
self.indent()
|
|
293
|
-
self.emitBegin("")
|
|
294
|
-
self._to_str_impl(schema["items"])
|
|
295
|
-
self.undent()
|
|
296
|
-
self.emit("],")
|
|
297
|
-
else:
|
|
298
|
-
self.emit("Unknown type! %s" % stype)
|
|
299
|
-
self.emitEnd("", "")
|
|
300
|
-
|
|
301
|
-
self.string = "".join(self.value)
|
|
302
|
-
return self.string
|
|
303
|
-
|
|
304
|
-
def to_str(self, from_cache):
|
|
305
|
-
"""Prototype object based on the schema, in Python code with comments.
|
|
306
|
-
|
|
307
|
-
Args:
|
|
308
|
-
from_cache: callable(name, seen), Callable that retrieves an object
|
|
309
|
-
prototype for a schema with the given name. Seen is a list of schema
|
|
310
|
-
names already seen as we recursively descend the schema definition.
|
|
311
|
-
|
|
312
|
-
Returns:
|
|
313
|
-
Prototype object based on the schema, in Python code with comments.
|
|
314
|
-
The lines of the code will all be properly indented.
|
|
315
|
-
"""
|
|
316
|
-
self.from_cache = from_cache
|
|
317
|
-
return self._to_str_impl(self.schema)
|
gam/googleapiclient/version.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Copyright 2021 Google LLC
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
14
|
-
|
|
15
|
-
__version__ = "2.164.0"
|
gam/iso8601/__init__.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2007 - 2015 Michael Twomey
|
|
4
|
-
#
|
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
6
|
-
# copy of this software and associated documentation files (the
|
|
7
|
-
# "Software"), to deal in the Software without restriction, including
|
|
8
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
# permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
# the following conditions:
|
|
12
|
-
#
|
|
13
|
-
# The above copyright notice and this permission notice shall be included
|
|
14
|
-
# in all copies or substantial portions of the Software.
|
|
15
|
-
#
|
|
16
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
17
|
-
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
24
|
-
"""ISO 8601 date time string parsing
|
|
25
|
-
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
__all__ = ["parse_date", "ParseError", "UTC"]
|
gam/iso8601/iso8601.py
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""ISO 8601 date time string parsing
|
|
3
|
-
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from datetime import (datetime, timedelta, tzinfo)
|
|
7
|
-
import time as _time
|
|
8
|
-
import re
|
|
9
|
-
|
|
10
|
-
ISO8601_REGEX = re.compile(r'^(?P<year>[0-9]{4})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})(?P<separator>[ T])(?P<hour>[0-9]{2}):(?P<minute>[0-9]{2}):(?P<second>[0-9]{2})([.,](?P<second_fraction>[0-9]+)){0,1}(?P<timezone>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9]{2}):(?P<tz_minute>[0-9]{2}))$')
|
|
11
|
-
ISO8601_TZ_REGEX = re.compile(r'^(?P<timezone>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9]{2}):(?P<tz_minute>[0-9]{2}))$')
|
|
12
|
-
|
|
13
|
-
class ParseError(Exception):
|
|
14
|
-
"""Raised when there is a problem parsing a date string"""
|
|
15
|
-
|
|
16
|
-
# Yoinked from python docs
|
|
17
|
-
ZERO = timedelta(0)
|
|
18
|
-
class Utc(tzinfo):
|
|
19
|
-
"""UTC Timezone
|
|
20
|
-
|
|
21
|
-
"""
|
|
22
|
-
def utcoffset(self, dt):
|
|
23
|
-
return ZERO
|
|
24
|
-
|
|
25
|
-
def tzname(self, dt):
|
|
26
|
-
return "UTC"
|
|
27
|
-
|
|
28
|
-
def dst(self, dt):
|
|
29
|
-
return ZERO
|
|
30
|
-
|
|
31
|
-
def __repr__(self):
|
|
32
|
-
return "<iso8601.Utc>"
|
|
33
|
-
|
|
34
|
-
UTC = Utc()
|
|
35
|
-
|
|
36
|
-
class FixedOffset(tzinfo):
|
|
37
|
-
"""Fixed offset in hours and minutes from UTC
|
|
38
|
-
|
|
39
|
-
"""
|
|
40
|
-
def __init__(self, offset_hours, offset_minutes, name):
|
|
41
|
-
self.__offset_hours = offset_hours # Keep for later __getinitargs__
|
|
42
|
-
self.__offset_minutes = offset_minutes # Keep for later __getinitargs__
|
|
43
|
-
self.__offset = timedelta(hours=offset_hours, minutes=offset_minutes)
|
|
44
|
-
self.__name = name
|
|
45
|
-
|
|
46
|
-
def __eq__(self, other):
|
|
47
|
-
if isinstance(other, FixedOffset):
|
|
48
|
-
return (other.__offset == self.__offset) and (other.__name == self.__name)
|
|
49
|
-
if isinstance(other, tzinfo):
|
|
50
|
-
return other == self
|
|
51
|
-
return False
|
|
52
|
-
|
|
53
|
-
def __getinitargs__(self):
|
|
54
|
-
return (self.__offset_hours, self.__offset_minutes, self.__name)
|
|
55
|
-
|
|
56
|
-
def utcoffset(self, dt):
|
|
57
|
-
return self.__offset
|
|
58
|
-
|
|
59
|
-
def tzname(self, dt):
|
|
60
|
-
return self.__name
|
|
61
|
-
|
|
62
|
-
def dst(self, dt):
|
|
63
|
-
return ZERO
|
|
64
|
-
|
|
65
|
-
def __repr__(self):
|
|
66
|
-
return "<FixedOffset %r %r>" % (self.__name, self.__offset)
|
|
67
|
-
|
|
68
|
-
# A class capturing the platform's idea of local time.
|
|
69
|
-
|
|
70
|
-
STDOFFSET = timedelta(seconds = -_time.timezone)
|
|
71
|
-
if _time.daylight:
|
|
72
|
-
DSTOFFSET = timedelta(seconds = -_time.altzone)
|
|
73
|
-
else:
|
|
74
|
-
DSTOFFSET = STDOFFSET
|
|
75
|
-
|
|
76
|
-
DSTDIFF = DSTOFFSET - STDOFFSET
|
|
77
|
-
|
|
78
|
-
class LocalTimezone(tzinfo):
|
|
79
|
-
"""Local time zone
|
|
80
|
-
|
|
81
|
-
"""
|
|
82
|
-
|
|
83
|
-
def utcoffset(self, dt):
|
|
84
|
-
if self._isdst(dt):
|
|
85
|
-
return DSTOFFSET
|
|
86
|
-
else:
|
|
87
|
-
return STDOFFSET
|
|
88
|
-
|
|
89
|
-
def dst(self, dt):
|
|
90
|
-
if self._isdst(dt):
|
|
91
|
-
return DSTDIFF
|
|
92
|
-
else:
|
|
93
|
-
return ZERO
|
|
94
|
-
|
|
95
|
-
def tzname(self, dt):
|
|
96
|
-
return _time.tzname[self._isdst(dt)]
|
|
97
|
-
|
|
98
|
-
def _isdst(self, dt):
|
|
99
|
-
tt = (dt.year, dt.month, dt.day,
|
|
100
|
-
dt.hour, dt.minute, dt.second,
|
|
101
|
-
dt.weekday(), 0, 0)
|
|
102
|
-
stamp = _time.mktime(tt)
|
|
103
|
-
tt = _time.localtime(stamp)
|
|
104
|
-
return tt.tm_isdst > 0
|
|
105
|
-
|
|
106
|
-
Local = LocalTimezone()
|
|
107
|
-
|
|
108
|
-
def parse_timezone(matches):
|
|
109
|
-
"""Parses ISO 8601 time zone specs into tzinfo offsets
|
|
110
|
-
|
|
111
|
-
"""
|
|
112
|
-
|
|
113
|
-
if matches["timezone"] == "Z":
|
|
114
|
-
return UTC
|
|
115
|
-
sign = matches["tz_sign"]
|
|
116
|
-
hours = int(matches['tz_hour'])
|
|
117
|
-
minutes = int(matches['tz_minute'])
|
|
118
|
-
description = "%s%02d:%02d" % (sign, hours, minutes)
|
|
119
|
-
if sign == "-":
|
|
120
|
-
hours = -hours
|
|
121
|
-
minutes = -minutes
|
|
122
|
-
return FixedOffset(hours, minutes, description)
|
|
123
|
-
|
|
124
|
-
def parse_timezone_str(tzstring):
|
|
125
|
-
m = ISO8601_TZ_REGEX.match(tzstring)
|
|
126
|
-
if not m:
|
|
127
|
-
raise ParseError("Unable to parse timezone string %r" % tzstring)
|
|
128
|
-
groups = m.groupdict()
|
|
129
|
-
return parse_timezone(groups)
|
|
130
|
-
|
|
131
|
-
def parse_date(datestring):
|
|
132
|
-
"""Parses ISO 8601 dates into datetime objects
|
|
133
|
-
|
|
134
|
-
The timezone is parsed from the date string. However it is quite common to
|
|
135
|
-
have dates without a timezone (not strictly correct). In this case the
|
|
136
|
-
default timezone specified in default_timezone is used. This is UTC by
|
|
137
|
-
default.
|
|
138
|
-
|
|
139
|
-
:param datestring: The date to parse as a string
|
|
140
|
-
:returns: A datetime.datetime instance
|
|
141
|
-
:raises: ParseError when there is a problem parsing the date or
|
|
142
|
-
constructing the datetime instance.
|
|
143
|
-
|
|
144
|
-
"""
|
|
145
|
-
m = ISO8601_REGEX.match(datestring)
|
|
146
|
-
if not m:
|
|
147
|
-
raise ParseError("Unable to parse date string %r" % datestring)
|
|
148
|
-
groups = m.groupdict()
|
|
149
|
-
tz = parse_timezone(groups)
|
|
150
|
-
try:
|
|
151
|
-
return (datetime(year=int(groups['year']),
|
|
152
|
-
month=int(groups['month']),
|
|
153
|
-
day=int(groups['day']),
|
|
154
|
-
hour=int(groups['hour']),
|
|
155
|
-
minute=int(groups['minute']),
|
|
156
|
-
second=int(groups['second']),
|
|
157
|
-
tzinfo=tz),
|
|
158
|
-
tz)
|
|
159
|
-
except Exception as e:
|
|
160
|
-
raise ParseError(e)
|