spei-python 1.0.2__tar.gz → 1.0.4__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 (41) hide show
  1. {spei_python-1.0.2 → spei_python-1.0.4}/PKG-INFO +3 -5
  2. {spei_python-1.0.2 → spei_python-1.0.4}/pyproject.toml +6 -8
  3. {spei_python-1.0.2 → spei_python-1.0.4}/spei/checksum/generator.py +5 -7
  4. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/cda.py +41 -25
  5. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/orden.py +48 -51
  6. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/payments.py +4 -4
  7. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/respuesta.py +12 -5
  8. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/validators.py +40 -1
  9. spei_python-1.0.4/spei/types/common.py +18 -0
  10. spei_python-1.0.2/spei/types/common.py +0 -41
  11. {spei_python-1.0.2 → spei_python-1.0.4}/README.md +0 -0
  12. {spei_python-1.0.2 → spei_python-1.0.4}/spei/README.md +0 -0
  13. {spei_python-1.0.2 → spei_python-1.0.4}/spei/__init__.py +0 -0
  14. {spei_python-1.0.2 → spei_python-1.0.4}/spei/cep_generator.py +0 -0
  15. {spei_python-1.0.2 → spei_python-1.0.4}/spei/checksum/__init__.py +0 -0
  16. {spei_python-1.0.2 → spei_python-1.0.4}/spei/checksum/factory.py +0 -0
  17. {spei_python-1.0.2 → spei_python-1.0.4}/spei/checksum/types.py +0 -0
  18. {spei_python-1.0.2 → spei_python-1.0.4}/spei/client.py +0 -0
  19. {spei_python-1.0.2 → spei_python-1.0.4}/spei/errors/__init__.py +0 -0
  20. {spei_python-1.0.2 → spei_python-1.0.4}/spei/errors/sice.py +0 -0
  21. {spei_python-1.0.2 → spei_python-1.0.4}/spei/errors/spei.py +0 -0
  22. {spei_python-1.0.2 → spei_python-1.0.4}/spei/exceptions.py +0 -0
  23. {spei_python-1.0.2 → spei_python-1.0.4}/spei/mappings.py +0 -0
  24. {spei_python-1.0.2 → spei_python-1.0.4}/spei/requests/__init__.py +0 -0
  25. {spei_python-1.0.2 → spei_python-1.0.4}/spei/requests/acuse.py +0 -0
  26. {spei_python-1.0.2 → spei_python-1.0.4}/spei/requests/cda.py +0 -0
  27. {spei_python-1.0.2 → spei_python-1.0.4}/spei/requests/orden.py +0 -0
  28. {spei_python-1.0.2 → spei_python-1.0.4}/spei/requests/respuesta.py +0 -0
  29. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/__init__.py +0 -0
  30. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/acuse.py +0 -0
  31. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/ensesion.py +0 -0
  32. {spei_python-1.0.2 → spei_python-1.0.4}/spei/resources/mensaje.py +0 -0
  33. {spei_python-1.0.2 → spei_python-1.0.4}/spei/responses/__init__.py +0 -0
  34. {spei_python-1.0.2 → spei_python-1.0.4}/spei/responses/acuse.py +0 -0
  35. {spei_python-1.0.2 → spei_python-1.0.4}/spei/responses/orden.py +0 -0
  36. {spei_python-1.0.2 → spei_python-1.0.4}/spei/responses/respuesta.py +0 -0
  37. {spei_python-1.0.2 → spei_python-1.0.4}/spei/sice.py +0 -0
  38. {spei_python-1.0.2 → spei_python-1.0.4}/spei/types/__init__.py +0 -0
  39. {spei_python-1.0.2 → spei_python-1.0.4}/spei/types/sice.py +0 -0
  40. {spei_python-1.0.2 → spei_python-1.0.4}/spei/types/spei.py +0 -0
  41. {spei_python-1.0.2 → spei_python-1.0.4}/spei/utils.py +0 -0
@@ -1,13 +1,11 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: spei-python
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary:
5
5
  Author: tech
6
6
  Author-email: tech@fondeadora.com
7
- Requires-Python: >=3.8.1,<4.0
7
+ Requires-Python: >=3.11,<4.0
8
8
  Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
