src/reportlab/platypus/paraparser.py
changeset 3187 2d5a6655556e
parent 3165 cbda9e7d0ee3
child 3188 be6793854075
equal deleted inserted replaced
3186:baf61467fa9a 3187:2d5a6655556e
     7 import re
     7 import re
     8 from types import TupleType, UnicodeType, StringType
     8 from types import TupleType, UnicodeType, StringType
     9 import sys
     9 import sys
    10 import os
    10 import os
    11 import copy
    11 import copy
       
    12 import base64
       
    13 try:
       
    14     import cPickle as pickle
       
    15 except:
       
    16     import pickle
    12 import unicodedata
    17 import unicodedata
    13 import reportlab.lib.sequencer
    18 import reportlab.lib.sequencer
    14 from reportlab.lib.abag import ABag
    19 from reportlab.lib.abag import ABag
    15 from reportlab.lib.utils import ImageReader
    20 from reportlab.lib.utils import ImageReader
    16 
    21 
   174                 'valign':('valign',_valignpc),
   179                 'valign':('valign',_valignpc),
   175                 }
   180                 }
   176 _indexAttrMap = {
   181 _indexAttrMap = {
   177                 'name': ('name',None),
   182                 'name': ('name',None),
   178                 'item': ('item',None),
   183                 'item': ('item',None),
       
   184                 'offset': ('offset',None),
       
   185                 'format': ('format',None),
   179                 }
   186                 }
   180 
   187 
   181 def _addAttributeNames(m):
   188 def _addAttributeNames(m):
   182     K = m.keys()
   189     K = m.keys()
   183     for k in K:
   190     for k in K:
   894 
   901 
   895     def start_index(self,attr):
   902     def start_index(self,attr):
   896         attr=self.getAttributes(attr,_indexAttrMap)
   903         attr=self.getAttributes(attr,_indexAttrMap)
   897         defn = ABag()
   904         defn = ABag()
   898         if attr.has_key('item'):
   905         if attr.has_key('item'):
   899             defn.label = attr['item']
   906             label = attr['item']
   900         else:
   907         else:
   901             self._syntax_error('<index> needs at least an item attribute')
   908             self._syntax_error('<index> needs at least an item attribute')
   902         if attr.has_key('name'):
   909         if attr.has_key('name'):
   903             name = attr['name']
   910             name = attr['name']
   904         else:
   911         else:
   905             name = DEFAULT_INDEX_NAME
   912             name = DEFAULT_INDEX_NAME
       
   913         format = attr.get('format',None)
       
   914         if format is not None and format not in ('123','I','i','ABC','abc'):
       
   915             raise ValueError('index tag format is %r not valid 123 I i ABC or abc' % offset)
       
   916         offset = attr.get('offset',None)
       
   917         if offset is not None:
       
   918             try:
       
   919                 offset = int(offset)
       
   920             except:
       
   921                 raise ValueError('index tag offset is %r not an int' % offset)
       
   922         defn.label = base64.encodestring(cPickle.dumps((label,format,offset))).strip
   906         defn.name = name
   923         defn.name = name
   907         defn.kind='index'
   924         defn.kind='index'
   908         self._push(cbDefn=defn)
   925         self._push(cbDefn=defn)
   909         self.handle_data('')
   926         self.handle_data('')
   910         self._pop()
   927         self._pop()