aspyx 1.5.2__py3-none-any.whl → 1.5.3__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 aspyx might be problematic. Click here for more details.

aspyx/di/aop/aop.py CHANGED
@@ -14,7 +14,7 @@ from enum import auto, Enum
14
14
  from typing import Optional, Dict, Type, Callable
15
15
 
16
16
  from aspyx.reflection import Decorators, TypeDescriptor
17
- from aspyx.di import injectable, order, Providers, ClassInstanceProvider, Environment, PostProcessor
17
+ from aspyx.di import injectable, order, Environment, PostProcessor
18
18
 
19
19
  class AOPException(Exception):
20
20
  """
@@ -197,25 +197,25 @@ class ClassAspectTarget(AspectTarget):
197
197
  #descriptor = TypeDescriptor.for_type(func)
198
198
  # type
199
199
 
200
- if len(self.types) > 0:
200
+ if self.types:
201
201
  if next((type for type in self.types if issubclass(clazz, type)), None) is None:
202
202
  return False
203
203
 
204
204
  # decorators
205
205
 
206
- if len(self.decorators) > 0:
206
+ if self.decorators:
207
207
  if next((decorator for decorator in self.decorators if class_descriptor.has_decorator(decorator)), None) is None:
208
208
  return False
209
209
 
210
210
  # names
211
211
 
212
- if len(self.names) > 0:
212
+ if self.names:
213
213
  if next((name for name in self.names if name == clazz.__name__), None) is None:
214
214
  return False
215
215
 
216
216
  # patterns
217
217
 
218
- if len(self.patterns) > 0:
218
+ if self.patterns:
219
219
  if next((pattern for pattern in self.patterns if re.fullmatch(pattern, clazz.__name__) is not None), None) is None:
220
220
  return False
221
221
 
@@ -245,7 +245,7 @@ class MethodAspectTarget(AspectTarget):
245
245
 
246
246
  # classes
247
247
 
248
- if len(self.belonging_to) > 0:
248
+ if self.belonging_to:
249
249
  match = False
250
250
  for classes in self.belonging_to:
251
251
  if classes._matches(clazz, func):
@@ -262,25 +262,25 @@ class MethodAspectTarget(AspectTarget):
262
262
 
263
263
  # type
264
264
 
265
- if len(self.types) > 0:
265
+ if self.types:
266
266
  if next((type for type in self.types if issubclass(clazz, type)), None) is None:
267
267
  return False
268
268
 
269
269
  # decorators
270
270
 
271
- if len(self.decorators) > 0:
271
+ if self.decorators:
272
272
  if next((decorator for decorator in self.decorators if method_descriptor.has_decorator(decorator)), None) is None:
273
273
  return False
274
274
 
275
275
  # names
276
276
 
277
- if len(self.names) > 0:
277
+ if self.names:
278
278
  if next((name for name in self.names if name == func.__name__), None) is None:
279
279
  return False
280
280
 
281
281
  # patterns
282
282
 
283
- if len(self.patterns) > 0:
283
+ if self.patterns:
284
284
  if next((pattern for pattern in self.patterns if re.fullmatch(pattern, func.__name__) is not None), None) is None:
285
285
  return False
286
286
 
@@ -474,7 +474,7 @@ class Invocation:
474
474
  """
475
475
  Proceed to the next aspect in the around chain up to the original method.
476
476
  """
477
- if len(args) > 0 or len(kwargs) > 0: # as soon as we have args, we replace the current ones
477
+ if args or kwargs: # as soon as we have args, we replace the current ones
478
478
  self.args = args
479
479
  self.kwargs = kwargs
480
480
 
@@ -486,7 +486,7 @@ class Invocation:
486
486
  """
487
487
  Proceed to the next aspect in the around chain up to the original method.
488
488
  """
489
- if len(args) > 0 or len(kwargs) > 0: # as soon as we have args, we replace the current ones
489
+ if args or kwargs: # as soon as we have args, we replace the current ones
490
490
  self.args = args
491
491
  self.kwargs = kwargs
492
492
 
@@ -575,7 +575,7 @@ class Advices:
575
575
  afters = cls.collect(clazz, member, AspectType.AFTER, environment)
576
576
  errors = cls.collect(clazz, member, AspectType.ERROR, environment)
577
577
 
578
- if len(befores) > 0 or len(arounds) > 0 or len(afters) > 0 or len(errors) > 0:
578
+ if befores or arounds or afters or errors:
579
579
  return Aspects(
580
580
  before=befores,
581
581
  around=arounds,
@@ -160,7 +160,7 @@ class ExceptionManager:
160
160
  for i in range(0, len(chain) - 1):
161
161
  chain[i].next = chain[i + 1]
162
162
 
163
- if len(chain) > 0:
163
+ if chain:
164
164
  return chain[0]
165
165
  else:
166
166
  return None
@@ -2,9 +2,11 @@
2
2
  A module with threading related utilities
3
3
  """