9
  Classifier: Programming Language :: Python :: 3.11
12
10
  Classifier: Programming Language :: Python :: 3.12
13
11
  Classifier: Programming Language :: Python :: 3.13
@@ -1,13 +1,13 @@
1
1
  [tool.poetry]
2
2
  name = "spei-python"
3
- version = "1.0.2"
3
+ version = "1.0.4"
4
4
  description = ""
5
5
  authors = ["tech <tech@fondeadora.com>"]
6
6
  readme = "README.md"
7
- packages = [{include = "spei"}]
7
+ packages = [{ include = "spei" }]
8
8
 
9
9
  [tool.poetry.dependencies]
10
- python = ">=3.8.1,<4.0"
10
+ python = ">=3.11,<4.0"
11
11
  lxml = "^5.0.0"
12
12
  pydantic = ">=1.10.17,<3"
13
13
  requests = "^2.32.2"
@@ -32,12 +32,10 @@ build-backend = "poetry.core.masonry.api"
32
32
 
33
33
  [tool.commitizen]
34
34
  name = "cz_conventional_commits"
35
- version = "1.0.2"
35
+ version = "1.0.4"
36
36
  tag_format = "v$version"
37
37
  bump_message = "bump: Semantic Release Bot: Release Version: $new_version 🤖🚀 [skip ci]"
38
- version_files = [
39
- "pyproject.toml:version",
40
- ]
38
+ version_files = ["pyproject.toml:version"]
41
39
 
42
40
  [tool.black]
43
41
  skip-string-normalization = true
@@ -46,4 +44,4 @@ line-length = 88
46
44
  # this was added to fix the issue: Package docutils (0.21.post1) not found.
47
45
  [[tool.poetry.source]]
48
46
  name = "pypi-public"
49
- url = "https://pypi.org/simple/"
47
+ url = "https://pypi.org/simple/"
@@ -1,4 +1,4 @@
1
- from datetime import datetime
1
+ from datetime import date
2
2
  from decimal import Decimal
3
3
  from typing import Optional, Tuple
4
4
 
@@ -19,12 +19,10 @@ class ChecksumGenerator(object):
19
19
  low = amount_as_cents - (tens_of_millons * 10**9)
20
20
  return high, low
21
21
 
22
- def _fecha_to_bytearray(self, fecha_operacion: int) -> bytearray:
23
- fecha_operacion_dt = datetime.strptime(str(fecha_operacion), '%Y%m%d')
24
-
25
- day = int.to_bytes(int(fecha_operacion_dt.day), 1, 'big')
26
- month = int.to_bytes(int(fecha_operacion_dt.month), 1, 'big')
27
- year = int.to_bytes(int(fecha_operacion_dt.year), 2, 'big')
22
+ def _fecha_to_bytearray(self, fecha_operacion: date) -> bytearray:
23
+ day = int.to_bytes(int(fecha_operacion.day), 1, 'big')
24
+ month = int.to_bytes(int(fecha_operacion.month), 1, 'big')
25
+ year = int.to_bytes(int(fecha_operacion.year), 2, 'big')
28
26
 
29
27
  return bytearray(day + month + year)
30
28
 
@@ -1,10 +1,12 @@
1
+ from datetime import date, datetime
1
2
  from typing import Optional
2
3
 
3
4
  from lxml import etree
4
5
  from pydantic import BaseModel, ConfigDict
5
6
 
6
7
  from spei import types
7
- from spei.types.common import DateInt, InstitutionCode
8
+ from spei.resources.validators import normalize_invalid_chars
9
+ from spei.types.common import InstitutionCode
8
10
  from spei.utils import to_pascal_case, to_snake_case # noqa: WPS347
9
11
 
10
12
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -17,8 +19,8 @@ class CDA(BaseModel):
17
19
 
18
20
  id: int
19
21
  mensaje_id: int
20
- op_fecha_oper: DateInt
21
- op_fecha_abono: DateInt
22
+ op_fecha_oper: date
23
+ op_fecha_abono: date
22
24
  op_hora_abono: int
23
25
 
24
26
  op_cve_rastreo: str
