Mercurial > public > mercurial-scm > hg
comparison mercurial/url.py @ 13420:051f498628f7
url: refactor _gen_sendfile
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 16 Feb 2011 04:28:17 +0100 |
parents | 1cc73868c740 |
children | bd8bfa85d5a5 |
comparison
equal
deleted
inserted
replaced
13419:1cc73868c740 | 13420:051f498628f7 |
---|---|
289 return ret | 289 return ret |
290 | 290 |
291 def __len__(self): | 291 def __len__(self): |
292 return self._len | 292 return self._len |
293 | 293 |
294 def _gen_sendfile(connection): | 294 def _gen_sendfile(orgsend): |
295 def _sendfile(self, data): | 295 def _sendfile(self, data): |
296 # send a file | 296 # send a file |
297 if isinstance(data, httpsendfile): | 297 if isinstance(data, httpsendfile): |
298 # if auth required, some data sent twice, so rewind here | 298 # if auth required, some data sent twice, so rewind here |
299 data.seek(0) | 299 data.seek(0) |
300 for chunk in util.filechunkiter(data): | 300 for chunk in util.filechunkiter(data): |
301 connection.send(self, chunk) | 301 orgsend(self, chunk) |
302 else: | 302 else: |
303 connection.send(self, data) | 303 orgsend(self, data) |
304 return _sendfile | 304 return _sendfile |
305 | 305 |
306 has_https = hasattr(urllib2, 'HTTPSHandler') | 306 has_https = hasattr(urllib2, 'HTTPSHandler') |
307 if has_https: | 307 if has_https: |
308 try: | 308 try: |
351 | 351 |
352 raise socket.error, msg | 352 raise socket.error, msg |
353 | 353 |
354 class httpconnection(keepalive.HTTPConnection): | 354 class httpconnection(keepalive.HTTPConnection): |
355 # must be able to send big bundle as stream. | 355 # must be able to send big bundle as stream. |
356 send = _gen_sendfile(keepalive.HTTPConnection) | 356 send = _gen_sendfile(keepalive.HTTPConnection.send) |
357 | 357 |
358 def connect(self): | 358 def connect(self): |
359 if has_https and self.realhostport: # use CONNECT proxy | 359 if has_https and self.realhostport: # use CONNECT proxy |
360 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 360 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
361 self.sock.connect((self.host, self.port)) | 361 self.sock.connect((self.host, self.port)) |
593 self.host) | 593 self.host) |
594 | 594 |
595 class httpsconnection(BetterHTTPS): | 595 class httpsconnection(BetterHTTPS): |
596 response_class = keepalive.HTTPResponse | 596 response_class = keepalive.HTTPResponse |
597 # must be able to send big bundle as stream. | 597 # must be able to send big bundle as stream. |
598 send = _gen_sendfile(BetterHTTPS) | 598 send = _gen_sendfile(BetterHTTPS.send) |
599 getresponse = keepalive.wrapgetresponse(httplib.HTTPSConnection) | 599 getresponse = keepalive.wrapgetresponse(httplib.HTTPSConnection) |
600 | 600 |
601 def connect(self): | 601 def connect(self): |
602 if self.realhostport: # use CONNECT proxy | 602 if self.realhostport: # use CONNECT proxy |
603 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 603 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |