mirror of
https://github.com/hoshikawa2/python_redaction.git
synced 2026-03-06 18:21:00 +00:00
adjustments for items in [ ].
bug: value with same name of an attribute was considered an attribute.
This commit is contained in:
24
Redaction.py
24
Redaction.py
@@ -27,11 +27,12 @@ import re
|
|||||||
|
|
||||||
class Redaction():
|
class Redaction():
|
||||||
|
|
||||||
def repl_value(self, message, pattern, r):
|
def repl_value(self, message, pattern):
|
||||||
flag_aspas = False
|
flag_aspas = False
|
||||||
flag_attribute = False
|
flag_attribute = False
|
||||||
# flag_vezes = 0
|
# flag_vezes = 0
|
||||||
flag_dois_pontos = False
|
flag_dois_pontos = False
|
||||||
|
flag_colchetes = False
|
||||||
i = 0
|
i = 0
|
||||||
z = pattern
|
z = pattern
|
||||||
str_acc = ""
|
str_acc = ""
|
||||||
@@ -51,14 +52,24 @@ class Redaction():
|
|||||||
flag_attribute = False
|
flag_attribute = False
|
||||||
flag_dois_pontos = False
|
flag_dois_pontos = False
|
||||||
flag_aspas = False
|
flag_aspas = False
|
||||||
if ((message[i] == "}" or message[i] == "]" or message[i] == ",") and flag_dois_pontos and not flag_aspas and flag_attribute):
|
flag_colchetes = False
|
||||||
|
if ((message[i] == "}" or message[i] == "]") and not flag_aspas):
|
||||||
flag_attribute = False
|
flag_attribute = False
|
||||||
flag_dois_pontos = False
|
flag_dois_pontos = False
|
||||||
flag_aspas = False
|
flag_aspas = False
|
||||||
|
flag_colchetes = False
|
||||||
|
str_acc = ""
|
||||||
|
if (flag_dois_pontos and not flag_aspas and message[i] == "["):
|
||||||
|
flag_colchetes = True
|
||||||
|
if (message[i] == "," and not flag_aspas and not flag_colchetes):
|
||||||
|
flag_attribute = False
|
||||||
|
flag_dois_pontos = False
|
||||||
|
flag_aspas = False
|
||||||
|
flag_colchetes = False
|
||||||
str_acc = ""
|
str_acc = ""
|
||||||
if ((message[i] == "'" or message[i] == "\"")):
|
if ((message[i] == "'" or message[i] == "\"")):
|
||||||
flag_aspas = not flag_aspas
|
flag_aspas = not flag_aspas
|
||||||
if (flag_aspas == False and flag_attribute == True and flag_dois_pontos and len(str_acc) > 0):
|
if (flag_aspas == False and flag_attribute == True and flag_dois_pontos and len(str_acc) > 0 and not flag_colchetes):
|
||||||
flag_attribute = False
|
flag_attribute = False
|
||||||
flag_dois_pontos = False
|
flag_dois_pontos = False
|
||||||
str_acc = ""
|
str_acc = ""
|
||||||
@@ -68,12 +79,7 @@ class Redaction():
|
|||||||
def repl(self, attribute_pattern, message):
|
def repl(self, attribute_pattern, message):
|
||||||
msg_return = []
|
msg_return = []
|
||||||
for pattern in attribute_pattern:
|
for pattern in attribute_pattern:
|
||||||
x = re.finditer(pattern, message)
|
message = self.repl_value(message, pattern)
|
||||||
for y in x:
|
|
||||||
msg_aux1 = []
|
|
||||||
for reg in y.regs:
|
|
||||||
for r in reg:
|
|
||||||
message = self.repl_value(message, pattern, r)
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def change(self, sensitive_pattern, message):
|
def change(self, sensitive_pattern, message):
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ SENSITIVE_PATTERNS = [
|
|||||||
|
|
||||||
ATTRIBUTE_PATTERNS = [
|
ATTRIBUTE_PATTERNS = [
|
||||||
"nome",
|
"nome",
|
||||||
|
"$ref",
|
||||||
"cpf",
|
"cpf",
|
||||||
"teste",
|
"teste",
|
||||||
"valor",
|
"valor",
|
||||||
@@ -21,7 +22,8 @@ ATTRIBUTE_PATTERNS = [
|
|||||||
"chave",
|
"chave",
|
||||||
"description",
|
"description",
|
||||||
"items",
|
"items",
|
||||||
"example"
|
"example",
|
||||||
|
"required"
|
||||||
]
|
]
|
||||||
|
|
||||||
Messages = [
|
Messages = [
|
||||||
@@ -34,7 +36,8 @@ Messages = [
|
|||||||
"User's phone number: (123) 456-7890",
|
"User's phone number: (123) 456-7890",
|
||||||
"User's date of birth: 04/29/1990",
|
"User's date of birth: 04/29/1990",
|
||||||
"User's IP address: 192.168.1.1",
|
"User's IP address: 192.168.1.1",
|
||||||
"User's API key: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"
|
"User's API key: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
|
||||||
|
'{ "nome": "João Silva", "cpf": "123.456.789-00", "teste": "Teste Valor", "valor": 200.00, "original": "Original Valor", "type": "Tipo Valor", "solicitacaoPagador": "Solicitação Pagador", "expiracao": "2021-12-31", "chave": "Chave Valor", "description": "Descrição Valor", "items": ["Item1", "Item2"], "example": "Exemplo Valor"}'
|
||||||
]
|
]
|
||||||
|
|
||||||
redaction = Redaction.Redaction()
|
redaction = Redaction.Redaction()
|
||||||
|
|||||||
Reference in New Issue
Block a user