@@ -69,27 +71,6 @@ class CDA(BaseModel):
69
71
  op_nom_prov_rem_nac: Optional[str] = None
70
72
  model_config = ConfigDict(use_enum_values=True)
71
73
 
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
74
  @classmethod
94
75
  def parse_xml(cls, mensaje_element):
95
76
  genera_cda = mensaje_element.find('generaCda')
@@ -102,7 +83,42 @@ class CDA(BaseModel):
102
83
 
103
84
  for element in datos_cta.getchildren():
104
85
  tag = to_snake_case(element.tag)
105
- if tag in cls.model_fields:
86
+
87
+ if tag not in cls.model_fields:
88
+ continue
89
+
90
+ if tag == 'op_fecha_oper':
91
+ cda_data[tag] = datetime.strptime(element.text, '%d%m%Y').date()
92
+ else:
106
93
  cda_data[tag] = element.text
107
94
 
108
95
  return cls(**cda_data)
96
+
97
+ def build_xml(self) -> etree._Element: # noqa: WPS437
98
+ mensaje = etree.Element(
99
+ etree.QName(ENVIO_PRAXIS_NS, 'datosCda'),
100
+ idCda=str(self.id),
101
+ idMensaje=str(self.mensaje_id),
102
+ attrib={},
103
+ nsmap={'env': ENVIO_PRAXIS_NS},
104
+ )
105
+
106
+ elements = self.model_dump(exclude_none=True, exclude={'id', 'mensaje_id'})
107
+
108
+ for element, value in elements.items(): # noqa: WPS110
109
+ if element not in self.model_fields:
110
+ continue
111
+
112
+ if 'op_fecha' in element:
113
+ value = value.strftime('%d%m%Y')
114
+
115
+ pascal_case_element = to_pascal_case(element)
116
+ subelement = etree.SubElement(
117
+ mensaje,
118
+ etree.QName(ENVIO_PRAXIS_NS, pascal_case_element),
119
+ attrib={},
120
+ nsmap=None,
121
+ )
122
+ subelement.text = normalize_invalid_chars(value)
123
+
124
+ return mensaje
@@ -1,4 +1,5 @@
1
1
  import re
2
+ from datetime import date, datetime
2
3
  from typing import Any, Dict, Optional
3
4
 
4
5
  from lxml import etree
@@ -6,13 +7,13 @@ from lxml.etree import _Element # noqa: WPS450, WPS458
6
7
  from pydantic import BaseModel, ConfigDict, field_validator
7
8
 
8
9
  from spei import types
9
- from spei.resources.validators import validate_alphanumeric
10
- from spei.types.common import DateInt, InstitutionCode
10
+ from spei.resources.validators import normalize_invalid_chars
11
+ from spei.types.common import InstitutionCode
11
12
  from spei.utils import to_camel_case, to_pascal_case, to_snake_case # noqa: WPS347
12
13
 
13
14
  SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
14
15
  PRAXIS_NS = 'http://www.praxis.com.mx/'
