Remove sql injection problem

lp bug: https://launchpad.net/bugs/429327 fixed

bzr revid: hda@tinyerp.com-20091021072449-rc9usc422tb0kv2f
This commit is contained in:
HDA (OpenERP) 2009-10-21 12:54:49 +05:30
parent 251b6720ca
commit b7f6bc4c8e
46 changed files with 2027 additions and 1960 deletions

View File

@ -729,7 +729,7 @@ class account_move(osv.osv):
def _amount_compute(self, cr, uid, ids, name, args, context, where =''): def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
if not ids: return {} if not ids: return {}
cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,ids))+') group by move_id') cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,map(int, ids)))+') group by move_id')
result = dict(cr.fetchall()) result = dict(cr.fetchall())
for id in ids: for id in ids:
result.setdefault(id, 0.0) result.setdefault(id, 0.0)
@ -807,7 +807,7 @@ class account_move(osv.osv):
if new_name: if new_name:
self.write(cr, uid, [move.id], {'name':new_name}) self.write(cr, uid, [move.id], {'name':new_name})
cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',)) cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('posted',))
else: else:
raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !')) raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))
return True return True
@ -820,7 +820,7 @@ class account_move(osv.osv):
if not line.journal_id.update_posted: if not line.journal_id.update_posted:
raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.')) raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
if len(ids): if len(ids):
cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('draft',)) cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('draft',))
return True return True
def write(self, cr, uid, ids, vals, context={}): def write(self, cr, uid, ids, vals, context={}):
@ -1177,7 +1177,7 @@ class account_tax_code(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False
@ -1797,7 +1797,7 @@ class account_account_template(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str,ids))+')') cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False
@ -1856,7 +1856,7 @@ class account_tax_code_template(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -397,7 +397,7 @@ class account_invoice(osv.osv):
l.id \ l.id \
from account_move_line l \ from account_move_line l \
left join account_invoice i on (i.move_id=l.move_id) \ left join account_invoice i on (i.move_id=l.move_id) \
where i.id in ('+','.join(map(str,ids))+') and l.account_id=i.account_id') where i.id in ('+','.join(map(str,map(int, ids)))+') and l.account_id=i.account_id')
res = map(lambda x: x[0], cr.fetchall()) res = map(lambda x: x[0], cr.fetchall())
return res return res
@ -680,7 +680,7 @@ class account_invoice(osv.osv):
def action_number(self, cr, uid, ids, *args): def action_number(self, cr, uid, ids, *args):
cr.execute('SELECT id, type, number, move_id, reference ' \ cr.execute('SELECT id, type, number, move_id, reference ' \
'FROM account_invoice ' \ 'FROM account_invoice ' \
'WHERE id IN ('+','.join(map(str,ids))+')') 'WHERE id IN ('+','.join(map(str, ids))+')')
obj_inv = self.browse(cr, uid, ids)[0] obj_inv = self.browse(cr, uid, ids)[0]
for (id, invtype, number, move_id, reference) in cr.fetchall(): for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number: if not number:

View File

@ -166,7 +166,7 @@ class partner_balance(report_sxw.rml_parse):
## ##
self.date_lst_string ='' self.date_lst_string =''
if self.date_lst: if self.date_lst:
self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\'' self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\''
## Compute Code ## Compute Code

View File

@ -162,7 +162,7 @@ class third_party_ledger(rml_parse.rml_parse):
self.date_lst_string = '' self.date_lst_string = ''
if self.date_lst: if self.date_lst:
self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\'' self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\''
# #
#new_ids = [id for (id,) in self.cr.fetchall()] #new_ids = [id for (id,) in self.cr.fetchall()]
if data['form']['result_selection'] == 'supplier': if data['form']['result_selection'] == 'supplier':

View File

@ -43,7 +43,7 @@ def _remove_entries(self, cr, uid, data, context):
period_journal = data_fyear.end_journal_period_id period_journal = data_fyear.end_journal_period_id
ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)]) ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
if ids_move: if ids_move:
cr.execute('delete from account_move where id in ('+','.join(map(str,ids_move))+')') cr.execute('delete from account_move where id in ('+','.join(map(str, ids_move))+')')
#cr.execute('UPDATE account_journal_period ' \ #cr.execute('UPDATE account_journal_period ' \
# 'SET state = %s ' \ # 'SET state = %s ' \
# 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)', # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)',

View File

@ -42,7 +42,7 @@ class account_move_line(osv.osv):
WHERE move_line_id = ml.id WHERE move_line_id = ml.id
AND po.state != 'cancel') as amount AND po.state != 'cancel') as amount
FROM account_move_line ml FROM account_move_line ml
WHERE id in (%s)""" % (",".join(map(str, ids)))) WHERE id in (%s)""" % (",".join(map(str,map(int, ids)))))
r=dict(cr.fetchall()) r=dict(cr.fetchall())
return r return r

View File

@ -225,7 +225,7 @@ class payment_line(osv.osv):
inner join payment_line pl inner join payment_line pl
on (ml.id = pl.move_line_id) on (ml.id = pl.move_line_id)
where pl.id in (%s)"""% where pl.id in (%s)"""%
(self.translate(name), ','.join(map(str,ids))) ) (self.translate(name), ','.join(map(str, ids))))
res = dict(cr.fetchall()) res = dict(cr.fetchall())
if name == 'partner_id': if name == 'partner_id':

View File

@ -404,7 +404,7 @@ class account_voucher(osv.osv):
def action_number(self, cr, uid, ids, *args): def action_number(self, cr, uid, ids, *args):
cr.execute('SELECT id, type, number, move_id, reference ' \ cr.execute('SELECT id, type, number, move_id, reference ' \
'FROM account_voucher ' \ 'FROM account_voucher ' \
'WHERE id IN ('+','.join(map(str,ids))+')') 'WHERE id IN ('+','.join(map(str, ids))+')')
for (id, invtype, number, move_id, reference) in cr.fetchall(): for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number: if not number:
number = self.pool.get('ir.sequence').get(cr, uid, invtype) number = self.pool.get('ir.sequence').get(cr, uid, invtype)

View File

@ -19,7 +19,6 @@
# #
############################################################################## ##############################################################################
{ {
'name': 'Analytic Journal Billing Rate', 'name': 'Analytic Journal Billing Rate',
'version': '1.0', 'version': '1.0',

View File

@ -94,12 +94,12 @@ class auction_dates(osv.osv):
RETURN: True RETURN: True
""" """
# objects vendus mais non factures # objects vendus mais non factures
cr.execute('select count(*) as c from auction_lots where auction_id in ('+','.join(map(str,ids))+') and state=%s and obj_price>0', ('draft',)) cr.execute('select count(*) as c from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',))
nbr = cr.fetchone()[0] nbr = cr.fetchone()[0]
ach_uids = {} ach_uids = {}
cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and state=%s and obj_price>0', ('draft',)) cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',))
r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None) r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None)
cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and obj_price>0') cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and obj_price>0')
ids2 = [x[0] for x in cr.fetchall()] ids2 = [x[0] for x in cr.fetchall()]
# for auction in auction_ids: # for auction in auction_ids:
c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{}) c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{})

View File

