datatypes 0.31.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.
Files changed (53) hide show
  1. datatypes/__init__.py +169 -0
  2. datatypes/collections/__init__.py +25 -0
  3. datatypes/collections/container.py +248 -0
  4. datatypes/collections/mapping.py +1226 -0
  5. datatypes/collections/sequence.py +311 -0
  6. datatypes/command.py +596 -0
  7. datatypes/compat.py +206 -0
  8. datatypes/config/__init__.py +13 -0
  9. datatypes/config/environ/__init__.py +33 -0
  10. datatypes/config/environ/base.py +332 -0
  11. datatypes/config/environ/token.py +173 -0
  12. datatypes/config/parser.py +256 -0
  13. datatypes/config/settings.py +352 -0
  14. datatypes/copy.py +151 -0
  15. datatypes/csv.py +547 -0
  16. datatypes/datetime.py +1243 -0
  17. datatypes/decorators/__init__.py +31 -0
  18. datatypes/decorators/base.py +449 -0
  19. datatypes/decorators/descriptor.py +490 -0
  20. datatypes/decorators/misc.py +152 -0
  21. datatypes/email.py +439 -0
  22. datatypes/enum.py +176 -0
  23. datatypes/event.py +299 -0
  24. datatypes/exception.py +13 -0
  25. datatypes/filetypes/__init__.py +10 -0
  26. datatypes/filetypes/html.py +540 -0
  27. datatypes/filetypes/toml.py +275 -0
  28. datatypes/http.py +1443 -0
  29. datatypes/logging.py +475 -0
  30. datatypes/number.py +586 -0
  31. datatypes/parse.py +362 -0
  32. datatypes/path.py +4358 -0
  33. datatypes/profile.py +246 -0
  34. datatypes/reflection/__init__.py +24 -0
  35. datatypes/reflection/inspect.py +3475 -0
  36. datatypes/reflection/other.py +843 -0
  37. datatypes/reflection/path.py +639 -0
  38. datatypes/server.py +642 -0
  39. datatypes/service.py +212 -0
  40. datatypes/ssh.py +812 -0
  41. datatypes/string.py +1632 -0
  42. datatypes/token/__init__.py +16 -0
  43. datatypes/token/abnf.py +1696 -0
  44. datatypes/token/base.py +921 -0
  45. datatypes/token/word.py +259 -0
  46. datatypes/typing.py +126 -0
  47. datatypes/url.py +988 -0
  48. datatypes/utils.py +179 -0
  49. datatypes-0.31.0.dist-info/METADATA +38 -0
  50. datatypes-0.31.0.dist-info/RECORD +53 -0
  51. datatypes-0.31.0.dist-info/WHEEL +5 -0
  52. datatypes-0.31.0.dist-info/licenses/LICENSE.txt +21 -0
  53. datatypes-0.31.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,311 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ List like objects