15
- _WHITESPACE_PATTERN = re.compile(r'\s+')
16
+ _DATE_PATTERN = re.compile(r'^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$')
16
17
  _CAMEL_CASE_FIELDS = frozenset(
17
18
  (
18
19
  'op_rastreo_ori',
@@ -29,7 +30,7 @@ class Orden(BaseModel):
29
30
 
30
31
  id: int
31
32
  categoria: types.CategoriaOrdenPago
32
- op_fecha_oper: DateInt
33
+ op_fecha_oper: date
33
34
  op_folio: int
34
35
  op_monto: str
35
36
  op_tp_clave: types.TipoPagoOrdenPago
@@ -86,7 +87,7 @@ class Orden(BaseModel):
86
87
  # original info
87
88
  op_folio_ori: Optional[int] = None
88
89
  paq_folio_ori: Optional[int] = None
89
- op_fecha_oper_ori: Optional[DateInt] = None
90
+ op_fecha_oper_ori: Optional[date] = None
90
91
  op_rastreo_ori: Optional[str] = None
91
92
  op_monto_intereses: Optional[float] = None
92
93
  op_monto_ori: Optional[float] = None
@@ -106,7 +107,7 @@ class Orden(BaseModel):
106
107
  op_cert_comer_env: Optional[int] = None
107
108
  op_digito_ver_comer: Optional[int] = None
108
109
  # karpay system info
109
- op_fecha_cap: Optional[DateInt] = None
110
+ op_fecha_cap: Optional[date] = None
110
111
  op_folio_servidor: Optional[int] = None
111
112
  op_usu_autoriza: Optional[str] = None
112
113
  op_err_clave: Optional[types.CodigoError] = None
@@ -150,52 +151,50 @@ class Orden(BaseModel):
150
151
  nsmap=None,
151
152
  )
152
153
 
153
- elements = self.dict(
154
+ elements = self.model_dump(
154
155
  exclude_none=True,
155
156
  exclude={'id', 'categoria', 'op_ins_clave_ord'},
156
157
  )
157
158
 
158
159
  for element, value in elements.items(): # noqa: WPS110
159
- if element in self.model_fields:
160
- if element == 'op_ins_clave_ben':
161
- subelement = etree.SubElement(
162
- ordenpago,
163
- 'OpInsClave',
164
- attrib={},
165
- nsmap=None,
166
- )
167
- subelement.text = str(value)
168
- continue
169
-
170
- if element == 'op_firma_dig': # Lower case o in op
171
- subelement = etree.SubElement(
172
- ordenpago,
173
- 'opFirmaDig',
174
- attrib={},
175
- nsmap=None,
176
- )
177
- subelement.text = str(value)
178
- continue
179
-
180
- text = self._process_text(str(value), element)
181
-
182
- if element in _CAMEL_CASE_FIELDS:
183
- subelement = etree.SubElement(
184
- ordenpago,
185
- to_camel_case(element),
186
- attrib={},
187
- nsmap=None,
188
- )
189
- subelement.text = text
190
- continue
160
+ if element not in self.model_fields:
161
+ continue
191
162
 
163
+ if element == 'op_ins_clave_ben':
192
164
  subelement = etree.SubElement(
193
165
  ordenpago,
194
- to_pascal_case(element),
166
+ 'OpInsClave',
195
167
  attrib={},
196
168
  nsmap=None,
197
169
  )
198
- subelement.text = text
170
+ subelement.text = str(value)
171
+ continue
172
+
173
+ if element == 'op_firma_dig': # Lower case o in op
174
+ subelement = etree.SubElement(
175
+ ordenpago,
176
+ 'opFirmaDig',
177
+ attrib={},
178
+ nsmap=None,
179
+ )
180
+ subelement.text = str(value)
181
+ continue
182
+
183
+ if 'op_fecha' in element:
184
+ value = value.strftime('%Y%m%d')
185
+
186
+ tag = (
187
+ to_camel_case(element)
188
+ if element in _CAMEL_CASE_FIELDS
189
+ else to_pascal_case(element)
190
+ )
191
+ subelement = etree.SubElement(
192
+ ordenpago,
193
+ tag,
194
+ attrib={},
195
+ nsmap=None,
196
+ )
197
+ subelement.text = normalize_invalid_chars(str(value))
199
198
 
200
199
  return ordenpago
201
200
 
@@ -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,11 @@ 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)
235
+ if tag not in cls.model_fields:
236
+ return
238
237
 
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
238
+ if 'op_fecha' in tag:
239
+ orden_data[tag] = datetime.strptime(stripped, '%Y%m%d').date()
240
+ return
241
+
242
+ orden_data[tag] = stripped
@@ -1,10 +1,10 @@
1
1
  # mypy: disable-error-code="override"
2
2
 
3
+ from datetime import date
3
4
  from typing import Optional
4
5
 
5
6
  from spei import types
6
7
  from spei.resources.orden import Orden
7
- from spei.types.common import DateInt
8
8
 
9
9
 
10
10
  class TerceroATercero(Orden):
@@ -326,7 +326,7 @@ class DevolucionExtemporaneaNoAcreditada(Orden):
326
326
  op_folio_ori: Optional[int] = None
327
327
  paq_folio_ori: Optional[int] = None
328
328
 
329
- op_fecha_oper_ori: DateInt
329
+ op_fecha_oper_ori: date
330
330
  op_rastreo_ori: str
331
331
  op_monto_intereses: float
332
332
  op_monto_ori: float
@@ -345,7 +345,7 @@ class DevolucionExtemporaneaAcreditada(Orden):
345
345
  op_folio_ori: Optional[int] = None
346
346
  paq_folio_ori: Optional[int] = None
347
347
 
348
- op_fecha_oper_ori: DateInt
348
+ op_fecha_oper_ori: date
349
349
  op_rastreo_ori: str
350
350
  op_monto_ori: float
351
351
 
@@ -367,7 +367,7 @@ class DevolucionExtemporaneaEspecialAcreditada(Orden):
367
367
  op_folio_ori: Optional[int] = None
368
368
  paq_folio_ori: Optional[int] = None
369
369
 
370
- op_fecha_oper_ori: DateInt
370
+ op_fecha_oper_ori: date
371
371
  op_rastreo_ori: str
372
372
  op_monto_ori: float
373
373
 
@@ -26,13 +26,20 @@ class Respuesta(BaseModel):
26
26
  model_config = ConfigDict(use_enum_values=True)
27
27
 
28
28
  def build_xml(self):
29
- respuesta = etree.Element('respuesta')
29
+ respuesta = etree.Element('respuesta', attrib={}, nsmap=None)
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)
35
- subelement.text = str(value)
32
+ if element not in self.model_fields:
33
+ continue
34
+
35
+ pascal_case_element = to_pascal_case(element)
36
+ subelement = etree.SubElement(
37
+ respuesta,
38
+ pascal_case_element,
39
+ attrib={},
40
+ nsmap=None,
41
+ )
42
+ subelement.text = str(value)
36
43
 