@ -1,34 +1,35 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
__version__ = '0.9'
__version__ = '0.9'
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,322 +1,323 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
from reportlab.lib.units import inch
from common import MultiWidthBarcode from reportlab.lib.units import inch
from string import digits from common import MultiWidthBarcode
from string import digits
_patterns = {
0 : 'BaBbBb', 1 : 'BbBaBb', 2 : 'BbBbBa', _patterns = {
3 : 'AbAbBc', 4 : 'AbAcBb', 5 : 'AcAbBb', 0 : 'BaBbBb', 1 : 'BbBaBb', 2 : 'BbBbBa',
6 : 'AbBbAc', 7 : 'AbBcAb', 8 : 'AcBbAb', 3 : 'AbAbBc', 4 : 'AbAcBb', 5 : 'AcAbBb',
9 : 'BbAbAc', 10 : 'BbAcAb', 11 : 'BcAbAb', 6 : 'AbBbAc', 7 : 'AbBcAb', 8 : 'AcBbAb',
12 : 'AaBbCb', 13 : 'AbBaCb', 14 : 'AbBbCa', 9 : 'BbAbAc', 10 : 'BbAcAb', 11 : 'BcAbAb',
15 : 'AaCbBb', 16 : 'AbCaBb', 17 : 'AbCbBa', 12 : 'AaBbCb', 13 : 'AbBaCb', 14 : 'AbBbCa',
18 : 'BbCbAa', 19 : 'BbAaCb', 20 : 'BbAbCa', 15 : 'AaCbBb', 16 : 'AbCaBb', 17 : 'AbCbBa',
21 : 'BaCbAb', 22 : 'BbCaAb', 23 : 'CaBaCa', 18 : 'BbCbAa', 19 : 'BbAaCb', 20 : 'BbAbCa',
24 : 'CaAbBb', 25 : 'CbAaBb', 26 : 'CbAbBa', 21 : 'BaCbAb', 22 : 'BbCaAb', 23 : 'CaBaCa',
27 : 'CaBbAb', 28 : 'CbBaAb', 29 : 'CbBbAa', 24 : 'CaAbBb', 25 : 'CbAaBb', 26 : 'CbAbBa',
30 : 'BaBaBc', 31 : 'BaBcBa', 32 : 'BcBaBa', 27 : 'CaBbAb', 28 : 'CbBaAb', 29 : 'CbBbAa',
33 : 'AaAcBc', 34 : 'AcAaBc', 35 : 'AcAcBa', 30 : 'BaBaBc', 31 : 'BaBcBa', 32 : 'BcBaBa',
36 : 'AaBcAc', 37 : 'AcBaAc', 38 : 'AcBcAa', 33 : 'AaAcBc', 34 : 'AcAaBc', 35 : 'AcAcBa',
39 : 'BaAcAc', 40 : 'BcAaAc', 41 : 'BcAcAa', 36 : 'AaBcAc', 37 : 'AcBaAc', 38 : 'AcBcAa',
42 : 'AaBaCc', 43 : 'AaBcCa', 44 : 'AcBaCa', 39 : 'BaAcAc', 40 : 'BcAaAc', 41 : 'BcAcAa',
45 : 'AaCaBc', 46 : 'AaCcBa', 47 : 'AcCaBa', 42 : 'AaBaCc', 43 : 'AaBcCa', 44 : 'AcBaCa',
48 : 'CaCaBa', 49 : 'BaAcCa', 50 : 'BcAaCa', 45 : 'AaCaBc', 46 : 'AaCcBa', 47 : 'AcCaBa',
51 : 'BaCaAc', 52 : 'BaCcAa', 53 : 'BaCaCa', 48 : 'CaCaBa', 49 : 'BaAcCa', 50 : 'BcAaCa',
54 : 'CaAaBc', 55 : 'CaAcBa', 56 : 'CcAaBa', 51 : 'BaCaAc', 52 : 'BaCcAa', 53 : 'BaCaCa',
57 : 'CaBaAc', 58 : 'CaBcAa', 59 : 'CcBaAa', 54 : 'CaAaBc', 55 : 'CaAcBa', 56 : 'CcAaBa',
60 : 'CaDaAa', 61 : 'BbAdAa', 62 : 'DcAaAa', 57 : 'CaBaAc', 58 : 'CaBcAa', 59 : 'CcBaAa',
63 : 'AaAbBd', 64 : 'AaAdBb', 65 : 'AbAaBd', 60 : 'CaDaAa', 61 : 'BbAdAa', 62 : 'DcAaAa',
66 : 'AbAdBa', 67 : 'AdAaBb', 68 : 'AdAbBa', 63 : 'AaAbBd', 64 : 'AaAdBb', 65 : 'AbAaBd',
69 : 'AaBbAd', 70 : 'AaBdAb', 71 : 'AbBaAd', 66 : 'AbAdBa', 67 : 'AdAaBb', 68 : 'AdAbBa',
72 : 'AbBdAa', 73 : 'AdBaAb', 74 : 'AdBbAa', 69 : 'AaBbAd', 70 : 'AaBdAb', 71 : 'AbBaAd',
75 : 'BdAbAa', 76 : 'BbAaAd', 77 : 'DaCaAa', 72 : 'AbBdAa', 73 : 'AdBaAb', 74 : 'AdBbAa',
78 : 'BdAaAb', 79 : 'AcDaAa', 80 : 'AaAbDb', 75 : 'BdAbAa', 76 : 'BbAaAd', 77 : 'DaCaAa',
81 : 'AbAaDb', 82 : 'AbAbDa', 83 : 'AaDbAb', 78 : 'BdAaAb', 79 : 'AcDaAa', 80 : 'AaAbDb',
84 : 'AbDaAb', 85 : 'AbDbAa', 86 : 'DaAbAb', 81 : 'AbAaDb', 82 : 'AbAbDa', 83 : 'AaDbAb',
87 : 'DbAaAb', 88 : 'DbAbAa', 89 : 'BaBaDa', 84 : 'AbDaAb', 85 : 'AbDbAa', 86 : 'DaAbAb',
90 : 'BaDaBa', 91 : 'DaBaBa', 92 : 'AaAaDc', 87 : 'DbAaAb', 88 : 'DbAbAa', 89 : 'BaBaDa',
93 : 'AaAcDa', 94 : 'AcAaDa', 95 : 'AaDaAc', 90 : 'BaDaBa', 91 : 'DaBaBa', 92 : 'AaAaDc',
96 : 'AaDcAa', 97 : 'DaAaAc', 98 : 'DaAcAa', 93 : 'AaAcDa', 94 : 'AcAaDa', 95 : 'AaDaAc',
99 : 'AaCaDa', 100 : 'AaDaCa', 101 : 'CaAaDa', 96 : 'AaDcAa', 97 : 'DaAaAc', 98 : 'DaAcAa',
102 : 'DaAaCa', 103 : 'BaAdAb', 104 : 'BaAbAd', 99 : 'AaCaDa', 100 : 'AaDaCa', 101 : 'CaAaDa',
105 : 'BaAbCb', 106 : 'BcCaAaB' 102 : 'DaAaCa', 103 : 'BaAdAb', 104 : 'BaAbAd',
} 105 : 'BaAbCb', 106 : 'BcCaAaB'
}
starta, startb, startc, stop = 103, 104, 105, 106
starta, startb, startc, stop = 103, 104, 105, 106
seta = {
' ' : 0, '!' : 1, '"' : 2, '#' : 3, seta = {
'$' : 4, '%' : 5, '&' : 6, '\'' : 7, ' ' : 0, '!' : 1, '"' : 2, '#' : 3,
'(' : 8, ')' : 9, '*' : 10, '+' : 11, '$' : 4, '%' : 5, '&' : 6, '\'' : 7,
',' : 12, '-' : 13, '.' : 14, '/' : 15, '(' : 8, ')' : 9, '*' : 10, '+' : 11,
'0' : 16, '1' : 17, '2' : 18, '3' : 19, ',' : 12, '-' : 13, '.' : 14, '/' : 15,
'4' : 20, '5' : 21, '6' : 22, '7' : 23, '0' : 16, '1' : 17, '2' : 18, '3' : 19,
'8' : 24, '9' : 25, ':' : 26, ';' : 27, '4' : 20, '5' : 21, '6' : 22, '7' : 23,
'<' : 28, '=' : 29, '>' : 30, '?' : 31, '8' : 24, '9' : 25, ':' : 26, ';' : 27,
'@' : 32, 'A' : 33, 'B' : 34, 'C' : 35, '<' : 28, '=' : 29, '>' : 30, '?' : 31,
'D' : 36, 'E' : 37, 'F' : 38, 'G' : 39, '@' : 32, 'A' : 33, 'B' : 34, 'C' : 35,
'H' : 40, 'I' : 41, 'J' : 42, 'K' : 43, 'D' : 36, 'E' : 37, 'F' : 38, 'G' : 39,
'L' : 44, 'M' : 45, 'N' : 46, 'O' : 47, 'H' : 40, 'I' : 41, 'J' : 42, 'K' : 43,
'P' : 48, 'Q' : 49, 'R' : 50, 'S' : 51, 'L' : 44, 'M' : 45, 'N' : 46, 'O' : 47,
'T' : 52, 'U' : 53, 'V' : 54, 'W' : 55, 'P' : 48, 'Q' : 49, 'R' : 50, 'S' : 51,
'X' : 56, 'Y' : 57, 'Z' : 58, '[' : 59, 'T' : 52, 'U' : 53, 'V' : 54, 'W' : 55,
'\\' : 60, ']' : 61, '^' : 62, '_' : 63, 'X' : 56, 'Y' : 57, 'Z' : 58, '[' : 59,
'\x00' : 64, '\x01' : 65, '\x02' : 66, '\x03' : 67, '\\' : 60, ']' : 61, '^' : 62, '_' : 63,
'\x04' : 68, '\x05' : 69, '\x06' : 70, '\x07' : 71, '\x00' : 64, '\x01' : 65, '\x02' : 66, '\x03' : 67,
'\x08' : 72, '\x09' : 73, '\x0a' : 74, '\x0b' : 75, '\x04' : 68, '\x05' : 69, '\x06' : 70, '\x07' : 71,
'\x0c' : 76, '\x0d' : 77, '\x0e' : 78, '\x0f' : 79, '\x08' : 72, '\x09' : 73, '\x0a' : 74, '\x0b' : 75,
'\x10' : 80, '\x11' : 81, '\x12' : 82, '\x13' : 83, '\x0c' : 76, '\x0d' : 77, '\x0e' : 78, '\x0f' : 79,
'\x14' : 84, '\x15' : 85, '\x16' : 86, '\x17' : 87, '\x10' : 80, '\x11' : 81, '\x12' : 82, '\x13' : 83,
'\x18' : 88, '\x19' : 89, '\x1a' : 90, '\x1b' : 91, '\x14' : 84, '\x15' : 85, '\x16' : 86, '\x17' : 87,
'\x1c' : 92, '\x1d' : 93, '\x1e' : 94, '\x1f' : 95, '\x18' : 88, '\x19' : 89, '\x1a' : 90, '\x1b' : 91,
'\xf3' : 96, '\xf2' : 97, 'SHIFT' : 98, 'TO_C' : 99, '\x1c' : 92, '\x1d' : 93, '\x1e' : 94, '\x1f' : 95,
'TO_B' : 100, '\xf4' : 101, '\xf1' : 102 '\xf3' : 96, '\xf2' : 97, 'SHIFT' : 98, 'TO_C' : 99,
} 'TO_B' : 100, '\xf4' : 101, '\xf1' : 102
}
setb = {
' ' : 0, '!' : 1, '"' : 2, '#' : 3, setb = {
'$' : 4, '%' : 5, '&' : 6, '\'' : 7, ' ' : 0, '!' : 1, '"' : 2, '#' : 3,
'(' : 8, ')' : 9, '*' : 10, '+' : 11, '$' : 4, '%' : 5, '&' : 6, '\'' : 7,
',' : 12, '-' : 13, '.' : 14, '/' : 15, '(' : 8, ')' : 9, '*' : 10, '+' : 11,
'0' : 16, '1' : 17, '2' : 18, '3' : 19, ',' : 12, '-' : 13, '.' : 14, '/' : 15,
'4' : 20, '5' : 21, '6' : 22, '7' : 23, '0' : 16, '1' : 17, '2' : 18, '3' : 19,
'8' : 24, '9' : 25, ':' : 26, ';' : 27, '4' : 20, '5' : 21, '6' : 22, '7' : 23,
'<' : 28, '=' : 29, '>' : 30, '?' : 31, '8' : 24, '9' : 25, ':' : 26, ';' : 27,
'@' : 32, 'A' : 33, 'B' : 34, 'C' : 35, '<' : 28, '=' : 29, '>' : 30, '?' : 31,
'D' : 36, 'E' : 37, 'F' : 38, 'G' : 39, '@' : 32, 'A' : 33, 'B' : 34, 'C' : 35,
'H' : 40, 'I' : 41, 'J' : 42, 'K' : 43, 'D' : 36, 'E' : 37, 'F' : 38, 'G' : 39,
'L' : 44, 'M' : 45, 'N' : 46, 'O' : 47, 'H' : 40, 'I' : 41, 'J' : 42, 'K' : 43,
'P' : 48, 'Q' : 49, 'R' : 50, 'S' : 51, 'L' : 44, 'M' : 45, 'N' : 46, 'O' : 47,
'T' : 52, 'U' : 53, 'V' : 54, 'W' : 55, 'P' : 48, 'Q' : 49, 'R' : 50, 'S' : 51,
'X' : 56, 'Y' : 57, 'Z' : 58, '[' : 59, 'T' : 52, 'U' : 53, 'V' : 54, 'W' : 55,
'\\' : 60, ']' : 61, '^' : 62, '_' : 63, 'X' : 56, 'Y' : 57, 'Z' : 58, '[' : 59,
'`' : 64, 'a' : 65, 'b' : 66, 'c' : 67, '\\' : 60, ']' : 61, '^' : 62, '_' : 63,
'd' : 68, 'e' : 69, 'f' : 70, 'g' : 71, '`' : 64, 'a' : 65, 'b' : 66, 'c' : 67,
'h' : 72, 'i' : 73, 'j' : 74, 'k' : 75, 'd' : 68, 'e' : 69, 'f' : 70, 'g' : 71,
'l' : 76, 'm' : 77, 'n' : 78, 'o' : 79, 'h' : 72, 'i' : 73, 'j' : 74, 'k' : 75,
'p' : 80, 'q' : 81, 'r' : 82, 's' : 83, 'l' : 76, 'm' : 77, 'n' : 78, 'o' : 79,
't' : 84, 'u' : 85, 'v' : 86, 'w' : 87, 'p' : 80, 'q' : 81, 'r' : 82, 's' : 83,
'x' : 88, 'y' : 89, 'z' : 90, '{' : 91, 't' : 84, 'u' : 85, 'v' : 86, 'w' : 87,
'|' : 92, '}' : 93, '~' : 94, '\x7f' : 95, 'x' : 88, 'y' : 89, 'z' : 90, '{' : 91,
'\xf3' : 96, '\xf2' : 97, 'SHIFT' : 98, 'TO_C' : 99, '|' : 92, '}' : 93, '~' : 94, '\x7f' : 95,
'\xf4' : 100, 'TO_A' : 101, '\xf1' : 102 '\xf3' : 96, '\xf2' : 97, 'SHIFT' : 98, 'TO_C' : 99,
} '\xf4' : 100, 'TO_A' : 101, '\xf1' : 102
}
setc = {
'00': 0, '01': 1, '02': 2, '03': 3, '04': 4, setc = {
'05': 5, '06': 6, '07': 7, '08': 8, '09': 9, '00': 0, '01': 1, '02': 2, '03': 3, '04': 4,
'10':10, '11':11, '12':12, '13':13, '14':14, '05': 5, '06': 6, '07': 7, '08': 8, '09': 9,
'15':15, '16':16, '17':17, '18':18, '19':19, '10':10, '11':11, '12':12, '13':13, '14':14,
'20':20, '21':21, '22':22, '23':23, '24':24, '15':15, '16':16, '17':17, '18':18, '19':19,
'25':25, '26':26, '27':27, '28':28, '29':29, '20':20, '21':21, '22':22, '23':23, '24':24,
'30':30, '31':31, '32':32, '33':33, '34':34, '25':25, '26':26, '27':27, '28':28, '29':29,
'35':35, '36':36, '37':37, '38':38, '39':39, '30':30, '31':31, '32':32, '33':33, '34':34,
'40':40, '41':41, '42':42, '43':43, '44':44, '35':35, '36':36, '37':37, '38':38, '39':39,
'45':45, '46':46, '47':47, '48':48, '49':49, '40':40, '41':41, '42':42, '43':43, '44':44,
'50':50, '51':51, '52':52, '53':53, '54':54, '45':45, '46':46, '47':47, '48':48, '49':49,
'55':55, '56':56, '57':57, '58':58, '59':59, '50':50, '51':51, '52':52, '53':53, '54':54,
'60':60, '61':61, '62':62, '63':63, '64':64, '55':55, '56':56, '57':57, '58':58, '59':59,
'65':65, '66':66, '67':67, '68':68, '69':69, '60':60, '61':61, '62':62, '63':63, '64':64,
'70':70, '71':71, '72':72, '73':73, '74':74, '65':65, '66':66, '67':67, '68':68, '69':69,
'75':75, '76':76, '77':77, '78':78, '79':79, '70':70, '71':71, '72':72, '73':73, '74':74,
'80':80, '81':81, '82':82, '83':83, '84':84, '75':75, '76':76, '77':77, '78':78, '79':79,
'85':85, '86':86, '87':87, '88':88, '89':89, '80':80, '81':81, '82':82, '83':83, '84':84,
'90':90, '91':91, '92':92, '93':93, '94':94, '85':85, '86':86, '87':87, '88':88, '89':89,
'95':95, '96':96, '97':97, '98':98, '99':99, '90':90, '91':91, '92':92, '93':93, '94':94,
'95':95, '96':96, '97':97, '98':98, '99':99,
'TO_B' : 100, 'TO_A' : 101, '\xf1' : 102
} 'TO_B' : 100, 'TO_A' : 101, '\xf1' : 102
}
setmap = {
'TO_A' : (seta, setb), setmap = {
'TO_B' : (setb, seta), 'TO_A' : (seta, setb),
'TO_C' : (setc, None), 'TO_B' : (setb, seta),
'START_A' : (starta, seta, setb), 'TO_C' : (setc, None),
'START_B' : (startb, setb, seta), 'START_A' : (starta, seta, setb),
'START_C' : (startc, setc, None), 'START_B' : (startb, setb, seta),
} 'START_C' : (startc, setc, None),
tos = setmap.keys() }
tos = setmap.keys()
class Code128(MultiWidthBarcode):
""" class Code128(MultiWidthBarcode):
Code 128 is a very compact symbology that can encode the entire """
128 character ASCII set, plus 4 special control codes, Code 128 is a very compact symbology that can encode the entire
(FNC1-FNC4, expressed in the input string as \xf1 to \xf4). 128 character ASCII set, plus 4 special control codes,
Code 128 can also encode digits at double density (2 per byte) (FNC1-FNC4, expressed in the input string as \xf1 to \xf4).
and has a mandatory checksum. Code 128 is well supported and Code 128 can also encode digits at double density (2 per byte)
commonly used -- for example, by UPS for tracking labels. and has a mandatory checksum. Code 128 is well supported and
commonly used -- for example, by UPS for tracking labels.
Because of these qualities, Code 128 is probably the best choice
for a linear symbology today (assuming you have a choice). Because of these qualities, Code 128 is probably the best choice
for a linear symbology today (assuming you have a choice).
Options that may be passed to constructor:
Options that may be passed to constructor:
value (int, or numeric string. required.):
The value to encode. value (int, or numeric string. required.):
The value to encode.
xdim (float, default .0075):
X-Dimension, or width of the smallest element xdim (float, default .0075):
Minumum is .0075 inch (7.5 mils). X-Dimension, or width of the smallest element
Minumum is .0075 inch (7.5 mils).
height (float, see default below):
Height of the symbol. Default is the height of the two height (float, see default below):
bearer bars (if they exist) plus the greater of .25 inch Height of the symbol. Default is the height of the two
or .15 times the symbol's length. bearer bars (if they exist) plus the greater of .25 inch
or .15 times the symbol's length.
quiet (bool, default 1):
Wether to include quiet zones in the symbol. quiet (bool, default 1):
Wether to include quiet zones in the symbol.
lquiet (float, see default below):
Quiet zone size to left of code, if quiet is true. lquiet (float, see default below):
Default is the greater of .25 inch, or 10 xdim Quiet zone size to left of code, if quiet is true.
Default is the greater of .25 inch, or 10 xdim
rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true. rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true.
Sources of Information on Code 128:
Sources of Information on Code 128:
http://www.semiconductor.agilent.com/barcode/sg/Misc/code_128.html
http://www.adams1.com/pub/russadam/128code.html http://www.semiconductor.agilent.com/barcode/sg/Misc/code_128.html
http://www.barcodeman.com/c128.html http://www.adams1.com/pub/russadam/128code.html
http://www.barcodeman.com/c128.html
Official Spec, "ANSI/AIM BC4-1999, ISS" is available for US$45 from
http://www.aimglobal.org/aimstore/ Official Spec, "ANSI/AIM BC4-1999, ISS" is available for US$45 from
""" http://www.aimglobal.org/aimstore/
def __init__(self, value='', **args): """
self.xdim = inch * 0.0075 def __init__(self, value='', **args):
self.lquiet = None self.xdim = inch * 0.0075
self.rquiet = None self.lquiet = None
self.quiet = 1 self.rquiet = None
self.height = None self.quiet = 1
self.height = None
if type(value) is type(1):
value = str(value) if type(value) is type(1):
value = str(value)
for (k, v) in args.items():
setattr(self, k, v) for (k, v) in args.items():
setattr(self, k, v)
if self.quiet:
if self.lquiet is None: if self.quiet:
self.lquiet = max(inch * 0.25, self.xdim * 10.0) if self.lquiet is None:
self.rquiet = max(inch * 0.25, self.xdim * 10.0) self.lquiet = max(inch * 0.25, self.xdim * 10.0)
else: self.rquiet = max(inch * 0.25, self.xdim * 10.0)
self.lquiet = self.rquiet = 0.0 else:
self.lquiet = self.rquiet = 0.0
MultiWidthBarcode.__init__(self, value)
MultiWidthBarcode.__init__(self, value)
def validate(self):
vval = "" def validate(self):
self.valid = 1 vval = ""
for c in self.value: self.valid = 1
if ord(c) > 127 and c not in '\xf1\xf2\xf3\xf4': for c in self.value:
self.valid = 0 if ord(c) > 127 and c not in '\xf1\xf2\xf3\xf4':
continue self.valid = 0
vval = vval + c continue
self.validated = vval vval = vval + c
return vval self.validated = vval
return vval
def _trailingDigitsToC(self, l):
# Optimization: trailing digits -> set C double-digits def _trailingDigitsToC(self, l):
c = 1 # Optimization: trailing digits -> set C double-digits
savings = -1 # the TO_C costs one character c = 1
rl = ['STOP'] savings = -1 # the TO_C costs one character
while c < len(l): rl = ['STOP']
i = (-c - 1) while c < len(l):
if l[i] == '\xf1': i = (-c - 1)
c = c + 1 if l[i] == '\xf1':
rl.insert(0, '\xf1') c = c + 1
continue rl.insert(0, '\xf1')
elif len(l[i]) == 1 and l[i] in digits \ continue
and len(l[i-1]) == 1 and l[i-1] in digits: elif len(l[i]) == 1 and l[i] in digits \
c = c + 2 and len(l[i-1]) == 1 and l[i-1] in digits:
savings = savings + 1 c = c + 2
rl.insert(0, l[i-1] + l[i]) savings = savings + 1
continue rl.insert(0, l[i-1] + l[i])
else: continue
break else:
if savings > 0: break
return l[:-c] + ['TO_C'] + rl if savings > 0:
else: return l[:-c] + ['TO_C'] + rl
return l else:
return l
def encode(self):
# First, encode using only B def encode(self):
s = self.validated # First, encode using only B
l = ['START_B'] s = self.validated
for c in s: l = ['START_B']
if not setb.has_key(c): for c in s:
l = l + ['TO_A', c, 'TO_B'] if not setb.has_key(c):
else: l = l + ['TO_A', c, 'TO_B']
l.append(c) else:
l.append('STOP') l.append(c)
l.append('STOP')
l = self._trailingDigitsToC(l)
l = self._trailingDigitsToC(l)
# Finally, replace START_X,TO_Y with START_Y
if l[1] in tos: # Finally, replace START_X,TO_Y with START_Y
l[:2] = ['START_' + l[1][-1]] if l[1] in tos:
l[:2] = ['START_' + l[1][-1]]
# print `l`
# print `l`
# encode into numbers
start, set, shset = setmap[l[0]] # encode into numbers
e = [start] start, set, shset = setmap[l[0]]
e = [start]
l = l[1:-1]
while l: l = l[1:-1]
c = l[0] while l:
if c == 'SHIFT': c = l[0]
e = e + [set[c], shset[l[1]]] if c == 'SHIFT':
l = l[2:] e = e + [set[c], shset[l[1]]]
elif c in tos: l = l[2:]
e.append(set[c]) elif c in tos:
set, shset = setmap[c] e.append(set[c])
l = l[1:] set, shset = setmap[c]
else: l = l[1:]
e.append(set[c]) else:
l = l[1:] e.append(set[c])
l = l[1:]
c = e[0]
for i in range(1, len(e)): c = e[0]
c = c + i * e[i] for i in range(1, len(e)):
self.encoded = e + [c % 103, stop] c = c + i * e[i]
return self.encoded self.encoded = e + [c % 103, stop]
return self.encoded
def decompose(self):
dval = '' def decompose(self):
for c in self.encoded: dval = ''
dval = dval + _patterns[c] for c in self.encoded:
self.decomposed = dval dval = dval + _patterns[c]
return self.decomposed self.decomposed = dval
return self.decomposed
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,256 +1,257 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
from reportlab.lib.units import inch
from common import Barcode from reportlab.lib.units import inch
import string from common import Barcode
import string
_patterns = {
'0': ("bsbSBsBsb", 0), '1': ("BsbSbsbsB", 1), _patterns = {
'2': ("bsBSbsbsB", 2), '3': ("BsBSbsbsb", 3), '0': ("bsbSBsBsb", 0), '1': ("BsbSbsbsB", 1),
'4': ("bsbSBsbsB", 4), '5': ("BsbSBsbsb", 5), '2': ("bsBSbsbsB", 2), '3': ("BsBSbsbsb", 3),
'6': ("bsBSBsbsb", 6), '7': ("bsbSbsBsB", 7), '4': ("bsbSBsbsB", 4), '5': ("BsbSBsbsb", 5),
'8': ("BsbSbsBsb", 8), '9': ("bsBSbsBsb", 9), '6': ("bsBSBsbsb", 6), '7': ("bsbSbsBsB", 7),
'A': ("BsbsbSbsB", 10), 'B': ("bsBsbSbsB", 11), '8': ("BsbSbsBsb", 8), '9': ("bsBSbsBsb", 9),
'C': ("BsBsbSbsb", 12), 'D': ("bsbsBSbsB", 13), 'A': ("BsbsbSbsB", 10), 'B': ("bsBsbSbsB", 11),
'E': ("BsbsBSbsb", 14), 'F': ("bsBsBSbsb", 15), 'C': ("BsBsbSbsb", 12), 'D': ("bsbsBSbsB", 13),
'G': ("bsbsbSBsB", 16), 'H': ("BsbsbSBsb", 17), 'E': ("BsbsBSbsb", 14), 'F': ("bsBsBSbsb", 15),
'I': ("bsBsbSBsb", 18), 'J': ("bsbsBSBsb", 19), 'G': ("bsbsbSBsB", 16), 'H': ("BsbsbSBsb", 17),
'K': ("BsbsbsbSB", 20), 'L': ("bsBsbsbSB", 21), 'I': ("bsBsbSBsb", 18), 'J': ("bsbsBSBsb", 19),
'M': ("BsBsbsbSb", 22), 'N': ("bsbsBsbSB", 23), 'K': ("BsbsbsbSB", 20), 'L': ("bsBsbsbSB", 21),
'O': ("BsbsBsbSb", 24), 'P': ("bsBsBsbSb", 25), 'M': ("BsBsbsbSb", 22), 'N': ("bsbsBsbSB", 23),
'Q': ("bsbsbsBSB", 26), 'R': ("BsbsbsBSb", 27), 'O': ("BsbsBsbSb", 24), 'P': ("bsBsBsbSb", 25),
'S': ("bsBsbsBSb", 28), 'T': ("bsbsBsBSb", 29), 'Q': ("bsbsbsBSB", 26), 'R': ("BsbsbsBSb", 27),
'U': ("BSbsbsbsB", 30), 'V': ("bSBsbsbsB", 31), 'S': ("bsBsbsBSb", 28), 'T': ("bsbsBsBSb", 29),
'W': ("BSBsbsbsb", 32), 'X': ("bSbsBsbsB", 33), 'U': ("BSbsbsbsB", 30), 'V': ("bSBsbsbsB", 31),
'Y': ("BSbsBsbsb", 34), 'Z': ("bSBsBsbsb", 35), 'W': ("BSBsbsbsb", 32), 'X': ("bSbsBsbsB", 33),
'-': ("bSbsbsBsB", 36), '.': ("BSbsbsBsb", 37), 'Y': ("BSbsBsbsb", 34), 'Z': ("bSBsBsbsb", 35),
' ': ("bSBsbsBsb", 38), '*': ("bSbsBsBsb", 39), '-': ("bSbsbsBsB", 36), '.': ("BSbsbsBsb", 37),
'$': ("bSbSbSbsb", 40), '/': ("bSbSbsbSb", 41), ' ': ("bSBsbsBsb", 38), '*': ("bSbsBsBsb", 39),
'+': ("bSbsbSbSb", 42), '%': ("bsbSbSbSb", 43) '$': ("bSbSbSbsb", 40), '/': ("bSbSbsbSb", 41),
} '+': ("bSbsbSbSb", 42), '%': ("bsbSbSbSb", 43)
}
_valchars = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', _valchars = [
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'X', 'Y', 'Z', '-', '.', ' ', '*', '$', '/', '+', '%' 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
] 'X', 'Y', 'Z', '-', '.', ' ', '*', '$', '/', '+', '%'
]
_extended = {
'\0': "%U", '\01': "$A", '\02': "$B", '\03': "$C", _extended = {
'\04': "$D", '\05': "$E", '\06': "$F", '\07': "$G", '\0': "%U", '\01': "$A", '\02': "$B", '\03': "$C",
'\010': "$H", '\011': "$I", '\012': "$J", '\013': "$K", '\04': "$D", '\05': "$E", '\06': "$F", '\07': "$G",
'\014': "$L", '\015': "$M", '\016': "$N", '\017': "$O", '\010': "$H", '\011': "$I", '\012': "$J", '\013': "$K",
'\020': "$P", '\021': "$Q", '\022': "$R", '\023': "$S", '\014': "$L", '\015': "$M", '\016': "$N", '\017': "$O",
'\024': "$T", '\025': "$U", '\026': "$V", '\027': "$W", '\020': "$P", '\021': "$Q", '\022': "$R", '\023': "$S",
'\030': "$X", '\031': "$Y", '\032': "$Z", '\033': "%A", '\024': "$T", '\025': "$U", '\026': "$V", '\027': "$W",
'\034': "%B", '\035': "%C", '\036': "%D", '\037': "%E", '\030': "$X", '\031': "$Y", '\032': "$Z", '\033': "%A",
'!': "/A", '"': "/B", '#': "/C", '$': "/D", '\034': "%B", '\035': "%C", '\036': "%D", '\037': "%E",
'%': "/E", '&': "/F", '\'': "/G", '(': "/H", '!': "/A", '"': "/B", '#': "/C", '$': "/D",
')': "/I", '*': "/J", '+': "/K", ',': "/L", '%': "/E", '&': "/F", '\'': "/G", '(': "/H",
'/': "/O", ':': "/Z", ';': "%F", '<': "%G", ')': "/I", '*': "/J", '+': "/K", ',': "/L",
'=': "%H", '>': "%I", '?': "%J", '@': "%V", '/': "/O", ':': "/Z", ';': "%F", '<': "%G",
'[': "%K", '\\': "%L", ']': "%M", '^': "%N", '=': "%H", '>': "%I", '?': "%J", '@': "%V",
'_': "%O", '`': "%W", 'a': "+A", 'b': "+B", '[': "%K", '\\': "%L", ']': "%M", '^': "%N",
'c': "+C", 'd': "+D", 'e': "+E", 'f': "+F", '_': "%O", '`': "%W", 'a': "+A", 'b': "+B",
'g': "+G", 'h': "+H", 'i': "+I", 'j': "+J", 'c': "+C", 'd': "+D", 'e': "+E", 'f': "+F",
'k': "+K", 'l': "+L", 'm': "+M", 'n': "+N", 'g': "+G", 'h': "+H", 'i': "+I", 'j': "+J",
'o': "+O", 'p': "+P", 'q': "+Q", 'r': "+R", 'k': "+K", 'l': "+L", 'm': "+M", 'n': "+N",
's': "+S", 't': "+T", 'u': "+U", 'v': "+V", 'o': "+O", 'p': "+P", 'q': "+Q", 'r': "+R",
'w': "+W", 'x': "+X", 'y': "+Y", 'z': "+Z", 's': "+S", 't': "+T", 'u': "+U", 'v': "+V",
'{': "%P", '|': "%Q", '}': "%R", '~': "%S", 'w': "+W", 'x': "+X", 'y': "+Y", 'z': "+Z",
'\177': "%T" '{': "%P", '|': "%Q", '}': "%R", '~': "%S",
} '\177': "%T"
}
_stdchrs = string.digits + string.uppercase + "-. *$/+%"
_extchrs = _stdchrs + string.lowercase + \ _stdchrs = string.digits + string.uppercase + "-. *$/+%"
"\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017" + \ _extchrs = _stdchrs + string.lowercase + \
"\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" + \ "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017" + \
"!'#&\"(),:;<=>?@[\\]^_`{|}~\177" "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" + \
"!'#&\"(),:;<=>?@[\\]^_`{|}~\177"
def _encode39(str, cksum):
newval = "*" def _encode39(str, cksum):
v = 0 newval = "*"
for c in str: v = 0
v = v + _patterns[c][1] for c in str:
newval = newval + c v = v + _patterns[c][1]
v = v % 43 newval = newval + c
if cksum: v = v % 43
newval = newval + _valchars[v] if cksum:
return newval + '*' newval = newval + _valchars[v]
return newval + '*'
class _Code39Base(Barcode):
def __init__(self, value = "", **args): class _Code39Base(Barcode):
self.xdim = inch * 0.0075 def __init__(self, value = "", **args):
self.lquiet = None self.xdim = inch * 0.0075
self.rquiet = None self.lquiet = None
self.quiet = 1 self.rquiet = None
self.gap = None self.quiet = 1
self.height = None self.gap = None
self.ratio = 2.2 self.height = None
self.checksum = 0 self.ratio = 2.2
self.bearers = 0.0 self.checksum = 0
self.bearers = 0.0
for (k, v) in args.items():
setattr(self, k, v) for (k, v) in args.items():
setattr(self, k, v)
if self.quiet:
if self.lquiet is None: if self.quiet:
self.lquiet = max(inch * 0.25, self.xdim * 10.0) if self.lquiet is None:
self.rquiet = max(inch * 0.25, self.xdim * 10.0) self.lquiet = max(inch * 0.25, self.xdim * 10.0)
else: self.rquiet = max(inch * 0.25, self.xdim * 10.0)
self.lquiet = self.rquiet = 0.0 else:
self.lquiet = self.rquiet = 0.0
Barcode.__init__(self, value)
Barcode.__init__(self, value)
def decompose(self):
dval = "" def decompose(self):
for c in self.encoded: dval = ""
dval = dval + _patterns[c][0] + 'i' for c in self.encoded:
self.decomposed = dval[:-1] dval = dval + _patterns[c][0] + 'i'
return self.decomposed self.decomposed = dval[:-1]
return self.decomposed
class Standard39(_Code39Base):
""" class Standard39(_Code39Base):
Interleaved 2 of 5 is a numeric-only barcode. It encodes an even """
number of digits; if an odd number is given, a 0 is prepended. Interleaved 2 of 5 is a numeric-only barcode. It encodes an even
number of digits; if an odd number is given, a 0 is prepended.
Options that may be passed to constructor:
Options that may be passed to constructor:
value (int, or numeric string. required.):
The value to encode. value (int, or numeric string. required.):
The value to encode.
xdim (float, default .0075):
X-Dimension, or width of the smallest element xdim (float, default .0075):
Minumum is .0075 inch (7.5 mils). X-Dimension, or width of the smallest element
Minumum is .0075 inch (7.5 mils).
ratio (float, default 2.2):
The ratio of wide elements to narrow elements. ratio (float, default 2.2):
Must be between 2.0 and 3.0 (or 2.2 and 3.0 if the The ratio of wide elements to narrow elements.
xdim is greater than 20 mils (.02 inch)) Must be between 2.0 and 3.0 (or 2.2 and 3.0 if the
xdim is greater than 20 mils (.02 inch))
gap (float or None, default None):
width of intercharacter gap. None means "use xdim". gap (float or None, default None):
width of intercharacter gap. None means "use xdim".
height (float, see default below):
Height of the symbol. Default is the height of the two height (float, see default below):
bearer bars (if they exist) plus the greater of .25 inch Height of the symbol. Default is the height of the two
or .15 times the symbol's length. bearer bars (if they exist) plus the greater of .25 inch
or .15 times the symbol's length.
checksum (bool, default 0):
Wether to compute and include the check digit checksum (bool, default 0):
Wether to compute and include the check digit
bearers (float, in units of xdim. default 0):
Height of bearer bars (horizontal bars along the top and bearers (float, in units of xdim. default 0):
bottom of the barcode). Default is 0 (no bearers). Height of bearer bars (horizontal bars along the top and
bottom of the barcode). Default is 0 (no bearers).
quiet (bool, default 1):
Wether to include quiet zones in the symbol. quiet (bool, default 1):
Wether to include quiet zones in the symbol.
lquiet (float, see default below):
Quiet zone size to left of code, if quiet is true. lquiet (float, see default below):
Default is the greater of .25 inch, or .15 times the symbol's Quiet zone size to left of code, if quiet is true.
length. Default is the greater of .25 inch, or .15 times the symbol's
length.
rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true. rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true.
Sources of Information on Code 39:
Sources of Information on Code 39:
http://www.semiconductor.agilent.com/barcode/sg/Misc/code_39.html
http://www.adams1.com/pub/russadam/39code.html http://www.semiconductor.agilent.com/barcode/sg/Misc/code_39.html
http://www.barcodeman.com/c39_1.html http://www.adams1.com/pub/russadam/39code.html
http://www.barcodeman.com/c39_1.html
Official Spec, "ANSI/AIM BC1-1995, USS" is available for US$45 from
http://www.aimglobal.org/aimstore/ Official Spec, "ANSI/AIM BC1-1995, USS" is available for US$45 from
""" http://www.aimglobal.org/aimstore/
"""
def validate(self):
vval = "" def validate(self):
self.valid = 1 vval = ""
for c in self.value: self.valid = 1
if c in string.lowercase: for c in self.value:
c = string.upper(c) if c in string.lowercase:
if c not in _stdchrs: c = string.upper(c)
self.valid = 0 if c not in _stdchrs:
continue self.valid = 0
vval = vval + c continue
self.validated = vval vval = vval + c
return vval self.validated = vval
return vval
def encode(self):
self.encoded = _encode39(self.validated, self.checksum) def encode(self):
return self.encoded self.encoded = _encode39(self.validated, self.checksum)
return self.encoded
class Extended39(_Code39Base):
""" class Extended39(_Code39Base):
Extended Code 39 is a convention for encoding additional characters """
not present in stanmdard Code 39 by using pairs of characters to Extended Code 39 is a convention for encoding additional characters
represent the characters missing in Standard Code 39. not present in stanmdard Code 39 by using pairs of characters to
represent the characters missing in Standard Code 39.
See Standard39 for arguments.
See Standard39 for arguments.
Sources of Information on Extended Code 39:
Sources of Information on Extended Code 39:
http://www.semiconductor.agilent.com/barcode/sg/Misc/xcode_39.html
http://www.barcodeman.com/c39_ext.html http://www.semiconductor.agilent.com/barcode/sg/Misc/xcode_39.html
""" http://www.barcodeman.com/c39_ext.html
"""
def validate(self):
vval = "" def validate(self):
self.valid = 1 vval = ""
for c in self.value: self.valid = 1
if c not in _extchrs: for c in self.value:
self.valid = 0 if c not in _extchrs:
continue self.valid = 0
vval = vval + c continue
self.validated = vval vval = vval + c
return vval self.validated = vval
return vval
def encode(self):
self.encoded = "" def encode(self):
for c in self.validated: self.encoded = ""
if _extended.has_key(c): for c in self.validated:
self.encoded = self.encoded + _extended[c] if _extended.has_key(c):
elif c in _stdchrs: self.encoded = self.encoded + _extended[c]
self.encoded = self.encoded + c elif c in _stdchrs:
else: self.encoded = self.encoded + c
raise ValueError else:
self.encoded = _encode39(self.encoded, self.checksum) raise ValueError
return self.encoded self.encoded = _encode39(self.encoded, self.checksum)
return self.encoded
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,233 +1,234 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
from reportlab.lib.units import inch
from common import MultiWidthBarcode from reportlab.lib.units import inch
import string from common import MultiWidthBarcode
import string
_patterns = {
'0' : ('AcAaAb', 0), '1' : ('AaAbAc', 1), '2' : ('AaAcAb', 2), _patterns = {
'3' : ('AaAdAa', 3), '4' : ('AbAaAc', 4), '5' : ('AbAbAb', 5), '0' : ('AcAaAb', 0), '1' : ('AaAbAc', 1), '2' : ('AaAcAb', 2),
'6' : ('AbAcAa', 6), '7' : ('AaAaAd', 7), '8' : ('AcAbAa', 8), '3' : ('AaAdAa', 3), '4' : ('AbAaAc', 4), '5' : ('AbAbAb', 5),
'9' : ('AdAaAa', 9), 'A' : ('BaAaAc', 10), 'B' : ('BaAbAb', 11), '6' : ('AbAcAa', 6), '7' : ('AaAaAd', 7), '8' : ('AcAbAa', 8),
'C' : ('BaAcAa', 12), 'D' : ('BbAaAb', 13), 'E' : ('BbAbAa', 14), '9' : ('AdAaAa', 9), 'A' : ('BaAaAc', 10), 'B' : ('BaAbAb', 11),
'F' : ('BcAaAa', 15), 'G' : ('AaBaAc', 16), 'H' : ('AaBbAb', 17), 'C' : ('BaAcAa', 12), 'D' : ('BbAaAb', 13), 'E' : ('BbAbAa', 14),
'I' : ('AaBcAa', 18), 'J' : ('AbBaAb', 19), 'K' : ('AcBaAa', 20), 'F' : ('BcAaAa', 15), 'G' : ('AaBaAc', 16), 'H' : ('AaBbAb', 17),
'L' : ('AaAaBc', 21), 'M' : ('AaAbBb', 22), 'N' : ('AaAcBa', 23), 'I' : ('AaBcAa', 18), 'J' : ('AbBaAb', 19), 'K' : ('AcBaAa', 20),
'O' : ('AbAaBb', 24), 'P' : ('AcAaBa', 25), 'Q' : ('BaBaAb', 26), 'L' : ('AaAaBc', 21), 'M' : ('AaAbBb', 22), 'N' : ('AaAcBa', 23),
'R' : ('BaBbAa', 27), 'S' : ('BaAaBb', 28), 'T' : ('BaAbBa', 29), 'O' : ('AbAaBb', 24), 'P' : ('AcAaBa', 25), 'Q' : ('BaBaAb', 26),
'U' : ('BbAaBa', 30), 'V' : ('BbBaAa', 31), 'W' : ('AaBaBb', 32), 'R' : ('BaBbAa', 27), 'S' : ('BaAaBb', 28), 'T' : ('BaAbBa', 29),
'X' : ('AaBbBa', 33), 'Y' : ('AbBaBa', 34), 'Z' : ('AbCaAa', 35), 'U' : ('BbAaBa', 30), 'V' : ('BbBaAa', 31), 'W' : ('AaBaBb', 32),
'-' : ('AbAaCa', 36), '.' : ('CaAaAb', 37), ' ' : ('CaAbAa', 38), 'X' : ('AaBbBa', 33), 'Y' : ('AbBaBa', 34), 'Z' : ('AbCaAa', 35),
'$' : ('CbAaAa', 39), '/' : ('AaBaCa', 40), '+' : ('AaCaBa', 41), '-' : ('AbAaCa', 36), '.' : ('CaAaAb', 37), ' ' : ('CaAbAa', 38),
'%' : ('BaAaCa', 42), '#' : ('AbAbBa', 43), '!' : ('CaBaAa', 44), '$' : ('CbAaAa', 39), '/' : ('AaBaCa', 40), '+' : ('AaCaBa', 41),
'=' : ('CaAaBa', 45), '&' : ('AbBbAa', 46), '%' : ('BaAaCa', 42), '#' : ('AbAbBa', 43), '!' : ('CaBaAa', 44),
'start' : ('AaAaDa', -1), 'stop' : ('AaAaDaA', -2) '=' : ('CaAaBa', 45), '&' : ('AbBbAa', 46),
} 'start' : ('AaAaDa', -1), 'stop' : ('AaAaDaA', -2)
}
_charsbyval = {}
for k, v in _patterns.items(): _charsbyval = {}
_charsbyval[v[1]] = k for k, v in _patterns.items():
_charsbyval[v[1]] = k
_extended = {
'\x00' : '!U', '\x01' : '#A', '\x02' : '#B', '\x03' : '#C', _extended = {
'\x04' : '#D', '\x05' : '#E', '\x06' : '#F', '\x07' : '#G', '\x00' : '!U', '\x01' : '#A', '\x02' : '#B', '\x03' : '#C',
'\x08' : '#H', '\x09' : '#I', '\x0a' : '#J', '\x0b' : '#K', '\x04' : '#D', '\x05' : '#E', '\x06' : '#F', '\x07' : '#G',
'\x0c' : '#L', '\x0d' : '#M', '\x0e' : '#N', '\x0f' : '#O', '\x08' : '#H', '\x09' : '#I', '\x0a' : '#J', '\x0b' : '#K',
'\x10' : '#P', '\x11' : '#Q', '\x12' : '#R', '\x13' : '#S', '\x0c' : '#L', '\x0d' : '#M', '\x0e' : '#N', '\x0f' : '#O',
'\x14' : '#T', '\x15' : '#U', '\x16' : '#V', '\x17' : '#W', '\x10' : '#P', '\x11' : '#Q', '\x12' : '#R', '\x13' : '#S',
'\x18' : '#X', '\x19' : '#Y', '\x1a' : '#Z', '\x1b' : '!A', '\x14' : '#T', '\x15' : '#U', '\x16' : '#V', '\x17' : '#W',
'\x1c' : '!B', '\x1d' : '!C', '\x1e' : '!D', '\x1f' : '!E', '\x18' : '#X', '\x19' : '#Y', '\x1a' : '#Z', '\x1b' : '!A',
'!' : '=A', '"' : '=B', '#' : '=C', '$' : '=D', '\x1c' : '!B', '\x1d' : '!C', '\x1e' : '!D', '\x1f' : '!E',
'%' : '=E', '&' : '=F', '\'' : '=G', '(' : '=H', '!' : '=A', '"' : '=B', '#' : '=C', '$' : '=D',
')' : '=I', '*' : '=J', '+' : '=K', ',' : '=L', '%' : '=E', '&' : '=F', '\'' : '=G', '(' : '=H',
'/' : '=O', ':' : '=Z', ';' : '!F', '<' : '!G', ')' : '=I', '*' : '=J', '+' : '=K', ',' : '=L',
'=' : '!H', '>' : '!I', '?' : '!J', '@' : '!V', '/' : '=O', ':' : '=Z', ';' : '!F', '<' : '!G',
'[' : '!K', '\\' : '!L', ']' : '!M', '^' : '!N', '=' : '!H', '>' : '!I', '?' : '!J', '@' : '!V',
'_' : '!O', '`' : '!W', 'a' : '&A', 'b' : '&B', '[' : '!K', '\\' : '!L', ']' : '!M', '^' : '!N',
'c' : '&C', 'd' : '&D', 'e' : '&E', 'f' : '&F', '_' : '!O', '`' : '!W', 'a' : '&A', 'b' : '&B',
'g' : '&G', 'h' : '&H', 'i' : '&I', 'j' : '&J', 'c' : '&C', 'd' : '&D', 'e' : '&E', 'f' : '&F',
'k' : '&K', 'l' : '&L', 'm' : '&M', 'n' : '&N', 'g' : '&G', 'h' : '&H', 'i' : '&I', 'j' : '&J',
'o' : '&O', 'p' : '&P', 'q' : '&Q', 'r' : '&R', 'k' : '&K', 'l' : '&L', 'm' : '&M', 'n' : '&N',
's' : '&S', 't' : '&T', 'u' : '&U', 'v' : '&V', 'o' : '&O', 'p' : '&P', 'q' : '&Q', 'r' : '&R',
'w' : '&W', 'x' : '&X', 'y' : '&Y', 'z' : '&Z', 's' : '&S', 't' : '&T', 'u' : '&U', 'v' : '&V',
'{' : '!P', '|' : '!Q', '}' : '!R', '~' : '!S', 'w' : '&W', 'x' : '&X', 'y' : '&Y', 'z' : '&Z',
'\x7f' : '!T' '{' : '!P', '|' : '!Q', '}' : '!R', '~' : '!S',
} '\x7f' : '!T'
}
def _encode93(str):
s = map(None, str) def _encode93(str):
s.reverse() s = map(None, str)
s.reverse()
# compute 'C' checksum
i = 0; v = 1; c = 0 # compute 'C' checksum
while i < len(s): i = 0; v = 1; c = 0
c = c + v * _patterns[s[i]][1] while i < len(s):
i = i + 1; v = v + 1 c = c + v * _patterns[s[i]][1]
if v > 20: i = i + 1; v = v + 1
v = 1 if v > 20:
s.insert(0, _charsbyval[c % 47]) v = 1
s.insert(0, _charsbyval[c % 47])
# compute 'K' checksum
i = 0; v = 1; c = 0 # compute 'K' checksum
while i < len(s): i = 0; v = 1; c = 0
c = c + v * _patterns[s[i]][1] while i < len(s):
i = i + 1; v = v + 1 c = c + v * _patterns[s[i]][1]
if v > 15: i = i + 1; v = v + 1
v = 1 if v > 15:
s.insert(0, _charsbyval[c % 47]) v = 1
s.insert(0, _charsbyval[c % 47])
s.reverse()
s.reverse()
return string.join(s, '')
return string.join(s, '')
class _Code93Base(MultiWidthBarcode):
def __init__(self, value='', **args): class _Code93Base(MultiWidthBarcode):
self.xdim = inch * 0.0075 def __init__(self, value='', **args):
self.lquiet = None self.xdim = inch * 0.0075
self.rquiet = None self.lquiet = None
self.quiet = 1 self.rquiet = None
self.height = None self.quiet = 1
self.height = None
if type(value) is type(1):
value = str(value) if type(value) is type(1):
value = str(value)
for (k, v) in args.items():
setattr(self, k, v) for (k, v) in args.items():
setattr(self, k, v)
if self.quiet:
if self.lquiet is None: if self.quiet:
self.lquiet = max(inch * 0.25, self.xdim * 10.0) if self.lquiet is None:
self.rquiet = max(inch * 0.25, self.xdim * 10.0) self.lquiet = max(inch * 0.25, self.xdim * 10.0)
else: self.rquiet = max(inch * 0.25, self.xdim * 10.0)
self.lquiet = self.rquiet = 0.0 else:
self.lquiet = self.rquiet = 0.0
MultiWidthBarcode.__init__(self, value)
MultiWidthBarcode.__init__(self, value)
def decompose(self):
dval = _patterns['start'][0] def decompose(self):
for c in self.encoded: dval = _patterns['start'][0]
dval = dval + _patterns[c][0] for c in self.encoded:
self.decomposed = dval + _patterns['stop'][0] dval = dval + _patterns[c][0]
return self.decomposed self.decomposed = dval + _patterns['stop'][0]
return self.decomposed
class Standard93(_Code93Base):
""" class Standard93(_Code93Base):
Code 93 is a Uppercase alphanumeric symbology with some punctuation. """
See Extended Code 93 for a variant that can represent the entire Code 93 is a Uppercase alphanumeric symbology with some punctuation.
128 characrter ASCII set. See Extended Code 93 for a variant that can represent the entire
128 characrter ASCII set.
Options that may be passed to constructor:
Options that may be passed to constructor:
value (int, or numeric string. required.):
The value to encode. value (int, or numeric string. required.):
The value to encode.
xdim (float, default .0075):
X-Dimension, or width of the smallest element xdim (float, default .0075):
Minumum is .0075 inch (7.5 mils). X-Dimension, or width of the smallest element
Minumum is .0075 inch (7.5 mils).
height (float, see default below):
Height of the symbol. Default is the height of the two height (float, see default below):
bearer bars (if they exist) plus the greater of .25 inch Height of the symbol. Default is the height of the two
or .15 times the symbol's length. bearer bars (if they exist) plus the greater of .25 inch
or .15 times the symbol's length.
quiet (bool, default 1):
Wether to include quiet zones in the symbol. quiet (bool, default 1):
Wether to include quiet zones in the symbol.
lquiet (float, see default below):
Quiet zone size to left of code, if quiet is true. lquiet (float, see default below):
Default is the greater of .25 inch, or 10 xdim Quiet zone size to left of code, if quiet is true.
Default is the greater of .25 inch, or 10 xdim
rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true. rquiet (float, defaults as above):
Quiet zone size to right left of code, if quiet is true.
Sources of Information on Code 93:
Sources of Information on Code 93:
http://www.semiconductor.agilent.com/barcode/sg/Misc/code_93.html
http://www.semiconductor.agilent.com/barcode/sg/Misc/code_93.html
Official Spec, "NSI/AIM BC5-1995, USS" is available for US$45 from
http://www.aimglobal.org/aimstore/ Official Spec, "NSI/AIM BC5-1995, USS" is available for US$45 from
""" http://www.aimglobal.org/aimstore/
"""
def validate(self):
vval = "" def validate(self):
self.valid = 1 vval = ""
for c in self.value: self.valid = 1
if c in string.lowercase: for c in self.value:
c = string.upper(c) if c in string.lowercase:
if not _patterns.has_key(c): c = string.upper(c)
self.valid = 0 if not _patterns.has_key(c):
continue self.valid = 0
vval = vval + c continue
self.validated = vval vval = vval + c
return vval self.validated = vval
return vval
def encode(self):
self.encoded = _encode93(self.validated) def encode(self):
return self.encoded self.encoded = _encode93(self.validated)
return self.encoded
class Extended93(_Code93Base):
""" class Extended93(_Code93Base):
Extended Code 93 is a convention for encoding the entire 128 character """
set using pairs of characters to represent the characters missing in Extended Code 93 is a convention for encoding the entire 128 character
Standard Code 93. It is very much like Extended Code 39 in that way. set using pairs of characters to represent the characters missing in
Standard Code 93. It is very much like Extended Code 39 in that way.
See Standard93 for arguments.
""" See Standard93 for arguments.
"""
def validate(self):
vval = "" def validate(self):
self.valid = 1 vval = ""
for c in self.value: self.valid = 1
if not _patterns.has_key(c) and not _extended.has_key(c): for c in self.value:
self.valid = 0 if not _patterns.has_key(c) and not _extended.has_key(c):
continue self.valid = 0
vval = vval + c continue
self.validated = vval vval = vval + c
return vval self.validated = vval
return vval
def encode(self):
self.encoded = "" def encode(self):
for c in self.validated: self.encoded = ""
if _patterns.has_key(c): for c in self.validated:
self.encoded = self.encoded + c if _patterns.has_key(c):
elif _extended.has_key(c): self.encoded = self.encoded + c
self.encoded = self.encoded + _extended[c] elif _extended.has_key(c):
else: self.encoded = self.encoded + _extended[c]
raise ValueError else:
self.encoded = _encode93(self.encoded) raise ValueError
return self.encoded self.encoded = _encode93(self.encoded)
return self.encoded
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +1,83 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
from reportlab.lib.units import inch
from common import Barcode from reportlab.lib.units import inch
import string from common import Barcode
import string
# . 3 T Tracker
# , 2 D Descender # . 3 T Tracker
# ' 1 A Ascender # , 2 D Descender
# | 0 H Ascender/Descender # ' 1 A Ascender
# | 0 H Ascender/Descender
_rm_patterns = {
"0" : "--||", "1" : "-',|", "2" : "-'|,", "3" : "'-,|", _rm_patterns = {
"4" : "'-|,", "5" : "'',,", "6" : "-,'|", "7" : "-|-|", "0" : "--||", "1" : "-',|", "2" : "-'|,", "3" : "'-,|",
"8" : "-|',", "9" : "',-|", "A" : "',',", "B" : "'|-,", "4" : "'-|,", "5" : "'',,", "6" : "-,'|", "7" : "-|-|",
"C" : "-,|'", "D" : "-|,'", "E" : "-||-", "F" : "',,'", "8" : "-|',", "9" : "',-|", "A" : "',',", "B" : "'|-,",
"G" : "',|-", "H" : "'|,-", "I" : ",-'|", "J" : ",'-|", "C" : "-,|'", "D" : "-|,'", "E" : "-||-", "F" : "',,'",
"K" : ",'',", "L" : "|--|", "M" : "|-',", "N" : "|'-,", "G" : "',|-", "H" : "'|,-", "I" : ",-'|", "J" : ",'-|",
"O" : ",-|'", "P" : ",','", "Q" : ",'|-", "R" : "|-,'", "K" : ",'',", "L" : "|--|", "M" : "|-',", "N" : "|'-,",
"S" : "|-|-", "T" : "|',-", "U" : ",,''", "V" : ",|-'", "O" : ",-|'", "P" : ",','", "Q" : ",'|-", "R" : "|-,'",
"W" : ",|'-", "X" : "|,-'", "Y" : "|,'-", "Z" : "||--", "S" : "|-|-", "T" : "|',-", "U" : ",,''", "V" : ",|-'",
"W" : ",|'-", "X" : "|,-'", "Y" : "|,'-", "Z" : "||--",
# start, stop
"(" : "'-,'", ")" : "'|,|" # start, stop
} "(" : "'-,'", ")" : "'|,|"
}
_ozN_patterns = {
"0" : "||", "1" : "|'", "2" : "|,", "3" : "'|", "4" : "''", _ozN_patterns = {
"5" : "',", "6" : ",|", "7" : ",'", "8" : ",,", "9" : ".|" "0" : "||", "1" : "|'", "2" : "|,", "3" : "'|", "4" : "''",
} "5" : "',", "6" : ",|", "7" : ",'", "8" : ",,", "9" : ".|"
}
_ozC_patterns = {
"A" : "|||", "B" : "||'", "C" : "||,", "D" : "|'|", _ozC_patterns = {
"E" : "|''", "F" : "|',", "G" : "|,|", "H" : "|,'", "A" : "|||", "B" : "||'", "C" : "||,", "D" : "|'|",
"I" : "|,,", "J" : "'||", "K" : "'|'", "L" : "'|,", "E" : "|''", "F" : "|',", "G" : "|,|", "H" : "|,'",
"M" : "''|", "N" : "'''", "O" : "'',", "P" : "',|", "I" : "|,,", "J" : "'||", "K" : "'|'", "L" : "'|,",
"Q" : "','", "R" : "',,", "S" : ",||", "T" : ",|'", "M" : "''|", "N" : "'''", "O" : "'',", "P" : "',|",
"U" : ",|,", "V" : ",'|", "W" : ",''", "X" : ",',", "Q" : "','", "R" : "',,", "S" : ",||", "T" : ",|'",
"Y" : ",,|", "Z" : ",,'", "a" : "|,.", "b" : "|.|", "U" : ",|,", "V" : ",'|", "W" : ",''", "X" : ",',",
"c" : "|.'", "d" : "|.,", "e" : "|..", "f" : "'|.", "Y" : ",,|", "Z" : ",,'", "a" : "|,.", "b" : "|.|",
"g" : "''.", "h" : "',.", "i" : "'.|", "j" : "'.'", "c" : "|.'", "d" : "|.,", "e" : "|..", "f" : "'|.",
"k" : "'.,", "l" : "'..", "m" : ",|.", "n" : ",'.", "g" : "''.", "h" : "',.", "i" : "'.|", "j" : "'.'",
"o" : ",,.", "p" : ",.|", "q" : ",.'", "r" : ",.,", "k" : "'.,", "l" : "'..", "m" : ",|.", "n" : ",'.",
"s" : ",..", "t" : ".|.", "u" : ".'.", "v" : ".,.", "o" : ",,.", "p" : ",.|", "q" : ",.'", "r" : ",.,",
"w" : "..|", "x" : "..'", "y" : "..,", "z" : "...", "s" : ",..", "t" : ".|.", "u" : ".'.", "v" : ".,.",
"0" : ",,,", "1" : ".||", "2" : ".|'", "3" : ".|,", "w" : "..|", "x" : "..'", "y" : "..,", "z" : "...",
"4" : ".'|", "5" : ".''", "6" : ".',", "7" : ".,|", "0" : ",,,", "1" : ".||", "2" : ".|'", "3" : ".|,",
"8" : ".,'", "9" : ".,,", " " : "||.", "#" : "|'.", "4" : ".'|", "5" : ".''", "6" : ".',", "7" : ".,|",
} "8" : ".,'", "9" : ".,,", " " : "||.", "#" : "|'.",
}
#http://www.auspost.com.au/futurepost/
#http://www.auspost.com.au/futurepost/
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,56 +1,57 @@
#!/usr/bin/python # -*- coding: utf-8 -*-
from common import * #!/usr/bin/python
from code39 import * from common import *
from code93 import * from code39 import *
from code128 import * from code93 import *
from usps import * from code128 import *
from usps import *
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.styles import getSampleStyleSheet from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Paragraph, Frame from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus.flowables import XBox from reportlab.platypus import Paragraph, Frame
def run(): from reportlab.platypus.flowables import XBox
styles = getSampleStyleSheet() def run():
styleN = styles['Normal'] styles = getSampleStyleSheet()
styleH = styles['Heading1'] styleN = styles['Normal']
story = [] styleH = styles['Heading1']
story = []
story.append(Paragraph('I2of5', styleN))
story.append(I2of5(1234, xdim = inch*0.02, checksum=0)) story.append(Paragraph('I2of5', styleN))
story.append(Paragraph('MSI', styleN)) story.append(I2of5(1234, xdim = inch*0.02, checksum=0))
story.append(MSI(1234, xdim = inch*0.02)) story.append(Paragraph('MSI', styleN))
story.append(Paragraph('Codabar', styleN)) story.append(MSI(1234, xdim = inch*0.02))
story.append(Codabar("A012345B", xdim = inch*0.02)) story.append(Paragraph('Codabar', styleN))
story.append(Paragraph('Code 11', styleN)) story.append(Codabar("A012345B", xdim = inch*0.02))
story.append(Code11("01234545634563")) story.append(Paragraph('Code 11', styleN))
story.append(Paragraph('Code 39', styleN)) story.append(Code11("01234545634563"))
story.append(Standard39("A012345B%R")) story.append(Paragraph('Code 39', styleN))
story.append(Paragraph('Extended Code 39', styleN)) story.append(Standard39("A012345B%R"))
story.append(Extended39("A012345B}")) story.append(Paragraph('Extended Code 39', styleN))
story.append(Paragraph('Code93', styleN)) story.append(Extended39("A012345B}"))
story.append(Standard93("CODE 93")) story.append(Paragraph('Code93', styleN))
story.append(Paragraph('Extended Code93', styleN)) story.append(Standard93("CODE 93"))
story.append(Extended93("L@@K! Code 93 :-)")) #, xdim=0.005 * inch)) story.append(Paragraph('Extended Code93', styleN))
story.append(Paragraph('Code 128', styleN)) story.append(Extended93("L@@K! Code 93 :-)")) #, xdim=0.005 * inch))
c=Code128("AB-12345678") #, xdim=0.005 * inch) story.append(Paragraph('Code 128', styleN))
#print 'WIDTH =', (c.width / inch), 'XDIM =', (c.xdim / inch) c=Code128("AB-12345678") #, xdim=0.005 * inch)
#print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch) #print 'WIDTH =', (c.width / inch), 'XDIM =', (c.xdim / inch)
story.append(c) #print 'LQ =', (c.lquiet / inch), 'RQ =', (c.rquiet / inch)
story.append(Paragraph('USPS FIM', styleN)) story.append(c)
story.append(FIM("A")) story.append(Paragraph('USPS FIM', styleN))
story.append(Paragraph('USPS POSTNET', styleN)) story.append(FIM("A"))
story.append(POSTNET('78247-1043')) story.append(Paragraph('USPS POSTNET', styleN))
story.append(Paragraph('Label Size', styleN)) story.append(POSTNET('78247-1043'))
story.append(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"')) story.append(Paragraph('Label Size', styleN))
story.append(Paragraph('Label Size', styleN)) story.append(XBox((2.0 + 5.0/8.0)*inch, 1 * inch, '1x2-5/8"'))
story.append(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"')) story.append(Paragraph('Label Size', styleN))
c = Canvas('out.pdf') story.append(XBox((1.75)*inch, .5 * inch, '1/2x1-3/4"'))
f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1) c = Canvas('out.pdf')
f.addFromList(story, c) f = Frame(inch, inch, 6*inch, 9*inch, showBoundary=1)
c.save() f.addFromList(story, c)
c.save()
if __name__=='__main__':
run() if __name__=='__main__':
run()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,232 +1,233 @@
# # -*- coding: utf-8 -*-
# Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org> #
# All rights reserved. # Copyright (c) 1996-2000 Tyler C. Sarna <tsarna@sarna.org>
# # All rights reserved.
# Redistribution and use in source and binary forms, with or without #
# modification, are permitted provided that the following conditions # Redistribution and use in source and binary forms, with or without
# are met: # modification, are permitted provided that the following conditions
# 1. Redistributions of source code must retain the above copyright # are met:
# notice, this list of conditions and the following disclaimer. # 1. Redistributions of source code must retain the above copyright
# 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer.
# notice, this list of conditions and the following disclaimer in the # 2. Redistributions in binary form must reproduce the above copyright
# documentation and/or other materials provided with the distribution. # notice, this list of conditions and the following disclaimer in the
# 3. All advertising materials mentioning features or use of this software # documentation and/or other materials provided with the distribution.
# must display the following acknowledgement: # 3. All advertising materials mentioning features or use of this software
# This product includes software developed by Tyler C. Sarna. # must display the following acknowledgement:
# 4. Neither the name of the author nor the names of contributors # This product includes software developed by Tyler C. Sarna.
# may be used to endorse or promote products derived from this software # 4. Neither the name of the author nor the names of contributors
# without specific prior written permission. # may be used to endorse or promote products derived from this software
# # without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND #
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# POSSIBILITY OF SUCH DAMAGE. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# # POSSIBILITY OF SUCH DAMAGE.
#
from reportlab.lib.units import inch
from common import Barcode from reportlab.lib.units import inch
import string from common import Barcode
import string
_fim_patterns = {
'A' : "|| | ||", _fim_patterns = {
'B' : "| || || |", 'A' : "|| | ||",
'C' : "|| | | ||", 'B' : "| || || |",
'D' : "||| | |||", 'C' : "|| | | ||",
# XXX There is an E. 'D' : "||| | |||",
# The below has been seen, but dunno if it is E or not: # XXX There is an E.
# 'E' : '|||| ||||' # The below has been seen, but dunno if it is E or not:
} # 'E' : '|||| ||||'
}
_postnet_patterns = {
'1' : "...||", '2' : "..|.|", '3' : "..||.", '4' : ".|..|", _postnet_patterns = {
'5' : ".|.|.", '6' : ".||..", '7' : "|...|", '8' : "|..|.", '1' : "...||", '2' : "..|.|", '3' : "..||.", '4' : ".|..|",
'9' : "|.|..", '0' : "||...", 'S' : "|", '5' : ".|.|.", '6' : ".||..", '7' : "|...|", '8' : "|..|.",
} '9' : "|.|..", '0' : "||...", 'S' : "|",
}
class FIM(Barcode):
"""" class FIM(Barcode):
FIM (Facing ID Marks) encode only one letter. """"
There are currently four defined: FIM (Facing ID Marks) encode only one letter.
There are currently four defined:
A Courtesy reply mail with pre-printed POSTNET
B Business reply mail without pre-printed POSTNET A Courtesy reply mail with pre-printed POSTNET
C Business reply mail with pre-printed POSTNET B Business reply mail without pre-printed POSTNET
D OCR Readable mail without pre-printed POSTNET C Business reply mail with pre-printed POSTNET
D OCR Readable mail without pre-printed POSTNET
Interleaved 2 of 5 is a numeric-only barcode. It encodes an even
number of digits; if an odd number is given, a 0 is prepended. Interleaved 2 of 5 is a numeric-only barcode. It encodes an even
number of digits; if an odd number is given, a 0 is prepended.
Options that may be passed to constructor:
Options that may be passed to constructor:
value (single character string from the set A - D. required.):
The value to encode. value (single character string from the set A - D. required.):
The value to encode.
quiet (bool, default 1):
Wether to include quiet zones in the symbol. quiet (bool, default 1):
Wether to include quiet zones in the symbol.
The following may also be passed, but doing so will generate nonstandard
symbols which should not be used. This is mainly documented here to The following may also be passed, but doing so will generate nonstandard
show the defaults: symbols which should not be used. This is mainly documented here to
show the defaults:
height (float, default 5/8 inch):
Height of the code. This might legitimately be overriden to make height (float, default 5/8 inch):
a taller symbol that will 'bleed' off the edge of the paper, Height of the code. This might legitimately be overriden to make
leaving 5/8 inch remaining. a taller symbol that will 'bleed' off the edge of the paper,
leaving 5/8 inch remaining.
lquiet (float, default 1/4 inch):
Quiet zone size to left of code, if quiet is true. lquiet (float, default 1/4 inch):
Default is the greater of .25 inch, or .15 times the symbol's Quiet zone size to left of code, if quiet is true.
length. Default is the greater of .25 inch, or .15 times the symbol's
length.
rquiet (float, default 15/32 inch):
Quiet zone size to right left of code, if quiet is true. rquiet (float, default 15/32 inch):
Quiet zone size to right left of code, if quiet is true.
Sources of information on FIM:
Sources of information on FIM:
USPS Publication 25, A Guide to Business Mail Preparation
http://new.usps.com/cpim/ftp/pubs/pub25.pdf USPS Publication 25, A Guide to Business Mail Preparation
""" http://new.usps.com/cpim/ftp/pubs/pub25.pdf
"""
def __init__(self, value='', **args):
self.barwidth = inch * (1.0/32.0) def __init__(self, value='', **args):
self.barspace = inch * (1.0/16.0) self.barwidth = inch * (1.0/32.0)
self.height = inch * (5.0/8.0) self.barspace = inch * (1.0/16.0)
self.rquiet = inch * (0.25) self.height = inch * (5.0/8.0)
self.lquiet = inch * (15.0/32.0) self.rquiet = inch * (0.25)
self.quiet = 0 self.lquiet = inch * (15.0/32.0)
self.quiet = 0
for (k, v) in args.items():
setattr(self, k, v) for (k, v) in args.items():
setattr(self, k, v)
Barcode.__init__(self, value)
Barcode.__init__(self, value)
def validate(self):
self.valid = 1 def validate(self):
self.validated = '' self.valid = 1
for c in self.value: self.validated = ''
if c in string.whitespace: for c in self.value:
continue if c in string.whitespace:
elif c in "abcdABCD": continue
self.validated = self.validated + string.upper(c) elif c in "abcdABCD":
else: self.validated = self.validated + string.upper(c)
self.valid = 0 else:
self.valid = 0
if len(self.validated) != 1:
raise ValueError, "Input must be exactly one character" if len(self.validated) != 1:
raise ValueError, "Input must be exactly one character"
return self.validated
return self.validated
def decompose(self):
self.decomposed = '' def decompose(self):
for c in self.encoded: self.decomposed = ''
self.decomposed = self.decomposed + _fim_patterns[c] for c in self.encoded:
self.decomposed = self.decomposed + _fim_patterns[c]
return self.decomposed
return self.decomposed
def computeSize(self):
self.width = (len(self.decomposed) - 1) * self.barspace + self.barwidth def computeSize(self):
if self.quiet: self.width = (len(self.decomposed) - 1) * self.barspace + self.barwidth
self.xo = self.lquiet if self.quiet:
self.width = self.lquiet + self.width + self.rquiet self.xo = self.lquiet
else: self.width = self.lquiet + self.width + self.rquiet
self.xo = 0.0 else:
self.xo = 0.0
def draw(self):
left = self.xo def draw(self):
for c in self.decomposed: left = self.xo
if c == '|': for c in self.decomposed:
self.rect(left, 0.0, self.barwidth, self.height) if c == '|':
left = left + self.barspace self.rect(left, 0.0, self.barwidth, self.height)
left = left + self.barspace
class POSTNET(Barcode):
"""" class POSTNET(Barcode):
POSTNET is used in the US to encode "zip codes" (postal codes) on """"
mail. It can encode 5, 9, or 11 digit codes. I've read that it's POSTNET is used in the US to encode "zip codes" (postal codes) on
pointless to do 5 digits, since USPS will just have to re-print mail. It can encode 5, 9, or 11 digit codes. I've read that it's
them with 9 or 11 digits. pointless to do 5 digits, since USPS will just have to re-print
them with 9 or 11 digits.
Sources of information on POSTNET:
Sources of information on POSTNET:
USPS Publication 25, A Guide to Business Mail Preparation
http://new.usps.com/cpim/ftp/pubs/pub25.pdf USPS Publication 25, A Guide to Business Mail Preparation
""" http://new.usps.com/cpim/ftp/pubs/pub25.pdf
"""
def __init__(self, value='', **args):
self.sbarheight = inch * 0.050 def __init__(self, value='', **args):
self.fbarheight = inch * 0.125 self.sbarheight = inch * 0.050
self.barwide = inch * 0.018 self.fbarheight = inch * 0.125
self.spacewide = inch * 0.0275 self.barwide = inch * 0.018
self.spacewide = inch * 0.0275
for (k, v) in args.items():
setattr(self, k, v) for (k, v) in args.items():
setattr(self, k, v)
Barcode.__init__(self, value)
Barcode.__init__(self, value)
def validate(self):
self.validated = '' def validate(self):
self.valid = 1 self.validated = ''
count = 0 self.valid = 1
for c in self.value: count = 0
if c in (string.whitespace + '-'): for c in self.value:
pass if c in (string.whitespace + '-'):
elif c in string.digits: pass
count = count + 1 elif c in string.digits:
if count == 6: count = count + 1
self.validated = self.validated + '-' if count == 6:
self.validated = self.validated + c self.validated = self.validated + '-'
else: self.validated = self.validated + c
self.valid = 0 else:
self.valid = 0
if len(self.validated) not in [5, 10, 12]:
self.valid = 0 if len(self.validated) not in [5, 10, 12]:
self.valid = 0
return self.validated
return self.validated
def encode(self):
self.encoded = "S" def encode(self):
check = 0 self.encoded = "S"
for c in self.validated: check = 0
if c in string.digits: for c in self.validated:
self.encoded = self.encoded + c if c in string.digits:
check = check + string.atoi(c) self.encoded = self.encoded + c
elif c == '-': check = check + string.atoi(c)
pass elif c == '-':
else: pass
raise ValueError, "Invalid character in input" else:
check = (10 - (check % 10)) % 10 raise ValueError, "Invalid character in input"
self.encoded = self.encoded + `check` + 'S' check = (10 - (check % 10)) % 10
return self.encoded self.encoded = self.encoded + `check` + 'S'
return self.encoded
def decompose(self):
self.decomposed = '' def decompose(self):
for c in self.encoded: self.decomposed = ''
self.decomposed = self.decomposed + _postnet_patterns[c] for c in self.encoded:
return self.decomposed self.decomposed = self.decomposed + _postnet_patterns[c]
return self.decomposed
def computeSize(self):
self.width = len(self.decomposed) * self.barwide def computeSize(self):
self.width = self.width + (len(self.decomposed) - 1) * self.spacewide self.width = len(self.decomposed) * self.barwide
self.height = self.fbarheight self.width = self.width + (len(self.decomposed) - 1) * self.spacewide
self.xo = 0.0 self.height = self.fbarheight
self.xo = 0.0
def draw(self):
sdown = self.fbarheight - self.sbarheight def draw(self):
left = self.xo sdown = self.fbarheight - self.sbarheight
left = self.xo
for c in self.decomposed:
if c == '.': for c in self.decomposed:
h = self.sbarheight if c == '.':
else: h = self.sbarheight
h = self.fbarheight else:
self.rect(left, 0.0, self.barwide, h) h = self.fbarheight
left = left + self.barwide + self.spacewide self.rect(left, 0.0, self.barwide, h)
left = left + self.barwide + self.spacewide
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -79,7 +79,7 @@ def _makeInvoices(self, cr, uid, data, context):
# ids = order_obj.lots_invoice(cr, uid, data['ids'],context,invoice_number) # ids = order_obj.lots_invoice(cr, uid, data['ids'],context,invoice_number)
cr.commit() cr.commit()
return { return {
'domain': "[('id','in', ["+','.join(map(str,ids))+"])]", 'domain': "[('id','in', ["+','.join(map(str, ids))+"])]",
'name': 'Buyer invoices', 'name': 'Buyer invoices',
'view_type': 'form', 'view_type': 'form',
'view_mode': 'tree,form', 'view_mode': 'tree,form',

View File

@ -72,7 +72,7 @@ def _makeInvoices(self, cr, uid, data, context):
ids = order_obj.seller_trans_create(cr, uid, data['ids'],context) ids = order_obj.seller_trans_create(cr, uid, data['ids'],context)
cr.commit() cr.commit()
return { return {
'domain': "[('id','in', ["+','.join(map(str,ids))+"])]", 'domain': "[('id','in', ["+','.join(map(str, ids))+"])]",
'name': 'Seller invoices', 'name': 'Seller invoices',
'view_type': 'form', 'view_type': 'form',
'view_mode': 'tree,form', 'view_mode': 'tree,form',

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution

View File

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution

View File

@ -1,4 +1,3 @@
#!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
@ -21,7 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
#!/usr/bin/python
""" """
Tiny SXW2RML - The Open ERP's report engine Tiny SXW2RML - The Open ERP's report engine

View File

@ -81,7 +81,7 @@ class crm_case_section(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -55,7 +55,7 @@ class report_custom(report_int):
minbenef = 999999999999999999999 minbenef = 999999999999999999999
maxbenef = 0 maxbenef = 0
cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id in ('+','.join(map(str,ids))+') order by user_id') cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id in ('+','.join(map(str, ids))+') order by user_id')
res = cr.dictfetchall() res = cr.dictfetchall()
for row in res: for row in res:

View File

@ -301,7 +301,7 @@ class document_directory(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False
@ -523,7 +523,7 @@ class document_file(osv.osv):
def _data_get(self, cr, uid, ids, name, arg, context): def _data_get(self, cr, uid, ids, name, arg, context):
result = {} result = {}
cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str,ids))+')') cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str, ids))+')')
for id,r,l in cr.fetchall(): for id,r,l in cr.fetchall():
try: try:
value = file(os.path.join(self._get_filestore(cr), r), 'rb').read() value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()

