~ubuntu-branches/debian/squeeze/bzr/squeeze

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-02-17 17:47:40 UTC
  • mfrom: (1.4.5 upstream) (9.2.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100217174740-35yh6t5rjnztg9z6
Tags: 2.1.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
    trace,
72
72
    transport,
73
73
    ui,
 
74
    urlutils,
74
75
    )
75
76
 
76
77
 
80
81
        self.filesock = filesock
81
82
        self._report_activity = report_activity
82
83
 
 
84
    def report_activity(self, size, direction):
 
85
        if self._report_activity:
 
86
            self._report_activity(size, direction)
83
87
 
84
88
    def read(self, size=1):
85
89
        s = self.filesock.read(size)
86
 
        self._report_activity(len(s), 'read')
 
90
        self.report_activity(len(s), 'read')
87
91
        return s
88
92
 
89
93
    def readline(self):
93
97
        #  don't *need* the size parameter we'll stay with readline(self)
94
98
        #  --  vila 20090209
95
99
        s = self.filesock.readline()
96
 
        self._report_activity(len(s), 'read')
 
100
        self.report_activity(len(s), 'read')
97
101
        return s
98
102
 
99
103
    def __getattr__(self, name):
106
110
        self.sock = sock
107
111
        self._report_activity = report_activity
108
112
 
 
113
    def report_activity(self, size, direction):
 
114
        if self._report_activity:
 
115
            self._report_activity(size, direction)
 
116
 
109
117
    def sendall(self, s, *args):
110
118
        self.sock.sendall(s, *args)
111
 
        self._report_activity(len(s), 'write')
 
119
        self.report_activity(len(s), 'write')
112
120
 
113
121
    def recv(self, *args):
114
122
        s = self.sock.recv(*args)
115
 
        self._report_activity(len(s), 'read')
 
123
        self.report_activity(len(s), 'read')
116
124
        return s
117
125
 
118
126
    def makefile(self, mode='r', bufsize=-1):
219
227
    # we want to warn. But not below a given thresold.
220
228
    _range_warning_thresold = 1024 * 1024
221
229
 
222
 
    def __init__(self,
223
 
                 report_activity=None):
 
230
    def __init__(self, report_activity=None):
224
231
        self._response = None
225
232
        self._report_activity = report_activity
226
233
        self._ranges_received_whole_file = None
360
367
 
361
368
    def set_proxy(self, proxy, type):
362
369
        """Set the proxy and remember the proxied host."""
363
 
        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)
364
380
        urllib2.Request.set_proxy(self, proxy, type)
365
381
 
366
382
 
1051
1067
 
1052
1068
        auth = self.get_auth(request)
1053
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)
1054
1078
        # FIXME: the auth handler should be selected at a single place instead
1055
1079
        # of letting all handlers try to match all headers, but the current
1056
1080
        # design doesn't allow a simple implementation.
1152
1176
            and then during dialog with the server).
1153
1177
        """
1154
1178
        auth_conf = config.AuthenticationConfig()
1155
 
        user = auth['user']
1156
 
        password = auth['password']
 
1179
        user = auth.get('user', None)
 
1180
        password = auth.get('password', None)
1157
1181
        realm = auth['realm']
1158
1182
 
1159
1183
        if user is None:
1293
1317
            # Put useful info into auth
1294
1318
            self.update_auth(auth, 'scheme', scheme)
1295
1319
            self.update_auth(auth, 'realm', realm)
1296
 
            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):
1297
1322
                user, password = self.get_user_password(auth)
1298
1323
                self.update_auth(auth, 'user', user)
1299
1324
                self.update_auth(auth, 'password', password)
1358
1383
        # Put useful info into auth
1359
1384
        self.update_auth(auth, 'scheme', scheme)
1360
1385
        self.update_auth(auth, 'realm', realm)
1361
 
        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:
1362
1387
            user, password = self.get_user_password(auth)
1363
1388
            self.update_auth(auth, 'user', user)
1364
1389
            self.update_auth(auth, 'password', password)