/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/tests/http_utils.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from cStringIO import StringIO
17
18
import re
18
 
try:
19
 
    from urllib.request import (
20
 
        parse_http_list,
21
 
        parse_keqv_list,
22
 
        )
23
 
except ImportError:  # python < 3
24
 
    from urllib2 import (
25
 
        parse_http_list,
26
 
        parse_keqv_list,
27
 
        )
28
 
 
29
 
 
30
 
from .. import (
 
19
import urllib2
 
20
 
 
21
 
 
22
from bzrlib import (
31
23
    errors,
32
24
    osutils,
33
25
    tests,
34
26
    transport,
35
27
    )
36
 
from ..sixish import (
37
 
    BytesIO,
38
 
    )
39
 
from ..bzr.smart import (
 
28
from bzrlib.smart import (
40
29
    medium,
41
30
    )
42
 
from . import http_server
43
 
from ..transport import chroot
 
31
from bzrlib.tests import http_server
 
32
from bzrlib.transport import chroot
44
33
 
45
34
 
46
35
class HTTPServerWithSmarts(http_server.HttpServer):
57
46
class SmartRequestHandler(http_server.TestingHTTPRequestHandler):
58
47
    """Extend TestingHTTPRequestHandler to support smart client POSTs.
59
48
 
60
 
    XXX: This duplicates a fair bit of the logic in breezy.transport.http.wsgi.
 
49
    XXX: This duplicates a fair bit of the logic in bzrlib.transport.http.wsgi.
61
50
    """
62
51
 
63
52
    def do_POST(self):
92
81
        request_bytes = self.rfile.read(data_length)
93
82
        protocol_factory, unused_bytes = medium._get_protocol_factory_for_bytes(
94
83
            request_bytes)
95
 
        out_buffer = BytesIO()
 
84
        out_buffer = StringIO()
96
85
        smart_protocol_request = protocol_factory(t, out_buffer.write, '/')
97
86
        # Perhaps there should be a SmartServerHTTPMedium that takes care of
98
87
        # feeding the bytes in the http request to the smart_protocol_request,
216
205
    def redirect_to(self, host, port):
217
206
        """Redirect all requests to a specific host:port"""
218
207
        self.redirections = [('(.*)',
219
 
                              r'http://%s:%s\1' % (host, port),
 
208
                              r'http://%s:%s\1' % (host, port) ,
220
209
                              301)]
221
210
 
222
211
    def is_redirected(self, path):
363
352
            return False
364
353
        scheme, auth = auth_header.split(None, 1)
365
354
        if scheme.lower() == tcs.auth_scheme:
366
 
            auth_dict = parse_keqv_list(parse_http_list(auth))
 
355
            auth_dict = urllib2.parse_keqv_list(urllib2.parse_http_list(auth))
367
356
 
368
357
            return tcs.digest_authorized(auth_dict, self.command)
369
358
 
374
363
        header = 'Digest realm="%s", ' % tcs.auth_realm
375
364
        header += 'nonce="%s", algorithm="%s", qop="auth"' % (tcs.auth_nonce,
376
365
                                                              'MD5')
377
 
        self.send_header(tcs.auth_header_sent, header)
 
366
        self.send_header(tcs.auth_header_sent,header)
378
367
 
379
368
 
380
369
class DigestAndBasicAuthRequestHandler(DigestAuthRequestHandler):
392
381
        header = 'Digest realm="%s", ' % tcs.auth_realm
393
382
        header += 'nonce="%s", algorithm="%s", qop="auth"' % (tcs.auth_nonce,
394
383
                                                              'MD5')
395
 
        self.send_header(tcs.auth_header_sent, header)
 
384
        self.send_header(tcs.auth_header_sent,header)
396
385
 
397
386
 
398
387
class AuthServer(http_server.HttpServer):
457
446
        if realm != self.auth_realm:
458
447
            return False
459
448
        user = auth['username']
460
 
        if user not in self.password_of:
 
449
        if not self.password_of.has_key(user):
461
450
            return False
462
451
        algorithm= auth['algorithm']
463
452
        if algorithm != 'MD5':