/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/transport/http/_urllib2_wrappers.py

  • Committer: Jonathan Lange
  • Date: 2009-12-09 09:20:42 UTC
  • mfrom: (4881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20091209092042-s2zgqcf8f39yzxpj
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
# actual code more or less do that, tests should be written to
47
47
# ensure that.
48
48
 
 
49
import errno
49
50
import httplib
50
51
try:
51
52
    import kerberos
70
71
    trace,
71
72
    transport,
72
73
    ui,
 
74
    urlutils,
73
75
    )
74
76
 
75
77
 
79
81
        self.filesock = filesock
80
82
        self._report_activity = report_activity
81
83
 
 
84
    def report_activity(self, size, direction):
 
85
        if self._report_activity:
 
86
            self._report_activity(size, direction)
82
87
 
83
88
    def read(self, size=1):
84
89
        s = self.filesock.read(size)
85
 
        self._report_activity(len(s), 'read')
 
90
        self.report_activity(len(s), 'read')
86
91
        return s
87
92
 
88
93
    def readline(self):
92
97
        #  don't *need* the size parameter we'll stay with readline(self)
93
98
        #  --  vila 20090209
94
99
        s = self.filesock.readline()
95
 
        self._report_activity(len(s), 'read')
 
100
        self.report_activity(len(s), 'read')
96
101
        return s
97
102
 
98
103
    def __getattr__(self, name):
105
110
        self.sock = sock
106
111
        self._report_activity = report_activity
107
112
 
 
113
    def report_activity(self, size, direction):
 
114
        if self._report_activity:
 
115
            self._report_activity(size, direction)
 
116
 
108
117
    def sendall(self, s, *args):
109
118
        self.sock.sendall(s, *args)
110
 
        self._report_activity(len(s), 'write')
 
119
        self.report_activity(len(s), 'write')
111
120
 
112
121
    def recv(self, *args):
113
122
        s = self.sock.recv(*args)
114
 
        self._report_activity(len(s), 'read')
 
123
        self.report_activity(len(s), 'read')
115
124
        return s
116
125
 
117
126
    def makefile(self, mode='r', bufsize=-1):
218
227
    # we want to warn. But not below a given thresold.
219
228
    _range_warning_thresold = 1024 * 1024
220
229
 
221
 
    def __init__(self,
222
 
                 report_activity=None):
 
230
    def __init__(self, report_activity=None):
223
231
        self._response = None
224
232
        self._report_activity = report_activity
225
233
        self._ranges_received_whole_file = None
359
367
 
360
368
    def set_proxy(self, proxy, type):
361
369
        """Set the proxy and remember the proxied host."""
362
 
        self.proxied_host = self.get_host()
 
370
        host, port = urllib.splitport(self.get_host())
 
371
        if port is None:
 
372
            # We need to set the default port ourselves way before it gets set
 
373
            # in the HTTP[S]Connection object at build time.
 
374
            if self.type == 'https':
 
375
                conn_class = HTTPSConnection
 
376
            else:
 
377
                conn_class = HTTPConnection
 
378
            port = conn_class.default_port
 
379
        self.proxied_host = '%s:%s' % (host, port)
363
380
        urllib2.Request.set_proxy(self, proxy, type)
364
381
 
365
382
 
541
558
                        request.get_full_url(),
542
559
                        'Bad status line received',
543
560
                        orig_error=exc_val)
 
561
                elif (isinstance(exc_val, socket.error) and len(exc_val.args)
 
562
                      and exc_val.args[0] in (errno.ECONNRESET, 10054)):
 
563
                    raise errors.ConnectionReset(
 
564
                        "Connection lost while sending request.")
544
565
                else:
545
566
                    # All other exception are considered connection related.
546
567
 
1046
1067
 
1047
1068
        auth = self.get_auth(request)
1048
1069
        auth['modified'] = False
 
1070
        # Put some common info in auth if the caller didn't
 
1071
        if auth.get('path', None) is None:
 
1072
            (protocol, _, _,
 
1073
             host, port, path) = urlutils.parse_url(request.get_full_url())
 
1074
            self.update_auth(auth, 'protocol', protocol)
 
1075
            self.update_auth(auth, 'host', host)
 
1076
            self.update_auth(auth, 'port', port)
 
1077
            self.update_auth(auth, 'path', path)
1049
1078
        # FIXME: the auth handler should be selected at a single place instead
1050
1079
        # of letting all handlers try to match all headers, but the current
1051
1080
        # design doesn't allow a simple implementation.
1147
1176
            and then during dialog with the server).
1148
1177
        """
1149
1178
        auth_conf = config.AuthenticationConfig()
1150
 
        user = auth['user']
1151
 
        password = auth['password']
 
1179
        user = auth.get('user', None)
 
1180
        password = auth.get('password', None)
1152
1181
        realm = auth['realm']
1153
1182
 
1154
1183
        if user is None:
1288
1317
            # Put useful info into auth
1289
1318
            self.update_auth(auth, 'scheme', scheme)
1290
1319
            self.update_auth(auth, 'realm', realm)
1291
 
            if auth['user'] is None or auth['password'] is None:
 
1320
            if (auth.get('user', None) is None
 
1321
                or auth.get('password', None) is None):
1292
1322
                user, password = self.get_user_password(auth)
1293
1323
                self.update_auth(auth, 'user', user)
1294
1324
                self.update_auth(auth, 'password', password)
1353
1383
        # Put useful info into auth
1354
1384
        self.update_auth(auth, 'scheme', scheme)
1355
1385
        self.update_auth(auth, 'realm', realm)
1356
 
        if auth['user'] is None or auth['password'] is None:
 
1386
        if auth.get('user', None) is None or auth.get('password', None) is None:
1357
1387
            user, password = self.get_user_password(auth)
1358
1388
            self.update_auth(auth, 'user', user)
1359
1389
            self.update_auth(auth, 'password', password)