spei-python 1.0.1__tar.gz → 1.0.3__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.
Files changed (40) hide show
  1. {spei_python-1.0.1 → spei_python-1.0.3}/PKG-INFO +1 -1
  2. {spei_python-1.0.1 → spei_python-1.0.3}/pyproject.toml +2 -2
  3. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/cda.py +22 -22
  4. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/orden.py +7 -16
  5. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/payments.py +3 -3
  6. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/respuesta.py +3 -3
  7. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/validators.py +40 -1
  8. {spei_python-1.0.1 → spei_python-1.0.3}/README.md +0 -0
  9. {spei_python-1.0.1 → spei_python-1.0.3}/spei/README.md +0 -0
  10. {spei_python-1.0.1 → spei_python-1.0.3}/spei/__init__.py +0 -0
  11. {spei_python-1.0.1 → spei_python-1.0.3}/spei/cep_generator.py +0 -0
  12. {spei_python-1.0.1 → spei_python-1.0.3}/spei/checksum/__init__.py +0 -0
  13. {spei_python-1.0.1 → spei_python-1.0.3}/spei/checksum/factory.py +0 -0
  14. {spei_python-1.0.1 → spei_python-1.0.3}/spei/checksum/generator.py +0 -0
  15. {spei_python-1.0.1 → spei_python-1.0.3}/spei/checksum/types.py +0 -0
  16. {spei_python-1.0.1 → spei_python-1.0.3}/spei/client.py +0 -0
  17. {spei_python-1.0.1 → spei_python-1.0.3}/spei/errors/__init__.py +0 -0
  18. {spei_python-1.0.1 → spei_python-1.0.3}/spei/errors/sice.py +0 -0
  19. {spei_python-1.0.1 → spei_python-1.0.3}/spei/errors/spei.py +0 -0
  20. {spei_python-1.0.1 → spei_python-1.0.3}/spei/exceptions.py +0 -0
  21. {spei_python-1.0.1 → spei_python-1.0.3}/spei/mappings.py +0 -0
  22. {spei_python-1.0.1 → spei_python-1.0.3}/spei/requests/__init__.py +0 -0
  23. {spei_python-1.0.1 → spei_python-1.0.3}/spei/requests/acuse.py +0 -0
  24. {spei_python-1.0.1 → spei_python-1.0.3}/spei/requests/cda.py +0 -0
  25. {spei_python-1.0.1 → spei_python-1.0.3}/spei/requests/orden.py +0 -0
  26. {spei_python-1.0.1 → spei_python-1.0.3}/spei/requests/respuesta.py +0 -0
  27. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/__init__.py +0 -0
  28. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/acuse.py +0 -0
  29. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/ensesion.py +0 -0
  30. {spei_python-1.0.1 → spei_python-1.0.3}/spei/resources/mensaje.py +0 -0
  31. {spei_python-1.0.1 → spei_python-1.0.3}/spei/responses/__init__.py +0 -0
  32. {spei_python-1.0.1 → spei_python-1.0.3}/spei/responses/acuse.py +0 -0
  33. {spei_python-1.0.1 → spei_python-1.0.3}/spei/responses/orden.py +0 -0
  34. {spei_python-1.0.1 → spei_python-1.0.3}/spei/responses/respuesta.py +0 -0
  35. {spei_python-1.0.1 → spei_python-1.0.3}/spei/sice.py +0 -0
  36. {spei_python-1.0.1 → spei_python-1.0.3}/spei/types/__init__.py +0 -0
  37. {spei_python-1.0.1 → spei_python-1.0.3}/spei/types/common.py +0 -0
  38. {spei_python-1.0.1 → spei_python-1.0.3}/spei/types/sice.py +0 -0
  39. {spei_python-1.0.1 → spei_python-1.0.3}/spei/types/spei.py +0 -0
  40. {spei_python-1.0.1 → spei_python-1.0.3}/spei/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spei-python
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary:
5
5
  Author: tech
6
6
  Author-email: tech@fondeadora.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "spei-python"
3
- version = "1.0.1"
3
+ version = "1.0.3"
4
4
  description = ""
5
5
  authors = ["tech <tech@fondeadora.com>"]
6
6
  readme = "README.md"
@@ -32,7 +32,7 @@ build-backend = "poetry.core.masonry.api"
32
32
 
33
33
  [tool.commitizen]
34
34
  name = "cz_conventional_commits"
35
- version = "1.0.1"
35
+ version = "1.0.3"
36
36
  tag_format = "v$version"
37
37
  bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
