reach_commons 0.18.41__py3-none-any.whl → 0.18.43__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.
@@ -47,6 +47,7 @@ def get_secret(
47
47
  region_name: str = "us-east-1",
48
48
  host=os.getenv("MYSQL_HOST"),
49
49
  db_name=os.getenv("MYSQL_DB_NAME"),
50
+ port=os.getenv("MYSQL_PORT"),
50
51
  ) -> Dict[str, Any]:
51
52
  """
52
53
  Load DB credentials from AWS Secrets Manager and host from SSM Parameter Store.
@@ -76,6 +77,9 @@ def get_secret(
76
77
  secrets_data["host"] = host
77
78
  secrets_data["dbname"] = db_name
78
79
 
80
+ if port is None:
81
+ secrets_data["port"] = 3306
82
+
79
83
  missing = [
80
84
  key
81
85
  for key in ("host", "username", "password", "dbname")
@@ -2,6 +2,30 @@ from dataclasses import dataclass, field
2
2
  from math import ceil
3
3
  from typing import Union
4
4
 
5
+ # Basic GSM-7 char set (without extension table handling).
6
+ # If you want 100% accuracy for GSM-7, we can add the extension table later.
7
+ GSM7_BASIC = set(
8
+ "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ"
9
+ "ÆæßÉ !\"#¤%&'()*+,-./"
10
+ "0123456789:;<=>?"
11
+ "¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ"
12
+ "¿abcdefghijklmnopqrstuvwxyzäöñüà"
13
+ )
14
+
15
+
16
+ def is_gsm7(text: str) -> bool:
17
+ return all(ch in GSM7_BASIC for ch in text)
18
+
19
+
20
+ def ucs2_units(text: str) -> int:
21
+ # UTF-16 code units: emoji counts as 2 (surrogate pair), which matches UCS-2 segment math used in practice.
22
+ return len(text.encode("utf-16-be")) // 2
23
+
24
+
25
+ def fix_surrogates(text: str) -> str:
26
+ # Turns surrogate pairs like \uD83D\uDC96 into the real character (💖)
27
+ return text.encode("utf-16", "surrogatepass").decode("utf-16")
28
+
5
29
 
6
30
  @dataclass
7
31
  class MessageSmartEncoding:
@@ -31,15 +55,25 @@ class MessageSmartEncoding:
31
55
  segments: int = field(init=False)
32
56
 
33
57
  def __post_init__(self):
34
- # Convert body to string if it's a list
35
- if isinstance(self.body, list):
36
- body_text = " ".join(str(item) for item in self.body)
37
- else:
38
- body_text = self.body
58
+ body_text = (
59
+ " ".join(map(str, self.body))
60
+ if isinstance(self.body, list)
61
+ else str(self.body)
62
+ )
63
+ self.normalized_text = fix_surrogates(self.normalize(body_text))
39
64
 
40
- self.normalized_text = self.normalize(body_text)
41
- self.length = len(self.normalized_text)
42
- self.segments = ceil(self.length / 160)
65
+ if is_gsm7(self.normalized_text):
66
+ self.encoding = "GSM-7"
67
+ text_length = len(self.normalized_text)
68
+ self.length = text_length
69
+ per_segment = 160 if text_length <= 160 else 153
70
+ self.segments = ceil(text_length / per_segment)
71
+ else:
72
+ self.encoding = "UCS-2"
73
+ text_units_count = ucs2_units(self.normalized_text)
74
+ self.length = text_units_count
75
+ per_segment = 70 if text_units_count <= 70 else 67
76
+ self.segments = ceil(text_units_count / per_segment)
43
77
 
44
78
  def normalize(self, text: str) -> str:
45
79
  for char, replacement in self.replacements.items():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reach_commons
3
- Version: 0.18.41
3
+ Version: 0.18.43
4
4
  Summary: Reach Commons is a versatile utility library designed to streamline and enhance development workflows within the Reach ecosystem.
5
5
  License: MIT
6
6
  Author: Engineering
@@ -17,7 +17,7 @@ reach_commons/mongo/customer_persistence_async.py,sha256=BmcP8TXyyQah-GYM3wcKi1b
17
17
  reach_commons/mongo/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  reach_commons/reach_aws/__init__.py,sha256=xb97rt0lBd0wz9ZhULQ7YVAOceOS-AkvNVM4jfLOjYE,86
19
19
  reach_commons/reach_aws/commons.py,sha256=qQba0li75BIpmyVc0sDVrrxbtYvDCedF6RmFD-V4MYQ,259
20
- reach_commons/reach_aws/db_config.py,sha256=TIaZA-SspFuiIWYnYllg1-eAAISM7vBLXYqUj09HZLo,2713
20
+ reach_commons/reach_aws/db_config.py,sha256=UXi2FsJi_xE7L67-w2p9I2EhktIhWcIpbwL5lkmNp8k,2809
21
21
  reach_commons/reach_aws/dynamo_db.py,sha256=BL3QcKzx4uZic-Ui12tln_GMSKe297FdfyIzFPE7veE,7140
22
22
  reach_commons/reach_aws/exceptions.py,sha256=x0RL5ktNtzxg0KykhEVWReBq_dEtciK6B2vMs_s4C9k,915
23
23
  reach_commons/reach_aws/firehose.py,sha256=1xFKLWMv3bNo3PPW5gtaL6NqzUDyVil6B768slj2wbY,5674
@@ -27,9 +27,9 @@ reach_commons/reach_aws/s3.py,sha256=2MLlDNFx0SROJBpE_KjJefyrB7lMqTlrYuRhSZx4iKs
27
27
  reach_commons/reach_aws/sqs.py,sha256=IKKWrd-qbhMMVYUvGbaq1ouVRdx-0u-SqwYaTcp0tWY,21645
28
28
  reach_commons/reach_base_model.py,sha256=vgdGDcZr3iXMmyRhmBhOf_LKWB_6QzT3r_Yiyo6OmEk,3009
29
29
  reach_commons/redis_manager.py,sha256=yRed53ZKlbIb6rZnL53D1F_aB-xWT3nbeUP2cqYzhoc,3668
30
- reach_commons/sms_smart_encoding.py,sha256=92y0RmZ0l4ONHpC9qeO5KfViSNq64yE2rc7lhNDSZqE,1241
30
+ reach_commons/sms_smart_encoding.py,sha256=Hpc9tIgTJM0ZKdhloSjgIPQCi52gDAFEOKIoO2rtJ30,2537
31
31
  reach_commons/utils.py,sha256=dMgKIGqTgoSItuBI8oz81gKtW3qi21Jkljv9leS_V88,8475
32
32
  reach_commons/validations.py,sha256=x_lkrtlrCAJC_f7mZb19JjfKFbYlPFv-P84K_lbZyYs,1056
33
- reach_commons-0.18.41.dist-info/METADATA,sha256=RbAT9hck9WEqrlfCwigxRa1-JyL6AkcgnO0D5J-lcvw,1863
34
- reach_commons-0.18.41.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
35
- reach_commons-0.18.41.dist-info/RECORD,,
33
+ reach_commons-0.18.43.dist-info/METADATA,sha256=BY3z5YCwX2Koe9hUbM4vrG6I0cID8zGUz9DkPm2dNT0,1863
34
+ reach_commons-0.18.43.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
35
+ reach_commons-0.18.43.dist-info/RECORD,,