encommon 0.14.0__py3-none-any.whl → 0.15.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 (51) hide show
  1. encommon/colors/__init__.py +2 -2
  2. encommon/colors/{colors.py → color.py} +24 -24
  3. encommon/colors/test/{test_colors.py → test_color.py} +16 -16
  4. encommon/config/config.py +15 -15
  5. encommon/config/files.py +14 -14
  6. encommon/config/logger.py +6 -6
  7. encommon/config/params.py +47 -30
  8. encommon/config/paths.py +13 -13
  9. encommon/config/test/__init__.py +1 -1
  10. encommon/config/test/test_config.py +10 -16
  11. encommon/config/test/test_files.py +8 -7
  12. encommon/config/test/test_logger.py +11 -10
  13. encommon/config/test/test_paths.py +11 -10
  14. encommon/config/utils.py +2 -2
  15. encommon/crypts/params.py +28 -12
  16. encommon/crypts/test/test_crypts.py +5 -5
  17. encommon/crypts/test/test_hashes.py +2 -1
  18. encommon/times/__init__.py +2 -2
  19. encommon/times/common.py +2 -2
  20. encommon/times/params.py +76 -48
  21. encommon/times/parse.py +3 -3
  22. encommon/times/test/test_duration.py +3 -2
  23. encommon/times/test/test_time.py +123 -0
  24. encommon/times/test/test_timer.py +5 -4
  25. encommon/times/test/test_timers.py +10 -9
  26. encommon/times/test/test_window.py +4 -3
  27. encommon/times/test/test_windows.py +7 -6
  28. encommon/times/{times.py → time.py} +61 -12
  29. encommon/times/timer.py +10 -10
  30. encommon/times/timers.py +3 -3
  31. encommon/times/unitime.py +9 -0
  32. encommon/times/window.py +31 -31
  33. encommon/times/windows.py +10 -10
  34. encommon/types/classes.py +0 -13
  35. encommon/types/lists.py +6 -0
  36. encommon/types/notate.py +2 -1
  37. encommon/types/strings.py +5 -0
  38. encommon/types/test/test_empty.py +2 -1
  39. encommon/utils/sample.py +6 -5
  40. encommon/utils/stdout.py +2 -2
  41. encommon/utils/test/test_paths.py +3 -3
  42. encommon/utils/test/test_sample.py +2 -2
  43. encommon/utils/test/test_stdout.py +3 -3
  44. encommon/version.txt +1 -1
  45. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/METADATA +1 -1
  46. encommon-0.15.0.dist-info/RECORD +84 -0
  47. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/WHEEL +1 -1
  48. encommon/times/test/test_times.py +0 -122
  49. encommon-0.14.0.dist-info/RECORD +0 -84
  50. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/LICENSE +0 -0
  51. {encommon-0.14.0.dist-info → encommon-0.15.0.dist-info}/top_level.txt +0 -0
@@ -24,14 +24,63 @@ from .utils import strftime
24
24
 
25
25
 
26
26
 
