[reportlab-users] drive name in the Image relative path in z3c.rml

Yuan HOng hongyuan1306 at gmail.com
Tue Jun 12 21:38:44 EDT 2007


Hello,

In the z3c.rml, one can use [module]path to specify a relative image
path to a module path. However, under Windows, sometimes the
module.__file__ returned by python is an absolute path containing the
drive name, like z://path_name. zope.schema.Text.open seems to treat
it as an url and try to open it, causing the following error:

File "c:\python25\lib\site-packages\reportlab\platypus\doctemplate.py",
line 421, in handle_pageBegin
self.pageTemplate.onPage(self.canv,self)
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\template.py",
line 146, in drawOnCanvas
drawing.process()
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\directive.py",
line 108, in process
self.processSubDirectives()
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\directive.py",
line 101, in processSubDirectives
directive.process()
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\canvas.py",
line 304, in process
kwargs = dict(self.getAttributeValues(attrMapping=self.attrMapping))
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\directive.py",
line 58, in getAttributeValues
value = attr.bind(self).get()
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\attr.py",
line 101, in get
return self.fromUnicode(value)
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\attr.py",
line 306, in fromUnicode
fileObj = super(Image, self).fromUnicode(value)
File "c:\python25\lib\site-packages\z3c.rml-0.5_r74231-py2.5.egg\z3c\rml\attr.py",
line 290, in fromUnicode
fileObj = self.open(value)
File "c:\python25\lib\urllib.py", line 82, in urlopen
return opener.open(url)
File "c:\python25\lib\urllib.py", line 187, in open
return self.open_unknown(fullurl, data)
File "c:\python25\lib\urllib.py", line 199, in open_unknown
raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: 'z'

I have made the following patch in attempt to fix this:

Index: attr.py
===================================================================
--- attr.py (revision 76646)
+++ attr.py (working copy)
@@ -282,6 +282,8 @@
modulepath, path = result.groups()
module = __import__(modulepath, {}, {}, (modulepath))
value = os.path.join(os.path.dirname(module.__file__), path)
+ if os.path.splitdrive(value)[0]:
+ value = 'file:///' + value
if self.doNotOpen:
return value
# Open/Download the file


--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn


More information about the reportlab-users mailing list