maleo-foundation 0.0.49__py3-none-any.whl → 0.0.51__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.
@@ -1,9 +1,7 @@
1
1
  from __future__ import annotations
2
2
  from .general import BaseGeneralClients
3
3
  from .google import GoogleClients
4
- from .utils import BaseClientUtils
5
4
 
6
5
  class BaseClients:
7
6
  General = BaseGeneralClients
8
- Google = GoogleClients
9
- Utils = BaseClientUtils
7
+ Google = GoogleClients
@@ -4,10 +4,11 @@ from fastapi.responses import JSONResponse
4
4
  from functools import wraps
5
5
  from starlette.exceptions import HTTPException as StarletteHTTPException
6
6
  from sqlalchemy.exc import SQLAlchemyError
7
+ from typing import Optional
7
8
  from maleo_foundation.models.responses import BaseResponses
8
9
  from maleo_foundation.models.transfers.results.service.general import BaseServiceGeneralResultsTransfers
9
10
  from maleo_foundation.models.transfers.results.service.query import BaseServiceQueryResultsTransfers
10
- from maleo_foundation.utils.logger import BaseLogger
11
+ from maleo_foundation.utils.logger import BaseLogger, LoggerFactory
11
12
 
12
13
  class BaseExceptions:
13
14
  @staticmethod
@@ -25,10 +26,16 @@ class BaseExceptions:
25
26
  @staticmethod
26
27
  def database_exception_handler(
27
28
  operation:str,
28
- logger:BaseLogger,
29
+ logger:Optional[BaseLogger] = None,
30
+ logger_factory:Optional[LoggerFactory] = None,
29
31
  fail_result_class:type[BaseServiceQueryResultsTransfers.Fail] = BaseServiceQueryResultsTransfers.Fail
30
32
  ):
31
33
  """Decorator to handle database-related exceptions consistently."""
34
+ if logger is not None and logger_factory is not None:
35
+ raise RuntimeError("Only one of 'logger' or 'logger_factory' should be provided, not both.")
36
+ if logger is None and logger_factory is None:
37
+ raise RuntimeError("One of 'logger' or 'logger_factory' must be provided.")
38
+ logger = logger or logger_factory()
32
39
  def decorator(func):
33
40
  @wraps(func)
34
41
  def wrapper(*args, **kwargs):
@@ -54,10 +61,16 @@ class BaseExceptions:
54
61
  @staticmethod
55
62
  def service_exception_handler(
56
63
  operation:str,
57
- logger:BaseLogger,
64
+ logger:Optional[BaseLogger] = None,
65
+ logger_factory:Optional[LoggerFactory] = None,
58
66
  fail_result_class:type[BaseServiceGeneralResultsTransfers.Fail] = BaseServiceGeneralResultsTransfers.Fail
59
67
  ):
60
68
  """Decorator to handle service-related exceptions consistently."""
69
+ if logger is not None and logger_factory is not None:
70
+ raise RuntimeError("Only one of 'logger' or 'logger_factory' should be provided, not both.")
71
+ if logger is None and logger_factory is None:
72
+ raise RuntimeError("One of 'logger' or 'logger_factory' must be provided.")
73
+ logger = logger or logger_factory()
61
74
  def decorator(func):
62
75
  @wraps(func)
63
76
  def wrapper(*args, **kwargs):
@@ -84,4 +84,6 @@ class BaseLogger(logging.Logger):
84
84
  for handler in list(self.handlers):
85
85
  self.removeHandler(handler)
86
86
  handler.close()
87
- self.handlers.clear()
87
+ self.handlers.clear()
88
+
89
+ LoggerFactory = Callable[[], BaseLogger]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.49
3
+ Version: 0.0.51
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -3,7 +3,7 @@ maleo_foundation/constants.py,sha256=aBmEfWlBqZxi0k-n6h2NM1YRLOjMnheEiLyQcjP-zCQ
3
3
  maleo_foundation/enums.py,sha256=uXA5fLFeDXwlspUjU4DXSB68dfanxEwIJhsAMZXhsYo,2359
