/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: Jelmer Vernooij
  • Date: 2019-06-03 23:48:08 UTC
  • mfrom: (7316 work)
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190603234808-15yk5c7054tj8e2b
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
def escape(relpath, safe='/~'):
166
166
    """Escape relpath to be a valid url."""
167
167
    if not isinstance(relpath, str) and sys.version_info[0] == 2:
168
 
        # GZ 2019-06-16: Should use _fs_enc instead here really?
169
168
        relpath = relpath.encode('utf-8')
170
169
    return quote(relpath, safe=safe)
171
170
 
282
281
# jam 20060502 Sorted to 'l' because the final target is 'local_path_from_url'
283
282
def _posix_local_path_from_url(url):
284
283
    """Convert a url like file:///path/to/foo into /path/to/foo"""
285
 
    url = strip_segment_parameters(url)
 
284
    url = split_segment_parameters_raw(url)[0]
286
285
    file_localhost_prefix = 'file://localhost/'
287
286
    if url.startswith(file_localhost_prefix):
288
287
        path = url[len(file_localhost_prefix) - 1:]
310
309
    if not url.startswith('file://'):
311
310
        raise InvalidURL(url, 'local urls must start with file:///, '
312
311
                         'UNC path urls must start with file://')
313
 
    url = strip_segment_parameters(url)
 
312
    url = split_segment_parameters_raw(url)[0]
314
313
    # We strip off all 3 slashes
315
314
    win32_url = url[len('file:'):]
316
315
    # check for UNC path: //HOST/path
574
573
    return (base_url, parameters)
575
574
 
576
575
 
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
 
 
587
576
def join_segment_parameters_raw(base, *subsegments):
588
577
    """Create a new URL by adding subsegments to an existing one.
589
578
 
832
821
    is used without a path, e.g. c:foo-bar => foo-bar.
833
822
    If no /, path separator or : is found, the from_location is returned.
834
823
    """
835
 
    from_location = strip_segment_parameters(from_location)
 
824
    from_location, unused_params = split_segment_parameters(from_location)
836
825
    if from_location.find("/") >= 0 or from_location.find(os.sep) >= 0:
837
826
        return os.path.basename(from_location.rstrip("/\\"))
838
827
    else: