src/reportlab/platypus/paraparser.py
branchpy33
changeset 3994 9c38aba205e1
parent 3961 8c5743bc6489
child 4004 ebd460ef8d2f
equal deleted inserted replaced
3993:f807a6e50a63 3994:9c38aba205e1
    17     import pickle
    17     import pickle
    18 import unicodedata
    18 import unicodedata
    19 import reportlab.lib.sequencer
    19 import reportlab.lib.sequencer
    20 
    20 
    21 from reportlab.lib.abag import ABag
    21 from reportlab.lib.abag import ABag
    22 from reportlab.lib.utils import ImageReader, isPy3, annotateException, encode_label, asUnicode, UniChr
    22 from reportlab.lib.utils import ImageReader, isPy3, annotateException, encode_label, asUnicode, asBytes, UniChr
    23 from reportlab.lib.colors import toColor, white, black, red, Color
    23 from reportlab.lib.colors import toColor, white, black, red, Color
    24 from reportlab.lib.fonts import tt2ps, ps2tt
    24 from reportlab.lib.fonts import tt2ps, ps2tt
    25 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
    25 from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
    26 from reportlab.lib.units import inch,mm,cm,pica
    26 from reportlab.lib.units import inch,mm,cm,pica
    27 if isPy3:
    27 if isPy3:
   491 
   491 
   492 known_entities = dict([(k,UniChr(v)) for k,v in name2codepoint.items()])
   492 known_entities = dict([(k,UniChr(v)) for k,v in name2codepoint.items()])
   493 for k in greeks:
   493 for k in greeks:
   494     if k not in known_entities:
   494     if k not in known_entities:
   495         known_entities[k] = greeks[k]
   495         known_entities[k] = greeks[k]
       
   496 f = isPy3 and asBytes or asUnicode
       
   497 K = list(known_entities.keys())
       
   498 for k in K:
       
   499     known_entities[f(k)] = known_entities[k]
       
   500 del k, f, K
   496 
   501 
   497 #------------------------------------------------------------------------
   502 #------------------------------------------------------------------------
   498 class ParaFrag(ABag):
   503 class ParaFrag(ABag):
   499     """class ParaFrag contains the intermediate representation of string
   504     """class ParaFrag contains the intermediate representation of string
   500     segments as they are being parsed by the ParaParser.
   505     segments as they are being parsed by the ParaParser.
  1176         end()
  1181         end()
  1177 
  1182 
  1178     def handle_entityref(self, name):
  1183     def handle_entityref(self, name):
  1179         "Handles a named entity.  "
  1184         "Handles a named entity.  "
  1180         try:
  1185         try:
  1181             v = UniChr(known_entities[name])
  1186             v = known_entities[name]
  1182         except:
  1187         except:
  1183             v = u'&%s;' % name
  1188             v = u'&%s;' % name
  1184         self.handle_data(v)
  1189         self.handle_data(v)
  1185 
  1190 
  1186 if __name__=='__main__':
  1191 if __name__=='__main__':
  1187     from reportlab.platypus import cleanBlockQuotedText
  1192     from reportlab.platypus import cleanBlockQuotedText
  1188     from reportlab.lib.styles import _baseFontName
  1193     from reportlab.lib.styles import _baseFontName