~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

  • Committer: Martin Pool
  • Date: 2007-06-15 07:01:24 UTC
  • mfrom: (2528 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2530.
  • Revision ID: mbp@sourcefrog.net-20070615070124-clpwqh5gxc4wbf9l
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
608
608
                # Otherwise take the url decoded one
609
609
                res[i] = decoded
610
610
    return u'/'.join(res)
 
611
 
 
612
 
 
613
def derive_to_location(from_location):
 
614
    """Derive a TO_LOCATION given a FROM_LOCATION.
 
615
 
 
616
    The normal case is a FROM_LOCATION of http://foo/bar => bar.
 
617
    The Right Thing for some logical destinations may differ though
 
618
    because no / may be present at all. In that case, the result is
 
619
    the full name without the scheme indicator, e.g. lp:foo-bar => foo-bar.
 
620
    This latter case also applies when a Windows drive
 
621
    is used without a path, e.g. c:foo-bar => foo-bar.
 
622
    If no /, path separator or : is found, the from_location is returned.
 
623
    """
 
624
    if from_location.find("/") >= 0 or from_location.find(os.sep) >= 0:
 
625
        return os.path.basename(from_location.rstrip("/\\"))
 
626
    else:
 
627
        sep = from_location.find(":")
 
628
        if sep > 0:
 
629
            return from_location[sep+1:]
 
630
        else:
 
631
            return from_location