src/reportlab/graphics/barcode/code93.py
branchpy33
changeset 3794 398ea04239b5
parent 3723 99aa837b6703
child 3975 4a3599863c11
equal deleted inserted replaced
3793:cc3f9cc828f7 3794:398ea04239b5
    30 # POSSIBILITY OF SUCH DAMAGE.
    30 # POSSIBILITY OF SUCH DAMAGE.
    31 #
    31 #
    32 
    32 
    33 from reportlab.lib.units import inch
    33 from reportlab.lib.units import inch
    34 from .common import MultiWidthBarcode
    34 from .common import MultiWidthBarcode
    35 import string
       
    36 
    35 
    37 _patterns = {
    36 _patterns = {
    38   '0' : ('AcAaAb', 0),  '1' : ('AaAbAc', 1),  '2' : ('AaAcAb', 2),
    37   '0' : ('AcAaAb', 0),  '1' : ('AaAbAc', 1),  '2' : ('AaAcAb', 2),
    39   '3' : ('AaAdAa', 3),  '4' : ('AbAaAc', 4),  '5' : ('AbAbAb', 5),
    38   '3' : ('AaAdAa', 3),  '4' : ('AbAaAc', 4),  '5' : ('AbAbAb', 5),
    40   '6' : ('AbAcAa', 6),  '7' : ('AaAaAd', 7),  '8' : ('AcAbAa', 8),
    39   '6' : ('AbAcAa', 6),  '7' : ('AaAaAd', 7),  '8' : ('AcAbAa', 8),
   106             v = 1
   105             v = 1
   107     s.insert(0, _charsbyval[c % 47])
   106     s.insert(0, _charsbyval[c % 47])
   108 
   107 
   109     s.reverse()
   108     s.reverse()
   110 
   109 
   111     return string.join(s, '')
   110     return ''.join(s)
   112 
   111 
   113 class _Code93Base(MultiWidthBarcode):
   112 class _Code93Base(MultiWidthBarcode):
   114     barWidth = inch * 0.0075
   113     barWidth = inch * 0.0075
   115     lquiet = None
   114     lquiet = None
   116     rquiet = None
   115     rquiet = None
   182     http://www.aimglobal.org/aimstore/
   181     http://www.aimglobal.org/aimstore/
   183     """
   182     """
   184     def validate(self):
   183     def validate(self):
   185         vval = ""
   184         vval = ""
   186         self.valid = 1
   185         self.valid = 1
   187         for c in self.value:
   186         for c in self.value.upper():
   188             if c in string.lowercase:
       
   189                 c = string.upper(c)
       
   190             if c not in _patterns:
   187             if c not in _patterns:
   191                 self.valid = 0
   188                 self.valid = 0
   192                 continue
   189                 continue
   193             vval = vval + c
   190             vval = vval + c
   194         self.validated = vval
   191         self.validated = vval