author | andy_robinson |
Mon, 08 Sep 2003 14:16:38 +0000 | |
changeset 2044 | 3be472f4a6dd |
parent 2007 | 2759dd179707 |
child 2045 | cc042609c62e |
permissions | -rw-r--r-- |
494 | 1 |
#copyright ReportLab Inc. 2000 |
2 |
#see license.txt for license details |
|
3 |
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/lib/utils.py?cvsroot=reportlab |
|
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
4 |
#$Header: /tmp/reportlab/reportlab/lib/utils.py,v 1.45 2003/09/08 14:16:37 andy_robinson Exp $ |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
5 |
__version__=''' $Id: utils.py,v 1.45 2003/09/08 14:16:37 andy_robinson Exp $ ''' |
562 | 6 |
|
1375 | 7 |
import string, os, sys |
413 | 8 |
from types import * |
674 | 9 |
from reportlab.lib.logger import warnOnce |
413 | 10 |
SeqTypes = (ListType,TupleType) |
562 | 11 |
|
1837
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
12 |
|
1902 | 13 |
if os.name == 'mac': |
14 |
#with the Mac, we need to tag the file in a special |
|
15 |
#way so the system knows it is a PDF file. |
|
16 |
#This supplied by Joe Strout |
|
2007 | 17 |
_KNOWN_MAC_EXT = { |
18 |
'BMP' : ('ogle','BMP '), |
|
19 |
'EPS' : ('ogle','EPSF'), |
|
20 |
'EPSF': ('ogle','EPSF'), |
|
21 |
'GIF' : ('ogle','GIFf'), |
|
22 |
'JPG' : ('ogle','JPEG'), |
|
23 |
'JPEG': ('ogle','JPEG'), |
|
24 |
'PCT' : ('ttxt','PICT'), |
|
25 |
'PICT': ('ttxt','PICT'), |
|
26 |
'PNG' : ('ogle','PNGf'), |
|
27 |
'PPM' : ('ogle','.PPM'), |
|
28 |
'TIF' : ('ogle','TIFF'), |
|
29 |
'TIFF': ('ogle','TIFF'), |
|
30 |
'PDF': ('CARO','PDF '), |
|
31 |
} |
|
32 |
def markfilename(filename,creatorcode=None,filetype=None,ext='PDF'): |
|
1902 | 33 |
try: |
2007 | 34 |
if creatorcode is None or filetype is None and ext is not None: |
35 |
try: |
|
36 |
creatorcode, filetype = _KNOWN_MAC_EXT[ext] |
|
37 |
except: |
|
38 |
return |
|
1902 | 39 |
macfs.FSSpec(filename).SetCreatorType(creatorcode,filetype) |
40 |
except: |
|
41 |
pass |
|
42 |
else: |
|
43 |
def markfilename(filename,creatorcode=None,filetype=None): |
|
44 |
pass |
|
45 |
||
1837
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
46 |
def isFileSystemDistro(): |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
47 |
"""Attempt to detect if this copy of reportlab is running in a |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
48 |
file system (as opposed to mostly running in a zip or McMillan |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
49 |
archive or Jar file). This is used by test cases, so that |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
50 |
we can write test cases that don't get activated in a compiled |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
51 |
distribution.""" |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
52 |
# is this safe enough? |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
53 |
import reportlab.pdfgen.canvas |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
54 |
hypothetical_location = reportlab.pdfgen.canvas |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
55 |
return os.path.isfile(hypothetical_location) |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
56 |
|
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
57 |
def isCompactDistro(): |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
58 |
return not isFileSystemDistro() |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
59 |
|
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
60 |
def isSourceDistro(): |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
61 |
import reportlab.pdfgen.canvas |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
62 |
hypothetical_location = reportlab.pdfgen.canvas |
a3920893b1b8
Back in synch, diagnostic function for distro type added
andy_robinson
parents:
1835
diff
changeset
|
63 |
|
1143 | 64 |
def _checkImportError(errMsg): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
65 |
if string.lower(string.strip(str(errMsg)[0:16]))!='no module named': raise |
1143 | 66 |
|
413 | 67 |
try: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
68 |
#raise ImportError |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
69 |
### NOTE! FP_STR SHOULD PROBABLY ALWAYS DO A PYTHON STR() CONVERSION ON ARGS |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
70 |
### IN CASE THEY ARE "LAZY OBJECTS". ACCELLERATOR DOESN'T DO THIS (YET) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
71 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
72 |
from _rl_accel import fp_str # in case of builtin version |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
73 |
except ImportError, errMsg: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
74 |
_checkImportError(errMsg) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
75 |
from reportlab.lib._rl_accel import fp_str # specific |
674 | 76 |
except ImportError, errMsg: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
77 |
#_checkImportError(errMsg) # this effectively requires _rl_accel... should not be required |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
78 |
def fp_str(*a): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
79 |
if len(a)==1 and type(a[0]) in SeqTypes: a = a[0] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
80 |
s = [] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
81 |
for i in a: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
82 |
s.append('%0.6f' % i) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
83 |
return string.join(s) |
448 | 84 |
|
981 | 85 |
#hack test for comma users |
86 |
if ',' in fp_str(0.25): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
87 |
_FP_STR = fp_str |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
88 |
def fp_str(*a): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
89 |
return string.replace(apply(_FP_STR,a),',','.') |
981 | 90 |
|
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
91 |
def recursiveImport(modulename, baseDir=None, noCWD=0, debug=0): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
92 |
"""Dynamically imports possible packagized module, or raises ImportError""" |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
93 |
import imp |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
94 |
parts = string.split(modulename, '.') |
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
95 |
name = parts[0] |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
96 |
|
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
97 |
if baseDir is None: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
98 |
path = sys.path[:] |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
99 |
else: |
1834 | 100 |
if type(baseDir) not in SeqTypes: |
1833
135322abc191
Fix recursivImport for case when baseDir is a sequence
rgbecker
parents:
1821
diff
changeset
|
101 |
path = [baseDir] |
135322abc191
Fix recursivImport for case when baseDir is a sequence
rgbecker
parents:
1821
diff
changeset
|
102 |
else: |
135322abc191
Fix recursivImport for case when baseDir is a sequence
rgbecker
parents:
1821
diff
changeset
|
103 |
path = list(baseDir) |
1835 | 104 |
path = filter(None,path) |
1396
40d1361f08b7
Enhanced the error message from recursiveImport
andy_robinson
parents:
1389
diff
changeset
|
105 |
|
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
106 |
if noCWD: |
1999 | 107 |
while '.' in path: |
108 |
if debug: print 'removed . from path' |
|
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
109 |
path.remove('.') |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
110 |
abspath = os.path.abspath('.') |
1999 | 111 |
while abspath in path: |
112 |
if debug: print 'removed "%s" from path' % abspath |
|
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
113 |
path.remove(abspath) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
114 |
else: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
115 |
if '.' not in path: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
116 |
path.insert(0,'.') |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
117 |
|
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
118 |
if debug: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
119 |
import pprint |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
120 |
pp = pprint.pprint |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
121 |
print 'path=',pp(path) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
122 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
123 |
#make import errors a bit more informative |
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
124 |
fullName = name |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
125 |
try: |
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
126 |
(file, pathname, description) = imp.find_module(name, path) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
127 |
childModule = parentModule = imp.load_module(name, file, pathname, description) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
128 |
if debug: print 'imported module = %s' % parentModule |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
129 |
for name in parts[1:]: |
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
130 |
fullName = fullName + '.' + name |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
131 |
if debug: print 'trying part %s' % name |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
132 |
(file, pathname, description) = imp.find_module(name, [os.path.dirname(parentModule.__file__)]) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
133 |
childModule = imp.load_module(fullName, file, pathname, description) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
134 |
if debug: print 'imported module = %s' % childModule |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
135 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
136 |
setattr(parentModule, name, childModule) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
137 |
parentModule = childModule |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
138 |
except ImportError: |
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
139 |
msg = "cannot import '%s' while attempting recursive import of '%s'" % (fullName, modulename) |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
140 |
if baseDir: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
141 |
msg = msg + " under paths '%s'" % `path` |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
142 |
raise ImportError, msg |
1396
40d1361f08b7
Enhanced the error message from recursiveImport
andy_robinson
parents:
1389
diff
changeset
|
143 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
144 |
return childModule |
1389
6e5ba87ce34e
added function recursiveImport('package1.package2.module') in r/lib/utils
andy_robinson
parents:
1387
diff
changeset
|
145 |
|
1821
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
146 |
|
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
147 |
def recursiveGetAttr(obj, name): |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
148 |
"Can call down into e.g. object1.object2[4].attr" |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
149 |
return eval(name, obj.__dict__) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
150 |
|
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
151 |
def recursiveSetAttr(obj, name, value): |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
152 |
"Can call down into e.g. object1.object2[4].attr = value" |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
153 |
#get the thing above last. |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
154 |
tokens = string.split(name, '.') |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
155 |
#print 'name=%s, tokens=%s' % (name, tokens) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
156 |
if len(tokens) == 1: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
157 |
setattr(obj, name, value) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
158 |
else: |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
159 |
most = string.join(tokens[:-1], '.') |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
160 |
last = tokens[-1] |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
161 |
#print 'most=%s, last=%s' % (most, last) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
162 |
parent = recursiveGetAttr(obj, most) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
163 |
#print 'parent=%s' % parent |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
164 |
setattr(parent, last, value) |
7854ddd0fc30
Fixed recursive import, setting and gettign attributes
andy_robinson
parents:
1683
diff
changeset
|
165 |
|
674 | 166 |
def import_zlib(): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
167 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
168 |
import zlib |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
169 |
except ImportError, errMsg: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
170 |
_checkImportError(errMsg) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
171 |
zlib = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
172 |
from reportlab.rl_config import ZLIB_WARNINGS |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
173 |
if ZLIB_WARNINGS: warnOnce('zlib not available') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
174 |
return zlib |
674 | 175 |
|
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
176 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
177 |
# Image Capability Detection. Set a flag canHandleImages |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
178 |
# to tell us if either PIL or Java imaging libraries present. |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
179 |
# define PIL_Image as either None, or an alias for the PIL.Image |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
180 |
# module, as there are 2 ways to import it |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
181 |
|
760 | 182 |
try: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
183 |
from PIL import Image |
760 | 184 |
except ImportError, errMsg: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
185 |
_checkImportError(errMsg) |
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
186 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
187 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
188 |
import Image |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
189 |
except ImportError, errMsg: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
190 |
_checkImportError(errMsg) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
191 |
Image = None |
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
192 |
|
760 | 193 |
PIL_Image = Image |
194 |
del Image |
|
674 | 195 |
|
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
196 |
# overall flag for can handle images |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
197 |
if PIL_Image: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
198 |
canHandleImages = 1 |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
199 |
else: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
200 |
#java? |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
201 |
try: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
202 |
import javax.imageio |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
203 |
import java.awt.image |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
204 |
canHandleImages = 1 |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
205 |
except: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
206 |
canHandleImages = 0 |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
207 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
208 |
if not canHandleImages: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
209 |
warnOnce('Python or Java Imaging Libraries not available, unable to import bitmaps') |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
210 |
|
1586
d600d8ffaa21
This seems adequate if we avoid Dinuisms like writing to initialised StringIOs
rgbecker
parents:
1584
diff
changeset
|
211 |
__StringIO=None |
1580 | 212 |
def getStringIO(buf=None): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
213 |
'''unified StringIO instance interface''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
214 |
global __StringIO |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
215 |
if not __StringIO: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
216 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
217 |
from cStringIO import StringIO |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
218 |
except ImportError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
219 |
from StringIO import StringIO |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
220 |
__StringIO = StringIO |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
221 |
return buf is not None and __StringIO(buf) or __StringIO() |
1580 | 222 |
|
1375 | 223 |
class ArgvDictValue: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
224 |
'''A type to allow clients of getArgvDict to specify a conversion function''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
225 |
def __init__(self,value,func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
226 |
self.value = value |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
227 |
self.func = func |
1375 | 228 |
|
229 |
def getArgvDict(**kw): |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
230 |
''' Builds a dictionary from its keyword arguments with overrides from sys.argv. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
231 |
Attempts to be smart about conversions, but the value can be an instance |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
232 |
of ArgDictValue to allow specifying a conversion function. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
233 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
234 |
def handleValue(v,av,func): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
235 |
if func: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
236 |
v = func(av) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
237 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
238 |
t = type(v) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
239 |
if t is StringType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
240 |
v = av |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
241 |
elif t is FloatType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
242 |
v = float(av) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
243 |
elif t is IntType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
244 |
v = int(av) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
245 |
elif t is ListType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
246 |
v = list(eval(av)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
247 |
elif t is TupleType: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
248 |
v = tuple(eval(av)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
249 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
250 |
raise TypeError, "Can't convert string '%s' to %s" % (av,str(t)) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
251 |
return v |
1387 | 252 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
253 |
A = sys.argv[1:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
254 |
R = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
255 |
for k, v in kw.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
256 |
if isinstance(v,ArgvDictValue): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
257 |
v, func = v.value, v.func |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
258 |
else: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
259 |
func = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
260 |
handled = 0 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
261 |
ke = k+'=' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
262 |
for a in A: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
263 |
if string.find(a,ke)==0: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
264 |
av = a[len(ke):] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
265 |
A.remove(a) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
266 |
R[k] = handleValue(v,av,func) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
267 |
handled = 1 |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
268 |
break |
1387 | 269 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
270 |
if not handled: R[k] = handleValue(v,v,func) |
1387 | 271 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
272 |
return R |
1375 | 273 |
|
452 | 274 |
def getHyphenater(hDict=None): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
275 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
276 |
from reportlab.lib.pyHnj import Hyphen |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
277 |
if hDict is None: hDict=os.path.join(os.path.dirname(__file__),'hyphen.mashed') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
278 |
return Hyphen(hDict) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
279 |
except ImportError, errMsg: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
280 |
if str(errMsg)!='No module named pyHnj': raise |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
281 |
return None |
452 | 282 |
|
448 | 283 |
def _className(self): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
284 |
'''Return a shortened class name''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
285 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
286 |
name = self.__class__.__name__ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
287 |
i=string.rfind(name,'.') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
288 |
if i>=0: return name[i+1:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
289 |
return name |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
290 |
except AttributeError: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
291 |
return str(self) |
1538 | 292 |
|
1575 | 293 |
def open_for_read(name,mode='b'): |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
294 |
'''attempt to open a file or URL for reading''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
295 |
import urllib |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
296 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
297 |
t, o = urllib.splittype(name) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
298 |
if not t or t=='file': raise ValueError |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
299 |
o = urllib.urlopen(name) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
300 |
return getStringIO(o.read()) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
301 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
302 |
return open(name,'r'+mode) |
1575 | 303 |
|
2044
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
304 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
305 |
class ImageReader: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
306 |
"Wraps up either PIL or Java to get data from bitmaps" |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
307 |
def __init__(self, fileName): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
308 |
#start wih lots of null private fields, to be populated by |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
309 |
#the relevant engine. |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
310 |
self.fileName = fileName |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
311 |
self._image = None |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
312 |
self._width = None |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
313 |
self._height = None |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
314 |
self._transparent = None |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
315 |
self._data = None |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
316 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
317 |
#detect which library we are using and open the image |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
318 |
if sys.platform[0:4] == 'java': |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
319 |
from javax.imageio import ImageIO |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
320 |
from java.io import File |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
321 |
self._image = ImageIO.read(File(fileName)) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
322 |
else: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
323 |
import PIL.Image |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
324 |
self._image = PIL.Image.open(fileName) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
325 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
326 |
def getSize(self): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
327 |
if (self._width is None or self._height is None): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
328 |
if sys.platform[0:4] == 'java': |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
329 |
self._width = self._image.getWidth() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
330 |
self._height = self._image.getHeight() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
331 |
else: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
332 |
self._width, self._height = self._image.size |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
333 |
return (self._width, self._height) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
334 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
335 |
def getRgbData(self): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
336 |
"Return byte array of RGB data as string" |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
337 |
if self._data is None: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
338 |
if sys.platform[0:4] == 'java': |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
339 |
import jarray |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
340 |
from java.awt.image import PixelGrabber |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
341 |
width, height = self.getSize() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
342 |
buffer = jarray.zeros(width*height, 'i') |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
343 |
pg = PixelGrabber(self._image, 0,0,width,height,buffer,0,width) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
344 |
pg.grabPixels() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
345 |
# there must be a way to do this with a cast not a byte-level loop, |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
346 |
# I just haven't found it yet... |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
347 |
pixels = [] |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
348 |
for i in range(len(buffer)): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
349 |
rgb = buffer[i] |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
350 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
351 |
rg, b = divmod(rgb, 256) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
352 |
r, g = divmod(rg, 256) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
353 |
pix = chr(r % 256) + chr(g % 256) + chr(b % 256) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
354 |
pixels.append(pix) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
355 |
self._data = ''.join(pixels) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
356 |
else: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
357 |
rgb = self._image.convert('RGB') |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
358 |
self._data = rgb.tostring() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
359 |
return self._data |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
360 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
361 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
362 |
def getImageData(imageFileName): |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
363 |
"Get width, height and RGB pixels from image file. Wraps Java/PIL" |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
364 |
if sys.platform[0:4] == 'java': |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
365 |
from java.awt.image import BufferedImage, PixelGrabber |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
366 |
from javax.imageio import ImageIO |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
367 |
from java.io import File |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
368 |
#pixels = buffer.tostring() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
369 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
370 |
else: |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
371 |
import PIL.Image |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
372 |
img = PIL.Image.open(imageFileName) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
373 |
width, height = img.size |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
374 |
rgb = img.convert('RGB') |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
375 |
data = rgb.tostring() |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
376 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
377 |
return (width, height, data) |
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
378 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
379 |
|
3be472f4a6dd
Various work on abstracting out images, plus outstanding patches
andy_robinson
parents:
2007
diff
changeset
|
380 |
|
1538 | 381 |
class DebugMemo: |
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
382 |
'''Intended as a simple report back encapsulator |
1545 | 383 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
384 |
Typical usages |
1683 | 385 |
1) To record error data |
386 |
dbg = DebugMemo(fn='dbgmemo.dbg',myVar=value) |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
387 |
dbg.add(anotherPayload='aaaa',andagain='bbb') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
388 |
dbg.dump() |
1543
3681c7d8898d
Slight formatting improvements & added payload method
rgbecker
parents:
1538
diff
changeset
|
389 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
390 |
2) To show the recorded info |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
391 |
dbg = DebugMemo(fn='dbgmemo.dbg',mode='r') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
392 |
dbg.load() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
393 |
dbg.show() |
1543
3681c7d8898d
Slight formatting improvements & added payload method
rgbecker
parents:
1538
diff
changeset
|
394 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
395 |
3) To re-use recorded information |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
396 |
dbg = DebugMemo(fn='dbgmemo.dbg',mode='r') |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
397 |
dbg.load() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
398 |
myTestFunc(dbg.payload('myVar'),dbg.payload('andagain')) |
1545 | 399 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
400 |
in addition to the payload variables the dump records many useful bits |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
401 |
of information which are also printed in the show() method. |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
402 |
''' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
403 |
def __init__(self,fn='rl_dbgmemo.dbg',mode='w',getScript=1,modules=(),**kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
404 |
import time, socket |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
405 |
self.fn = fn |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
406 |
if mode!='w': return |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
407 |
self.store = store = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
408 |
if sys.exc_info() != (None,None,None): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
409 |
import traceback |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
410 |
s = getStringIO() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
411 |
traceback.print_exc(None,s) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
412 |
store['__traceback'] = s.getvalue() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
413 |
cwd=os.getcwd() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
414 |
lcwd = os.listdir(cwd) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
415 |
exed = os.path.abspath(os.path.dirname(sys.argv[0])) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
416 |
store.update({ 'gmt': time.asctime(time.gmtime(time.time())), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
417 |
'platform': sys.platform, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
418 |
'version': sys.version, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
419 |
'executable': sys.executable, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
420 |
'prefix': sys.prefix, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
421 |
'path': sys.path, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
422 |
'argv': sys.argv, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
423 |
'cwd': cwd, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
424 |
'hostname': socket.gethostname(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
425 |
'lcwd': lcwd, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
426 |
}) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
427 |
if exed!=cwd: store.update({'exed': exed, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
428 |
'lexed': os.listdir(exed), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
429 |
}) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
430 |
if hasattr(os,'uname'): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
431 |
store.update({ |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
432 |
'uname': os.uname(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
433 |
'ctermid': os.ctermid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
434 |
'getgid': os.getgid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
435 |
'getuid': os.getuid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
436 |
'getegid': os.getegid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
437 |
'geteuid': os.geteuid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
438 |
'getlogin': os.getlogin(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
439 |
'getgroups': os.getgroups(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
440 |
'getpgrp': os.getpgrp(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
441 |
'getpid': os.getpid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
442 |
'getppid': os.getppid(), |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
443 |
}) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
444 |
if getScript: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
445 |
fn = os.path.abspath(sys.argv[0]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
446 |
if os.path.isfile(fn): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
447 |
store['__script'] = open(fn,'r').read() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
448 |
module_versions = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
449 |
for n,m in sys.modules.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
450 |
if n=='reportlab' or n=='rlextra' or n[:10]=='reportlab.' or n[:8]=='rlextra.': |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
451 |
v = getattr(m,'__version__',None) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
452 |
if v: module_versions[n] = v |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
453 |
store['__module_versions'] = module_versions |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
454 |
self.store['__payload'] = {} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
455 |
self._add(kw) |
1538 | 456 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
457 |
def _add(self,D): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
458 |
payload = self.store['__payload'] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
459 |
for k, v in D.items(): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
460 |
payload[k] = v |
1538 | 461 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
462 |
def add(self,**kw): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
463 |
self._add(kw) |
1538 | 464 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
465 |
def dump(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
466 |
import pickle |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
467 |
pickle.dump(self.store,open(self.fn,'wb')) |
1538 | 468 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
469 |
def load(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
470 |
import pickle |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
471 |
self.store = pickle.load(open(self.fn,'rb')) |
1538 | 472 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
473 |
def _show_module_versions(self,k,v): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
474 |
print k[2:] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
475 |
K = v.keys() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
476 |
K.sort() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
477 |
for k in K: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
478 |
vk = v[k] |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
479 |
try: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
480 |
m = recursiveImport(k,sys.path[:],1) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
481 |
d = getattr(m,'__version__',None)==vk and 'SAME' or 'DIFFERENT' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
482 |
except: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
483 |
m = None |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
484 |
d = '??????unknown??????' |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
485 |
print ' %s = %s (%s)' % (k,vk,d) |
1538 | 486 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
487 |
def _banner(self,k,what): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
488 |
print '###################%s %s##################' % (what,k[2:]) |
1538 | 489 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
490 |
def _start(self,k): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
491 |
self._banner(k,'Start ') |
1538 | 492 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
493 |
def _finish(self,k): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
494 |
self._banner(k,'Finish ') |
1538 | 495 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
496 |
def _show_lines(self,k,v): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
497 |
self._start(k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
498 |
print v |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
499 |
self._finish(k) |
1538 | 500 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
501 |
def _show_payload(self,k,v): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
502 |
if v: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
503 |
import pprint |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
504 |
self._start(k) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
505 |
pprint.pprint(v) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
506 |
self._finish(k) |
1538 | 507 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
508 |
specials = {'__module_versions': _show_module_versions, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
509 |
'__payload': _show_payload, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
510 |
'__traceback': _show_lines, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
511 |
'__script': _show_lines, |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
512 |
} |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
513 |
def show(self): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
514 |
K = self.store.keys() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
515 |
K.sort() |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
516 |
for k in K: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
517 |
if k not in self.specials.keys(): print '%-15s = %s' % (k,self.store[k]) |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
518 |
for k in K: |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
519 |
if k in self.specials.keys(): apply(self.specials[k],(self,k,self.store[k])) |
1543
3681c7d8898d
Slight formatting improvements & added payload method
rgbecker
parents:
1538
diff
changeset
|
520 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
521 |
def payload(self,name): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
522 |
return self.store['__payload'][name] |
1561 | 523 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
524 |
def __setitem__(self,name,value): |
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
525 |
self.store['__payload'][name] = value |
1561 | 526 |
|
1677
1450177dd19e
Exterminated all tab characters and added a test to make sure
andy_robinson
parents:
1650
diff
changeset
|
527 |
def __getitem__(self,name): |
1833
135322abc191
Fix recursivImport for case when baseDir is a sequence
rgbecker
parents:
1821
diff
changeset
|
528 |
return self.store['__payload'][name] |