~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

Factor out another win32 special case and add platform independent tests for it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
194
194
local_path_to_url = _posix_local_path_to_url
195
195
local_path_from_url = _posix_local_path_from_url
196
196
MIN_ABS_FILEURL_LENGTH = len('file:///')
 
197
WIN32_MIN_ABS_FILEURL_LENGTH = len('file:///C|/')
197
198
 
198
199
if sys.platform == 'win32':
199
200
    local_path_to_url = _win32_local_path_to_url
200
201
    local_path_from_url = _win32_local_path_from_url
201
202
 
202
 
    MIN_ABS_FILEURL_LENGTH = len('file:///C|/')
 
203
    MIN_ABS_FILEURL_LENGTH = WIN32_MIN_ABS_FILEURL_LENGTH
203
204
 
204
205
 
205
206
_url_scheme_re = re.compile(r'^(?P<scheme>[^:/]{2,})://(?P<path>.*)$')
343
344
    return url_base + head, tail
344
345
 
345
346
 
 
347
def _win32_strip_local_trailing_slash(url):
 
348
    """Strip slashes after the drive letter"""
 
349
    if len(url) > WIN32_MIN_ABS_FILEURL_LENGTH:
 
350
        return url[:-1]
 
351
    else:
 
352
        return url
 
353
 
 
354
 
346
355
def strip_trailing_slash(url):
347
356
    """Strip trailing slash, except for root paths.
348
357
 
368
377
        # Nothing to do
369
378
        return url
370
379
    if sys.platform == 'win32' and url.startswith('file:///'):
371
 
        # This gets handled specially, because the 'top-level'
372
 
        # of a win32 path is actually the drive letter
373
 
        if len(url) > MIN_ABS_FILEURL_LENGTH:
374
 
            return url[:-1]
375
 
        else:
376
 
            return url
 
380
        return _win32_strip_local_trailing_slash(url)
377
381
 
378
382
    scheme_loc, first_path_slash = _find_scheme_and_separator(url)
379
383
    if scheme_loc is None: