~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/urlutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Bazaar-NG -- distributed version control
 
1
# Bazaar -- distributed version control
2
2
#
3
3
# Copyright (C) 2006 by Canonical Ltd
4
4
#
19
19
"""A collection of function for handling URL operations."""
20
20
 
21
21
import os
22
 
from posixpath import split as _posix_split, normpath as _posix_normpath
23
22
import re
24
23
import sys
 
24
 
 
25
from bzrlib.lazy_import import lazy_import
 
26
lazy_import(globals(), """
 
27
from posixpath import split as _posix_split, normpath as _posix_normpath
25
28
import urllib
26
29
 
27
 
import bzrlib.errors as errors
28
 
import bzrlib.osutils
 
30
from bzrlib import (
 
31
    errors,
 
32
    osutils,
 
33
    )
 
34
""")
29
35
 
30
36
 
31
37
def basename(url, exclude_trailing_slash=True):
75
81
 
76
82
    base = local_path_from_url(base)
77
83
    path = local_path_from_url(path)
78
 
    return escape(bzrlib.osutils.relpath(base, path))
 
84
    return escape(osutils.relpath(base, path))
79
85
 
80
86
 
81
87
def _find_scheme_and_separator(url):
129
135
        if m:
130
136
            # Absolute URL
131
137
            scheme = m.group('scheme')
 
138
            # this skips .. normalisation, making http://host/../../..
 
139
            # be rather strange.
132
140
            path = m.group('path').split('/')
133
141
        else:
134
142
            for chunk in arg.split('/'):
166
174
    # importing directly from posixpath allows us to test this 
167
175
    # on non-posix platforms
168
176
    return 'file://' + escape(_posix_normpath(
169
 
        bzrlib.osutils._posix_abspath(path)))
 
177
        osutils._posix_abspath(path)))
170
178
 
171
179
 
172
180
def _win32_local_path_from_url(url):
195
203
    #       which actually strips trailing space characters.
196
204
    #       The worst part is that under linux ntpath.abspath has different
197
205
    #       semantics, since 'nt' is not an available module.
198
 
    win32_path = bzrlib.osutils._nt_normpath(
199
 
        bzrlib.osutils._win32_abspath(path)).replace('\\', '/')
 
206
    win32_path = osutils._nt_normpath(
 
207
        osutils._win32_abspath(path)).replace('\\', '/')
200
208
    return 'file:///' + win32_path[0].upper() + ':' + escape(win32_path[2:])
201
209
 
202
210