View File

@ -101,7 +101,7 @@ class hr_employee_category(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False
@ -150,7 +150,7 @@ class hr_employee(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -43,7 +43,7 @@ class hr_department(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -1,3 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
__name__ = "Change signs of old holiday requests" __name__ = "Change signs of old holiday requests"
def migrate(cr, version): def migrate(cr, version):

View File

@ -1,3 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
__name__ = "Convert the Holidays Per User limits into positive leave request" __name__ = "Convert the Holidays Per User limits into positive leave request"
def migrate(cr, version): def migrate(cr, version):

View File

@ -38,7 +38,7 @@ class wiz_timesheet_open(wizard.interface):
view_type = 'form,tree' view_type = 'form,tree'
if len(ids) > 1: if len(ids) > 1:
view_type = 'tree,form' view_type = 'tree,form'
domain = "[('id','in',["+','.join(map(str,ids))+"]),('user_id', '=', uid)]" domain = "[('id','in',["+','.join(map(str, ids))+"]),('user_id', '=', uid)]"
elif len(ids)==1: elif len(ids)==1:
ts.write(cr, uid, ids, {'date_current': time.strftime('%Y-%m-%d')}) ts.write(cr, uid, ids, {'date_current': time.strftime('%Y-%m-%d')})
domain = "[('user_id', '=', uid)]" domain = "[('user_id', '=', uid)]"

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# #
# account_move_line.py # account_move_line.py
# l10n_ch # l10n_ch

View File

@ -1,4 +1,4 @@
# # -*- coding: utf-8 -*-
# bank.py # bank.py
# l10n_ch # l10n_ch
# #

View File

@ -1,6 +1,3 @@
#!/usr/bin/python
#coding: latin-1 #coding: latin-1
############################################################################## ##############################################################################
@ -32,7 +29,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
#!/usr/bin/python
""" """
Tiny SXW2RML - The Tiny ERP's report engine Tiny SXW2RML - The Tiny ERP's report engine

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# #
# __init__.py # __init__.py
# #

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# #
# config.py # config.py
# #

View File

@ -401,7 +401,7 @@ class Partner(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -217,7 +217,7 @@ class mrp_bom(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 500 level = 500
while len(ids): while len(ids):
cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -208,7 +208,7 @@ class product_category(osv.osv):
def _check_recursion(self, cr, uid, ids): def _check_recursion(self, cr, uid, ids):
level = 100 level = 100
while len(ids): while len(ids):
cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str,ids))+')') cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str, ids))+')')
ids = filter(None, map(lambda x:x[0], cr.fetchall())) ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level: if not level:
return False return False

