From f500633d158a3eaa71f2fd9fdb7ba00cf7abc96e Mon Sep 17 00:00:00 2001 From: gabriel-logan Date: Wed, 23 Aug 2023 01:03:07 -0300 Subject: [PATCH] Fixing bugs python lib --- pythonVersion/README.md | 22 ++++++++++++++++ .../src/multiform_validator.egg-info/PKG-INFO | 22 +++++++++++++++- .../src/multiform_validator/cnpjValidator.py | 3 +-- .../src/multiform_validator/cpfValidator.py | 2 -- .../multiform_validator/identifyFlagCard.py | 22 ++++++++-------- .../multiform_validator/isCreditCardValid.py | 25 +++++++++++-------- .../src/multiform_validator/isEmail.py | 1 - 7 files changed, 71 insertions(+), 26 deletions(-) diff --git a/pythonVersion/README.md b/pythonVersion/README.md index 428ae8b..f784766 100644 --- a/pythonVersion/README.md +++ b/pythonVersion/README.md @@ -26,6 +26,28 @@ If you want to help me, you can buy me a coffee (: pip install multiform-validator ``` +# Avaliable for while + +- **cnpjValidator**: CNPJ validation. +- **cpfValidator**: CPF validation. +- **getOnlyEmail**: Extracts only the email or emails address from a string. +- **identifyFlagCard**: Identifies the flag of a credit card. +- **isCreditCardValid**: Credit card validation. +- **isEmail**: Email address validation format. +- **passwordStrengthTester**: Password strength test. +- **validateBRPhoneNumber**: Brazilian phone number validation. + +from multiform_validator import ( + cnpjIsValid, + cpfIsValid, + getOnlyEmail, + identifyFlagCard, + isCreditCardValid, + isEmail, + passwordStrengthTester, + validateBRPhoneNumber +) + # Data Validator This package contains various modules for validating different types of data. Below are the available validation modules: diff --git a/pythonVersion/src/multiform_validator.egg-info/PKG-INFO b/pythonVersion/src/multiform_validator.egg-info/PKG-INFO index b93ada3..4d74843 100644 --- a/pythonVersion/src/multiform_validator.egg-info/PKG-INFO +++ b/pythonVersion/src/multiform_validator.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: multiform-validator -Version: 0.0.3 +Version: 0.0.5 Summary: A small example package Author: Gabriel Logan Project-URL: Homepage, https://github.com/gabriel-logan/multiform-validator/tree/main/pythonVersion @@ -40,6 +40,26 @@ If you want to help me, you can buy me a coffee (: pip install multiform-validator ``` +# Avaliable for while + +- **cnpjValidator**: CNPJ validation. +- **cpfValidator**: CPF validation. +- **getOnlyEmail**: Extracts only the email or emails address from a string. +- **identifyFlagCard**: Identifies the flag of a credit card. +- **isCreditCardValid**: Credit card validation. +- **isEmail**: Email address validation format. +- **passwordStrengthTester**: Password strength test. +- **validateBRPhoneNumber**: Brazilian phone number validation. + +from .cpfValidator import cpfValidator as +from .cnpjValidator import cnpjValidator as cnpjIsValid +from .getOnlyEmail import getOnlyEmail +from .isEmail import isEmail +from .identifyFlagCard import identifyFlagCard +from .isCreditCardValid import isCreditCardValid +from .passwordStrengthTester import passwordStrengthTester +from .validateBRPhoneNumber import validateBRPhoneNumber + # Data Validator This package contains various modules for validating different types of data. Below are the available validation modules: diff --git a/pythonVersion/src/multiform_validator/cnpjValidator.py b/pythonVersion/src/multiform_validator/cnpjValidator.py index 669db08..dbaae63 100644 --- a/pythonVersion/src/multiform_validator/cnpjValidator.py +++ b/pythonVersion/src/multiform_validator/cnpjValidator.py @@ -17,7 +17,7 @@ def calculate_second_verifier(cnpj_base, first_verifier): default_error_msg = ['CNPJ invalid', 'CNPJ must have 14 numerical digits', 'CNPJ is not valid', 'Unknown error'] -def cnpjValidator(cnpj: str, errorMsg: list[str, str or None]=default_error_msg) -> object[bool, str or None]: +def cnpjValidator(cnpj: str, errorMsg: list[str, str or None]=default_error_msg) -> dict[bool, str or None]: if not isinstance(cnpj, str): raise TypeError('The input should be a string.') @@ -59,4 +59,3 @@ def get_error_message(index): 'isValid': False, 'errorMsg': get_error_message(3), # 'Unknown error' } - diff --git a/pythonVersion/src/multiform_validator/cpfValidator.py b/pythonVersion/src/multiform_validator/cpfValidator.py index 8c2d5be..ed71f67 100644 --- a/pythonVersion/src/multiform_validator/cpfValidator.py +++ b/pythonVersion/src/multiform_validator/cpfValidator.py @@ -90,5 +90,3 @@ def getErrorMessage(index): "isValid": False, "errorMsg": getErrorMessage(3), } - - diff --git a/pythonVersion/src/multiform_validator/identifyFlagCard.py b/pythonVersion/src/multiform_validator/identifyFlagCard.py index fed2f50..614e10f 100644 --- a/pythonVersion/src/multiform_validator/identifyFlagCard.py +++ b/pythonVersion/src/multiform_validator/identifyFlagCard.py @@ -1,18 +1,20 @@ +import re + def identifyFlagCard(cardNumber: str): if not isinstance(cardNumber, str): raise TypeError('The input should be a string.') bandeiras = [ - {'name': 'Visa', 'interval': '^4'}, - {'name': 'Mastercard', 'interval': '^5[1-5]'}, - {'name': 'American Express', 'interval': '^3[47]'}, - {'name': 'Discover', 'interval': '^6(?:011|5)'}, - {'name': 'JCB', 'interval': '^(?:2131|1800|35\d{3})'}, - {'name': 'Diners Club', 'interval': '^3(?:0[0-5]|[68])'}, - {'name': 'Maestro', 'interval': '^(?:5[0678]\d\d|6304|6390|67\d\d)'}, - {'name': 'UnionPay', 'interval': '^(62|88)'}, - {'name': 'Elo', 'interval': '^63[789]'}, - {'name': 'Hipercard', 'interval': '^(3841|60)'}, + {'name': 'Visa', 'interval': re.compile('^4')}, + {'name': 'Mastercard', 'interval': re.compile('^5[1-5]')}, + {'name': 'American Express', 'interval': re.compile('^3[47]')}, + {'name': 'Discover', 'interval': re.compile('^6(?:011|5)')}, + {'name': 'JCB', 'interval': re.compile('^(?:2131|1800|35\d{3})')}, + {'name': 'Diners Club', 'interval': re.compile('^3(?:0[0-5]|[68])')}, + {'name': 'Maestro', 'interval': re.compile('^(?:5[0678]\d\d|6304|6390|67\d\d)')}, + {'name': 'UnionPay', 'interval': re.compile('^(62|88)')}, + {'name': 'Elo', 'interval': re.compile('^63[789]')}, + {'name': 'Hipercard', 'interval': re.compile('^(3841|60)')}, ] def find_interval(band): diff --git a/pythonVersion/src/multiform_validator/isCreditCardValid.py b/pythonVersion/src/multiform_validator/isCreditCardValid.py index 7a8ce20..d328b9b 100644 --- a/pythonVersion/src/multiform_validator/isCreditCardValid.py +++ b/pythonVersion/src/multiform_validator/isCreditCardValid.py @@ -1,19 +1,24 @@ -def isCreditCardValid(cardNumber: str): +def isCreditCardValid(cardNumber: str) -> bool: if not isinstance(cardNumber, str): raise TypeError('The input should be a string.') - digits = list(map(int, filter(str.isdigit, cardNumber))) - tamanho_do_digito = len(digits) - sum_value = 0 - is_even = False + # Remove espaços em branco e verifica se todos os caracteres são dígitos + cardNumber = cardNumber.replace(" ", "") + if not cardNumber.isdigit(): + return False - for i in range(tamanho_do_digito - 1, -1, -1): + digits = list(map(int, cardNumber)) + tamanhoDoDigito = len(digits) + totalSum = 0 + isEven = False + + for i in range(tamanhoDoDigito - 1, -1, -1): digit = digits[i] - if is_even: + if isEven: digit *= 2 if digit > 9: digit -= 9 - sum_value += digit - is_even = not is_even + totalSum += digit + isEven = not isEven - return sum_value % 10 == 0 + return totalSum % 10 == 0 diff --git a/pythonVersion/src/multiform_validator/isEmail.py b/pythonVersion/src/multiform_validator/isEmail.py index 4c49519..3d9976a 100644 --- a/pythonVersion/src/multiform_validator/isEmail.py +++ b/pythonVersion/src/multiform_validator/isEmail.py @@ -21,4 +21,3 @@ def isEmail(email: str) -> bool: return True except Exception: return False -