arcane-flask 2.0.4__tar.gz → 2.0.6__tar.gz

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,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: arcane-flask
3
- Version: 2.0.4
3
+ Version: 2.0.6
4
4
  Summary: Utility functions for flask apps.
5
5
  Author: Arcane
6
6
  Author-email: product@wearcane.com
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
15
16
  Requires-Dist: arcane-core (>=1.6.0,<2.0.0)
16
17
  Requires-Dist: arcane-datastore (>=1.1.0,<2.0.0)
17
18
  Requires-Dist: arcane-pubsub (>=1.1.0,<2.0.0)
@@ -1,9 +1,9 @@
1
- from audioop import add
2
1
  import functools
3
2
  import inspect
4
3
  import time
5
4
  import json
6
- from typing import Callable, Union, Dict
5
+ from typing import Callable, Optional, Union, Dict
6
+ import logging
7
7
 
8
8
  import backoff
9
9
  from firebase_admin import auth as firebase_auth
@@ -75,7 +75,7 @@ def check_access_rights(service: str,
75
75
  is_appengine_cron = request.headers.get('X-Appengine-Cron', False)
76
76
 
77
77
  if is_appengine_cron:
78
- print("App Engine calls service : " + service)
78
+ logging.info("App Engine calls service : " + service)
79
79
  return job_func(*args, **kwargs)
80
80
 
81
81
  claims = {}
@@ -245,7 +245,7 @@ def get_user_email(token: str=None, auth_enabled=True) -> Union[str, None]:
245
245
  raise ValueError(f'Uid key is mapped to {repr(mail_str)} (type: {type(mail_str)}) value in claims')
246
246
  return mail_str
247
247
 
248
- def get_user_uid(token: str=None) ->str:
248
+ def get_user_uid(token: Optional[str]=None) -> str:
249
249
  """
250
250
  Retrieve user firebase uid from connexion header.
251
251
 
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
  from typing import Callable
3
+ import logging
3
4
  from flask import request
4
5
 
5
6
  from .authentication import get_user_email
@@ -30,14 +31,16 @@ def catch_exceptions_service(service: str, auth_enabled=True) -> Callable:
30
31
 
31
32
  message += f"Args : {str(args)} / kwargs : {str(kwargs)} / headers : {request.environ.get('HTTP_ORIGIN')}"
32
33
 
33
- print(message)
34
+ logging.info(message)
34
35
  raise e
35
36
  return wrapper
36
37
  return catch_exceptions
37
38
 
38
39
 
39
40
  def add_id_to_exceptions() -> Callable:
40
- """ Catch if an exception is raised after an endpoint call and add the request id
41
+ """
42
+ Deprecated, should not be used anymore (not needed with setup_logging)
43
+ Catch if an exception is raised after an endpoint call and add the request id
41
44
  """
42
45
  def catch_exceptions(job_func: Callable) -> Callable:
43
46
  @functools.wraps(job_func)
@@ -19,7 +19,7 @@ def adscale_log(
19
19
  except KeyError:
20
20
  pass
21
21
 
22
- print(f"[{service}][{request_id}] {msg}")
22
+ logging.info(f"[{service}][{request_id}] {msg}")
23
23
 
24
24
 
25
25
  class RequestFormatter(logging.Formatter):
@@ -46,7 +46,19 @@ class RequestFormatter(logging.Formatter):
46
46
  else:
47
47
  record.cloud_trace = None
48
48
 
49
- record.msg = json.dumps(record.msg)
49
+ # Handle exception information properly
50
+ if record.exc_info:
51
+ # Format the exception with stack trace as a single string
52
+ exc_text = self.formatException(record.exc_info)
53
+ # Combine the message with the exception info
54
+ full_message = f"{record.getMessage()}\n{exc_text}"
55
+ else:
56
+ full_message = record.getMessage()
57
+
58
+ # JSON encode the complete message to escape newlines and special characters
59
+ record.msg = json.dumps(full_message)
60
+ # Clear args to prevent double formatting
61
+ record.args = None
50
62
 
51
63
  return super().format(record)
52
64
 
@@ -81,5 +93,4 @@ def setup_logging(
81
93
  )
82
94
 
83
95
  root = logging.getLogger()
84
- root.addHandler(handler)
85
96
  return root
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "arcane-flask"
3
3
 
4
- version = "2.0.4"
4
+ version = "2.0.6"
5
5
 
6
6
 
7
7
  description = "Utility functions for flask apps."
File without changes