class IS_CPF_OR_CNPJ(object):
def __init__(self, format=True, error_message='Digite apenas os números!'):
self.format = format
self.error_message = error_message
def __call__(self, value):
try:
#return (value, 'cpf incorreto'+str(value))
#return (value, 'cpf incorreto'+str(cl))
c = []
for d in value:
if d.isdigit():
c.append(d)
cl = str(''.join(c))
#return (value, 'cpf incorreto'+str(cl))
if len(cl) == 11:
cpf = cl
cnpj = None
elif len(cl) == 14:
cpf = None
cnpj = cl
else:
return (value, 'Número de dígitos incorreto para CPF ou CNPJ')
#return(cpf,'aquiok'+str(len(cpf)==11))
if cpf:
def valida(value):
def calcdv(numb):
result = int()
seq = reversed(((range(9, id_type[1], -1)*2)[:len(numb)]))
#return (value,'to fundo1')
for digit, base in zip(numb, seq):
result += int(digit)*int(base)
dv = result % 11
#return (value,'to fundo1'+str(dv))
return (dv-10) and dv or 0
id_type = ['CPF', -1]
numb, xdv = value[:-2], value[-2:]
dv1 = calcdv(numb)
#return (value,'entrei'+str(dv1))
dv2 = calcdv(numb + str(dv1))
return (('%d%d' % (dv1, dv2) == xdv and True or False), id_type[0])
try:
cpf=str(value)
#return(cpf,'aquiok'+str(len(cpf)==11))
if len(cpf)>=11:
#return (value, 'cpf acima de 11')
c = []
for d in cpf:
if d.isdigit():
c.append(d)
cl = str(''.join(c))
#return (value, 'cpf incorreto'+str(cl))
if len(cl) == 11:
if valida(cl)[0] == True:
return(value,None)
else:
cStudy Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math Blog do Xandeo t Study Of Math Study Of Math Study Of Math Study Of Math
jStudy Of Math Safety Studyofmath Study Of Math Szh B%3E%3C A%3E%20%7C%20%3Ca%20href Study Of Math Blog do Xandei g Study Of Math Study Of Math