author | rgbecker |
Wed, 08 Sep 2010 15:11:10 +0000 | |
changeset 3440 | 739ddbe7feab |
parent 3434 | 3c14212cc997 |
child 3552 | 20ecbcc53c15 |
permissions | -rw-r--r-- |
2332 | 1 |
#Copyright ReportLab Europe Ltd. 2000-2004 |
494 | 2 |
#see license.txt for license details |
2332 | 3 |
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/platypus/paraparser.py |
2321 | 4 |
__version__=''' $Id$ ''' |
3032 | 5 |
__doc__='''The parser used to process markup within paragraphs''' |
96 | 6 |
import string |
119 | 7 |
import re |
2575 | 8 |
from types import TupleType, UnicodeType, StringType |
96 | 9 |
import sys |
10 |
import os |
|
11 |
import copy |
|
3187
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
12 |
import base64 |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
13 |
try: |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
14 |
import cPickle as pickle |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
15 |
except: |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
16 |
import pickle |
2693 | 17 |
import unicodedata |
279 | 18 |
import reportlab.lib.sequencer |
518 | 19 |
from reportlab.lib.abag import ABag |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
20 |
from reportlab.lib.utils import ImageReader |
1160 | 21 |
|
2376 | 22 |
from reportlab.lib import xmllib |
96 | 23 |
|
248 | 24 |
from reportlab.lib.colors import toColor, white, black, red, Color |
96 | 25 |
from reportlab.lib.fonts import tt2ps, ps2tt |
119 | 26 |
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY |
1940 | 27 |
from reportlab.lib.units import inch,mm,cm,pica |
2410 | 28 |
_re_para = re.compile(r'^\s*<\s*para(?:\s+|>|/>)') |
96 | 29 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
30 |
sizeDelta = 2 # amount to reduce font size by for super and sub script |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
31 |
subFraction = 0.5 # fraction of font size that a sub script should be lowered |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
32 |
superFraction = 0.5 # fraction of font size that a super script should be raised |
96 | 33 |
|
3165 | 34 |
DEFAULT_INDEX_NAME='_indexAdd' |
35 |
||
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
36 |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
37 |
def _convnum(s, unit=1, allowRelative=True): |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
38 |
if s[0] in ('+','-') and allowRelative: |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
39 |
try: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
40 |
return ('relative',int(s)*unit) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
41 |
except ValueError: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
42 |
return ('relative',float(s)*unit) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
43 |
else: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
44 |
try: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
45 |
return int(s)*unit |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
46 |
except ValueError: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
47 |
return float(s)*unit |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
48 |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
49 |
def _num(s, unit=1, allowRelative=True): |
1940 | 50 |
"""Convert a string like '10cm' to an int or float (in points). |
51 |
The default unit is point, but optionally you can use other |
|
52 |
default units like mm. |
|
53 |
""" |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
54 |
if s.endswith('cm'): |
1940 | 55 |
unit=cm |
56 |
s = s[:-2] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
57 |
if s.endswith('in'): |
1940 | 58 |
unit=inch |
59 |
s = s[:-2] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
60 |
if s.endswith('pt'): |
1940 | 61 |
unit=1 |
62 |
s = s[:-2] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
63 |
if s.endswith('i'): |
1940 | 64 |
unit=inch |
65 |
s = s[:-1] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
66 |
if s.endswith('mm'): |
1940 | 67 |
unit=mm |
68 |
s = s[:-2] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
69 |
if s.endswith('pica'): |
1940 | 70 |
unit=pica |
71 |
s = s[:-4] |
|
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
72 |
return _convnum(s,unit,allowRelative) |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
73 |
|
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
74 |
def _numpct(s,unit=1,allowRelative=False): |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
75 |
if s.endswith('%'): |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
76 |
return _PCT(_convnum(s[:-1],allowRelative=allowRelative)) |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
77 |
else: |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
78 |
return _num(s,unit,allowRelative) |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
79 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
80 |
class _PCT: |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
81 |
def __init__(self,v): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
82 |
self._value = v*0.01 |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
83 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
84 |
def normalizedValue(self,normalizer): |
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
85 |
normalizer = normalizer or getattr(self,'_normalizer') |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
86 |
return normalizer*self._value |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
87 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
88 |
def _valignpc(s): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
89 |
s = s.lower() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
90 |
if s in ('baseline','sub','super','top','text-top','middle','bottom','text-bottom'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
91 |
return s |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
92 |
if s.endswith('%'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
93 |
n = _convnum(s[:-1]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
94 |
if isinstance(n,tuple): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
95 |
n = n[1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
96 |
return _PCT(n) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
97 |
n = _num(s) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
98 |
if isinstance(n,tuple): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
99 |
n = n[1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
100 |
return n |
119 | 101 |
|
2836 | 102 |
def _autoLeading(x): |
103 |
x = x.lower() |
|
104 |
if x in ('','min','max','off'): |
|
105 |
return x |
|
106 |
raise ValueError('Invalid autoLeading=%r' % x ) |
|
107 |
||
119 | 108 |
def _align(s): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
109 |
s = string.lower(s) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
110 |
if s=='left': return TA_LEFT |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
111 |
elif s=='right': return TA_RIGHT |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
112 |
elif s=='justify': return TA_JUSTIFY |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
113 |
elif s in ('centre','center'): return TA_CENTER |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
114 |
else: raise ValueError |
119 | 115 |
|
116 |
_paraAttrMap = {'font': ('fontName', None), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
117 |
'face': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
118 |
'fontsize': ('fontSize', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
119 |
'size': ('fontSize', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
120 |
'leading': ('leading', _num), |
2836 | 121 |
'autoleading': ('autoLeading', _autoLeading), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
122 |
'lindent': ('leftIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
123 |
'rindent': ('rightIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
124 |
'findent': ('firstLineIndent', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
125 |
'align': ('alignment', _align), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
126 |
'spaceb': ('spaceBefore', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
127 |
'spacea': ('spaceAfter', _num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
128 |
'bfont': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
129 |
'bfontsize': ('bulletFontSize',_num), |
2860
3f14d66194c2
platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents:
2857
diff
changeset
|
130 |
'boffsety': ('bulletOffsetY',_num), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
131 |
'bindent': ('bulletIndent',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
132 |
'bcolor': ('bulletColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
133 |
'color':('textColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
134 |
'backcolor':('backColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
135 |
'bgcolor':('backColor',toColor), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
136 |
'bg':('backColor',toColor), |
1940 | 137 |
'fg': ('textColor',toColor), |
138 |
} |
|
119 | 139 |
|
250 | 140 |
_bulletAttrMap = { |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
141 |
'font': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
142 |
'face': ('bulletFontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
143 |
'size': ('bulletFontSize',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
144 |
'fontsize': ('bulletFontSize',_num), |
2860
3f14d66194c2
platypus: added bulletOffsetY inspired by haraldarminmassa@gmail.com
rgbecker
parents:
2857
diff
changeset
|
145 |
'offsety': ('bulletOffsetY',_num), |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
146 |
'indent': ('bulletIndent',_num), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
147 |
'color': ('bulletColor',toColor), |
1940 | 148 |
'fg': ('bulletColor',toColor), |
149 |
} |
|
250 | 150 |
|
119 | 151 |
#things which are valid font attributes |
152 |
_fontAttrMap = {'size': ('fontSize', _num), |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
153 |
'face': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
154 |
'name': ('fontName', None), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
155 |
'fg': ('textColor', toColor), |
1940 | 156 |
'color':('textColor', toColor), |
2446 | 157 |
'backcolor':('backColor',toColor), |
158 |
'bgcolor':('backColor',toColor), |
|
1940 | 159 |
} |
2575 | 160 |
#things which are valid font attributes |
161 |
_linkAttrMap = {'size': ('fontSize', _num), |
|
162 |
'face': ('fontName', None), |
|
163 |
'name': ('fontName', None), |
|
164 |
'fg': ('textColor', toColor), |
|
165 |
'color':('textColor', toColor), |
|
166 |
'backcolor':('backColor',toColor), |
|
167 |
'bgcolor':('backColor',toColor), |
|
168 |
'dest': ('link', None), |
|
169 |
'destination': ('link', None), |
|
170 |
'target': ('link', None), |
|
2594 | 171 |
'href': ('link', None), |
2575 | 172 |
} |
2744 | 173 |
_anchorAttrMap = {'fontSize': ('fontSize', _num), |
174 |
'fontName': ('fontName', None), |
|
175 |
'name': ('name', None), |
|
176 |
'fg': ('textColor', toColor), |
|
177 |
'color':('textColor', toColor), |
|
178 |
'backcolor':('backColor',toColor), |
|
179 |
'bgcolor':('backColor',toColor), |
|
180 |
'href': ('href', None), |
|
181 |
} |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
182 |
_imgAttrMap = { |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
183 |
'src': ('src', None), |
3434
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
184 |
'width': ('width',_numpct), |
3c14212cc997
platypus: preliminary working version of % height/width for <img> tag
rgbecker
parents:
3368
diff
changeset
|
185 |
'height':('height',_numpct), |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
186 |
'valign':('valign',_valignpc), |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
187 |
} |
3165 | 188 |
_indexAttrMap = { |
189 |
'name': ('name',None), |
|
190 |
'item': ('item',None), |
|
3187
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
191 |
'offset': ('offset',None), |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
192 |
'format': ('format',None), |
3165 | 193 |
} |
119 | 194 |
|
195 |
def _addAttributeNames(m): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
196 |
K = m.keys() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
197 |
for k in K: |
1944 | 198 |
n = m[k][0] |
3326 | 199 |
if n not in m: m[n] = m[k] |
1944 | 200 |
n = string.lower(n) |
3326 | 201 |
if n not in m: m[n] = m[k] |
119 | 202 |
|
203 |
_addAttributeNames(_paraAttrMap) |
|
204 |
_addAttributeNames(_fontAttrMap) |
|
250 | 205 |
_addAttributeNames(_bulletAttrMap) |
2747 | 206 |
_addAttributeNames(_anchorAttrMap) |
207 |
_addAttributeNames(_linkAttrMap) |
|
119 | 208 |
|
209 |
def _applyAttributes(obj, attr): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
210 |
for k, v in attr.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
211 |
if type(v) is TupleType and v[0]=='relative': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
212 |
#AR 20/5/2000 - remove 1.5.2-ism |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
213 |
#v = v[1]+getattr(obj,k,0) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
214 |
if hasattr(obj, k): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
215 |
v = v[1]+getattr(obj,k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
216 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
217 |
v = v[1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
218 |
setattr(obj,k,v) |
102 | 219 |
|
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
220 |
#Named character entities intended to be supported from the special font |
2200
be0cfccc662a
Fixed up tabs and whitespace in all source files
andy_robinson
parents:
2053
diff
changeset
|
221 |
#with additions suggested by Christoph Zwerschke who also suggested the |
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
222 |
#numeric entity names that follow. |
96 | 223 |
greeks = { |
3137 | 224 |
'Aacute': '\xc3\x81', |
225 |
'aacute': '\xc3\xa1', |
|
226 |
'Acirc': '\xc3\x82', |
|
227 |
'acirc': '\xc3\xa2', |
|
228 |
'acute': '\xc2\xb4', |
|
229 |
'AElig': '\xc3\x86', |
|
230 |
'aelig': '\xc3\xa6', |
|
231 |
'Agrave': '\xc3\x80', |
|
232 |
'agrave': '\xc3\xa0', |
|
2575 | 233 |
'alefsym': '\xe2\x84\xb5', |
234 |
'Alpha': '\xce\x91', |
|
235 |
'alpha': '\xce\xb1', |
|
236 |
'and': '\xe2\x88\xa7', |
|
237 |
'ang': '\xe2\x88\xa0', |
|
3137 | 238 |
'Aring': '\xc3\x85', |
239 |
'aring': '\xc3\xa5', |
|
2575 | 240 |
'asymp': '\xe2\x89\x88', |
3137 | 241 |
'Atilde': '\xc3\x83', |
242 |
'atilde': '\xc3\xa3', |
|
243 |
'Auml': '\xc3\x84', |
|
244 |
'auml': '\xc3\xa4', |
|
245 |
'bdquo': '\xe2\x80\x9e', |
|
2575 | 246 |
'Beta': '\xce\x92', |
247 |
'beta': '\xce\xb2', |
|
3137 | 248 |
'brvbar': '\xc2\xa6', |
2575 | 249 |
'bull': '\xe2\x80\xa2', |
250 |
'cap': '\xe2\x88\xa9', |
|
3137 | 251 |
'Ccedil': '\xc3\x87', |
252 |
'ccedil': '\xc3\xa7', |
|
253 |
'cedil': '\xc2\xb8', |
|
254 |
'cent': '\xc2\xa2', |
|
2575 | 255 |
'Chi': '\xce\xa7', |
256 |
'chi': '\xcf\x87', |
|
3137 | 257 |
'circ': '\xcb\x86', |
2575 | 258 |
'clubs': '\xe2\x99\xa3', |
259 |
'cong': '\xe2\x89\x85', |
|
3137 | 260 |
'copy': '\xc2\xa9', |
261 |
'crarr': '\xe2\x86\xb5', |
|
2575 | 262 |
'cup': '\xe2\x88\xaa', |
3137 | 263 |
'curren': '\xc2\xa4', |
264 |
'dagger': '\xe2\x80\xa0', |
|
265 |
'Dagger': '\xe2\x80\xa1', |
|
2575 | 266 |
'darr': '\xe2\x86\x93', |
267 |
'dArr': '\xe2\x87\x93', |
|
3137 | 268 |
'deg': '\xc2\xb0', |
2575 | 269 |
'delta': '\xce\xb4', |
270 |
'Delta': '\xe2\x88\x86', |
|
271 |
'diams': '\xe2\x99\xa6', |
|
3137 | 272 |
'divide': '\xc3\xb7', |
273 |
'Eacute': '\xc3\x89', |
|
274 |
'eacute': '\xc3\xa9', |
|
275 |
'Ecirc': '\xc3\x8a', |
|
276 |
'ecirc': '\xc3\xaa', |
|
277 |
'Egrave': '\xc3\x88', |
|
278 |
'egrave': '\xc3\xa8', |
|
2575 | 279 |
'empty': '\xe2\x88\x85', |
3137 | 280 |
'emsp': '\xe2\x80\x83', |
281 |
'ensp': '\xe2\x80\x82', |
|
2575 | 282 |
'Epsilon': '\xce\x95', |
283 |
'epsilon': '\xce\xb5', |
|
284 |
'epsiv': '\xce\xb5', |
|
285 |
'equiv': '\xe2\x89\xa1', |
|
286 |
'Eta': '\xce\x97', |
|
287 |
'eta': '\xce\xb7', |
|
3137 | 288 |
'ETH': '\xc3\x90', |
289 |
'eth': '\xc3\xb0', |
|
290 |
'Euml': '\xc3\x8b', |
|
291 |
'euml': '\xc3\xab', |
|
2575 | 292 |
'euro': '\xe2\x82\xac', |
293 |
'exist': '\xe2\x88\x83', |
|
3137 | 294 |
'fnof': '\xc6\x92', |
2575 | 295 |
'forall': '\xe2\x88\x80', |
3137 | 296 |
'frac12': '\xc2\xbd', |
297 |
'frac14': '\xc2\xbc', |
|
298 |
'frac34': '\xc2\xbe', |
|
2575 | 299 |
'frasl': '\xe2\x81\x84', |
300 |
'Gamma': '\xce\x93', |
|
301 |
'gamma': '\xce\xb3', |
|
302 |
'ge': '\xe2\x89\xa5', |
|
303 |
'harr': '\xe2\x86\x94', |
|
304 |
'hArr': '\xe2\x87\x94', |
|
305 |
'hearts': '\xe2\x99\xa5', |
|
306 |
'hellip': '\xe2\x80\xa6', |
|
3137 | 307 |
'Iacute': '\xc3\x8d', |
308 |
'iacute': '\xc3\xad', |
|
309 |
'Icirc': '\xc3\x8e', |
|
310 |
'icirc': '\xc3\xae', |
|
311 |
'iexcl': '\xc2\xa1', |
|
312 |
'Igrave': '\xc3\x8c', |
|
313 |
'igrave': '\xc3\xac', |
|
2575 | 314 |
'image': '\xe2\x84\x91', |
315 |
'infin': '\xe2\x88\x9e', |
|
316 |
'int': '\xe2\x88\xab', |
|
317 |
'Iota': '\xce\x99', |
|
318 |
'iota': '\xce\xb9', |
|
3137 | 319 |
'iquest': '\xc2\xbf', |
2575 | 320 |
'isin': '\xe2\x88\x88', |
3137 | 321 |
'Iuml': '\xc3\x8f', |
322 |
'iuml': '\xc3\xaf', |
|
2575 | 323 |
'Kappa': '\xce\x9a', |
324 |
'kappa': '\xce\xba', |
|
325 |
'Lambda': '\xce\x9b', |
|
326 |
'lambda': '\xce\xbb', |
|
327 |
'lang': '\xe2\x8c\xa9', |
|
3137 | 328 |
'laquo': '\xc2\xab', |
2575 | 329 |
'larr': '\xe2\x86\x90', |
330 |
'lArr': '\xe2\x87\x90', |
|
331 |
'lceil': '\xef\xa3\xae', |
|
3137 | 332 |
'ldquo': '\xe2\x80\x9c', |
2575 | 333 |
'le': '\xe2\x89\xa4', |
334 |
'lfloor': '\xef\xa3\xb0', |
|
335 |
'lowast': '\xe2\x88\x97', |
|
336 |
'loz': '\xe2\x97\x8a', |
|
3137 | 337 |
'lrm': '\xe2\x80\x8e', |
338 |
'lsaquo': '\xe2\x80\xb9', |
|
339 |
'lsquo': '\xe2\x80\x98', |
|
340 |
'macr': '\xc2\xaf', |
|
341 |
'mdash': '\xe2\x80\x94', |
|
342 |
'micro': '\xc2\xb5', |
|
343 |
'middot': '\xc2\xb7', |
|
2575 | 344 |
'minus': '\xe2\x88\x92', |
345 |
'mu': '\xc2\xb5', |
|
346 |
'Mu': '\xce\x9c', |
|
347 |
'nabla': '\xe2\x88\x87', |
|
3137 | 348 |
'nbsp': '\xc2\xa0', |
349 |
'ndash': '\xe2\x80\x93', |
|
2575 | 350 |
'ne': '\xe2\x89\xa0', |
351 |
'ni': '\xe2\x88\x8b', |
|
352 |
'notin': '\xe2\x88\x89', |
|
3137 | 353 |
'not': '\xc2\xac', |
2575 | 354 |
'nsub': '\xe2\x8a\x84', |
3137 | 355 |
'Ntilde': '\xc3\x91', |
356 |
'ntilde': '\xc3\xb1', |
|
2575 | 357 |
'Nu': '\xce\x9d', |
358 |
'nu': '\xce\xbd', |
|
3137 | 359 |
'Oacute': '\xc3\x93', |
360 |
'oacute': '\xc3\xb3', |
|
361 |
'Ocirc': '\xc3\x94', |
|
362 |
'ocirc': '\xc3\xb4', |
|
363 |
'OElig': '\xc5\x92', |
|
364 |
'oelig': '\xc5\x93', |
|
365 |
'Ograve': '\xc3\x92', |
|
366 |
'ograve': '\xc3\xb2', |
|
2575 | 367 |
'oline': '\xef\xa3\xa5', |
368 |
'omega': '\xcf\x89', |
|
369 |
'Omega': '\xe2\x84\xa6', |
|
370 |
'Omicron': '\xce\x9f', |
|
371 |
'omicron': '\xce\xbf', |
|
372 |
'oplus': '\xe2\x8a\x95', |
|
3137 | 373 |
'ordf': '\xc2\xaa', |
374 |
'ordm': '\xc2\xba', |
|
2575 | 375 |
'or': '\xe2\x88\xa8', |
3137 | 376 |
'Oslash': '\xc3\x98', |
377 |
'oslash': '\xc3\xb8', |
|
378 |
'Otilde': '\xc3\x95', |
|
379 |
'otilde': '\xc3\xb5', |
|
2575 | 380 |
'otimes': '\xe2\x8a\x97', |
3137 | 381 |
'Ouml': '\xc3\x96', |
382 |
'ouml': '\xc3\xb6', |
|
383 |
'para': '\xc2\xb6', |
|
2575 | 384 |
'part': '\xe2\x88\x82', |
3137 | 385 |
'permil': '\xe2\x80\xb0', |
2575 | 386 |
'perp': '\xe2\x8a\xa5', |
3137 | 387 |
'phis': '\xcf\x86', |
2575 | 388 |
'Phi': '\xce\xa6', |
389 |
'phi': '\xcf\x95', |
|
3137 | 390 |
'piv': '\xcf\x96', |
2575 | 391 |
'Pi': '\xce\xa0', |
392 |
'pi': '\xcf\x80', |
|
3137 | 393 |
'plusmn': '\xc2\xb1', |
394 |
'pound': '\xc2\xa3', |
|
2575 | 395 |
'prime': '\xe2\x80\xb2', |
3137 | 396 |
'Prime': '\xe2\x80\xb3', |
2575 | 397 |
'prod': '\xe2\x88\x8f', |
398 |
'prop': '\xe2\x88\x9d', |
|
399 |
'Psi': '\xce\xa8', |
|
400 |
'psi': '\xcf\x88', |
|
401 |
'radic': '\xe2\x88\x9a', |
|
402 |
'rang': '\xe2\x8c\xaa', |
|
3137 | 403 |
'raquo': '\xc2\xbb', |
2575 | 404 |
'rarr': '\xe2\x86\x92', |
405 |
'rArr': '\xe2\x87\x92', |
|
406 |
'rceil': '\xef\xa3\xb9', |
|
3137 | 407 |
'rdquo': '\xe2\x80\x9d', |
2575 | 408 |
'real': '\xe2\x84\x9c', |
3137 | 409 |
'reg': '\xc2\xae', |
2575 | 410 |
'rfloor': '\xef\xa3\xbb', |
411 |
'Rho': '\xce\xa1', |
|
412 |
'rho': '\xcf\x81', |
|
3137 | 413 |
'rlm': '\xe2\x80\x8f', |
414 |
'rsaquo': '\xe2\x80\xba', |
|
415 |
'rsquo': '\xe2\x80\x99', |
|
416 |
'sbquo': '\xe2\x80\x9a', |
|
417 |
'Scaron': '\xc5\xa0', |
|
418 |
'scaron': '\xc5\xa1', |
|
2575 | 419 |
'sdot': '\xe2\x8b\x85', |
3137 | 420 |
'sect': '\xc2\xa7', |
421 |
'shy': '\xc2\xad', |
|
2575 | 422 |
'sigmaf': '\xcf\x82', |
423 |
'sigmav': '\xcf\x82', |
|
3137 | 424 |
'Sigma': '\xce\xa3', |
425 |
'sigma': '\xcf\x83', |
|
2575 | 426 |
'sim': '\xe2\x88\xbc', |
427 |
'spades': '\xe2\x99\xa0', |
|
3137 | 428 |
'sube': '\xe2\x8a\x86', |
2575 | 429 |
'sub': '\xe2\x8a\x82', |
430 |
'sum': '\xe2\x88\x91', |
|
3137 | 431 |
'sup1': '\xc2\xb9', |
432 |
'sup2': '\xc2\xb2', |
|
433 |
'sup3': '\xc2\xb3', |
|
434 |
'supe': '\xe2\x8a\x87', |
|
2575 | 435 |
'sup': '\xe2\x8a\x83', |
3137 | 436 |
'szlig': '\xc3\x9f', |
2575 | 437 |
'Tau': '\xce\xa4', |
438 |
'tau': '\xcf\x84', |
|
439 |
'there4': '\xe2\x88\xb4', |
|
440 |
'thetasym': '\xcf\x91', |
|
441 |
'thetav': '\xcf\x91', |
|
3137 | 442 |
'Theta': '\xce\x98', |
443 |
'theta': '\xce\xb8', |
|
444 |
'thinsp': '\xe2\x80\x89', |
|
445 |
'THORN': '\xc3\x9e', |
|
446 |
'thorn': '\xc3\xbe', |
|
447 |
'tilde': '\xcb\x9c', |
|
448 |
'times': '\xc3\x97', |
|
2575 | 449 |
'trade': '\xef\xa3\xaa', |
3137 | 450 |
'Uacute': '\xc3\x9a', |
451 |
'uacute': '\xc3\xba', |
|
2575 | 452 |
'uarr': '\xe2\x86\x91', |
453 |
'uArr': '\xe2\x87\x91', |
|
3137 | 454 |
'Ucirc': '\xc3\x9b', |
455 |
'ucirc': '\xc3\xbb', |
|
456 |
'Ugrave': '\xc3\x99', |
|
457 |
'ugrave': '\xc3\xb9', |
|
458 |
'uml': '\xc2\xa8', |
|
2575 | 459 |
'upsih': '\xcf\x92', |
460 |
'Upsilon': '\xce\xa5', |
|
461 |
'upsilon': '\xcf\x85', |
|
3137 | 462 |
'Uuml': '\xc3\x9c', |
463 |
'uuml': '\xc3\xbc', |
|
2575 | 464 |
'weierp': '\xe2\x84\x98', |
465 |
'Xi': '\xce\x9e', |
|
466 |
'xi': '\xce\xbe', |
|
3137 | 467 |
'Yacute': '\xc3\x9d', |
468 |
'yacute': '\xc3\xbd', |
|
469 |
'yen': '\xc2\xa5', |
|
470 |
'yuml': '\xc3\xbf', |
|
471 |
'Yuml': '\xc5\xb8', |
|
2575 | 472 |
'Zeta': '\xce\x96', |
473 |
'zeta': '\xce\xb6', |
|
3137 | 474 |
'zwj': '\xe2\x80\x8d', |
475 |
'zwnj': '\xe2\x80\x8c', |
|
476 |
||
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
477 |
} |
96 | 478 |
|
479 |
#------------------------------------------------------------------------ |
|
518 | 480 |
class ParaFrag(ABag): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
481 |
"""class ParaFrag contains the intermediate representation of string |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
482 |
segments as they are being parsed by the XMLParser. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
483 |
fontname, fontSize, rise, textColor, cbDefn |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
484 |
""" |
96 | 485 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
486 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
487 |
_greek2Utf8=None |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
488 |
def _greekConvert(data): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
489 |
global _greek2Utf8 |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
490 |
if not _greek2Utf8: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
491 |
from reportlab.pdfbase.rl_codecs import RL_Codecs |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
492 |
import codecs |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
493 |
dm = decoding_map = codecs.make_identity_dict(xrange(32,256)) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
494 |
for k in xrange(0,32): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
495 |
dm[k] = None |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
496 |
dm.update(RL_Codecs._RL_Codecs__rl_codecs_data['symbol'][0]) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
497 |
_greek2Utf8 = {} |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
498 |
for k,v in dm.iteritems(): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
499 |
if not v: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
500 |
u = '\0' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
501 |
else: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
502 |
u = unichr(v).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
503 |
_greek2Utf8[chr(k)] = u |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
504 |
return ''.join(map(_greek2Utf8.__getitem__,data)) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
505 |
|
96 | 506 |
#------------------------------------------------------------------ |
267
52a348f6c4c3
noted replication of XML markup comment between paraparser.py and paragraph.py
aaron_watters
parents:
266
diff
changeset
|
507 |
# !!! NOTE !!! THIS TEXT IS NOW REPLICATED IN PARAGRAPH.PY !!! |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
508 |
# The ParaFormatter will be able to format the following |
96 | 509 |
# tags: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
510 |
# < /b > - bold |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
511 |
# < /i > - italics |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
512 |
# < u > < /u > - underline |
2644 | 513 |
# < strike > < /strike > - strike through |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
514 |
# < super > < /super > - superscript |
1736 | 515 |
# < sup > < /sup > - superscript |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
516 |
# < sub > < /sub > - subscript |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
517 |
# <font name=fontfamily/fontname color=colorname size=float> |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
518 |
# < bullet > </bullet> - bullet text (at head of para only) |
3165 | 519 |
# <onDraw name=callable label="a label"/> |
520 |
# <index [name="callablecanvasattribute"] label="a label"/> |
|
2670 | 521 |
# <link>link text</link> |
522 |
# attributes of links |
|
523 |
# size/fontSize=num |
|
524 |
# name/face/fontName=name |
|
525 |
# fg/textColor/color=color |
|
526 |
# backcolor/backColor/bgcolor=color |
|
527 |
# dest/destination/target/href/link=target |
|
2745 | 528 |
# <a>anchor text</a> |
2744 | 529 |
# attributes of anchors |
530 |
# fontSize=num |
|
531 |
# fontName=name |
|
532 |
# fg/textColor/color=color |
|
533 |
# backcolor/backColor/bgcolor=color |
|
534 |
# href=href |
|
535 |
# <a name="anchorpoint"/> |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
536 |
# <unichar name="unicode character name"/> |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
537 |
# <unichar value="unicode code point"/> |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
538 |
# <img src="path" width="1in" height="1in" valign="bottom"/> |
3440
739ddbe7feab
paaraparser/paragraph.py: add info re percentage in <img> for idea contributed by Roberto Alsina <ralsina@netmanagers.com.ar>
rgbecker
parents:
3434
diff
changeset
|
539 |
# width="w%" --> fontSize*w/100 idea from Roberto Alsina |
739ddbe7feab
paaraparser/paragraph.py: add info re percentage in <img> for idea contributed by Roberto Alsina <ralsina@netmanagers.com.ar>
rgbecker
parents:
3434
diff
changeset
|
540 |
# height="h%" --> linewidth*h/100 <ralsina@netmanagers.com.ar> |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
541 |
# <greek> - </greek> |
1683 | 542 |
# |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
543 |
# The whole may be surrounded by <para> </para> tags |
119 | 544 |
# |
96 | 545 |
# It will also be able to handle any MathML specified Greek characters. |
546 |
#------------------------------------------------------------------ |
|
547 |
class ParaParser(xmllib.XMLParser): |
|
548 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
549 |
#---------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
550 |
# First we will define all of the xml tag handler functions. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
551 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
552 |
# start_<tag>(attributes) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
553 |
# end_<tag>() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
554 |
# |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
555 |
# While parsing the xml ParaFormatter will call these |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
556 |
# functions to handle the string formatting tags. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
557 |
# At the start of each tag the corresponding field will |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
558 |
# be set to 1 and at the end tag the corresponding field will |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
559 |
# be set to 0. Then when handle_data is called the options |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
560 |
# for that data will be aparent by the current settings. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
561 |
#---------------------------------------------------------- |
96 | 562 |
|
1940 | 563 |
def __getattr__( self, attrName ): |
564 |
"""This way we can handle <TAG> the same way as <tag> (ignoring case).""" |
|
2369 | 565 |
if attrName!=attrName.lower() and attrName!="caseSensitive" and not self.caseSensitive and \ |
566 |
(attrName.startswith("start_") or attrName.startswith("end_")): |
|
567 |
return getattr(self,attrName.lower()) |
|
1940 | 568 |
raise AttributeError, attrName |
569 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
570 |
#### bold |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
571 |
def start_b( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
572 |
self._push(bold=1) |
96 | 573 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
574 |
def end_b( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
575 |
self._pop(bold=1) |
96 | 576 |
|
1940 | 577 |
def start_strong( self, attributes ): |
578 |
self._push(bold=1) |
|
579 |
||
580 |
def end_strong( self ): |
|
581 |
self._pop(bold=1) |
|
582 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
583 |
#### italics |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
584 |
def start_i( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
585 |
self._push(italic=1) |
96 | 586 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
587 |
def end_i( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
588 |
self._pop(italic=1) |
96 | 589 |
|
1940 | 590 |
def start_em( self, attributes ): |
591 |
self._push(italic=1) |
|
592 |
||
593 |
def end_em( self ): |
|
594 |
self._pop(italic=1) |
|
595 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
596 |
#### underline |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
597 |
def start_u( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
598 |
self._push(underline=1) |
96 | 599 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
600 |
def end_u( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
601 |
self._pop(underline=1) |
96 | 602 |
|
2644 | 603 |
#### strike |
604 |
def start_strike( self, attributes ): |
|
605 |
self._push(strike=1) |
|
606 |
||
607 |
def end_strike( self ): |
|
608 |
self._pop(strike=1) |
|
609 |
||
2575 | 610 |
#### link |
611 |
def start_link(self, attributes): |
|
612 |
self._push(**self.getAttributes(attributes,_linkAttrMap)) |
|
613 |
||
614 |
def end_link(self): |
|
615 |
frag = self._stack[-1] |
|
616 |
del self._stack[-1] |
|
617 |
assert frag.link!=None |
|
618 |
||
2744 | 619 |
#### anchor |
620 |
def start_a(self, attributes): |
|
621 |
A = self.getAttributes(attributes,_anchorAttrMap) |
|
2893
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
622 |
name = A.get('name',None) |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
623 |
if name is not None: |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
624 |
name = name.strip() |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
625 |
if not name: |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
626 |
self._syntax_error('<a name="..."/> anchor variant requires non-blank name') |
2744 | 627 |
if len(A)>1: |
628 |
self._syntax_error('<a name="..."/> anchor variant only allows name attribute') |
|
629 |
A = dict(name=A['name']) |
|
630 |
A['_selfClosingTag'] = 'anchor' |
|
631 |
else: |
|
2893
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
632 |
href = A.get('href','').strip() |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
633 |
if not href: |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
634 |
self._syntax_error('<a> tag must have non-blank name or href attribute') |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
635 |
A['link'] = href #convert to our link form |
7432e06445ba
paraparser.py: improved checking on <a> tag attributes
rgbecker
parents:
2861
diff
changeset
|
636 |
A.pop('href') |
2744 | 637 |
self._push(**A) |
638 |
||
639 |
def end_a(self): |
|
640 |
frag = self._stack[-1] |
|
641 |
sct = getattr(frag,'_selfClosingTag','') |
|
642 |
if sct: |
|
643 |
assert sct=='anchor' and frag.name,'Parser failure in <a/>' |
|
644 |
defn = frag.cbDefn = ABag() |
|
645 |
defn.label = defn.kind = 'anchor' |
|
646 |
defn.name = frag.name |
|
647 |
del frag.name, frag._selfClosingTag |
|
648 |
self.handle_data('') |
|
649 |
self._pop() |
|
650 |
else: |
|
651 |
del self._stack[-1] |
|
652 |
assert frag.link!=None |
|
2742 | 653 |
|
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
654 |
def start_img(self,attributes): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
655 |
A = self.getAttributes(attributes,_imgAttrMap) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
656 |
if not A.get('src'): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
657 |
self._syntax_error('<img> needs src attribute') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
658 |
A['_selfClosingTag'] = 'img' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
659 |
self._push(**A) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
660 |
|
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
661 |
def end_img(self): |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
662 |
frag = self._stack[-1] |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
663 |
assert getattr(frag,'_selfClosingTag',''),'Parser failure in <img/>' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
664 |
defn = frag.cbDefn = ABag() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
665 |
defn.kind = 'img' |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
666 |
defn.src = getattr(frag,'src',None) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
667 |
defn.image = ImageReader(defn.src) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
668 |
size = defn.image.getSize() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
669 |
defn.width = getattr(frag,'width',size[0]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
670 |
defn.height = getattr(frag,'height',size[1]) |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
671 |
defn.valign = getattr(frag,'valign','bottom') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
672 |
del frag._selfClosingTag |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
673 |
self.handle_data('') |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
674 |
self._pop() |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
675 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
676 |
#### super script |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
677 |
def start_super( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
678 |
self._push(super=1) |
96 | 679 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
680 |
def end_super( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
681 |
self._pop(super=1) |
96 | 682 |
|
2376 | 683 |
start_sup = start_super |
684 |
end_sup = end_super |
|
1736 | 685 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
686 |
#### sub script |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
687 |
def start_sub( self, attributes ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
688 |
self._push(sub=1) |
96 | 689 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
690 |
def end_sub( self ): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
691 |
self._pop(sub=1) |
96 | 692 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
693 |
#### greek script |
2376 | 694 |
#### add symbol encoding |
695 |
def handle_charref(self, name): |
|
696 |
try: |
|
2575 | 697 |
if name[0]=='x': |
698 |
n = int(name[1:],16) |
|
1931
784fce255e2d
Added in more special entities as suggested by Christoph Zwerschke
rgbecker
parents:
1736
diff
changeset
|
699 |
else: |
2575 | 700 |
n = int(name) |
701 |
except ValueError: |
|
2376 | 702 |
self.unknown_charref(name) |
703 |
return |
|
2575 | 704 |
self.handle_data(unichr(n).encode('utf8')) |
134 | 705 |
|
2376 | 706 |
def handle_entityref(self,name): |
3326 | 707 |
if name in greeks: |
2376 | 708 |
self.handle_data(greeks[name]) |
709 |
else: |
|
710 |
xmllib.XMLParser.handle_entityref(self,name) |
|
134 | 711 |
|
2376 | 712 |
def syntax_error(self,lineno,message): |
713 |
self._syntax_error(message) |
|
134 | 714 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
715 |
def _syntax_error(self,message): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
716 |
if message[:10]=="attribute " and message[-17:]==" value not quoted": return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
717 |
self.errors.append(message) |
134 | 718 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
719 |
def start_greek(self, attr): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
720 |
self._push(greek=1) |
96 | 721 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
722 |
def end_greek(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
723 |
self._pop(greek=1) |
96 | 724 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
725 |
def start_unichar(self, attr): |
3326 | 726 |
if 'name' in attr: |
727 |
if 'code' in attr: |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
728 |
self._syntax_error('<unichar/> invalid with both name and code attributes') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
729 |
try: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
730 |
v = unicodedata.lookup(attr['name']).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
731 |
except KeyError: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
732 |
self._syntax_error('<unichar/> invalid name attribute\n"%s"' % name) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
733 |
v = '\0' |
3326 | 734 |
elif 'code' in attr: |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
735 |
try: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
736 |
v = unichr(int(eval(attr['code']))).encode('utf8') |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
737 |
except: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
738 |
self._syntax_error('<unichar/> invalid code attribute %s' % attr['code']) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
739 |
v = '\0' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
740 |
else: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
741 |
v = None |
2664 | 742 |
if attr: |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
743 |
self._syntax_error('<unichar/> invalid attribute %s' % attr.keys()[0]) |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
744 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
745 |
if v is not None: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
746 |
self.handle_data(v) |
2585 | 747 |
self._push(_selfClosingTag='unichar') |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
748 |
|
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
749 |
def end_unichar(self): |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
750 |
self._pop() |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
751 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
752 |
def start_font(self,attr): |
2575 | 753 |
self._push(**self.getAttributes(attr,_fontAttrMap)) |
96 | 754 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
755 |
def end_font(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
756 |
self._pop() |
96 | 757 |
|
2663 | 758 |
def start_br(self, attr): |
759 |
#just do the trick to make sure there is no content |
|
2664 | 760 |
self._push(_selfClosingTag='br',lineBreak=True,text='') |
2663 | 761 |
|
762 |
def end_br(self): |
|
2664 | 763 |
frag = self._stack[-1] |
764 |
assert frag._selfClosingTag=='br' and frag.lineBreak,'Parser failure in <br/>' |
|
765 |
del frag._selfClosingTag |
|
766 |
self.handle_data('') |
|
767 |
self._pop() |
|
2663 | 768 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
769 |
def _initial_frag(self,attr,attrMap,bullet=0): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
770 |
style = self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
771 |
if attr!={}: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
772 |
style = copy.deepcopy(style) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
773 |
_applyAttributes(style,self.getAttributes(attr,attrMap)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
774 |
self._style = style |
119 | 775 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
776 |
# initialize semantic values |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
777 |
frag = ParaFrag() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
778 |
frag.sub = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
779 |
frag.super = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
780 |
frag.rise = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
781 |
frag.underline = 0 |
2644 | 782 |
frag.strike = 0 |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
783 |
frag.greek = 0 |
2575 | 784 |
frag.link = None |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
785 |
if bullet: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
786 |
frag.fontName, frag.bold, frag.italic = ps2tt(style.bulletFontName) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
787 |
frag.fontSize = style.bulletFontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
788 |
frag.textColor = hasattr(style,'bulletColor') and style.bulletColor or style.textColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
789 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
790 |
frag.fontName, frag.bold, frag.italic = ps2tt(style.fontName) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
791 |
frag.fontSize = style.fontSize |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
792 |
frag.textColor = style.textColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
793 |
return frag |
250 | 794 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
795 |
def start_para(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
796 |
self._stack = [self._initial_frag(attr,_paraAttrMap)] |
119 | 797 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
798 |
def end_para(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
799 |
self._pop() |
119 | 800 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
801 |
def start_bullet(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
802 |
if hasattr(self,'bFragList'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
803 |
self._syntax_error('only one <bullet> tag allowed') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
804 |
self.bFragList = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
805 |
frag = self._initial_frag(attr,_bulletAttrMap,1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
806 |
frag.isBullet = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
807 |
self._stack.append(frag) |
250 | 808 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
809 |
def end_bullet(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
810 |
self._pop() |
250 | 811 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
812 |
#--------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
813 |
def start_seqdefault(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
814 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
815 |
default = attr['id'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
816 |
except KeyError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
817 |
default = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
818 |
self._seq.setDefaultCounter(default) |
266 | 819 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
820 |
def end_seqdefault(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
821 |
pass |
1683 | 822 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
823 |
def start_seqreset(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
824 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
825 |
id = attr['id'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
826 |
except KeyError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
827 |
id = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
828 |
try: |
2368 | 829 |
base = int(attr['base']) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
830 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
831 |
base=0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
832 |
self._seq.reset(id, base) |
266 | 833 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
834 |
def end_seqreset(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
835 |
pass |
744
2abd99baf95b
Accepts seqdefault/seqDefault and seqreset/seqReset
andy_robinson
parents:
677
diff
changeset
|
836 |
|
2368 | 837 |
def start_seqchain(self, attr): |
838 |
try: |
|
839 |
order = attr['order'] |
|
840 |
except KeyError: |
|
841 |
order = '' |
|
842 |
order = order.split() |
|
843 |
seq = self._seq |
|
844 |
for p,c in zip(order[:-1],order[1:]): |
|
845 |
seq.chain(p, c) |
|
846 |
end_seqchain = end_seqreset |
|
847 |
||
848 |
def start_seqformat(self, attr): |
|
849 |
try: |
|
850 |
id = attr['id'] |
|
851 |
except KeyError: |
|
852 |
id = None |
|
853 |
try: |
|
854 |
value = attr['value'] |
|
855 |
except KeyError: |
|
856 |
value = '1' |
|
857 |
self._seq.setFormat(id,value) |
|
858 |
end_seqformat = end_seqreset |
|
859 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
860 |
# AR hacking in aliases to allow the proper casing for RML. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
861 |
# the above ones should be deprecated over time. 2001-03-22 |
2368 | 862 |
start_seqDefault = start_seqdefault |
863 |
end_seqDefault = end_seqdefault |
|
864 |
start_seqReset = start_seqreset |
|
865 |
end_seqReset = end_seqreset |
|
866 |
start_seqChain = start_seqchain |
|
867 |
end_seqChain = end_seqchain |
|
868 |
start_seqFormat = start_seqformat |
|
869 |
end_seqFormat = end_seqformat |
|
1683 | 870 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
871 |
def start_seq(self, attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
872 |
#if it has a template, use that; otherwise try for id; |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
873 |
#otherwise take default sequence |
3326 | 874 |
if 'template' in attr: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
875 |
templ = attr['template'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
876 |
self.handle_data(templ % self._seq) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
877 |
return |
3326 | 878 |
elif 'id' in attr: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
879 |
id = attr['id'] |
1683 | 880 |
else: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
881 |
id = None |
2694
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
882 |
increment = attr.get('inc', None) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
883 |
if not increment: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
884 |
output = self._seq.nextf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
885 |
else: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
886 |
#accepts "no" for do not increment, or an integer. |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
887 |
#thus, 0 and 1 increment by the right amounts. |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
888 |
if increment.lower() == 'no': |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
889 |
output = self._seq.thisf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
890 |
else: |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
891 |
incr = int(increment) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
892 |
output = self._seq.thisf(id) |
dd0ea6474ea0
fixes to crashing PTO trailer when empty, and numbering
andy
parents:
2693
diff
changeset
|
893 |
self._seq.reset(id, self._seq._this() + incr) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
894 |
self.handle_data(output) |
1683 | 895 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
896 |
def end_seq(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
897 |
pass |
266 | 898 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
899 |
def start_onDraw(self,attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
900 |
defn = ABag() |
3326 | 901 |
if 'name' in attr: defn.name = attr['name'] |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
902 |
else: self._syntax_error('<onDraw> needs at least a name attribute') |
506 | 903 |
|
3326 | 904 |
if 'label' in attr: defn.label = attr['label'] |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
905 |
defn.kind='onDraw' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
906 |
self._push(cbDefn=defn) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
907 |
self.handle_data('') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
908 |
self._pop() |
3111
86a3158c50bd
reportlab: improved support for onDraw and SimpleIndex
rgbecker
parents:
3032
diff
changeset
|
909 |
end_onDraw=end_seq |
86a3158c50bd
reportlab: improved support for onDraw and SimpleIndex
rgbecker
parents:
3032
diff
changeset
|
910 |
|
3165 | 911 |
def start_index(self,attr): |
912 |
attr=self.getAttributes(attr,_indexAttrMap) |
|
913 |
defn = ABag() |
|
3326 | 914 |
if 'item' in attr: |
3187
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
915 |
label = attr['item'] |
3165 | 916 |
else: |
917 |
self._syntax_error('<index> needs at least an item attribute') |
|
3326 | 918 |
if 'name' in attr: |
3165 | 919 |
name = attr['name'] |
920 |
else: |
|
921 |
name = DEFAULT_INDEX_NAME |
|
3187
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
922 |
format = attr.get('format',None) |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
923 |
if format is not None and format not in ('123','I','i','ABC','abc'): |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
924 |
raise ValueError('index tag format is %r not valid 123 I i ABC or abc' % offset) |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
925 |
offset = attr.get('offset',None) |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
926 |
if offset is not None: |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
927 |
try: |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
928 |
offset = int(offset) |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
929 |
except: |
2d5a6655556e
tableofcontents/paraparser: allow for format and offset parameters
rgbecker
parents:
3165
diff
changeset
|
930 |
raise ValueError('index tag offset is %r not an int' % offset) |
3188
be6793854075
paraparser.py: fix broken code and wrong module name
rgbecker
parents:
3187
diff
changeset
|
931 |
defn.label = base64.encodestring(pickle.dumps((label,format,offset))).strip() |
3165 | 932 |
defn.name = name |
933 |
defn.kind='index' |
|
934 |
self._push(cbDefn=defn) |
|
935 |
self.handle_data('') |
|
936 |
self._pop() |
|
937 |
end_index=end_seq |
|
2663 | 938 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
939 |
#--------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
940 |
def _push(self,**attr): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
941 |
frag = copy.copy(self._stack[-1]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
942 |
_applyAttributes(frag,attr) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
943 |
self._stack.append(frag) |
96 | 944 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
945 |
def _pop(self,**kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
946 |
frag = self._stack[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
947 |
del self._stack[-1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
948 |
for k, v in kw.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
949 |
assert getattr(frag,k)==v |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
950 |
return frag |
96 | 951 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
952 |
def getAttributes(self,attr,attrMap): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
953 |
A = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
954 |
for k, v in attr.items(): |
1940 | 955 |
if not self.caseSensitive: |
956 |
k = string.lower(k) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
957 |
if k in attrMap.keys(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
958 |
j = attrMap[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
959 |
func = j[1] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
960 |
try: |
2575 | 961 |
A[j[0]] = (func is None) and v or func(v) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
962 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
963 |
self._syntax_error('%s: invalid value %s'%(k,v)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
964 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
965 |
self._syntax_error('invalid attribute name %s'%k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
966 |
return A |
119 | 967 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
968 |
#---------------------------------------------------------------- |
96 | 969 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
970 |
def __init__(self,verbose=0): |
1944 | 971 |
self.caseSensitive = 0 |
2376 | 972 |
xmllib.XMLParser.__init__(self,verbose=verbose) |
266 | 973 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
974 |
def _iReset(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
975 |
self.fragList = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
976 |
if hasattr(self, 'bFragList'): delattr(self,'bFragList') |
250 | 977 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
978 |
def _reset(self, style): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
979 |
'''reset the parser''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
980 |
xmllib.XMLParser.reset(self) |
96 | 981 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
982 |
# initialize list of string segments to empty |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
983 |
self.errors = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
984 |
self._style = style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
985 |
self._iReset() |
96 | 986 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
987 |
#---------------------------------------------------------------- |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
988 |
def handle_data(self,data): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
989 |
"Creates an intermediate representation of string segments." |
96 | 990 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
991 |
frag = copy.copy(self._stack[-1]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
992 |
if hasattr(frag,'cbDefn'): |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
993 |
kind = frag.cbDefn.kind |
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
994 |
if data: self._syntax_error('Only empty <%s> tag allowed' % kind) |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
995 |
elif hasattr(frag,'_selfClosingTag'): |
2663 | 996 |
if data!='': self._syntax_error('No content allowed in %s tag' % frag._selfClosingTag) |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
997 |
return |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
998 |
else: |
1736 | 999 |
# if sub and super are both on they will cancel each other out |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1000 |
if frag.sub == 1 and frag.super == 1: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1001 |
frag.sub = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1002 |
frag.super = 0 |
96 | 1003 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1004 |
if frag.sub: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1005 |
frag.rise = -frag.fontSize*subFraction |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1006 |
frag.fontSize = max(frag.fontSize-sizeDelta,3) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1007 |
elif frag.super: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1008 |
frag.rise = frag.fontSize*superFraction |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1009 |
frag.fontSize = max(frag.fontSize-sizeDelta,3) |
112 | 1010 |
|
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
1011 |
if frag.greek: |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
1012 |
frag.fontName = 'symbol' |
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
1013 |
data = _greekConvert(data) |
514
3784fe357a72
Slight optimisation in handle_data for cbdefn frags
rgbecker
parents:
508
diff
changeset
|
1014 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1015 |
# bold, italic, and underline |
2861 | 1016 |
frag.fontName = tt2ps(frag.fontName,frag.bold,frag.italic) |
96 | 1017 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1018 |
#save our data |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1019 |
frag.text = data |
514
3784fe357a72
Slight optimisation in handle_data for cbdefn frags
rgbecker
parents:
508
diff
changeset
|
1020 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1021 |
if hasattr(frag,'isBullet'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1022 |
delattr(frag,'isBullet') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1023 |
self.bFragList.append(frag) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1024 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1025 |
self.fragList.append(frag) |
96 | 1026 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1027 |
def handle_cdata(self,data): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1028 |
self.handle_data(data) |
211 | 1029 |
|
2376 | 1030 |
def _setup_for_parse(self,style): |
1031 |
self._seq = reportlab.lib.sequencer.getSequencer() |
|
1032 |
self._reset(style) # reinitialise the parser |
|
1033 |
||
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1034 |
def parse(self, text, style): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1035 |
"""Given a formatted string will return a list of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1036 |
ParaFrag objects with their calculated widths. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1037 |
If errors occur None will be returned and the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1038 |
self.errors holds a list of the error messages. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1039 |
""" |
2575 | 1040 |
# AR 20040612 - when we feed Unicode strings in, sgmlop |
1041 |
# tries to coerce to ASCII. Must intercept, coerce to |
|
1042 |
# any 8-bit encoding which defines most of 256 points, |
|
1043 |
# and revert at end. Yuk. Preliminary step prior to |
|
1044 |
# removal of parser altogether. |
|
2646
d177c247184a
platypus: eliminate StringType usages and cp1252 usage
rgbecker
parents:
2644
diff
changeset
|
1045 |
enc = self._enc = 'utf8' #our legacy default |
2575 | 1046 |
self._UNI = type(text) is UnicodeType |
1047 |
if self._UNI: |
|
1048 |
text = text.encode(enc) |
|
1049 |
||
2376 | 1050 |
self._setup_for_parse(style) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1051 |
# the xmlparser requires that all text be surrounded by xml |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1052 |
# tags, therefore we must throw some unused flags around the |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1053 |
# given string |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1054 |
if not(len(text)>=6 and text[0]=='<' and _re_para.match(text)): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1055 |
text = "<para>"+text+"</para>" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1056 |
self.feed(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1057 |
self.close() # force parsing to complete |
2376 | 1058 |
return self._complete_parse() |
1059 |
||
1060 |
def _complete_parse(self): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1061 |
del self._seq |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1062 |
style = self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1063 |
del self._style |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1064 |
if len(self.errors)==0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1065 |
fragList = self.fragList |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1066 |
bFragList = hasattr(self,'bFragList') and self.bFragList or None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1067 |
self._iReset() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1068 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1069 |
fragList = bFragList = None |
2575 | 1070 |
|
1071 |
if self._UNI: |
|
1072 |
#reconvert to unicode |
|
1073 |
if fragList: |
|
1074 |
for frag in fragList: |
|
1075 |
frag.text = unicode(frag.text, self._enc) |
|
1076 |
if bFragList: |
|
1077 |
for frag in bFragList: |
|
1078 |
frag.text = unicode(frag.text, self._enc) |
|
2664 | 1079 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1080 |
return style, fragList, bFragList |
96 | 1081 |
|
2376 | 1082 |
def _tt_parse(self,tt): |
1083 |
tag = tt[0] |
|
1084 |
try: |
|
1085 |
start = getattr(self,'start_'+tag) |
|
1086 |
end = getattr(self,'end_'+tag) |
|
1087 |
except AttributeError: |
|
1088 |
raise ValueError('Invalid tag "%s"' % tag) |
|
1089 |
start(tt[1] or {}) |
|
1090 |
C = tt[2] |
|
1091 |
if C: |
|
1092 |
M = self._tt_handlers |
|
1093 |
for c in C: |
|
1094 |
M[type(c) is TupleType](c) |
|
1095 |
end() |
|
1096 |
||
1097 |
def tt_parse(self,tt,style): |
|
1098 |
'''parse from tupletree form''' |
|
1099 |
self._setup_for_parse(style) |
|
1100 |
self._tt_handlers = self.handle_data,self._tt_parse |
|
1101 |
self._tt_parse(tt) |
|
1102 |
return self._complete_parse() |
|
1103 |
||
96 | 1104 |
if __name__=='__main__': |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1105 |
from reportlab.platypus import cleanBlockQuotedText |
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3326
diff
changeset
|
1106 |
from reportlab.lib.styles import _baseFontName |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1107 |
_parser=ParaParser() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1108 |
def check_text(text,p=_parser): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1109 |
print '##########' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1110 |
text = cleanBlockQuotedText(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1111 |
l,rv,bv = p.parse(text,style) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1112 |
if rv is None: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1113 |
for l in _parser.errors: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1114 |
print l |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1115 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1116 |
print 'ParaStyle', l.fontName,l.fontSize,l.textColor |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1117 |
for l in rv: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1118 |
print l.fontName,l.fontSize,l.textColor,l.bold, l.rise, '|%s|'%l.text[:25], |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1119 |
if hasattr(l,'cbDefn'): |
2857
487dc2450eec
reprotlab: inline images horizontal positioning OK
rgbecker
parents:
2836
diff
changeset
|
1120 |
print 'cbDefn',getattr(l.cbDefn,'name',''),getattr(l.cbDefn,'label',''),l.cbDefn.kind |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1121 |
else: print |
96 | 1122 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1123 |
style=ParaFrag() |
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3326
diff
changeset
|
1124 |
style.fontName=_baseFontName |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1125 |
style.fontSize = 12 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1126 |
style.textColor = black |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1127 |
style.bulletFontName = black |
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3326
diff
changeset
|
1128 |
style.bulletFontName=_baseFontName |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1129 |
style.bulletFontSize=12 |
96 | 1130 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1131 |
text=''' |
2584
0fed2bd8ef90
reportlab: fixed <greek> added <unichar [name=..|code=../> to paragraph
rgbecker
parents:
2575
diff
changeset
|
1132 |
<b><i><greek>a</greek>D</i></b>β<unichr value="0x394"/> |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1133 |
<font name="helvetica" size="15" color=green> |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1134 |
Tell me, O muse, of that ingenious hero who travelled far and wide |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1135 |
after</font> he had sacked the famous town of Troy. Many cities did he visit, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1136 |
and many were the nations with whose manners and customs he was acquainted; |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1137 |
moreover he suffered much by sea while trying to save his own life |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1138 |
and bring his men safely home; but do what he might he could not save |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1139 |
his men, for they perished through their own sheer folly in eating |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1140 |
the cattle of the Sun-god Hyperion; so the god prevented them from |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1141 |
ever reaching home. Tell me, too, about all these things, O daughter |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1142 |
of Jove, from whatsoever source you<super>1</super> may know them. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1143 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1144 |
check_text(text) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1145 |
check_text('<para> </para>') |
3368
afa025c34493
reportlab: new base font mechanism more fully applied
rgbecker
parents:
3326
diff
changeset
|
1146 |
check_text('<para font="%s" size=24 leading=28.8 spaceAfter=72>ReportLab -- Reporting for the Internet Age</para>'%_baseFontName) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1147 |
check_text(''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1148 |
<font color=red>τ</font>Tell me, O muse, of that ingenious hero who travelled far and wide |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1149 |
after he had sacked the famous town of Troy. Many cities did he visit, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1150 |
and many were the nations with whose manners and customs he was acquainted; |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1151 |
moreover he suffered much by sea while trying to save his own life |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1152 |
and bring his men safely home; but do what he might he could not save |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1153 |
his men, for they perished through their own sheer folly in eating |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1154 |
the cattle of the Sun-god Hyperion; so the god prevented them from |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1155 |
ever reaching home. Tell me, too, about all these things, O daughter |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1156 |
of Jove, from whatsoever source you may know them.''') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1157 |
check_text(''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1158 |
Telemachus took this speech as of good omen and rose at once, for |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1159 |
he was bursting with what he had to say. He stood in the middle of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1160 |
the assembly and the good herald Pisenor brought him his staff. Then, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1161 |
turning to Aegyptius, "Sir," said he, "it is I, as you will shortly |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1162 |
learn, who have convened you, for it is I who am the most aggrieved. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1163 |
I have not got wind of any host approaching about which I would warn |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1164 |
you, nor is there any matter of public moment on which I would speak. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1165 |
My grieveance is purely personal, and turns on two great misfortunes |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1166 |
which have fallen upon my house. The first of these is the loss of |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1167 |
my excellent father, who was chief among all you here present, and |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1168 |
was like a father to every one of you; the second is much more serious, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1169 |
and ere long will be the utter ruin of my estate. The sons of all |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1170 |
the chief men among you are pestering my mother to marry them against |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1171 |
her will. They are afraid to go to her father Icarius, asking him |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1172 |
to choose the one he likes best, and to provide marriage gifts for |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1173 |
his daughter, but day by day they keep hanging about my father's house, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1174 |
sacrificing our oxen, sheep, and fat goats for their banquets, and |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1175 |
never giving so much as a thought to the quantity of wine they drink. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1176 |
No estate can stand such recklessness; we have now no Ulysses to ward |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1177 |
off harm from our doors, and I cannot hold my own against them. I |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1178 |
shall never all my days be as good a man as he was, still I would |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1179 |
indeed defend myself if I had power to do so, for I cannot stand such |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1180 |
treatment any longer; my house is being disgraced and ruined. Have |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1181 |
respect, therefore, to your own consciences and to public opinion. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1182 |
Fear, too, the wrath of heaven, lest the gods should be displeased |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1183 |
and turn upon you. I pray you by Jove and Themis, who is the beginning |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1184 |
and the end of councils, [do not] hold back, my friends, and leave |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1185 |
me singlehanded- unless it be that my brave father Ulysses did some |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1186 |
wrong to the Achaeans which you would now avenge on me, by aiding |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1187 |
and abetting these suitors. Moreover, if I am to be eaten out of house |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1188 |
and home at all, I had rather you did the eating yourselves, for I |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1189 |
could then take action against you to some purpose, and serve you |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1190 |
with notices from house to house till I got paid in full, whereas |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1191 |
now I have no remedy."''') |
133 | 1192 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1160
diff
changeset
|
1193 |
check_text(''' |
133 | 1194 |
But as the sun was rising from the fair sea into the firmament of |
1195 |
heaven to shed light on mortals and immortals, they reached Pylos |
|
1196 |
the city of Neleus. Now the people of Pylos were gathered on the sea |
|
1197 |
shore to offer sacrifice of black bulls to Neptune lord of the Earthquake. |
|
1198 |
There were nine guilds with five hundred men in each, and there were |
|
1199 |
nine bulls to each guild. As they were eating the inward meats and |
|
1200 |
burning the thigh bones [on the embers] in the name of Neptune, Telemachus |
|