38
38
  version_files = [
@@ -4,7 +4,7 @@ from lxml import etree
4
4
  from pydantic import BaseModel, ConfigDict
5
5
 
6
6
  from spei import types
7
- from spei.types.common import DateInt, InstitutionCode
7
+ from spei.resources.validators import normalize_invalid_chars
8
8
  from spei.utils import to_pascal_case, to_snake_case # noqa: WPS347
9
9
 
10
10
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -69,27 +69,6 @@ class CDA(BaseModel):
69
69
  op_nom_prov_rem_nac: Optional[str] = None
70
70
  model_config = ConfigDict(use_enum_values=True)
71
71
 
72
- def build_xml(self) -> etree._Element: # noqa: WPS437
73
- mensaje = etree.Element(
74
- etree.QName(ENVIO_PRAXIS_NS, 'datosCda'),
75
- idCda=str(self.id),
76
- idMensaje=str(self.mensaje_id),
77
- nsmap={'env': ENVIO_PRAXIS_NS},
78
- )
79
-
80
- elements = self.dict(exclude_none=True, exclude={'id', 'mensaje_id'})
81
-
82
- for element, value in elements.items(): # noqa: WPS110
83
- if element in self.model_fields:
84
- upper_camel_case_element = to_pascal_case(element)
85
- subelement = etree.SubElement(
86
- mensaje,
87
- etree.QName(ENVIO_PRAXIS_NS, upper_camel_case_element),
88
- ) # noqa: E501
89
- subelement.text = str(value)
90
-
91
- return mensaje
92
-
93
72
  @classmethod
94
73
  def parse_xml(cls, mensaje_element):
95
74
  genera_cda = mensaje_element.find('generaCda')
@@ -106,3 +85,24 @@ class CDA(BaseModel):
106
85
  cda_data[tag] = element.text
107
86
 
108
87
  return cls(**cda_data)
88
+
89
+ def build_xml(self) -> etree._Element: # noqa: WPS437
90
+ mensaje = etree.Element(
91
+ etree.QName(ENVIO_PRAXIS_NS, 'datosCda'),
92
+ idCda=str(self.id),
93
+ idMensaje=str(self.mensaje_id),
94
+ nsmap={'env': ENVIO_PRAXIS_NS},
95
+ )
96
+
97
+ elements = self.dict(exclude_none=True, exclude={'id', 'mensaje_id'})
98
+
99
+ for element, value in elements.items(): # noqa: WPS110
100
+ if element in self.__fields__:
101
+ pascal_case_element = to_pascal_case(element)
102
+ subelement = etree.SubElement(
103
+ mensaje,
104
+ etree.QName(ENVIO_PRAXIS_NS, pascal_case_element),
105
+ )
106
+ subelement.text = normalize_invalid_chars(value)
107
+
108
+ return mensaje
@@ -6,13 +6,12 @@ from lxml.etree import _Element # noqa: WPS450, WPS458
6
6
  from pydantic import BaseModel, ConfigDict, field_validator
7
7
 
8
8
  from spei import types
9
- from spei.resources.validators import validate_alphanumeric
10
- from spei.types.common import DateInt, InstitutionCode
9
+ from spei.resources.validators import normalize_invalid_chars
11
10
  from spei.utils import to_camel_case, to_pascal_case, to_snake_case # noqa: WPS347
12
11
 
13
12
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
14
13
  PRAXIS_NS = 'http://www.praxis.com.mx/'
15
- _WHITESPACE_PATTERN = re.compile(r'\s+')
14
+ _DATE_PATTERN = re.compile(r'^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$')
16
15
  _CAMEL_CASE_FIELDS = frozenset(
17
16
  (
18
17
  'op_rastreo_ori',
@@ -76,7 +75,7 @@ class Orden(BaseModel):
76
75
  # additional general info
77
76
  op_iva: Optional[float] = None
78
77
  op_ref_numerica: Optional[int] = None
79
- op_ref_cobranza: Optional[int] = None
78
+ op_ref_cobranza: Optional[str] = None
80
79
  op_clave_pago: Optional[str] = None
81
80
  # refunds info
82
81
  op_to_clave: Optional[int] = None
@@ -177,7 +176,7 @@ class Orden(BaseModel):
177
176
  subelement.text = str(value)
178
177
  continue
179
178
 
180
- text = self._process_text(str(value), element)
179
+ text = normalize_invalid_chars(str(value))
181
180
 
182
181
  if element in _CAMEL_CASE_FIELDS:
183
182
  subelement = etree.SubElement(
@@ -223,7 +222,7 @@ class Orden(BaseModel):
223
222
  return
224
223
 
225
224
  tag = to_snake_case(element.tag)
226
- stripped = _WHITESPACE_PATTERN.sub(' ', element.text.strip())
225
+ stripped = element.text.strip()
227
226
 
228
227
  if tag == 'op_ins_clave':
229
228
  orden_data['op_ins_clave_ord'] = stripped
@@ -233,13 +232,5 @@ class Orden(BaseModel):
233
232
  orden_data['op_firma_dig'] = stripped
234
233
  return
235
234
 
236
- if tag in cls.model_fields:
237
- orden_data[tag] = cls._process_text(stripped, tag)
238
-
239
- @classmethod
240
- def _process_text(cls, text: str, tag: str) -> Optional[str]:
241
- """Process and validate the text content of an XML element."""
242
- try:
243
- return validate_alphanumeric(text)
244
- except ValueError as error:
245
- raise ValueError(f'{error} in {tag}') from error
235
+ if tag in cls.__fields__:
236
+ orden_data[tag] = stripped
@@ -21,7 +21,7 @@ class TerceroATercero(Orden):
21
21
  op_concepto_pag_2: str
22
22
  op_iva: Optional[float] = None
23
23
  op_ref_numerica: int
24
- op_ref_cobranza: Optional[int] = None
24
+ op_ref_cobranza: Optional[str] = None
25
25
 
26
26
 
27
27
  class TerceroAVentilla(Orden):
@@ -120,7 +120,7 @@ class TerceroATerceroFSW(Orden):
120
120
  op_concepto_pag_2: str
121
121
  op_iva: Optional[float] = None
122
122
  op_ref_numerica: int
123
- op_ref_cobranza: Optional[int] = None
123
+ op_ref_cobranza: Optional[str] = None
124
124
 
125
125
 
126
126
  class TerceroATerceroVostroFSW(Orden):
@@ -185,7 +185,7 @@ class Nomina(Orden):
185
185
  op_concepto_pag_2: str
186
186
  op_iva: Optional[float] = None
187
187
  op_ref_numerica: int
188
- op_ref_cobranza: Optional[int] = None
188
+ op_ref_cobranza: Optional[str] = None
189
189
 
190
190
 
191
191
  class PagoFactura(Orden):
@@ -29,9 +29,9 @@ class Respuesta(BaseModel):
29
29
  respuesta = etree.Element('respuesta')
30
30
 
31
31
  for element, value in self.dict(exclude={'categoria'}).items(): # noqa: WPS110
32
- if element in self.model_fields:
33
- upper_camel_case_element = to_pascal_case(element)
34
- subelement = etree.SubElement(respuesta, upper_camel_case_element)
32
+ if element in self.__fields__:
33
+ pascal_case_element = to_pascal_case(element)
34
+ subelement = etree.SubElement(respuesta, pascal_case_element)
35
35
  subelement.text = str(value)
36
36
 
37
37
  return respuesta
@@ -1,4 +1,12 @@
1
- # From “APÉNDICE B: TABLA DE CARACTERES VÁLIDOS Y CÓDIGOS ASCII RESPECTIVOS”
1
+ import logging
2
+ from typing import Any
3
+
4
+ from unidecode import unidecode
5
+
6
+ # Set up basic configuration for logging
7
+ logging.basicConfig(level=logging.WARNING)
8
+
9
+ # From "APÉNDICE B: TABLA DE CARACTERES VÁLIDOS Y CÓDIGOS ASCII RESPECTIVOS"
2
10
  # in SPEI Manual.
3
11
  VALID_CHARACTERS = frozenset(
4
12
  (
@@ -105,3 +113,34 @@ def validate_alphanumeric(text: str) -> str:
105
113
  raise ValueError(f'Invalid characters found: {invalid_chars}')
106
114
 
107
115
  return text
116
+
117
+
118
+ def normalize_invalid_chars(text: Any) -> str:
119
+ """Converts a text to a valid string.
120
+
121
+ Selectively replacing invalid characters with their ASCII
122
+ equivalents. Valid characters are preserved as-is, only invalid ones
123
+ are converted using unidecode. If the conversion is not possible,
124
+ the character is replaced with a '?' character.
125
+ """
126
+ result = []
127
+ text_str = str(text)
128
+
129
+ for char in text_str:
130
+ if char in VALID_CHARACTERS:
131
+ result.append(char)
132
+ else:
133
+ # Convert only this character to ASCII and validate it
134
+ ascii_char = unidecode(char)
135
+ # Take first char in case unidecode returns multiple chars
136
+ first_ascii = ascii_char[0] if ascii_char else ''
137
+ if first_ascii and first_ascii in VALID_CHARACTERS:
138
+ result.append(first_ascii)
139
+ else:
140
+ # Log a warning and replace with '?'
141
+ logging.warning(
142
+ f'Character "{char}" cannot be converted to a valid character, replacing with "?"', # noqa: E501
143
+ )
144
+ result.append('?')
145
+
146
+ return ''.join(result)
File without changes
File without changes
File without changes
File without changes
File without changes