brdocs-validation 0.2.0__py3-none-any.whl → 0.4.0__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.
br_docs/__init__.py CHANGED
@@ -1,12 +1,16 @@
1
1
  from pydantic.functional_validators import AfterValidator
2
2
  from typing_extensions import Annotated
3
3
 
4
+ from br_docs.validators.cert import CERTv
4
5
  from br_docs.validators.cnh import CNHv
5
6
  from br_docs.validators.cnpj import CNPJv
6
7
  from br_docs.validators.cns import CNSv
7
8
  from br_docs.validators.cpf import CPFv
8
9
  from br_docs.validators.nis import NISv
9
10
  from br_docs.validators.renavam import RENAVAMv
11
+ from br_docs.validators.te import TEv
12
+ from br_docs.validators.sei import SEIv
13
+
10
14
 
11
15
  CPF = Annotated[str, AfterValidator(CPFv())]
12
16
  CNPJ = Annotated[str, AfterValidator(CNPJv())]
@@ -14,3 +18,6 @@ CNH = Annotated[str, AfterValidator(CNHv())]
14
18
  NIS = Annotated[str, AfterValidator(NISv())]
15
19
  CNS = Annotated[str, AfterValidator(CNSv())]
16
20
  RENAVAM = Annotated[str, AfterValidator(RENAVAMv())]
21
+ TE = Annotated[str, AfterValidator(TEv())]
22
+ CERT = Annotated[str, AfterValidator(CERTv())]
23
+ SEI = Annotated[str, AfterValidator(SEIv())]
@@ -0,0 +1,26 @@
1
+ import re
2
+
3
+ from br_docs.validators import CheckDigits
4
+
5
+
6
+ class CERTv(CheckDigits):
7
+ """ Certidões de casamento, nascimento e óbito """
8
+ Patterns = re.compile(r"^\d{32}$"),
9
+ CHECK_DIGITS = 2
10
+ CertAlgarismsMultipliers = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
11
+
12
+ @classmethod
13
+ def calculate_digits(cls, non_digits: list[int]) -> tuple[int, ...]:
14
+ """ https://web.archive.org/web/20240227052915/http://ghiorzi.org/DVnew.htm#zc """
15
+ def sum_(slice_: int = 1, value: int | None = None) -> int:
16
+ numbers = non_digits
17
+ if value is not None:
18
+ numbers.append(value)
19
+ digit = sum(x * y for x, y in zip(numbers, cls.CertAlgarismsMultipliers[slice_:])) % 11
20
+ if digit == 10:
21
+ return 1
22
+ return digit
23
+
24
+ digit_one = sum_()
25
+ digit_two = sum_(0, digit_one)
26
+ return digit_one, digit_two
@@ -0,0 +1,17 @@
1
+ import re
2
+
3
+ from pydantic_core import PydanticCustomError
4
+
5
+
6
+ class SEIv:
7
+ Patterns = re.compile(r'^\d{5}-?\d{8}/?\d{4}-?\d{2}$')
8
+
9
+ def __call__(self, value: str) -> str:
10
+ self.validate(value)
11
+ return value
12
+
13
+ def validate(self, value: str) -> str:
14
+ check_format = bool(self.Patterns.match(value))
15
+ if check_format is not True:
16
+ raise PydanticCustomError('invalid', 'Invalid Value')
17
+ return value
@@ -0,0 +1,33 @@
1
+ import re
2
+
3
+ from pydantic_core import PydanticCustomError
4
+
5
+ from br_docs.validators import CheckDigits
6
+
7
+
8
+ class TEv(CheckDigits):
9
+ """ Titulo de eleitor """
10
+ Patterns = re.compile(r"^\d{12}$"),
11
+
12
+ def validate(self, value: str):
13
+ valid_value = self.calculate_digits(list(map(int, value)))[0]
14
+ if not valid_value:
15
+ raise PydanticCustomError(
16
+ 'invalid',
17
+ 'invalid value'
18
+ )
19
+
20
+ @staticmethod
21
+ def calculate_digits(value: list[int]) -> tuple[int]:
22
+ """ https://web.archive.org/web/20240226104136/https://exceldoseujeito.com.br/validar-cpf-cnpj-e-titulo-de-eleitor-parte-ii/ """
23
+ check_digit_one = sum(x*y for x, y in zip(value[:8], range(2, 10))) % 11
24
+ if check_digit_one == 10:
25
+ check_digit_one = 0
26
+
27
+ value.append(check_digit_one)
28
+ check_digit_two = sum(x*y for x, y in zip(value[8:], range(7, 10))) % 11
29
+ if check_digit_two == 10:
30
+ check_digit_two = 0
31
+ if check_digit_one == value[-3] and check_digit_two == value[-2] and 0 < int(str(value[8]) + str(value[9])) < 29:
32
+ return 1,
33
+ return 0,
@@ -1,24 +1,23 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: brdocs-validation
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Validate brazilian documents using Type Hints in classes inheriting Pydantic's (V2) BaseModel
5
5
  Author-email: Vinícius Aguiar <vaguiararqdevsoftware@proton.me>