27
- class Times:
27
+ class Time:
28
28
  """
29
29
  Interact with various time functions through one wrapper.
30
30
 
31
+ .. testsetup::
32
+ >>> time = Time('1/1/2000 12:00am')
33
+
34
+ Example
35
+ -------
36
+ >>> time = Time('1/1/2000 12:00am')
37
+ >>> time.stamp()
38
+ '2000-01-01T00:00:00.000000+0000'
39
+ >>> time.stamp('%m/%d/%Y')
40
+ '01/01/2000'
41
+
42
+ Example
43
+ -------
44
+ >>> time.epoch
45
+ 946684800.0
46
+ >>> time.time
47
+ datetime.time(0, 0)
48
+ >>> time.simple
49
+ '2000-01-01T00:00:00+0000'
50
+ >>> time.human
51
+ '01/01/2000 12:00AM UTC'
52
+
53
+ Example
54
+ -------
55
+ >>> time.before
56
+ Time('1999-12-31T23:59:59.999999+0000')
57
+ >>> time.after
58
+ Time('2000-01-01T00:00:00.000001+0000')
59
+
60
+ Example
61
+ -------
62
+ >>> time.shift('-1d')
63
+ Time('1999-12-31T00:00:00.000000+0000')
64
+
65
+ Example
66
+ -------
67
+ >>> time.shifz('US/Central')
68
+ Time('1999-12-31T18:00:00.000000-0600')
69
+
70
+ Example
71
+ -------
72
+ >>> time = Time('-1s')
73
+ >>> int(time.since)
74
+ 1
75
+
31
76
  Example
32
77
  -------
33
- >>> Times('1/1/2000 12:00am')
34
- Times('2000-01-01T00:00:00.000000+0000')
78
+ >>> time1 = Time('1/1/2000 12:00am')
79
+ >>> time2 = Time('1/1/2000 12:00am')
80
+ >>> time1 - time2
81
+ 0.0
82
+ >>> time1 + time2
83
+ 1893369600.0
35
84
 
36
85
  :param source: Time in various forms that will be parsed.
37
86
  :param anchor: Optional relative time; for snap notation.
@@ -73,7 +122,7 @@ class Times:
73
122
  :returns: String representation for values from instance.
74
123
  """
75
124
 
76
- return f"Times('{self.subsec}')"
125
+ return f"Time('{self.subsec}')"
77
126
 
78
127
 
79
128
  def __hash__(
@@ -398,7 +447,7 @@ class Times:
398
447
  @property
399
448
  def before(
400
449
  self,
401
- ) -> 'Times':
450
+ ) -> 'Time':
402
451
  """
403
452
  Return new object containing time just before the time.
404
453
 
@@ -410,13 +459,13 @@ class Times:
410
459
  source -= timedelta(
411
460
  microseconds=1)
412
461
 
413
- return Times(source)
462
+ return Time(source)
414
463
 
415
464
 
416
465
  @property
417
466
  def after(
418
467
  self,
419
- ) -> 'Times':
468
+ ) -> 'Time':
420
469
  """
421
470
  Return new object containing time just after the time.
422
471
 
@@ -428,7 +477,7 @@ class Times:
428
477
  source += timedelta(
429
478
  microseconds=1)
430
479
 
431
- return Times(source)
480
+ return Time(source)
432
481
 
433
482
 
434
483
  def stamp(
@@ -462,7 +511,7 @@ class Times:
462
511
  def shift(
463
512
  self,
464
513
  notate: str,
465
- ) -> 'Times':
514
+ ) -> 'Time':
466
515
  """
467
516
  Return the new instance of object shifted using snaptime.
468
517
 
@@ -472,14 +521,14 @@ class Times:
472
521
 
473
522
  source = self.__source
474
523
 
475
- return Times(
524
+ return Time(
476
525
  notate, anchor=source)
477
526
 
478
527
 
479
528
  def shifz(
480
529
  self,
481
530
  tzname: str,
482
- ) -> 'Times':
531
+ ) -> 'Time':
483
532
  """
484
533
  Return the new instance of object shifted using datetime.
485
534
 
@@ -498,5 +547,5 @@ class Times:
498
547
  source
499
548
  .astimezone(tzinfo))
500
549
 
