/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 breezy/urlutils.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-01-12 15:16:27 UTC
  • mfrom: (7441.1.2 strip-segment-parameters)
  • Revision ID: breezy.the.bot@gmail.com-20200112151627-meh6feoulbz777ns
Add strip_segment_parameters function.

Merged from https://code.launchpad.net/~jelmer/brz/strip-segment-parameters/+merge/377479

Show diffs side-by-side

added added

removed removed

Lines of Context:
282
282
# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
283
283
def _posix_local_path_from_url(url):
284
284
    """Convert a url like file:///path/to/foo into /path/to/foo"""
285
 
    url = split_segment_parameters_raw(url)[0]
 
285
    url = strip_segment_parameters(url)
286
286
    file_localhost_prefix = 'file://localhost/'
287
287
    if url.startswith(file_localhost_prefix):
288
288
        path = url[len(file_localhost_prefix) - 1:]
310
310
    if not url.startswith('file://'):
311
311
        raise InvalidURL(url, 'local urls must start with file:///, '
312
312
                         'UNC path urls must start with file://')
313
 
    url = split_segment_parameters_raw(url)[0]
 
313
    url = strip_segment_parameters(url)
314
314
    # We strip off all 3 slashes
315
315
    win32_url = url[len('file:'):]
316
316
    # check for UNC path: //HOST/path
574
574
    return (base_url, parameters)
575
575
 
576
576
 
 
577
def strip_segment_parameters(url):
 
578
    """Strip the segment parameters from a URL.
 
579
 
 
580
    :param url: A relative or absolute URL
 
581
    :return: url
 
582
    """
 
583
    base_url, subsegments = split_segment_parameters_raw(url)
 
584
    return base_url
 
585
 
 
586
 
577
587
def join_segment_parameters_raw(base, *subsegments):
578
588
    """Create a new URL by adding subsegments to an existing one.
579
589
 
822
832
    is used without a path, e.g. c:foo-bar => foo-bar.
823
833
    If no /, path separator or : is found, the from_location is returned.
824
834
    """
825
 
    from_location, unused_params = split_segment_parameters(from_location)
 
835
    from_location = strip_segment_parameters(from_location)
826
836
    if from_location.find("/") >= 0 or from_location.find(os.sep) >= 0:
827
837
        return os.path.basename(from_location.rstrip("/\\"))
828
838
    else: