11 |
matches= matcher.match (cuit) |
matches= matcher.match (cuit) |
12 |
if matches: |
if matches: |
13 |
cuit= "%s%s%s" % (matches.group (1), matches.group (2), matches.group (3)) |
cuit= "%s%s%s" % (matches.group (1), matches.group (2), matches.group (3)) |
|
else: |
|
|
return 0 |
|
14 |
|
|
15 |
# once unified, validate |
# once unified, validate |
16 |
magic= '5432765432' |
magic= '5432765432' |
17 |
# first 10 digits |
# first 10 digits |
18 |
data= cuit[:10] |
data= cuit[:10] |
19 |
# I *love* functional languages :) |
# I *love* functional languages :) |
20 |
try: |
check= 11 - (reduce (lambda x, y: x+y, map (lambda x, y: int(x)*int(y), data, magic)) % 11) |
21 |
check= 11 - (reduce (lambda x, y: x+y, map (lambda x, y: int(x)*int(y), data, magic)) % 11) |
if check==10: |
22 |
if check==10: |
check= 9 |
23 |
check= 9 |
elif check==11: |
24 |
elif check==11: |
check= 0 |
25 |
check= 0 |
|
26 |
|
return check==int(cuit[10]) |
|
return check==int(cuit[10]) |
|
|
# just in case they entered letters or the like |
|
|
except TypeError: |
|
|
return 0 |
|