6
6
  Maintainer-email: Vinícius Aguiar <vaguiararqdevsoftware@proton.me>
7
7
  Project-URL: Repository, https://github.com/vinicius-oa/BRdocs-validation
8
- Keywords: pydantic-v2,cpf-validador,cnpj-validador
8
+ Keywords: pydantic-v2,cpf-validador,cnpj-validador,validador-pispasep,validador-titulo-eleitor
9
9
  Classifier: Development Status :: 5 - Production/Stable
10
10
  Classifier: Framework :: Pydantic :: 2
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Topic :: Software Development :: Build Tools
13
13
  Classifier: License :: OSI Approved :: MIT License
14
14
  Classifier: Natural Language :: English
15
- Classifier: Programming Language :: Python :: 3.9
16
15
  Classifier: Programming Language :: Python :: 3.10
17
16
  Classifier: Programming Language :: Python :: 3.11
18
17
  Classifier: Programming Language :: Python :: 3.12
19
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
19
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.10
22
21
  Description-Content-Type: text/markdown
23
22
  License-File: LICENSE.txt
24
23
  Requires-Dist: pydantic >=2.0
@@ -33,7 +32,7 @@ Requires-Dist: ruff ; extra == 'dev'
33
32
 
34
33
  ![Test](https://github.com/vinicius-oa/BRdocs-validation/actions/workflows/test.yml/badge.svg)
35
34
  ![codecov](https://codecov.io/gh/vinicius-oa/BRdocs-validation/graph/badge.svg?token=Z211YIKO8L)
36
- ![PyPI version](https://badge.fury.io/py/brdocs-validation.svg)
35
+ ![PyPI - Version](https://img.shields.io/pypi/v/brdocs-validation?label=pypi%20package&color=2334D058)
37
36
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/brdocs-validation?color=2334D058)
38
37
  ![Pydantic V2](https://img.shields.io/badge/Pydantic_V2->=2.0-2334D058.svg)
39
38
 
@@ -45,18 +44,22 @@ pip install brdocs-validation
45
44
 
46
45
  ## Supported docs and its formats
47
46
 
48
- | Supports | Description | Format | Format's support |
49
- |:-----------------:|:----------------------------------------:|:-----------------------------------------------:|:------------------:|
50
- | CNPJ | | *12.345.678/9012-34* OR _Without special chars_ | |
51
- | CPF | | *123.456.789-01* OR _Without special chars_ | |
52
- | CNH | | Only numbers | Length: _11_ |
53
- | NIS/PIS/PASEP/NIT | Use _**NIS**_ type for _PIS, PASEP, NIT_ | *123.45678.90-1* OR _Only numbers_ | |
54
- | CNS | Cartão Nacional de Saúde | Only numbers | |
55
- | RENAVAM | | Only numbers | Length: _9, 10 & 11_ |
47
+ | Supports | Description | Format | Format's support |
48
+ |:-----------------:|:-----------------------------------------:|:-----------------------------------------------:|:--------------------:|
49
+ | CNPJ | | *12.345.678/9012-34* OR _Without special chars_ | |
50
+ | CPF | | *123.456.789-01* OR _Without special chars_ | |
51
+ | CNH | | Only numbers | Length: _11_ |
52
+ | NIS/PIS/PASEP/NIT | Use _**NIS**_ type for _PIS, PASEP, NIT_ | *123.45678.90-1* OR _Only numbers_ | |
53
+ | CNS | Cartão Nacional de Saúde | Only numbers | |
54
+ | RENAVAM | | Only numbers | Length: _9, 10 & 11_ |
55
+ | TE | Título de eleitor | Only numbers | |
56
+ | CERT | Certidão de casamento, nascimento e óbito | Only numbers | |
57
+ | SEI | Número do Processo SEI | 12345-67890123/4567-89 OR without special chars | |
58
+
56
59
  ## Usage
57
60
 
58
61
  ```python
59
- from br_docs import CNPJ, CPF, CNH, NIS, CNS, RENAVAM
62
+ from br_docs import CNPJ, CPF, CNH, NIS, CNS, RENAVAM, TE, CERT, SEI
60
63
  from pydantic import BaseModel
61
64
 
62
65
 
@@ -67,4 +70,7 @@ class User(BaseModel):
67
70
  nis: NIS
68
71
  cns: CNS
69
72
  renavam: RENAVAM
73
+ te: TE
74
+ cert: CERT
75
+ sei: SEI
70
76
  ```
@@ -1,15 +1,18 @@
1
- br_docs/__init__.py,sha256=ST17H5LBy8ZWrLDl3BHn56oI8cxegLDHCGdwrGMX3ZU,630
1
+ br_docs/__init__.py,sha256=YrOKIcR1Ie1C-fQw6MlWFklx7WHcuQ93Qid-rNMDKPE,886
2
2
  br_docs/validators/__init__.py,sha256=7DeKn9Uq2znYN-P2yAVRkqwGY-Bvh8GIEjbpCMe9sRQ,1021
3
+ br_docs/validators/cert.py,sha256=KpRxqavETcpSPVJbIWz7gfs-KjjnsuvmtZcV6mmAcI4,962
3
4
  br_docs/validators/cnh.py,sha256=3rjcusDdCdUD_id_oIWcMtM0biATDu_yYkuaq_NVSEg,1119
4
5
  br_docs/validators/cnpj.py,sha256=0avmB7_apQChP2WUHTfLxWEe6k9-4qA0jRbdu7mLqM4,914
5
6
  br_docs/validators/cns.py,sha256=sDiZEeoUZ2yo9J-3opE2ZjOTVO9eTCBlPBhRBlfuGcE,1140
6
7
  br_docs/validators/cpf.py,sha256=a9oxE3Su-RYpGKMAzO4SUD4kddm8qkbbhSVKFEhkOog,611
7
8
  br_docs/validators/nis.py,sha256=47wi0sLjsr9aDdxVuVfSMRtQfV9AnW32tm2j5hRjiO0,661
8
9
  br_docs/validators/renavam.py,sha256=IeJimMmERHGZ1b3Tjo731ThZzNR7dA1NeZA97r3CqOo,738
10
+ br_docs/validators/sei.py,sha256=WHy3exmb-5tlZuNmMxkTzyMHBOhUrm6uyj6nyozhXv4,448
11
+ br_docs/validators/te.py,sha256=KuGwM9pVydP1QKeKd6t57Ay4IG6augY11qIRwjLgDVo,1153
9
12
  br_docs/validators/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
13
  br_docs/validators/types/format.py,sha256=hj4f3KjW7mAz7l1F6pXby4_BahGNGdaIbNbmsQxrXTI,421
11
- brdocs_validation-0.2.0.dist-info/LICENSE.txt,sha256=FdwJdtrJG9B1E0C3y6BG6QhRznIfFLzPXdUzclDkZYs,1073
12
- brdocs_validation-0.2.0.dist-info/METADATA,sha256=qeAup21Ov9oIFM3KHxZJMgNzVe87pGz1AAIxXkSe_VI,3295
13
- brdocs_validation-0.2.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
14
- brdocs_validation-0.2.0.dist-info/top_level.txt,sha256=COjwP4hy4qNtPXnPVmsgWBi_-2Byyw_0gmjorp3UnRA,8
15
- brdocs_validation-0.2.0.dist-info/RECORD,,
14
+ brdocs_validation-0.4.0.dist-info/LICENSE.txt,sha256=FdwJdtrJG9B1E0C3y6BG6QhRznIfFLzPXdUzclDkZYs,1073
15
+ brdocs_validation-0.4.0.dist-info/METADATA,sha256=wBGHyOVXTBFMIr7HmSSSm30JY7PJdv-UEwQBL8Wo0nc,3828
16
+ brdocs_validation-0.4.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
17
+ brdocs_validation-0.4.0.dist-info/top_level.txt,sha256=COjwP4hy4qNtPXnPVmsgWBi_-2Byyw_0gmjorp3UnRA,8
18
+ brdocs_validation-0.4.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5