~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 05:32:16 UTC
  • mfrom: (1797 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620053216-817857d7ca3e9d1f
[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
398
400
        method = getattr(self, mname)
399
401
        method()
400
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
 
401
431
 
402
432
class TestingHTTPServer(BaseHTTPServer.HTTPServer):
403
433
    def __init__(self, server_address, RequestHandlerClass, test_case):