501
- return Times(
550
+ return Time(
502
551
  source, tzname=tzname)
encommon/times/timer.py CHANGED
@@ -11,7 +11,7 @@ from typing import Optional
11
11
 
12
12
  from .common import NUMERIC
13
13
  from .common import PARSABLE
14
- from .times import Times
14
+ from .time import Time
15
15
 
16
16
 
17
17
 
@@ -36,7 +36,7 @@ class Timer:
36
36
  """
37
37
 
38
38
  __timer: float
39
- __times: Times
39
+ __time: Time
40
40
 
41
41
 
42
42
  def __init__(
@@ -50,10 +50,10 @@ class Timer:
50
50
  """
51
51
 
52
52
  timer = float(timer)
53
- start = Times(start)
53
+ start = Time(start)
54
54
 
55
55
  self.__timer = timer
56
- self.__times = start
56
+ self.__time = start
57
57
 
58
58
 
59
59
  @property
@@ -70,16 +70,16 @@ class Timer:
70
70
 
71
71
 
72
72
  @property
73
- def times(
73
+ def time(
74
74
  self,
75
- ) -> Times:
75
+ ) -> Time:
76
76
  """
77
77
  Return the value for the attribute from class instance.
78
78
 
79
79
  :returns: Value for the attribute from class instance.
80
80
  """
81
81
 
82
- return self.__times
82
+ return self.__time
83
83
 
84
84
 
85
85
  @property
@@ -92,7 +92,7 @@ class Timer:
92
92
  :returns: Seconds that have elapsed since the interval.
93
93
  """
94
94
 
95
- return self.times.since
95
+ return self.time.since
96
96
 
97
97
 
98
98
  @property
@@ -141,7 +141,7 @@ class Timer:
141
141
  :param value: Override the time updated for timer value.
142
142
  """
143
143
 
144
- value = Times(
144
+ value = Time(
145
145
  value or 'now')
146
146
 
147
- self.__times = value
147
+ self.__time = value
encommon/times/timers.py CHANGED
@@ -21,8 +21,8 @@ from sqlalchemy.orm import sessionmaker
21
21
 
22
22
  from .common import PARSABLE
23
23
  from .params import TimersParams
24
+ from .time import Time
24
25
  from .timer import Timer
25
- from .times import Times
26
26
 
27
27
  if TYPE_CHECKING:
28
28
  from .params import TimerParams
@@ -322,12 +322,12 @@ class Timers:
322
322
 
323
323
  for unique, timer in items:
324
324
 
325
- update = Times('now')
325
+ update = Time('now')
326
326
 
327
327
  append = TimersTable(
328
328
  group=group,
329
329
  unique=unique,
330
- last=timer.times.subsec,
330
+ last=timer.time.subsec,
331
331
  update=update.subsec)
332
332
 
333
333
  session.merge(append)
encommon/times/unitime.py CHANGED
@@ -19,6 +19,15 @@ def unitime(
19
19
  """
20
20
  Return the seconds in integer format for provided input.
21
21
 
22
+ Example
23
+ -------
24
+ >>> unitime('1d')
25
+ 86400
26
+ >>> unitime('1y')
27
+ 31536000
28
+ >>> unitime('1w3d4h')
29
+ 878400
30
+
22
31
  :param input: Input that will be converted into seconds.
23
32
  :returns: Seconds in integer format for provided input.
24
33
  """
encommon/times/window.py CHANGED
@@ -17,7 +17,7 @@ from croniter import croniter
17
17
  from .common import PARSABLE
18
18
  from .common import SCHEDULE
19
19
  from .parse import parse_time
20
- from .times import Times
20
+ from .time import Time
21
21
 
22
22
 
23
23
 
@@ -42,13 +42,13 @@ class Window:
42
42
  """
43
43
 
44
44
  __window: SCHEDULE
45
- __start: Times
46
- __stop: Times
47
- __anchor: Times
45
+ __start: Time
46
+ __stop: Time
47
+ __anchor: Time
48
48
  __delay: float
49
49
 
50
- __wlast: Times
51
- __wnext: Times
50
+ __wlast: Time
51
+ __wnext: Time
52
52
 
53
53
 
54
54
  def __init__(
@@ -67,9 +67,9 @@ class Window:
67
67
  anchor = anchor or start
68
68
 
69
69
  window = copy(window)
70
- start = Times(start)
71
- stop = Times(stop)
72
- anchor = Times(anchor)
70
+ start = Time(start)
71
+ stop = Time(stop)
72
+ anchor = Time(anchor)
73
73
  delay = float(delay)
74
74
 
75
75
  assert stop > start
@@ -114,40 +114,40 @@ class Window:
114
114
  @property
115
115
  def start(
116
116
  self,
117
- ) -> Times:
117
+ ) -> Time:
118
118
  """
119
119
  Return the value for the attribute from class instance.
120
120
 
121
121
  :returns: Value for the attribute from class instance.
122
122
  """
123
123
 
124
- return Times(self.__start)
124
+ return Time(self.__start)
125
125
 
126
126
 
127
127
  @property
128
128
  def stop(
129
129
  self,
130
- ) -> Times:
130
+ ) -> Time:
131
131
  """
132
132
  Return the value for the attribute from class instance.
133
133
 
134
134
  :returns: Value for the attribute from class instance.
135
135
  """
136
136
 
137
- return Times(self.__stop)
137
+ return Time(self.__stop)
138
138
 
139
139
 
140
140
  @property
141
141
  def anchor(
142
142
  self,
143
- ) -> Times:
143
+ ) -> Time:
144
144
  """
145
145
  Return the value for the attribute from class instance.
146
146
 
147
147
  :returns: Value for the attribute from class instance.
148
148
  """
149
149
 
150
- return Times(self.__anchor)
150
+ return Time(self.__anchor)
151
151
 
152
152
 
153
153
  @property
@@ -166,51 +166,51 @@ class Window:
166
166
  @property
167
167
  def last(
168
168
  self,
169
- ) -> Times:
169
+ ) -> Time:
170
170
  """
171
171
  Return the value for the attribute from class instance.
172
172
 
173
173
  :returns: Value for the attribute from class instance.
174
174
  """
175
175
 
176
- return Times(self.__wlast)
176
+ return Time(self.__wlast)
177
177
 
178
178
 
179
179
  @property
180
180
  def next(
181
181
  self,
182
- ) -> Times:
182
+ ) -> Time:
183
183
  """
184
184
  Return the value for the attribute from class instance.
185
185
 
186
186
  :returns: Value for the attribute from class instance.
187
187
  """
188
188
 
189
- return Times(self.__wnext)
189
+ return Time(self.__wnext)
190
190
 
191
191
 
192
192
  @property
193
193
  def soonest(
194
194
  self,
195
- ) -> Times:
195
+ ) -> Time:
196
196
  """
197
197
  Return the value for the attribute from class instance.
198
198
 
199
199
  :returns: Value for the attribute from class instance.
200
200
  """
201
- return Times(Times() - self.delay)
201
+ return Time(Time() - self.delay)
202
202
 
203
203
 
204
204
  @property
205
205
  def latest(
206
206
  self,
207
- ) -> Times:
207
+ ) -> Time:
208
208
  """
209
209
  Return the value for the attribute from class instance.
210
210
 
211
211
  :returns: Value for the attribute from class instance.
212
212
  """
213
- return Times(self.stop - self.delay)
213
+ return Time(self.stop - self.delay)
214
214
 
215
215
 
216
216
  @property
@@ -230,7 +230,7 @@ class Window:
230
230
  self,
231
231
  anchor: PARSABLE,
232
232
  backward: bool = False,
233
- ) -> tuple[Times, Times]:
233
+ ) -> tuple[Time, Time]:
234
234
  """
235
235
  Determine next and last windows for window using anchor.
236
236
 
@@ -299,7 +299,7 @@ class Window:
299
299
  :param value: Override the time updated for window value.
300
300
  """
301
301
 
302
- value = Times(
302
+ value = Time(
303
303
  value or 'now')
304
304
 
305
305
  wlast, wnext = (
@@ -314,7 +314,7 @@ def window_croniter( # noqa: CFQ004
314
314
  schedule: str,
315
315
  anchor: PARSABLE,
316
316
  backward: bool = False,
317
- ) -> tuple[Times, Times]:
317
+ ) -> tuple[Time, Time]:
318
318
  """
319
319
  Determine next and previous times for cronjob schedule.
320
320
 
@@ -365,8 +365,8 @@ def window_croniter( # noqa: CFQ004
365
365
 
366
366
 
367
367
  return (
368
- Times(wlast),
369
- Times(wnext))
368
+ Time(wlast),
369
+ Time(wnext))
370
370
 
371
371
 
372
372
 
@@ -374,7 +374,7 @@ def window_interval(
374
374
  schedule: dict[str, int],
375
375
  anchor: PARSABLE,
376
376
  backward: bool = False,
377
- ) -> tuple[Times, Times]:
377
+ ) -> tuple[Time, Time]:
378
378
  """
379
379
  Determine next and previous times for interval schedule.
380
380
 
@@ -403,5 +403,5 @@ def window_interval(
403
403
 
404
404
 
405
405
  return (
406
- Times(wlast),
407
- Times(wnext))
406
+ Time(wlast),
407
+ Time(wnext))
encommon/times/windows.py CHANGED
@@ -21,7 +21,7 @@ from sqlalchemy.orm import sessionmaker
21
21
 
22
22
  from .common import PARSABLE
23
23
  from .params import WindowsParams
24
- from .times import Times
24
+ from .time import Time
25
25
  from .window import Window
26
26
 
27
27
  if TYPE_CHECKING:
@@ -114,8 +114,8 @@ class Windows:
114
114
  # pylint: disable=unsubscriptable-object
115
115
  sessionmaker[Session])
116
116
 
117
- __start: Times
118
- __stop: Times
117
+ __start: Time
118
+ __stop: Time
119
119
 
120
120
  __windows: WINDOWS
121
121
 
@@ -147,8 +147,8 @@ class Windows:
147
147
  self.__make_engine()
148
148
 
149
149
 
150
- start = Times(start)
151
- stop = Times(stop)
150
+ start = Time(start)
151
+ stop = Time(stop)
152
152
 
153
153
  assert stop > start
154
154
 
@@ -249,27 +249,27 @@ class Windows:
249
249
  @property
250
250
  def start(
251
251
  self,
252
- ) -> Times:
252
+ ) -> Time:
253
253
  """
254
254
  Return the value for the attribute from class instance.
255
255
 
256
256
  :returns: Value for the attribute from class instance.
257
257
  """
258
258
 
259
- return Times(self.__start)
259
+ return Time(self.__start)
260
260
 
261
261
 
262
262
  @property
263
263
  def stop(
264
264
  self,
265
- ) -> Times:
265
+ ) -> Time:
266
266
  """
267
267
  Return the value for the attribute from class instance.
268
268
 
269
269
  :returns: Value for the attribute from class instance.
270
270
  """
271
271
 
272
- return Times(self.__stop)
272
+ return Time(self.__stop)
273
273
 
274
274
 
275
275
  @property
@@ -386,7 +386,7 @@ class Windows:
386
386
 
387
387
  for unique, window in items:
388
388
 
389
- update = Times('now')
389
+ update = Time('now')
390
390
 
391
391
  append = WindowsTable(
392
392
  group=group,
encommon/types/classes.py CHANGED
@@ -7,8 +7,6 @@ is permitted, for more information consult the project license file.
7
7
 
8
8
 
9
9
 
10
- from typing import Any
11
-
12
10
  from pydantic import BaseModel as Pydantic
13
11
 
14
12
  from .types import DictStrAny
@@ -23,17 +21,6 @@ class BaseModel(Pydantic, extra='forbid'):
23
21
  """
24
22
 
25
23
 
26
- def __init__(
27
- self,
28
- **data: Any,
29
- ) -> None:
30
- """
31
- Initialize instance for class using provided parameters.
32
- """
33
-
34
- super().__init__(**data)
35
-
36
-
37
24
  @property
38
25
  def model_dumped(
39
26
  self,
encommon/types/lists.py CHANGED
@@ -19,6 +19,12 @@ def inlist(
19
19
  """
20
20
  Return the boolean indicating whether needle in haystack.
21
21
 
22
+ Example
23
+ -------
24
+ >>> haystack = [1, 2, 3]
25
+ >>> inlist(2, haystack)
26
+ True
27
+
22
28
  :param needle: Provided item that may be within haystack.
23
29
  :param haystack: List of items which may contain needle.
24
30
  :returns: Boolean indicating whether needle in haystack.
encommon/types/notate.py CHANGED
@@ -15,6 +15,7 @@ from typing import Optional
15
15
  from typing import Union
16
16
 
17
17
  from .empty import Empty
18
+ from .types import DictStrAny
18
19
 
19
20
 
20
21
 
@@ -25,7 +26,7 @@ _RECURSE = dict
25
26
 
26
27
 
27
28
  _SETABLE = Union[
28
- dict[str, Any],
29
+ DictStrAny,
29
30
  list[Any]]
30
31
 
31
32
  _GETABLE = Union[
encommon/types/strings.py CHANGED
@@ -121,6 +121,11 @@ def rplstr(
121
121
  """
122
122
  Return the source string with the match value replaced.
123
123
 
124
+ Example
125
+ -------
126
+ >>> rplstr('foo', 'foo', 'bar')
127
+ 'bar'
128
+
124
129
  :param source: String that to be processed and returned.
125
130
  :param match: What will be replaced within the string.
126
131
  :param value: Replace value for the string is matched.
@@ -10,6 +10,7 @@ is permitted, for more information consult the project license file.
10
10
  from copy import copy
11
11
  from copy import deepcopy
12
12
 
13
+ from ..classes import lattrs
13
14
  from ..empty import Empty
14
15
  from ..empty import EmptyType
15
16
 
@@ -23,7 +24,7 @@ def test_EmptyType() -> None:
23
24
  empty = EmptyType()
24
25
 
25
26
 
26
- attrs = list(empty.__dict__)
27
+ attrs = lattrs(empty)
27
28
 
28
29
  assert attrs == [
29
30
  '_EmptyType__empty']
encommon/utils/sample.py CHANGED
@@ -20,6 +20,7 @@ from pydantic import BaseModel
20
20
 
21
21
  from .files import read_text
22
22
  from .files import save_text
23
+ from ..types import DictStrAny
23
24
  from ..types import rplstr
24
25
 
25
26
 
@@ -35,7 +36,7 @@ def prep_sample( # noqa: CFQ004
35
36
  content: Any,
36
37
  *,
37
38
  default: Callable[[Any], str] = str,
38
- replace: Optional[dict[str, Any]] = None,
39
+ replace: Optional[DictStrAny] = None,
39
40
  indent: Optional[int] = 2,
40
41
  ) -> str:
41
42
  r"""
@@ -61,7 +62,7 @@ def prep_sample( # noqa: CFQ004
61
62
 
62
63
  def _default(
63
64
  value: Any, # noqa: ANN401
64
- ) -> dict[str, Any] | str:
65
+ ) -> DictStrAny | str:
65
66
 
66
67
  if is_dataclass(value):
67
68
 
@@ -104,7 +105,7 @@ def load_sample(
104
105
  update: bool = False,
105
106
  *,
106
107
  default: Callable[[Any], str] = str,
107
- replace: Optional[dict[str, Any]] = None,
108
+ replace: Optional[DictStrAny] = None,
108
109
  ) -> str:
109
110
  r"""
110
111
  Load the sample file and compare using provided content.
@@ -173,7 +174,7 @@ def load_sample(
173
174
  def read_sample(
174
175
  sample: str,
175
176
  *,
176
- replace: Optional[dict[str, Any]] = None,
177
+ replace: Optional[DictStrAny] = None,
177
178
  prefix: bool = True,
178
179
  ) -> str:
179
180
  """
@@ -204,7 +205,7 @@ def read_sample(
204
205
  def rvrt_sample(
205
206
  sample: str,
206
207
  *,
207
- replace: Optional[dict[str, Any]] = None,
208
+ replace: Optional[DictStrAny] = None,
208
209
  ) -> str:
209
210
  """
210
211
  Return the content after processing as the sample value.
encommon/utils/stdout.py CHANGED
@@ -23,7 +23,7 @@ from pydantic import BaseModel
23
23
 
24
24
  from .common import JOINABLE
25
25
  from ..times import Duration
26
- from ..times import Times
26
+ from ..times import Time
27
27
  from ..types import Empty
28
28
  from ..types import clsname
29
29
  from ..types.strings import COMMAD
@@ -287,7 +287,7 @@ def array_ansi( # noqa: CFQ001, CFQ004
287
287
  elif isinstance(source, Duration):
288
288
  color = colors.times
289
289
 
290
- elif isinstance(source, Times):
290
+ elif isinstance(source, Time):
291
291
  color = colors.times
292
292
 
293
293
  elif source is Empty: