Why doesn't os.normpath reset the leading double slash?

On Unix, os.path.normpath collapses multiple slashes into single slashes , unless exactly two traits appear that start with the path . Why an exception?

To illustrate, I get the following transformations:

//double/slash/stays -> //double/slash/stays /double/slash//gone// -> /double/slash/gone/ double//slash//gone/ -> double/slash/gone ///triple/slash/gone -> /triple/slash/gone ////quad/slash/gone -> /quad/slash/gone 

It seems strange to me. I can vaguely imagine that this is useful for SMB or URLS monsters, but I don’t think I care. Is there any hidden wisdom for Python behavior, or should I just collapse the lead // myself?

[update] In view of the answer below, it seems best not to collapse //, but simply accept it or treat it as an error.

+4
source share
1 answer

Because POSIX allows you to handle a path starting with two slashes in a specific way. In other words, // foo does not necessarily mean the same as / foo for all POSIX systems.

From IEEE Std 1003.1 :

A path starting with two consecutive slashes can be interpreted in accordance with the implementation, although more than two leading slashes should be considered as one slash.

See also this error report (which was closed as invalid).

+8
source

All Articles