src/reportlab/graphics/barcode/usps.py
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3966 d3d2b5e09c88
equal deleted inserted replaced
3722:29c11b905751 3723:99aa837b6703
    95     barHeight = inch * (5.0/8.0)
    95     barHeight = inch * (5.0/8.0)
    96     rquiet = inch * (0.25)
    96     rquiet = inch * (0.25)
    97     lquiet = inch * (15.0/32.0)
    97     lquiet = inch * (15.0/32.0)
    98     quiet = 0
    98     quiet = 0
    99     def __init__(self, value='', **args):
    99     def __init__(self, value='', **args):
   100         for (k, v) in list(args.items()):
   100         for k, v in args.items():
   101             setattr(self, k, v)
   101             setattr(self, k, v)
   102 
   102 
   103         Barcode.__init__(self, value)
   103         Barcode.__init__(self, value)
   104 
   104 
   105     def validate(self):
   105     def validate(self):
   107         self.validated = ''
   107         self.validated = ''
   108         for c in self.value:
   108         for c in self.value:
   109             if c in string.whitespace:
   109             if c in string.whitespace:
   110                 continue
   110                 continue
   111             elif c in "abcdABCD":
   111             elif c in "abcdABCD":
   112                 self.validated = self.validated + string.upper(c)
   112                 self.validated = self.validated + c.upper()
   113             else:
   113             else:
   114                 self.valid = 0
   114                 self.valid = 0
   115 
   115 
   116         if len(self.validated) != 1:
   116         if len(self.validated) != 1:
   117             raise ValueError("Input must be exactly one character")
   117             raise ValueError("Input must be exactly one character")
   160     barHeight = inch * 0.125
   160     barHeight = inch * 0.125
   161     barWidth = inch * 0.018
   161     barWidth = inch * 0.018
   162     spaceWidth = inch * 0.0275
   162     spaceWidth = inch * 0.0275
   163     def __init__(self, value='', **args):
   163     def __init__(self, value='', **args):
   164 
   164 
   165         for (k, v) in list(args.items()):
   165         for k, v in args.items():
   166             setattr(self, k, v)
   166             setattr(self, k, v)
   167 
   167 
   168         Barcode.__init__(self, value)
   168         Barcode.__init__(self, value)
   169 
   169 
   170     def validate(self):
   170     def validate(self):
   191         self.encoded = "S"
   191         self.encoded = "S"
   192         check = 0
   192         check = 0
   193         for c in self.validated:
   193         for c in self.validated:
   194             if c in string.digits:
   194             if c in string.digits:
   195                 self.encoded = self.encoded + c
   195                 self.encoded = self.encoded + c
   196                 check = check + string.atoi(c)
   196                 check = check + int(c)
   197             elif c == '-':
   197             elif c == '-':
   198                 pass
   198                 pass
   199             else:
   199             else:
   200                 raise ValueError("Invalid character in input")
   200                 raise ValueError("Invalid character in input")
   201         check = (10 - check) % 10
   201         check = (10 - check) % 10