~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

Split out win32 specific code so that it can be tested on all platforms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
291
291
    return "/".join(output_sections) or "."
292
292
 
293
293
 
 
294
def _win32_extract_drive_letter(url_base, path):
 
295
    """On win32 the drive letter needs to be added to the url base."""
 
296
    # Strip off the drive letter
 
297
    # path is currently /C:/foo
 
298
    if len(path) < 3 or path[2] not in ':|' or path[3] != '/':
 
299
        raise errors.InvalidURL(url_base + path, 
 
300
            'win32 file:/// paths need a drive letter')
 
301
    url_base += path[0:3] # file:// + /C:
 
302
    path = path[3:] # /foo
 
303
    return url_base, path
 
304
 
 
305
 
294
306
def split(url, exclude_trailing_slash=True):
295
307
    """Split a URL into its parent directory and a child directory.
296
308
 
320
332
 
321
333
    if sys.platform == 'win32' and url.startswith('file:///'):
322
334
        # Strip off the drive letter
 
335
        # url_base is currently file://
323
336
        # path is currently /C:/foo
324
 
        if path[2:3] not in ':|' or path[3:4] not in '\\/':
325
 
            raise errors.InvalidURL(url, 
326
 
                'win32 file:/// paths need a drive letter')
327
 
        url_base += path[0:3] # file:// + /C:
328
 
        path = path[3:] # /foo
 
337
        url_base, path = _win32_extract_drive_letter(url_base, path)
 
338
        # now it should be file:///C: and /foo
329
339
 
330
340
    if exclude_trailing_slash and len(path) > 1 and path.endswith('/'):
331
341
        path = path[:-1]