4
+
5
+ https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence
6
+ """
7
+ import bisect
8
+
9
+ from ..compat import *
10
+
11
+
12
+ # class FrozenList(list): # a read only list that can only be set via constructor
13
+
14
+
15
+ class AppendList(list):
16
+ """A READ ONLY list that does all adding of items through the append method
17
+ To customize this list just extend the append() method
18
+
19
+ https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
20
+ """
21
+ def __init__(self, iterable=None):
22
+ """
23
+ https://docs.python.org/3/library/stdtypes.html?highlight=list#list
24
+ """
25
+ super().__init__()
26
+
27
+ if iterable:
28
+ self.extend(iterable)
29
+
30
+ def append(self, x):
31
+ return super().append(x)
32
+
33
+ def extend(self, iterable):
34
+ for x in iterable:
35
+ self.append(x)
36
+
37
+ def pop(self, i):
38
+ raise NotImplementedError()
39
+ def insert(self, i, x):
40
+ raise NotImplementedError()
41
+ def __setitem__(self, i, x):
42
+ raise NotImplementedError()
43
+ def __delitem__(self, i):
44
+ raise NotImplementedError()
45
+ def remove(self, x):
46
+ raise NotImplementedError()
47
+
48
+
49
+ class SortedList(list):
50
+ """Keep a list sorted as you append or extend it
51
+
52
+ A sorted list, this sorts items from smallest to largest using key, so
53
+ if you want MaxQueue like functionality use negative values: .pop(-1) and
54
+ if you want MinQueue like functionality use positive values: .pop(0)
55
+
56
+ :Example:
57
+ # max sorted list
58
+ sl = SortedList(key=lambda x: -x, maxsize=3)
59
+ sl.extend([5, 10, 1, 4, 16, 20, 25])
60
+ print(sl) # [25, 20, 16]
61
+
62
+ https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
63
+ """
64
+ def __init__(self, iterable=None, key=None, maxsize=None):
65
+ """
66
+ :param iterable: Sequence, the initial values
67
+ :param key: Callable[[Any], Any], this takes in the item and returns
68
+ the value used for sorting
69
+ :param maxsize: int, the maximum number of items the list can have
70
+ """
71
+ if key:
72
+ self.key = key
73
+
74
+ self.maxsize = maxsize if (maxsize and maxsize > 0) else None
75
+
76
+ super().__init__()
77
+ if iterable:
78
+ for x in iterable:
79
+ self.append(x)
80
+
81
+ def key(self, x):
82
+ """Returns the key that will be used to order x
83
+
84
+ You can override this method to customize ordering
85
+
86
+ :param x: Any, the object being inserted
87
+ :returns: str|int|Any, the hashable object that will be used for
88
+ ordering
89
+ """
90
+ return x
91
+
92
+ def inserted(self, i, x):
93
+ """Called after x is inserted at position i
94
+
95
+ This is handy if you want to do some post insertion manipulation of
96
+ the list
97
+
98
+ :param i: int, the position x was inserted in the list, will be None
99
+ if x was inserted at the end of the list
100
+ :param x: Any, the object inserted into the list
101
+ """
102
+ if self.maxsize:
103
+ if len(self) > self.maxsize:
104
+ self.pop(-1)
105
+
106
+ def append(self, x):
107
+ # https://docs.python.org/3/library/bisect.html#bisect.bisect_right
108
+ i = bisect.bisect_right(self, self.key(x), key=self.key)
109
+ if i is None:
110
+ super().append(x)
111
+
112
+ else:
113
+ super().insert(i, x)
114
+
115
+ self.inserted(i, x)
116
+
117
+ def extend(self, iterable):
118
+ for x in iterable:
119
+ self.append(x)
120
+
121
+ def __reversed__(self):
122
+ index = len(self)
123
+ while index > 0:
124
+ index -= 1
125
+ yield self[index]
126
+
127
+ def insert(self, i, x):
128
+ raise NotImplementedError()
129
+ def __setitem__(self, i, x):
130
+ raise NotImplementedError()
131
+ def reverse(self):
132
+ raise NotImplementedError()
133
+ def sort(self):
134
+ raise NotImplementedError()
135
+
136
+ def full(self):
137
+ """
138
+ https://docs.python.org/3/library/queue.html#queue.Queue.full
139
+ """
140
+ return len(self) == self.maxsize
141
+
142
+ def empty(self):
143
+ """
144
+ https://docs.python.org/3/library/queue.html#queue.Queue.empty
145
+ """
146
+ return len(self) == 0
147
+
148
+
149
+ class Stack(list):
150
+ """An incredibly simple stack implementation"""
151
+ def push(self, v):
152
+ self.append(v)
153
+
154
+ def pop(self):
155
+ return super().pop(-1)
156
+
157
+ def peek(self):
158
+ return self[-1]
159
+
160
+ def __iter__(self):
161
+ """By default stacks are LIFO"""
162
+ for i in reversed(range(0, len(self))):
163
+ yield self[i]
164
+
165
+ def __reversed__(self):
166
+ """calling reverse on a stack would switch to normal list FIFO"""
167
+ return super().__iter__()
168
+
169
+ def insert(self, i, x):
170
+ raise NotImplementedError()
171
+ def __setitem__(self, i, x):
172
+ raise NotImplementedError()
173
+ def __delitem__(self, i):
174
+ raise NotImplementedError()
175
+ def reverse(self):
176
+ raise NotImplementedError()
177
+ def sort(self):
178
+ raise NotImplementedError()
179
+ def remove(self, x):
180
+ raise NotImplementedError()
181
+
182
+
183
+ class ListIterator(list):
184
+ """A base interface for iterators that should quack like a builtin list
185
+
186
+ it defines the list interface as much as possible
187
+
188
+ Taken from prom.query.BaseIterator on 12-15-2020
189
+
190
+ list interface methods:
191
+ https://docs.python.org/3/tutorial/datastructures.html#more-on-lists
192
+
193
+ http://docs.python.org/2/library/stdtypes.html#iterator-types
194
+ """
195
+ def __init__(self, *args, **kwargs):
196
+ super().__init__(*args, **kwargs)
197
+
198
+ def __next__(self):
199
+ """needed for py3 api compatibility"""
200
+ return self.next()
201
+
202
+ def __iter__(self):
203
+ return self
204
+
205
+ def __nonzero__(self):
206
+ return self.__bool__()
207
+
208
+ def __bool__(self):
209
+ for _ in self:
210
+ return True
211
+ return False
212
+
213
+ def __len__(self):
214
+ return self.count()
215
+
216
+ def __deepcopy__(self, *args, **kwargs):
217
+ return self.copy()
218
+
219
+ def __getslice__(self, i, j):
220
+ """required for slicing in python 2 when extending built-in types like list
221
+
222
+ https://docs.python.org/2/reference/datamodel.html#object.__getslice__
223
+ https://stackoverflow.com/questions/2936863/implementing-slicing-in-getitem#comment39878974_2936876
224
+ """
225
+ return self.__getitem__(slice(i, j))
226
+
227
+ def __reversed__(self):
228
+ it = self.copy()
229
+ it.reverse()
230
+ return it
231
+
232
+ def __iter__(self):
233
+ return self
234
+
235
+ def __getitem__(self, i):
236
+ if isinstance(i, slice):
237
+ return self.get_slice(i)
238
+
239
+ else:
240
+ return self.get_index(i)
241
+
242
+ def get_slice(self, s):
243
+ """s is a slice object
244
+
245
+ * s.start - lower bound
246
+ * s.stop - uppder bound
247
+ * s.step - step value
248
+
249
+ Any property of the slice instance can be None:
250
+
251
+ * [:N:N] - start is None
252
+ * [N:] - stop and step are None
253
+ * [:N] - start and step are None
254
+ * [N:N] - step is None
255
+ * [N::N] - stop and step are None
256
+
257
+ slice objects are described here: https://docs.python.org/3/reference/datamodel.html
258
+ under section 3.2 in the "slice objects" section
259
+ """
260
+ raise NotImplementedError()
261
+
262
+ def get_index(self, i):
263
+ raise NotImplementedError()
264
+
265
+ def next(self):
266
+ raise NotImplementedError()
267
+
268
+ def count(self):
269
+ """list interface compatibility"""
270
+ raise NotImplementedError()
271
+
272
+ def reverse(self):
273
+ """list interface compatibility"""
274
+ raise NotImplementedError()
275
+
276
+ def sort(self, *args, **kwargs):
277
+ """list interface compatibility"""
278
+ raise NotImplementedError()
279
+
280
+ def copy(self):
281
+ """list interface compatibility"""
282
+ raise NotImplementedError()
283
+
284
+ def index(self, x, start=None, end=None):
285
+ """list interface compatibility"""
286
+ raise NotImplementedError()
287
+
288
+ def append(self, x):
289
+ """list interface compatibility"""
290
+ raise NotImplementedError()
291
+
292
+ def extend(self, iterable):
293
+ """list interface compatibility"""
294
+ raise NotImplementedError()
295
+
296
+ def remove(self, x):
297
+ """list interface compatibility"""
298
+ raise NotImplementedError()
299
+
300
+ def pop(self, i=-1):
301
+ """list interface compatibility"""
302
+ raise NotImplementedError()
303
+
304
+ def clear(self):
305
+ """list interface compatibility"""
306
+ raise NotImplementedError()
307
+
308
+ def insert(self, i, x):
309
+ """list interface compatibility"""
310
+ raise NotImplementedError()
311
+