180
180
def _win32_local_path_from_url(url):
181
181
"""Convert a url like file:///C:/path/to/foo into C:/path/to/foo"""
182
if not url.startswith('file:///'):
183
raise errors.InvalidURL(url, 'local urls must start with file:///')
182
if not url.startswith('file://'):
183
raise errors.InvalidURL(url, 'local urls must start with file:///, '
184
'UNC path urls must start with file://')
184
185
# We strip off all 3 slashes
185
win32_url = url[len('file:///'):]
186
if (win32_url[0] not in ('abcdefghijklmnopqrstuvwxyz'
186
win32_url = url[len('file:'):]
187
# check for UNC path: //HOST/path
188
if not win32_url.startswith('///'):
189
if (win32_url[2] == '/'
190
or win32_url[3] in '|:'):
191
raise errors.InvalidURL(url, 'Win32 UNC path urls'
192
' have form file://HOST/path')
193
return unescape(win32_url)
194
# usual local path with drive letter
195
if (win32_url[3] not in ('abcdefghijklmnopqrstuvwxyz'
187
196
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
188
or win32_url[1] not in '|:'
189
or win32_url[2] != '/'):
197
or win32_url[4] not in '|:'
198
or win32_url[5] != '/'):
190
199
raise errors.InvalidURL(url, 'Win32 file urls start with'
191
200
' file:///x:/, where x is a valid drive letter')
192
return win32_url[0].upper() + u':' + unescape(win32_url[2:])
201
return win32_url[3].upper() + u':' + unescape(win32_url[5:])
195
204
def _win32_local_path_to_url(path):
205
214
# semantics, since 'nt' is not an available module.
206
215
win32_path = osutils._nt_normpath(
207
216
osutils._win32_abspath(path)).replace('\\', '/')
217
# check for UNC path \\HOST\path
218
if win32_path.startswith('//'):
219
return 'file:' + escape(win32_path)
208
220
return 'file:///' + win32_path[0].upper() + ':' + escape(win32_path[2:])