~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/__init__.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
There are separate implementation modules for each http client implementation.
20
20
"""
21
21
 
 
22
from collections import deque
 
23
from cStringIO import StringIO
22
24
import errno
23
25
import os
24
 
from collections import deque
25
 
from cStringIO import StringIO
 
26
import posixpath
26
27
import re
 
28
import sys
27
29
import urlparse
28
30
import urllib
29
31
from warnings import warn
30
32
 
31
33
from bzrlib.transport import Transport, register_transport, Server
32
34
from bzrlib.errors import (TransportNotPossible, NoSuchFile,
33
 
                           TransportError, ConnectionError)
34
 
from bzrlib.errors import BzrError, BzrCheckError
 
35
                           TransportError, ConnectionError, InvalidURL)
35
36
from bzrlib.branch import Branch
36
37
from bzrlib.trace import mutter
37
38
# TODO: load these only when running http tests
113
114
        implementation qualifier.
114
115
        """
115
116
        assert isinstance(relpath, basestring)
 
117
        if isinstance(relpath, unicode):
 
118
            raise InvalidURL(relpath, 'paths must not be unicode.')
116
119
        if isinstance(relpath, basestring):
117
120
            relpath_parts = relpath.split('/')
118
121
        else:
397
400
        method = getattr(self, mname)
398
401
        method()
399
402
 
 
403
    if sys.platform == 'win32':
 
404
        # On win32 you cannot access non-ascii filenames without
 
405
        # decoding them into unicode first.
 
406
        # However, under Linux, you can access bytestream paths
 
407
        # without any problems. If this function was always active
 
408
        # it would probably break tests when LANG=C was set
 
409
        def translate_path(self, path):
 
410
            """Translate a /-separated PATH to the local filename syntax.
 
411
 
 
412
            For bzr, all url paths are considered to be utf8 paths.
 
413
            On Linux, you can access these paths directly over the bytestream
 
414
            request, but on win32, you must decode them, and access them
 
415
            as Unicode files.
 
416
            """
 
417
            # abandon query parameters
 
418
            path = urlparse.urlparse(path)[2]
 
419
            path = posixpath.normpath(urllib.unquote(path))
 
420
            path = path.decode('utf-8')
 
421
            words = path.split('/')
 
422
            words = filter(None, words)
 
423
            path = os.getcwdu()
 
424
            for word in words:
 
425
                drive, word = os.path.splitdrive(word)
 
426
                head, word = os.path.split(word)
 
427
                if word in (os.curdir, os.pardir): continue
 
428
                path = os.path.join(path, word)
 
429
            return path
 
430
 
400
431
 
401
432
class TestingHTTPServer(BaseHTTPServer.HTTPServer):
402
433
    def __init__(self, server_address, RequestHandlerClass, test_case):