4
4
  maleo_foundation/extended_types.py,sha256=pIKt-_9tby4rmune3fmWcCW_mohaNRh_1lywBmdc-L4,301
5
5
  maleo_foundation/types.py,sha256=D_EtYK-sNeELSbc-ngX65iuQCRhZQB4TtV73P6Gl76o,1206
6
- maleo_foundation/clients/__init__.py,sha256=OnSF_sjpaPfxNthmTd8FfIni3su7wsJs501znsjwx14,251
6
+ maleo_foundation/clients/__init__.py,sha256=W8vydJYeDEi6gdmOZSBFSSDsfZJtb8C05CHErZgsZ30,188
7
7
  maleo_foundation/clients/general/__init__.py,sha256=l9eQrBeLW4aXtGU5aK3i6fD-msVR4526W7D9V8WCXIg,91
8
8
  maleo_foundation/clients/general/http.py,sha256=Awvs470hgdhZSZW_uoIFJGcJ5hcfDEIX0A2yUaP9UCA,1353
9
9
  maleo_foundation/clients/google/__init__.py,sha256=1uv6nF9QbATsSAcMimQOT7Y-eBljjDunBojNX6oAtS8,90
@@ -47,12 +47,12 @@ maleo_foundation/models/transfers/results/service/controllers/__init__.py,sha256
47
47
  maleo_foundation/models/transfers/results/service/controllers/rest.py,sha256=wCuFyOTQkuBs2cqjPsWnPy0XIsCfMqGByhrSy57qp7Y,1107
48
48
  maleo_foundation/utils/__init__.py,sha256=FavmL5XYGCm955EAKiWWcXYeU15p5rSzfcglpV2yI6c,387
49
49
  maleo_foundation/utils/controller.py,sha256=hapDGng4q5XTfaG18M3bbFsFGqEOlkNKRzGf8BMKrhs,2996
50
- maleo_foundation/utils/exceptions.py,sha256=mcvBwHm6uWpVQkPtO1T2j-GaTYEiyPOeGxiDL9-sjNA,3639
51
- maleo_foundation/utils/logger.py,sha256=ajEPK5XC4hAEcwMeM8JIyz9zXgXtLmIc_AIDynBtNjE,3366
50
+ maleo_foundation/utils/exceptions.py,sha256=nk3rD57fDR-D7BQkU1JEKV-Mu7FGMpLSEsqxdDZdKjU,4532
51
+ maleo_foundation/utils/logger.py,sha256=978P57JOhGR-WIu7xdPXBIwd3JrfLLA8WerVzxhE_Fs,3408
52
52
  maleo_foundation/utils/query.py,sha256=qKNcjf5J7_Q7NjA79BO6_TpZVdYcF8YIO68F9M501ew,4398
53
53
  maleo_foundation/utils/formatter/__init__.py,sha256=iKf5YCbEdg1qKnFHyKqqcQbqAqEeRUf8mhI3v3dQoj8,78
54
54
  maleo_foundation/utils/formatter/case.py,sha256=TmvvlfzGdC_omMTB5vAa40TZBxQ3hnr-SYeo0M52Rlg,1352
55
- maleo_foundation-0.0.49.dist-info/METADATA,sha256=TFd6x9MxoMc-Mul21sGodbEN05tmlVU8JrB0G7LZxXs,3160
56
- maleo_foundation-0.0.49.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
57
- maleo_foundation-0.0.49.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
58
- maleo_foundation-0.0.49.dist-info/RECORD,,
55
+ maleo_foundation-0.0.51.dist-info/METADATA,sha256=6vxQY_KG3-CyfA_SQx_xCtuDvG0yXVOZISSgs95ZY-o,3160
56
+ maleo_foundation-0.0.51.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
57
+ maleo_foundation-0.0.51.dist-info/top_level.txt,sha256=_iBos3F_bhEOdjOnzeiEYSrCucasc810xXtLBXI8cQc,17
58
+ maleo_foundation-0.0.51.dist-info/RECORD,,