37
44
  return respuesta
38
45
 
@@ -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)
@@ -0,0 +1,18 @@
1
+ # spei/types.py (or wherever you keep your custom types)
2
+ import re
3
+ from typing import Union
4
+
5
+ from pydantic import BeforeValidator
6
+ from typing_extensions import Annotated
7
+
8
+
9
+ def validate_institution_code(value: Union[str, int]) -> int:
10
+ """Validates and converts an institution code to a 3 or 5-digit integer."""
11
+ value_str = str(value)
12
+ if not re.match(r'^\d{3,5}$', value_str):
13
+ raise ValueError('must be exactly 3 or 5 digits')
14
+
15
+ return int(value_str)
16
+
17
+
18
+ InstitutionCode = Annotated[int, BeforeValidator(validate_institution_code)]
@@ -1,41 +0,0 @@
1
- # spei/types.py (or wherever you keep your custom types)
2
- import re
3
- from typing import Union
4
-
5
- from pydantic import BeforeValidator
6
- from typing_extensions import Annotated
7
-
8
-
9
- def validate_date_int(value: int) -> int: # noqa: WPS110
10
- """Validates and converts a date value to YYYYMMDD string format."""
11
- value_str = str(value)
12
- if not re.match(r'^\d{8}$', value_str):
13
- raise ValueError('must be 8 digits in YYYYMMDD format')
14
-
15
- # Additional date validation if needed
16
- year = int(value_str[:4])
17
- month = int(value_str[4:6])
18
- day = int(value_str[6:8])
19
-
20
- if year < 1900: # noqa: WPS432
21
- raise ValueError('invalid year')
22
-
23
- if not (1 <= month <= 12 and 1 <= day <= 31): # noqa: WPS432
24
- raise ValueError('invalid date')
25
-
26
- return int(value_str)
27
-
28
-
29
- DateInt = Annotated[int, BeforeValidator(validate_date_int)]
30
-
31
-
32
- def validate_institution_code(value: Union[str, int]) -> int:
33
- """Validates and converts an institution code to a 3 or 5-digit integer."""
34
- value_str = str(value)
35
- if not re.match(r'^\d{3,5}$', value_str):
36
- raise ValueError('must be exactly 3 or 5 digits')
37
-
38
- return int(value_str)
39
-
40
-
41
- InstitutionCode = Annotated[int, BeforeValidator(validate_institution_code)]
File without changes
File without changes
File without changes
File without changes
File without changes