Strange "feature" involving double slashes in Win98

Carlos Ribeiro carribeiro at gmail.com
Tue Sep 14 22:03:42 CEST 2004


Hello all.

I'm sending this to the list because I would like to know if someone
else has ever stumbled across this one, and also because one possible
solution is to patch, or simply "decorate", some of the Python
libraries functions (a few of the os and os.path calls). Note: if
you're going to reply, please read it *all* before doing so -- I've
already explored this problem quite a bit, and found no obvious
solution to it yet.

** The problem **

I am evaluating DrPython, one of the many IDEs available now. I had a
problem with it that I was able to track down to the particular way
the pathnames use by the program are constructed. To make a long story
short, Windows 98 doesn't like pathnames in the following format:

slashes: "c://somedir"  
backslashes: r"c:\\somedir"

(it doesn't matter if the string is provided with forward or back
slashes. If the double slash is located immediately after the drive
letter+comma, then it bombs. The result can be a weird immediate
error, but in some cases one has to expect for a long timeout. Double
slashes of any sort are permitted in the middle of the pathname,
though)

The problem seems to have an obvious explanation. As probably everyone
knows, Windows uses a double slash notation for the machine name in
SMB shares. But wait -- the pathname includes a drive letter, so it
must not be a SMB share name! Or could it be? I never had seen before
a share named like this:

c:\\machinename\somedir

I really don't know if the pathname above is valid in SMB or not. But
I have good reason to believe that it should be invalid, as it makes
no sense (because of the drive letter, of course). Knowing that, the
problem can be reproduced in the DOS prompt quite easily:

a) cd c:\\windows  --> fails with an "invalid folder" message
b) cd c:\\[my_workstation_name]  --> abort, retry or ignore

Example (b) failed that way because I have disabled file serving in my
PC. But it's strange to note that it handled it differently just
because I used my own workstation name. I also don't know if this that
way problem affects other versions of Windows besides Win98SE. If you
try it, please let me know.

** Solving the problem **

DrPython relies on string concatenation to build new pathnames. My
root dir is "c:/", and at some places in the code, other pieces are
concatenated to it, causing the problem. In Unix it doesn't happen --
double slashes are fine anywhere. Knowing that, there are three
possible solutions for the problem:

1) Never write pathnames starting with double slashes. 

It should be easy... but remember, I'm dealing with third party code
here. It will take some time for me to find out and correct all the
places where os functions are called with a pathname. I have tried to
do it, in fact, but still DrPython freezes from time to time due to
this problem as I find yet another place where a pathname is build
from the concationation of small pieces.

2) Fix os calls to correct the problem.

Not really sure about it... because  I'm afraid that not this is not
going to ship with the standard Python library. After all, it's a
Windows bug.

3) Decorate os calls to correct the problem.

For now, that's my best bet for a generic solution that doesn't break
anyone else's code. I can write a wrapper for some of the affected OS
calls, and eliminate the double slashes out of the pathname before
calling the original function. It might work , but I still have to
test it.


Well, that's the problem. What's I'm supposed to do?



-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list