Replace re.match with re.fullmatch

See [Benjamin-Loison/cpython/issues/43](https://github.com/Benjamin-Loison/cpython/issues/43).
This commit is contained in:
Benjamin Loison 2024-10-16 20:03:32 +02:00
parent 91fb433258
commit 4969025722
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -54,12 +54,12 @@ def readPdfBankStatement(filePath):
for line in lines:
if not started:
# We are interested in the content after this line:)
soldeCrediteurAuRegexMatch = SOLDE_CREDITEUR_AU_REGEX.match(line)
if COLUMNS_HEADER.match(line) is not None:
soldeCrediteurAuRegexMatch = SOLDE_CREDITEUR_AU_REGEX.fullmatch(line)
if COLUMNS_HEADER.fullmatch(line) is not None:
getIndex = lambda line, type_: line.index(type_) + len(type_)
debitIndex = getIndex(line, 'Débit')
creditIndex = getIndex(line, 'Crédit')
if soldeCrediteurAuRegexMatch is not None or (COLUMNS_HEADER.match(line) is not None and not firstPage):
if soldeCrediteurAuRegexMatch is not None or (COLUMNS_HEADER.fullmatch(line) is not None and not firstPage):
if soldeCrediteurAuRegexMatch is not None:
initialDate = datetime.strptime(soldeCrediteurAuRegexMatch.group(1), '%d.%m.%Y')
initialAmount = toFloat(soldeCrediteurAuRegexMatch.group(2))
@ -69,14 +69,14 @@ def readPdfBankStatement(filePath):
continue
else:
# We aren't interested in the content after this line:
if line.startswith('BNP PARIBAS SA au capital de') or END_PAGE_AFTER_THE_FIRST_ONE_REGEX.match(line) is not None:
if line.startswith('BNP PARIBAS SA au capital de') or END_PAGE_AFTER_THE_FIRST_ONE_REGEX.fullmatch(line) is not None:
firstPage = False
started = False
continue
# We aren't interested in the content after this line
else:
totalDesOperationsRegexMatch = TOTAL_DES_OPERATIONS_REGEX.match(line)
totalDesOperationsCreditOnlyRegexMatch = TOTAL_DES_OPERATIONS_CREDIT_ONLY_REGEX.match(line)
totalDesOperationsRegexMatch = TOTAL_DES_OPERATIONS_REGEX.fullmatch(line)
totalDesOperationsCreditOnlyRegexMatch = TOTAL_DES_OPERATIONS_CREDIT_ONLY_REGEX.fullmatch(line)
if totalDesOperationsRegexMatch is not None or totalDesOperationsCreditOnlyRegexMatch is not None:
# Note that transfer between accounts will be noted in both debits and credits, as trying to cancel would make benefits show as negative debit which does not make sense.
# Cannot just consider January as benefits only as `20240122.pdf` also contains an additional transfer between my accounts.
@ -88,7 +88,7 @@ def readPdfBankStatement(filePath):
print(f'{totalMonthlyDebit=}')
print(f'{totalMonthlyCredit=}')
break
firstLineOfPaymentRegexMatch = FIRST_LINE_OF_PAYMENT_REGEX.match(line)
firstLineOfPaymentRegexMatch = FIRST_LINE_OF_PAYMENT_REGEX.fullmatch(line)
if firstLineOfPaymentRegexMatch is not None:
if date is not None:
transactions += [{