/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-12-08 10:01:38 UTC
  • mfrom: (2162.2.8 win32.unc-path)
  • Revision ID: pqm@pqm.ubuntu.com-20061208100138-33b6d8665ca29dad
(bialix) support for win32 UNC path (bug #57869)

Show diffs side-by-side

added added

removed removed

Lines of Context:
179
179
 
180
180
def _win32_local_path_from_url(url):
181
181
    """Convert a url like file:///C:/path/to/foo into C:/path/to/foo"""
182
 
    if not url.startswith('file:///'):
183
 
        raise errors.InvalidURL(url, 'local urls must start with file:///')
 
182
    if not url.startswith('file://'):
 
183
        raise errors.InvalidURL(url, 'local urls must start with file:///, '
 
184
                                     'UNC path urls must start with file://')
184
185
    # We strip off all 3 slashes
185
 
    win32_url = url[len('file:///'):]
186
 
    if (win32_url[0] not in ('abcdefghijklmnopqrstuvwxyz'
 
186
    win32_url = url[len('file:'):]
 
187
    # check for UNC path: //HOST/path
 
188
    if not win32_url.startswith('///'):
 
189
        if (win32_url[2] == '/'
 
190
            or win32_url[3] in '|:'):
 
191
            raise errors.InvalidURL(url, 'Win32 UNC path urls'
 
192
                ' have form file://HOST/path')
 
193
        return unescape(win32_url)
 
194
    # usual local path with drive letter
 
195
    if (win32_url[3] not in ('abcdefghijklmnopqrstuvwxyz'
187
196
                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
188
 
        or win32_url[1] not in  '|:'
189
 
        or win32_url[2] != '/'):
 
197
        or win32_url[4] not in  '|:'
 
198
        or win32_url[5] != '/'):
190
199
        raise errors.InvalidURL(url, 'Win32 file urls start with'
191
200
                ' file:///x:/, where x is a valid drive letter')
192
 
    return win32_url[0].upper() + u':' + unescape(win32_url[2:])
 
201
    return win32_url[3].upper() + u':' + unescape(win32_url[5:])
193
202
 
194
203
 
195
204
def _win32_local_path_to_url(path):
205
214
    #       semantics, since 'nt' is not an available module.
206
215
    win32_path = osutils._nt_normpath(
207
216
        osutils._win32_abspath(path)).replace('\\', '/')
 
217
    # check for UNC path \\HOST\path
 
218
    if win32_path.startswith('//'):
 
219
        return 'file:' + escape(win32_path)
208
220
    return 'file:///' + win32_path[0].upper() + ':' + escape(win32_path[2:])
209
221
 
210
222