Mercurial > hg
comparison mercurial/keepalive.py @ 25660:328739ea70c3
global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".
This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.
This patch was produced by running `2to3 -f except -w -n .`.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 23 Jun 2015 22:20:08 -0700 |
parents | bb7a911b138e |
children | a16489f9132d |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
249 DEBUG.info("creating new connection to %s (%d)", | 249 DEBUG.info("creating new connection to %s (%d)", |
250 host, id(h)) | 250 host, id(h)) |
251 self._cm.add(host, h, 0) | 251 self._cm.add(host, h, 0) |
252 self._start_transaction(h, req) | 252 self._start_transaction(h, req) |
253 r = h.getresponse() | 253 r = h.getresponse() |
254 except (socket.error, httplib.HTTPException), err: | 254 except (socket.error, httplib.HTTPException) as err: |
255 raise urllib2.URLError(err) | 255 raise urllib2.URLError(err) |
256 | 256 |
257 # if not a persistent connection, don't try to reuse it | 257 # if not a persistent connection, don't try to reuse it |
258 if r.will_close: | 258 if r.will_close: |
259 self._cm.remove(h) | 259 self._cm.remove(h) |
341 'application/x-www-form-urlencoded') | 341 'application/x-www-form-urlencoded') |
342 if 'content-length' not in headers: | 342 if 'content-length' not in headers: |
343 h.putheader('Content-length', '%d' % len(data)) | 343 h.putheader('Content-length', '%d' % len(data)) |
344 else: | 344 else: |
345 h.putrequest('GET', req.get_selector(), **skipheaders) | 345 h.putrequest('GET', req.get_selector(), **skipheaders) |
346 except (socket.error), err: | 346 except (socket.error) as err: |
347 raise urllib2.URLError(err) | 347 raise urllib2.URLError(err) |
348 for k, v in headers.items(): | 348 for k, v in headers.items(): |
349 h.putheader(k, v) | 349 h.putheader(k, v) |
350 h.endheaders() | 350 h.endheaders() |
351 if req.has_data(): | 351 if req.has_data(): |
548 while data: | 548 while data: |
549 self.sock.sendall(data) | 549 self.sock.sendall(data) |
550 data = read(blocksize) | 550 data = read(blocksize) |
551 else: | 551 else: |
552 self.sock.sendall(str) | 552 self.sock.sendall(str) |
553 except socket.error, v: | 553 except socket.error as v: |
554 reraise = True | 554 reraise = True |
555 if v[0] == errno.EPIPE: # Broken pipe | 555 if v[0] == errno.EPIPE: # Broken pipe |
556 if self._HTTPConnection__state == httplib._CS_REQ_SENT: | 556 if self._HTTPConnection__state == httplib._CS_REQ_SENT: |
557 self._broken_pipe_resp = None | 557 self._broken_pipe_resp = None |
558 self._broken_pipe_resp = self.getresponse() | 558 self._broken_pipe_resp = self.getresponse() |
603 fo.close() | 603 fo.close() |
604 try: | 604 try: |
605 status, reason = fo.status, fo.reason | 605 status, reason = fo.status, fo.reason |
606 except AttributeError: | 606 except AttributeError: |
607 status, reason = None, None | 607 status, reason = None, None |
608 except IOError, e: | 608 except IOError as e: |
609 print " EXCEPTION: %s" % e | 609 print " EXCEPTION: %s" % e |
610 raise | 610 raise |
611 else: | 611 else: |
612 print " status = %s, reason = %s" % (status, reason) | 612 print " status = %s, reason = %s" % (status, reason) |
613 HANDLE_ERRORS = orig | 613 HANDLE_ERRORS = orig |