[reportlab-users] open_for_read and Window file paths

Robin Becker reportlab-users@reportlab.com
Thu, 03 Jun 2004 08:59:56 +0100


Eric Johnson wrote:
> 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
> 

too much sense. This is a running sore. Theoretically we should be only 
be using file: for local files, but that's probably too much of a pain 
for most people.

When urlopen fails we should certainly fall back to using the full name.
Can anyone think of a reliable rule for legal schemes that we should allow?
-- 
Robin Becker