[reportlab-users] open_for_read and Window file paths

Eric Johnson reportlab-users@reportlab.com
Thu, 3 Jun 2004 07:12:22 +0200 (MEST)


In the 2nd June CVS release there seems to be a bug in the
open_for_read utility in lib/utils.py

The code parses a potential filename using urlparse.
If the "scheme" field is non-empty then it attempts
to open filename using urlopen.
Any exceptions are trapped and then the "path" field
is opened using open_for_read_by_name method.

Unfortunately, this fails with Windows type paths since the drive
name is interpreted as a scheme and then the urlopen raises an
exception because it does not recognise the url type.
This would be ok except the open_for_read_by_name is given the path
field without the drive!

I ran into this problem when trying to use the Comic TTF font in
C:/WIN98/Fonts.
urlopen doesn't like 'c' as a url type
and then the code tries to open "\\Win98\\fonts\\comic.ttf" which
fails because my current drive was d: not c:

To fix this it would seem best to compare the "scheme" against a list
of values rather than just assuming a non-empty value is valid.

Hope this all makes sense.

Eric

-- 
+++ Jetzt WLAN-Router für alle DSL-Einsteiger und Wechsler +++
GMX DSL-Powertarife zudem 3 Monate gratis* http://www.gmx.net/dsl