/[papo]/papo/forms/cuit.py
ViewVC logotype

Diff of /papo/forms/cuit.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by styxman, Mon Mar 10 22:12:30 2003 UTC revision 1.4.2.1 by anthonyl, Fri Mar 14 22:45:25 2003 UTC
# Line 11  def validate (cuit): Line 11  def validate (cuit):
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  

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.4.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26