Code39Ext.py
Go to the documentation of this file.
00001 ''' 00002 Copyright (C) 2007 Martin Owens 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 ''' 00018 00019 import Code39 00020 00021 encode = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ') 00022 00023 map = {} 00024 00025 i = 0 00026 for char in encode: 00027 map[char] = i 00028 i = i + 1 00029 00030 # Extended encoding maps for full ASCII Code93 00031 def getMap(array): 00032 result = {} 00033 y = 0 00034 for x in array: 00035 result[chr(x)] = encode[y] 00036 y = y + 1 00037 00038 return result; 00039 00040 # MapA is eclectic, but B, C, D are all ASCII ranges 00041 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]) # % 00042 mapB = getMap(range(1, 26)) # $ 00043 mapC = getMap(range(33, 58)) # / 00044 mapD = getMap(range(97, 122)) # + 00045 00046 class Object(Code39.Object): 00047 def encode(self, text): 00048 # We are only going to extend the Code39 barcodes 00049 result = '' 00050 for char in text: 00051 if mapA.has_key(char): 00052 char = '%' + mapA[char] 00053 elif mapB.has_key(char): 00054 char = '$' + mapB[char] 00055 elif mapC.has_key(char): 00056 char = '/' + mapC[char] 00057 elif mapD.has_key(char): 00058 char = '+' + mapD[char] 00059 result = result + char 00060 00061 return Code39.Object.encode(self, result); 00062
