/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-15 17:30:26 UTC
  • mfrom: (1711.2.44 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060615173026-2d88f52257ef1aad
(jam) A few small win32 and sftp fixes.

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>.*)$')
291
292
    return "/".join(output_sections) or "."
292
293
 
293
294
 
 
295
def _win32_extract_drive_letter(url_base, path):
 
296
    """On win32 the drive letter needs to be added to the url base."""
 
297
    # Strip off the drive letter
 
298
    # path is currently /C:/foo
 
299
    if len(path) < 3 or path[2] not in ':|' or path[3] != '/':
 
300
        raise errors.InvalidURL(url_base + path, 
 
301
            'win32 file:/// paths need a drive letter')
 
302
    url_base += path[0:3] # file:// + /C:
 
303
    path = path[3:] # /foo
 
304
    return url_base, path
 
305
 
 
306
 
294
307
def split(url, exclude_trailing_slash=True):
295
308
    """Split a URL into its parent directory and a child directory.
296
309
 
320
333
 
321
334
    if sys.platform == 'win32' and url.startswith('file:///'):
322
335
        # Strip off the drive letter
 
336
        # url_base is currently file://
323
337
        # 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
 
338
        url_base, path = _win32_extract_drive_letter(url_base, path)
 
339
        # now it should be file:///C: and /foo
329
340
 
330
341
    if exclude_trailing_slash and len(path) > 1 and path.endswith('/'):
331
342
        path = path[:-1]
333
344
    return url_base + head, tail
334
345
 
335
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
 
336
355
def strip_trailing_slash(url):
337
356
    """Strip trailing slash, except for root paths.
338
357
 
358
377
        # Nothing to do
359
378
        return url
360
379
    if sys.platform == 'win32' and url.startswith('file:///'):
361
 
        # This gets handled specially, because the 'top-level'
362
 
        # of a win32 path is actually the drive letter
363
 
        if len(url) > MIN_ABS_FILEURL_LENGTH:
364
 
            return url[:-1]
365
 
        else:
366
 
            return url
 
380
        return _win32_strip_local_trailing_slash(url)
367
381
 
368
382
    scheme_loc, first_path_slash = _find_scheme_and_separator(url)
369
383
    if scheme_loc is None: