23c0d6a46a9633f92e82f1961378d8660844e3bd
1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2007 Martin Owens
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
20 import Code39
22 encode = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
24 map = {}
26 i = 0
27 for char in encode:
28 map[char] = i
29 i = i + 1
31 # Extended encoding maps for full ASCII Code93
32 def getMap(array):
33 result = {}
34 y = 0
35 for x in array:
36 result[chr(x)] = encode[y]
37 y = y + 1
39 return result;
41 # MapA is eclectic, but B, C, D are all ASCII ranges
42 mapA = getMap([27,28,29,30,31,59,60,61,62,63,91,92,93,94,95,123,124,125,126,127,0,64,96,127,127,127]) # %
43 mapB = getMap(range(1, 26)) # $
44 mapC = getMap(range(33, 58)) # /
45 mapD = getMap(range(97, 122)) # +
47 class Object(Code39.Object):
48 def encode(self, text):
49 # We are only going to extend the Code39 barcodes
50 result = ''
51 for char in text:
52 if mapA.has_key(char):
53 char = '%' + mapA[char]
54 elif mapB.has_key(char):
55 char = '$' + mapB[char]
56 elif mapC.has_key(char):
57 char = '/' + mapC[char]
58 elif mapD.has_key(char):
59 char = '+' + mapD[char]
60 result = result + char
62 return Code39.Object.encode(self, result);