4
4
  from .thread_local import ThreadLocal
5
+ from .context_local import ContextLocal
5
6
 
6
7
  imports = [ThreadLocal]
7
8
 
8
9
  __all__ = [
9
10
  "ThreadLocal",
11
+ "ContextLocal",
10
12
  ]
@@ -0,0 +1,48 @@
1
+ import contextvars
2
+ from contextlib import contextmanager
3
+ from typing import Generic, Optional, TypeVar, Any
4
+
5
+ T = TypeVar("T")
6
+
7
+ class ContextLocal(Generic[T]):
8
+ """
9
+ A context local value holder
10
+ """
11
+ # constructor
12
+
13
+ def __init__(self, name: str, default: Optional[T] = None):
14
+ self.var = contextvars.ContextVar(name, default=default)
15
+
16
+ # public
17
+
18
+ def get(self) -> Optional[T]:
19
+ """
20
+ return the current value or invoke the optional factory to compute one
21
+
22
+ Returns:
23
+ Optional[T]: the value associated with the current thread
24
+ """
25
+ return self.var.get()
26
+
27
+ def set(self, value: Optional[T]) -> Any:
28
+ """
29
+ set a value in the current thread
30
+
31
+ Args:
32
+ value: the value
33
+ """
34
+ return self.var.set(value)
35
+
36
+ def reset(self, token) -> None:
37
+ """
38
+ clear the value in the current thread
39
+ """
40
+ self.var.reset(token)
41
+
42
+ @contextmanager
43
+ def use(self, value):
44
+ token = self.set(value)
45
+ try:
46
+ yield
47
+ finally:
48
+ self.reset(token)
aspyx/util/__init__.py CHANGED
@@ -2,7 +2,9 @@
2
2
  This module provides utility functions.