View File

@ -165,7 +165,7 @@ class project(osv.osv):
default['name'] = proj.name+_(' (copy)') default['name'] = proj.name+_(' (copy)')
res = super(project, self).copy(cr, uid, id, default, context) res = super(project, self).copy(cr, uid, id, default, context)
ids = self.search(cr, uid, [('parent_id','child_of', [res])]) ids = self.search(cr, uid, [('parent_id','child_of', [res])])
cr.execute('update project_task set active=True where project_id in ('+','.join(map(str,ids))+')') cr.execute('update project_task set active=True where project_id in ('+','.join(map(str, ids))+')')
return res return res
def duplicate_template(self, cr, uid, ids,context={}): def duplicate_template(self, cr, uid, ids,context={}):

View File

@ -36,7 +36,7 @@ class wiz_timebox_open(wizard.interface):
raise wizard.except_wizard(_('Error !'), _('No timebox of the type "%s" defined !') % (tbtype,)) raise wizard.except_wizard(_('Error !'), _('No timebox of the type "%s" defined !') % (tbtype,))
view_type = 'form,tree' view_type = 'form,tree'
if len(ids) >= 1: if len(ids) >= 1:
domain = "[('id','in',["+','.join(map(str,ids))+"])]" domain = "[('id','in',["+','.join(map(str, ids))+"])]"
else: else:
domain = "[('user_id', '=', uid)]" domain = "[('user_id', '=', uid)]"
value = { value = {

View File

@ -111,7 +111,7 @@ class purchase_order(osv.osv):
LEFT JOIN LEFT JOIN
stock_picking p on (p.id=m.picking_id) stock_picking p on (p.id=m.picking_id)
WHERE WHERE
p.purchase_id in ('''+','.join(map(str,ids))+''') p.purchase_id in ('''+','.join(map(str, ids))+''')
GROUP BY m.state, p.purchase_id''') GROUP BY m.state, p.purchase_id''')
for oid,nbr,state in cr.fetchall(): for oid,nbr,state in cr.fetchall():
if state=='cancel': if state=='cancel':

View File

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import unittest import unittest
import pooler import pooler
import netsvc import netsvc

View File

@ -71,14 +71,14 @@ class report_tasks(report_int):
io = StringIO.StringIO() io = StringIO.StringIO()
if 'date_start' not in datas: if 'date_start' not in datas:
cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str,ids))+')') cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str, ids))+')')
dt = cr.fetchone()[0] dt = cr.fetchone()[0]
if dt: if dt:
datas['date_start'] = dt[:10] datas['date_start'] = dt[:10]
else: else:
datas['date_start'] = time.strftime('%Y-%m-%d') datas['date_start'] = time.strftime('%Y-%m-%d')
if 'date_stop' not in datas: if 'date_stop' not in datas:
cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str,ids))+')') cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str, ids))+')')
res = cr.fetchone() res = cr.fetchone()
datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d') datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')
if res[1] and datas['date_stop']<res[1]: if res[1] and datas['date_stop']<res[1]:

View File

@ -33,7 +33,7 @@ def action_traceability(type='move_history_ids', field='tracking_id'):
cr.execute('select id from ir_ui_view where model=%s and field_parent=%s and type=%s', ('stock.move', type, 'tree')) cr.execute('select id from ir_ui_view where model=%s and field_parent=%s and type=%s', ('stock.move', type, 'tree'))
view_id = cr.fetchone()[0] view_id = cr.fetchone()[0]
value = { value = {
'domain': "[('id','in',["+','.join(map(str,ids))+"])]", 'domain': "[('id','in',["+','.join(map(str, ids))+"])]",
'name': ((type=='move_history_ids') and 'Upstream Traceability') or 'Downstream Traceability', 'name': ((type=='move_history_ids') and 'Upstream Traceability') or 'Downstream Traceability',
'view_type': 'tree', 'view_type': 'tree',
'res_model': 'stock.move', 'res_model': 'stock.move',