sdata 1.5.0__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.
- sdata/__init__.py +140 -0
- sdata/base.py +684 -0
- sdata/contrib/__init__.py +0 -0
- sdata/contrib/piexif/__init__.py +12 -0
- sdata/contrib/piexif/_common.py +94 -0
- sdata/contrib/piexif/_dump.py +346 -0
- sdata/contrib/piexif/_exceptions.py +2 -0
- sdata/contrib/piexif/_exif.py +638 -0
- sdata/contrib/piexif/_insert.py +60 -0
- sdata/contrib/piexif/_load.py +270 -0
- sdata/contrib/piexif/_remove.py +56 -0
- sdata/contrib/piexif/_transplant.py +45 -0
- sdata/contrib/piexif/_webp.py +240 -0
- sdata/contrib/piexif/helper.py +66 -0
- sdata/contrib/ranger/__init__.py +8 -0
- sdata/contrib/ranger/collections/__init__.py +0 -0
- sdata/contrib/ranger/collections/rangebucketmap.py +346 -0
- sdata/contrib/ranger/collections/rangemap.py +396 -0
- sdata/contrib/ranger/collections/rangeset.py +483 -0
- sdata/contrib/ranger/range/__init__.py +0 -0
- sdata/contrib/ranger/range/cut.py +285 -0
- sdata/contrib/ranger/range/range.py +644 -0
- sdata/contrib/sobol_seq.py +394 -0
- sdata/contrib/sortedcontainers/LICENSE +13 -0
- sdata/contrib/sortedcontainers/__init__.py +74 -0
- sdata/contrib/sortedcontainers/sorteddict.py +789 -0
- sdata/contrib/sortedcontainers/sortedlist.py +2646 -0
- sdata/contrib/sortedcontainers/sortedset.py +733 -0
- sdata/contrib/sqlitedict.py +598 -0
- sdata/contrib/timeflake/__init__.py +40 -0
- sdata/contrib/timeflake/flake.py +69 -0
- sdata/contrib/timeflake/utils.py +47 -0
- sdata/deprecated/__init__.py +10 -0
- sdata/deprecated/data.py +1503 -0
- sdata/did/__init__.py +129 -0
- sdata/did/_http.py +67 -0
- sdata/did/base58btc.py +49 -0
- sdata/did/did_github.py +152 -0
- sdata/did/did_peer4.py +155 -0
- sdata/did/did_web.py +222 -0
- sdata/did/diddoc.py +75 -0
- sdata/did/ed25519.py +225 -0
- sdata/did/eddsa.py +107 -0
- sdata/did/errors.py +40 -0
- sdata/did/issue_vc.py +193 -0
- sdata/did/jose.py +126 -0
- sdata/did/keys.py +104 -0
- sdata/did/utils_didkey.py +161 -0
- sdata/did/verify_vp.py +158 -0
- sdata/doe.py +101 -0
- sdata/dtypes.py +510 -0
- sdata/experiments/__init__.py +331 -0
- sdata/experiments/blob0.py +131 -0
- sdata/experiments/file.py +42 -0
- sdata/experiments/filegroup.py +144 -0
- sdata/experiments/image_old.py +313 -0
- sdata/experiments/ks2.py +15 -0
- sdata/experiments/lapshear.py +8 -0
- sdata/experiments/material.py +7 -0
- sdata/experiments/parameters_deprecated.py +394 -0
- sdata/experiments/workbook.py +226 -0
- sdata/format.py +125 -0
- sdata/imagemeta.py +533 -0
- sdata/interactive.py +118 -0
- sdata/iolib/__init__.py +51 -0
- sdata/iolib/hashtree.py +264 -0
- sdata/iolib/json1sqlitestore.py +554 -0
- sdata/iolib/jsonsqlitestore.py +704 -0
- sdata/iolib/pud.py +242 -0
- sdata/iolib/reader.py +262 -0
- sdata/iolib/writer.py +419 -0
- sdata/metadata.py +882 -0
- sdata/parameter.py +414 -0
- sdata/schema.py +273 -0
- sdata/sclass/__init__.py +111 -0
- sdata/sclass/bfo_classes.py +362 -0
- sdata/sclass/blob.py +362 -0
- sdata/sclass/content.py +87 -0
- sdata/sclass/dataframe.py +1251 -0
- sdata/sclass/dataframegroup.py +187 -0
- sdata/sclass/dependency_graph.py +85 -0
- sdata/sclass/filereference.py +124 -0
- sdata/sclass/image.py +218 -0
- sdata/sclass/lazy_namespace.py +155 -0
- sdata/sclass/process.py +383 -0
- sdata/sclass/process_graph.py +221 -0
- sdata/sclass/zipfile.py +135 -0
- sdata/semantic.py +346 -0
- sdata/suuid.py +136 -0
- sdata/timestamp.py +336 -0
- sdata/tools.py +14 -0
- sdata/units.py +602 -0
- sdata/vocab.py +149 -0
- sdata-1.5.0.dist-info/METADATA +264 -0
- sdata-1.5.0.dist-info/RECORD +98 -0
- sdata-1.5.0.dist-info/WHEEL +5 -0
- sdata-1.5.0.dist-info/licenses/LICENSE-MIT +21 -0
- sdata-1.5.0.dist-info/top_level.txt +1 -0
sdata/timestamp.py
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"""ISO 8601 date time string parsing
|
|
2
|
+
|
|
3
|
+
Basic usage:
|
|
4
|
+
|
|
5
|
+
#>>> parse_date("2007-01-25T12:00:00Z")
|
|
6
|
+
|
|
7
|
+
datetime.datetime(2007, 1, 25, 12, 0, tzinfo=<iso8601.Utc ...>)
|
|
8
|
+
|
|
9
|
+
MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2007 - 2015 Michael Twomey
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
14
|
+
copy of this software and associated documentation files (the
|
|
15
|
+
"Software"), to deal in the Software without restriction, including
|
|
16
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
17
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
18
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
19
|
+
the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included
|
|
22
|
+
in all copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
25
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
26
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
27
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
28
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
30
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import time
|
|
35
|
+
import datetime
|
|
36
|
+
from decimal import Decimal
|
|
37
|
+
import sys
|
|
38
|
+
import re
|
|
39
|
+
import zoneinfo
|
|
40
|
+
|
|
41
|
+
__all__ = ["parse_date", "ParseError", "UTC",
|
|
42
|
+
"FixedOffset", "TimeStamp"]
|
|
43
|
+
|
|
44
|
+
if sys.version_info >= (3, 0, 0):
|
|
45
|
+
_basestring = str
|
|
46
|
+
else: # pragma: no cover - Python-2-Altpfad
|
|
47
|
+
_basestring = basestring
|
|
48
|
+
|
|
49
|
+
# Adapted from http://delete.me.uk/2005/03/iso8601.html
|
|
50
|
+
ISO8601_REGEX = re.compile(
|
|
51
|
+
r"""
|
|
52
|
+
(?P<year>[0-9]{4})
|
|
53
|
+
(
|
|
54
|
+
(
|
|
55
|
+
(-(?P<monthdash>[0-9]{1,2}))
|
|
56
|
+
|
|
|
57
|
+
(?P<month>[0-9]{2})
|
|
58
|
+
(?!$) # Don't allow YYYYMM
|
|
59
|
+
)
|
|
60
|
+
(
|
|
61
|
+
(
|
|
62
|
+
(-(?P<daydash>[0-9]{1,2}))
|
|
63
|
+
|
|
|
64
|
+
(?P<day>[0-9]{2})
|
|
65
|
+
)
|
|
66
|
+
(
|
|
67
|
+
(
|
|
68
|
+
(?P<separator>[ T])
|
|
69
|
+
(?P<hour>[0-9]{2})
|
|
70
|
+
(:{0,1}(?P<minute>[0-9]{2})){0,1}
|
|
71
|
+
(
|
|
72
|
+
:{0,1}(?P<second>[0-9]{1,2})
|
|
73
|
+
([.,](?P<second_fraction>[0-9]+)){0,1}
|
|
74
|
+
){0,1}
|
|
75
|
+
(?P<timezone>
|
|
76
|
+
Z
|
|
77
|
+
|
|
|
78
|
+
(
|
|
79
|
+
(?P<tz_sign>[-+])
|
|
80
|
+
(?P<tz_hour>[0-9]{2})
|
|
81
|
+
:{0,1}
|
|
82
|
+
(?P<tz_minute>[0-9]{2}){0,1}
|
|
83
|
+
)
|
|
84
|
+
){0,1}
|
|
85
|
+
){0,1}
|
|
86
|
+
)
|
|
87
|
+
){0,1} # YYYY-MM
|
|
88
|
+
){0,1} # YYYY only
|
|
89
|
+
$
|
|
90
|
+
""",
|
|
91
|
+
re.VERBOSE
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class ParseError(Exception):
|
|
96
|
+
"""Raised when there is a problem parsing a date string"""
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if sys.version_info >= (3, 2, 0):
|
|
100
|
+
UTC = datetime.timezone.utc
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def FixedOffset(offset_hours, offset_minutes, name):
|
|
104
|
+
return datetime.timezone(
|
|
105
|
+
datetime.timedelta(
|
|
106
|
+
hours=offset_hours, minutes=offset_minutes),
|
|
107
|
+
name)
|
|
108
|
+
else: # pragma: no cover - Python <3.2 Altpfad (eigene tzinfo-Klassen)
|
|
109
|
+
# Yoinked from python docs
|
|
110
|
+
ZERO = datetime.timedelta(0)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class Utc(datetime.tzinfo):
|
|
114
|
+
"""UTC Timezone
|
|
115
|
+
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
def utcoffset(self, dt):
|
|
119
|
+
return ZERO
|
|
120
|
+
|
|
121
|
+
def tzname(self, dt):
|
|
122
|
+
return "UTC"
|
|
123
|
+
|
|
124
|
+
def dst(self, dt):
|
|
125
|
+
return ZERO
|
|
126
|
+
|
|
127
|
+
def __repr__(self):
|
|
128
|
+
return "<iso8601.Utc>"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
UTC = Utc()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class FixedOffset(datetime.tzinfo):
|
|
135
|
+
"""Fixed offset in hours and minutes from UTC
|
|
136
|
+
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
def __init__(self, offset_hours, offset_minutes, name):
|
|
140
|
+
self.__offset_hours = offset_hours # Keep for later __getinitargs__
|
|
141
|
+
self.__offset_minutes = offset_minutes # Keep for later __getinitargs__
|
|
142
|
+
self.__offset = datetime.timedelta(
|
|
143
|
+
hours=offset_hours, minutes=offset_minutes)
|
|
144
|
+
self.__name = name
|
|
145
|
+
|
|
146
|
+
def __eq__(self, other):
|
|
147
|
+
if isinstance(other, FixedOffset):
|
|
148
|
+
return (
|
|
149
|
+
(other.__offset == self.__offset)
|
|
150
|
+
and
|
|
151
|
+
(other.__name == self.__name)
|
|
152
|
+
)
|
|
153
|
+
return NotImplemented
|
|
154
|
+
|
|
155
|
+
def __getinitargs__(self):
|
|
156
|
+
return (self.__offset_hours, self.__offset_minutes, self.__name)
|
|
157
|
+
|
|
158
|
+
def utcoffset(self, dt):
|
|
159
|
+
return self.__offset
|
|
160
|
+
|
|
161
|
+
def tzname(self, dt):
|
|
162
|
+
return self.__name
|
|
163
|
+
|
|
164
|
+
def dst(self, dt):
|
|
165
|
+
return ZERO
|
|
166
|
+
|
|
167
|
+
def __repr__(self):
|
|
168
|
+
return "<FixedOffset %r %r>" % (self.__name, self.__offset)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def to_int(d, key, default_to_zero=False, default=None, required=True):
|
|
172
|
+
"""Pull a value from the dict and convert to int
|
|
173
|
+
|
|
174
|
+
:param default_to_zero: If the value is None or empty, treat it as zero
|
|
175
|
+
:param default: If the value is missing in the dict use this default
|
|
176
|
+
|
|
177
|
+
"""
|
|
178
|
+
value = d.get(key) or default
|
|
179
|
+
if (value in ["", None]) and default_to_zero:
|
|
180
|
+
return 0
|
|
181
|
+
if value is None:
|
|
182
|
+
if required:
|
|
183
|
+
raise ParseError("Unable to read %s from %s" % (key, d))
|
|
184
|
+
else:
|
|
185
|
+
return int(value)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def parse_timezone(matches, default_timezone=UTC):
|
|
189
|
+
"""Parses ISO 8601 time zone specs into tzinfo offsets
|
|
190
|
+
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
if matches["timezone"] == "Z":
|
|
194
|
+
return UTC
|
|
195
|
+
# This isn't strictly correct, but it's common to encounter dates without
|
|
196
|
+
# timezones so I'll assume the default (which defaults to UTC).
|
|
197
|
+
# Addresses issue 4.
|
|
198
|
+
if matches["timezone"] is None:
|
|
199
|
+
return default_timezone
|
|
200
|
+
sign = matches["tz_sign"]
|
|
201
|
+
hours = to_int(matches, "tz_hour")
|
|
202
|
+
minutes = to_int(matches, "tz_minute", default_to_zero=True)
|
|
203
|
+
description = "%s%02d:%02d" % (sign, hours, minutes)
|
|
204
|
+
if sign == "-":
|
|
205
|
+
hours = -hours
|
|
206
|
+
minutes = -minutes
|
|
207
|
+
return FixedOffset(hours, minutes, description)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def parse_date(datestring, default_timezone=UTC):
|
|
211
|
+
"""Parses ISO 8601 dates into datetime objects
|
|
212
|
+
|
|
213
|
+
The timezone is parsed from the date string. However it is quite common to
|
|
214
|
+
have dates without a timezone (not strictly correct). In this case the
|
|
215
|
+
default timezone specified in default_timezone is used. This is UTC by
|
|
216
|
+
default.
|
|
217
|
+
|
|
218
|
+
:param datestring: The date to parse as a string
|
|
219
|
+
:param default_timezone: A datetime tzinfo instance to use when no timezone
|
|
220
|
+
is specified in the datestring. If this is set to
|
|
221
|
+
None then a naive datetime object is returned.
|
|
222
|
+
:returns: A datetime.datetime instance
|
|
223
|
+
:raises ParseError: when there is a problem parsing the date or
|
|
224
|
+
constructing the datetime instance.
|
|
225
|
+
|
|
226
|
+
"""
|
|
227
|
+
if not isinstance(datestring, _basestring):
|
|
228
|
+
raise ParseError("Expecting a string %r" % datestring)
|
|
229
|
+
m = ISO8601_REGEX.match(datestring)
|
|
230
|
+
if not m:
|
|
231
|
+
raise ParseError("Unable to parse date string %r" % datestring)
|
|
232
|
+
groups = m.groupdict()
|
|
233
|
+
|
|
234
|
+
tz = parse_timezone(groups, default_timezone=default_timezone)
|
|
235
|
+
|
|
236
|
+
groups["second_fraction"] = int(Decimal("0.%s" % (groups["second_fraction"] or 0)) * Decimal("1000000.0"))
|
|
237
|
+
|
|
238
|
+
try:
|
|
239
|
+
return datetime.datetime(
|
|
240
|
+
year=to_int(groups, "year"),
|
|
241
|
+
month=to_int(groups, "month", default=to_int(groups, "monthdash", required=False, default=1)),
|
|
242
|
+
day=to_int(groups, "day", default=to_int(groups, "daydash", required=False, default=1)),
|
|
243
|
+
hour=to_int(groups, "hour", default_to_zero=True),
|
|
244
|
+
minute=to_int(groups, "minute", default_to_zero=True),
|
|
245
|
+
second=to_int(groups, "second", default_to_zero=True),
|
|
246
|
+
microsecond=groups["second_fraction"],
|
|
247
|
+
tzinfo=tz,
|
|
248
|
+
)
|
|
249
|
+
except Exception as e:
|
|
250
|
+
raise ParseError(e)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def local_tzname():
|
|
254
|
+
"""determine 'Etc/GMT%+d', e.g. 'Etc/GMT-2'"""
|
|
255
|
+
if time.daylight:
|
|
256
|
+
offsetHour = time.altzone / 3600
|
|
257
|
+
else:
|
|
258
|
+
offsetHour = time.timezone / 3600
|
|
259
|
+
return 'Etc/GMT%+d' % offsetHour
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def get_utc_timestamp(dt):
|
|
263
|
+
"""datetime --> 2017-04-26T09:04:00.660000+00:00"""
|
|
264
|
+
if not isinstance(dt, datetime.datetime):
|
|
265
|
+
return
|
|
266
|
+
return dt.astimezone(tz=UTC)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def get_local_timestamp(dt):
|
|
270
|
+
"""datetime --> 2017-04-26T09:04:00.660000+02:00"""
|
|
271
|
+
tzname = local_tzname()
|
|
272
|
+
try:
|
|
273
|
+
tz = zoneinfo.ZoneInfo(tzname)
|
|
274
|
+
except zoneinfo.ZoneInfoNotFoundError: # pragma: no cover - System ohne tz-Datenbank
|
|
275
|
+
return dt.astimezone() # System-Lokalzeit (ohne tzdata)
|
|
276
|
+
return dt.astimezone(tz=tz)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class TimeStamp(object):
|
|
280
|
+
"""2017-04-26T09:04:00.660000+00:00"""
|
|
281
|
+
|
|
282
|
+
def __init__(self, datetimestr=None):
|
|
283
|
+
"""'2017-04-26T09:04:00.660000+00:00' --> datetime"""
|
|
284
|
+
if datetimestr is None:
|
|
285
|
+
self._datetime = datetime.datetime.now(tz=UTC)
|
|
286
|
+
else:
|
|
287
|
+
try:
|
|
288
|
+
self._datetime = parse_date(datetimestr)
|
|
289
|
+
except Exception as exp:
|
|
290
|
+
raise exp
|
|
291
|
+
|
|
292
|
+
def __repr__(self):
|
|
293
|
+
return self._datetime.isoformat()
|
|
294
|
+
|
|
295
|
+
def __str__(self):
|
|
296
|
+
return self._datetime.isoformat()
|
|
297
|
+
|
|
298
|
+
@property
|
|
299
|
+
def utc(self):
|
|
300
|
+
"""returns the utc.isoformat string
|
|
301
|
+
:returns: str"""
|
|
302
|
+
return get_utc_timestamp(self._datetime).isoformat()
|
|
303
|
+
|
|
304
|
+
@property
|
|
305
|
+
def local(self):
|
|
306
|
+
"""returns the datetime isoformat string for the local timezone
|
|
307
|
+
:returns: str"""
|
|
308
|
+
return get_local_timestamp(self._datetime).isoformat()
|
|
309
|
+
|
|
310
|
+
def today_str():
|
|
311
|
+
"""create timestamp for today (utc)
|
|
312
|
+
|
|
313
|
+
:return: '2020-12-11T00:00:00+00:00'
|
|
314
|
+
"""
|
|
315
|
+
today = datetime.datetime.today()
|
|
316
|
+
todaystr = datetime.date(today.year, today.month, today.day).isoformat()
|
|
317
|
+
return TimeStamp(todaystr).utc
|
|
318
|
+
|
|
319
|
+
def now_local_str():
|
|
320
|
+
"""create timestamp for now for local timezone
|
|
321
|
+
|
|
322
|
+
:return: '2020-12-11T00:00:00+00:00'
|
|
323
|
+
"""
|
|
324
|
+
todaystr = datetime.datetime.now().isoformat()
|
|
325
|
+
return TimeStamp(todaystr).local
|
|
326
|
+
|
|
327
|
+
def now_utc_str():
|
|
328
|
+
"""create timestamp for now for utc timezone
|
|
329
|
+
|
|
330
|
+
:return: '2020-12-11T00:00:00+00:00'
|
|
331
|
+
"""
|
|
332
|
+
todaystr = datetime.datetime.now().isoformat()
|
|
333
|
+
return TimeStamp(todaystr).utc
|
|
334
|
+
|
|
335
|
+
if __name__ == '__main__':
|
|
336
|
+
print(now_utc_str())
|
sdata/tools.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# -*-coding: utf-8-*-
|
|
2
|
+
|
|
3
|
+
def col_to_idx(col):
|
|
4
|
+
"""covert xls column to index
|
|
5
|
+
:param col .. column, e.g. 'AA'
|
|
6
|
+
|
|
7
|
+
:returns index, e.g. 26
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
val = lambda i, x: (26**i) * (ord(x.lower()) - ord('a') + 1)
|
|
11
|
+
return sum([val(i, x) for i, x in enumerate(col[::-1])]) - 1
|
|
12
|
+
|
|
13
|
+
if __name__ == '__main__':
|
|
14
|
+
print(col_to_idx("aB"))
|