3
3
  """
4
4
  from .stringbuilder import StringBuilder
5
+ from .logger import Logger
5
6
 
6
7
  __all__ = [
7
8
  "StringBuilder",
9
+ "Logger"
8
10
  ]
aspyx/util/logger.py ADDED
@@ -0,0 +1,15 @@
1
+ import logging
2
+ from typing import Optional, Dict
3
+
4
+ class Logger:
5
+ """just syntactic sugar"""
6
+
7
+ @classmethod
8
+ def configure(cls,
9
+ default_level: int = logging.INFO,
10
+ format: str = "[%(asctime)s] %(levelname)s in %(filename)s:%(lineno)d - %(message)s",
11
+ levels: Optional[Dict[str, int]] = None):
12
+ logging.basicConfig(level=default_level, format=format)
13
+ if levels is not None:
14
+ for name, level in levels.items():
15
+ logging.getLogger(name).setLevel(level)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aspyx
3
- Version: 1.5.2
3
+ Version: 1.5.3
4
4
  Summary: A DI and AOP library for Python
5
5
  Author-email: Andreas Ernst <andreas.ernst7@gmail.com>
6
6
  License: MIT License
@@ -2,7 +2,7 @@ aspyx/__init__.py,sha256=MsSFjiLMLJZ7QhUPpVBWKiyDnCzryquRyr329NoCACI,2
2
2
  aspyx/di/__init__.py,sha256=AGVU2VBWQyBxSssvbk_GOKrYWIYtcmSoIlupz-Oqxi4,1138
3
3
  aspyx/di/di.py,sha256=V_BAV6DmFCoepPqAXhBz2GW6NwYaKokHb03HMz6A5Sw,44639
4
4
  aspyx/di/aop/__init__.py,sha256=rn6LSpzFtUOlgaBATyhLRWBzFmZ6XoVKA9B8SgQzYEI,746
5
- aspyx/di/aop/aop.py,sha256=UqBpBI2nW6_8CLmY1j0F4cE2QVBQDgry9LWShVuxZKM,19367
5
+ aspyx/di/aop/aop.py,sha256=RaZRmQ1Ie6jZqYm0X93hWQ89xHn8vpDSnsmRgfAV68k,19180
6
6
  aspyx/di/configuration/__init__.py,sha256=flM9A79J2wfA5I8goQbxs4tTqYustR9tn_9s0YO2WJQ,484
7
7
  aspyx/di/configuration/configuration.py,sha256=cXW40bPXiUZ9hUtBoZkSATT3nLrDPWsSqxtgASIBQaM,4375
8
8
  aspyx/di/configuration/env_configuration_source.py,sha256=FXPvREzq2ZER6_GG5xdpx154TQQDxZVf7LW7cvaylAk,1446
@@ -10,15 +10,17 @@ aspyx/di/configuration/yaml_configuration_source.py,sha256=NDl3SeoLMNVlzHgfP-Ysv
10
10
  aspyx/di/threading/__init__.py,sha256=qrWdaq7MewQ2UmZy4J0Dn6BhY-ahfiG3xsv-EHqoqSE,191
11
11
  aspyx/di/threading/synchronized.py,sha256=6JOg5BXWrRIS5nRPH9iWR7T-kUglO4qWBQpLwhy99pI,1325
12
12
  aspyx/exception/__init__.py,sha256=OZwv-C3ZHD0Eg1rohCQMj575WLJ7lfYuk6PZD6sh1MA,211
13
- aspyx/exception/exception_manager.py,sha256=_pK4yTS5FJYj2SW1ijdBVD_6qrPUM9elMgZki2pf-Tw,5237
13
+ aspyx/exception/exception_manager.py,sha256=CVOjdI-y4m5GiE3TvSbwLpXXoAYqEyQLMN7jQhJYRn8,5228
14
14
  aspyx/reflection/__init__.py,sha256=r2sNJrfHDpuqaIYu4fTYsoo046gpgn4VTd7bsS3mQJY,282
15
15
  aspyx/reflection/proxy.py,sha256=1-pgw-TNORFXbV0gowFZqGd-bcWv1ny69bJhq8TLsKs,2761
16
16
  aspyx/reflection/reflection.py,sha256=BcqXJcMO36Gzq71O4aBsMqPynmBhYLI8V6J7DOInPAM,9142
17
- aspyx/threading/__init__.py,sha256=3clmbCDP37GPan3dWtxTQvpg0Ti4aFzruAbUClkHGi0,147
17
+ aspyx/threading/__init__.py,sha256=YWqLk-MOtSg4i3cdzRZUBR25okbbftRRxkaEdfrdMZo,207
18
+ aspyx/threading/context_local.py,sha256=IBjqfmuGgQSMB3EhYW9etcKEnErMQKaAVHD45s1mqOA,1111
18
19
  aspyx/threading/thread_local.py,sha256=86dNtbA4k2B-rNUUnZgn3_pU0DAojgLrRnh8RL6zf1E,1196
19
- aspyx/util/__init__.py,sha256=8H2yKkXu3nkRGeTerb8ialzKGfvzUx44XUWFUYcYuQM,125
20
+ aspyx/util/__init__.py,sha256=Uu6uZySb5v9WHS8ZooHmRXAxK_BhhKPUotv-LZyGQAI,165
21
+ aspyx/util/logger.py,sha256=S358l7RpBTSZtN8nivVLgX6HAp32vOQV-SDHDH0n9gc,547
20
22
  aspyx/util/stringbuilder.py,sha256=a-0T4YEXSJFUuQ3ztKN1ZPARkh8dIGMSkNEEJHRN7dc,856
21
- aspyx-1.5.2.dist-info/METADATA,sha256=mRlR5o-1WlYVvThk483KJTv738uNq5y02VkquUUsYDk,26490
22
- aspyx-1.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
23
- aspyx-1.5.2.dist-info/licenses/LICENSE,sha256=n4jfx_MNj7cBtPhhI7MCoB_K35cj1icP9yJ4Rh4vlvY,1070
24
- aspyx-1.5.2.dist-info/RECORD,,
23
+ aspyx-1.5.3.dist-info/METADATA,sha256=hPk9M5CUZDxxvrzf0s1hTnpfw-XTJu1gPqgTzAVf6w0,26490
24
+ aspyx-1.5.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ aspyx-1.5.3.dist-info/licenses/LICENSE,sha256=n4jfx_MNj7cBtPhhI7MCoB_K35cj1icP9yJ4Rh4vlvY,1070
26
+ aspyx-1.5.3.dist-info/RECORD,,
File without changes