# HG changeset patch # User Chris Angelico # Date 1393523415 -39600 # Node ID 6417a32c5df99f90f57c22ffb2975e0b64862422 # Parent 59d37fbf71cde0ddf89f11b7e34a20d758ab03bb Sweep through and make changes, where possible. SHOULD NOT BE APPLIED TO TRUNK but is a good proof-of-concept. The entire test suite passes (on Linux amd64, at least). diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/_osx_support.py --- a/Lib/_osx_support.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/_osx_support.py Fri Feb 28 04:50:15 2014 +1100 @@ -134,10 +134,13 @@ osx_version = _get_system_version() if osx_version: - try: - osx_version = tuple(int(i) for i in osx_version.split('.')) - except ValueError: - osx_version = '' + # PEP 463 automated translation: + osx_version = (tuple((int(i) for i in osx_version.split('.'))) except ValueError: '') + # try: + # osx_version = tuple(int(i) for i in osx_version.split('.')) + # except ValueError: + # osx_version = '' + # End PEP 463 translation return bool(osx_version >= (10, 4)) if osx_version else False diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/aifc.py --- a/Lib/aifc.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/aifc.py Fri Feb 28 04:50:15 2014 +1100 @@ -790,10 +790,13 @@ self._datalength = (self._datalength + 3) // 4 if self._datalength & 1: self._datalength = self._datalength + 1 - try: - self._form_length_pos = self._file.tell() - except (AttributeError, OSError): - self._form_length_pos = None + # PEP 463 automated translation: + self._form_length_pos = (self._file.tell() except (AttributeError, OSError): None) + # try: + # self._form_length_pos = self._file.tell() + # except (AttributeError, OSError): + # self._form_length_pos = None + # End PEP 463 translation commlength = self._write_form_length(self._datalength) if self._aifc: self._file.write(b'AIFC') diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/argparse.py --- a/Lib/argparse.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/argparse.py Fri Feb 28 04:50:15 2014 +1100 @@ -156,10 +156,13 @@ # default setting for width if width is None: - try: - width = int(_os.environ['COLUMNS']) - except (KeyError, ValueError): - width = 80 + # PEP 463 automated translation: + width = (int(_os.environ['COLUMNS']) except (KeyError, ValueError): 80) + # try: + # width = int(_os.environ['COLUMNS']) + # except (KeyError, ValueError): + # width = 80 + # End PEP 463 translation width -= 2 self._prog = prog diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/asyncio/selector_events.py Fri Feb 28 04:50:15 2014 +1100 @@ -350,10 +350,13 @@ self._extra['socket'] = sock self._extra['sockname'] = sock.getsockname() if 'peername' not in self._extra: - try: - self._extra['peername'] = sock.getpeername() - except socket.error: - self._extra['peername'] = None + # PEP 463 automated translation: + self._extra['peername'] = (sock.getpeername() except socket.error: None) + # try: + # self._extra['peername'] = sock.getpeername() + # except socket.error: + # self._extra['peername'] = None + # End PEP 463 translation self._loop = loop self._sock = sock self._sock_fd = sock.fileno() diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/asyncore.py --- a/Lib/asyncore.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/asyncore.py Fri Feb 28 04:50:15 2014 +1100 @@ -182,10 +182,13 @@ flags |= select.POLLOUT if flags: pollster.register(fd, flags) - try: - r = pollster.poll(timeout) - except InterruptedError: - r = [] + # PEP 463 automated translation: + r = (pollster.poll(timeout) except InterruptedError: []) + # try: + # r = pollster.poll(timeout) + # except InterruptedError: + # r = [] + # End PEP 463 translation for fd, flags in r: obj = map.get(fd) if obj is None: @@ -479,10 +482,13 @@ nil, t, v, tbinfo = compact_traceback() # sometimes a user repr method will crash. - try: - self_repr = repr(self) - except: - self_repr = '<__repr__(self) failed for object at %0x>' % id(self) + # PEP 463 automated translation: + self_repr = (repr(self) except BaseException: ('<__repr__(self) failed for object at %0x>' % id(self))) + # try: + # self_repr = repr(self) + # except: + # self_repr = '<__repr__(self) failed for object at %0x>' % id(self) + # End PEP 463 translation self.log_info( 'uncaptured python exception, closing channel %s (%s:%s %s)' % ( diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/cmd.py --- a/Lib/cmd.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/cmd.py Fri Feb 28 04:50:15 2014 +1100 @@ -122,10 +122,13 @@ line = self.cmdqueue.pop(0) else: if self.use_rawinput: - try: - line = input(self.prompt) - except EOFError: - line = 'EOF' + # PEP 463 automated translation: + line = (input(self.prompt) except EOFError: 'EOF') + # try: + # line = input(self.prompt) + # except EOFError: + # line = 'EOF' + # End PEP 463 translation else: self.stdout.write(self.prompt) self.stdout.flush() @@ -266,10 +269,13 @@ if cmd == '': compfunc = self.completedefault else: - try: - compfunc = getattr(self, 'complete_' + cmd) - except AttributeError: - compfunc = self.completedefault + # PEP 463 automated translation: + compfunc = (getattr(self, ('complete_' + cmd)) except AttributeError: self.completedefault) + # try: + # compfunc = getattr(self, 'complete_' + cmd) + # except AttributeError: + # compfunc = self.completedefault + # End PEP 463 translation else: compfunc = self.completenames self.completion_matches = compfunc(text, line, begidx, endidx) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/configparser.py --- a/Lib/configparser.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/configparser.py Fri Feb 28 04:50:15 2014 +1100 @@ -684,10 +684,13 @@ `name' attribute, `' is used. """ if source is None: - try: - source = f.name - except AttributeError: - source = '' + # PEP 463 automated translation: + source = (f.name except AttributeError: '') + # try: + # source = f.name + # except AttributeError: + # source = '' + # End PEP 463 translation self._read(f, source) def read_string(self, string, source=''): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/copy.py --- a/Lib/copy.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/copy.py Fri Feb 28 04:50:15 2014 +1100 @@ -76,10 +76,13 @@ if copier: return copier(x) - try: - issc = issubclass(cls, type) - except TypeError: # cls is not a class - issc = False + # PEP 463 automated translation: + issc = (issubclass(cls, type) except TypeError: False) + # try: + # issc = issubclass(cls, type) + # except TypeError: # cls is not a class + # issc = False + # End PEP 463 translation if issc: # treat it as a regular class: return _copy_immutable(x) @@ -154,10 +157,13 @@ if copier: y = copier(x, memo) else: - try: - issc = issubclass(cls, type) - except TypeError: # cls is not a class (old Boost; see SF #502085) - issc = 0 + # PEP 463 automated translation: + issc = (issubclass(cls, type) except TypeError: 0) + # try: + # issc = issubclass(cls, type) + # except TypeError: # cls is not a class (old Boost; see SF #502085) + # issc = 0 + # End PEP 463 translation if issc: y = _deepcopy_atomic(x, memo) else: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/copyreg.py --- a/Lib/copyreg.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/copyreg.py Fri Feb 28 04:50:15 2014 +1100 @@ -71,10 +71,13 @@ if getattr(self, "__slots__", None): raise TypeError("a class that defines __slots__ without " "defining __getstate__ cannot be pickled") - try: - dict = self.__dict__ - except AttributeError: - dict = None + # PEP 463 automated translation: + dict = (self.__dict__ except AttributeError: None) + # try: + # dict = self.__dict__ + # except AttributeError: + # dict = None + # End PEP 463 translation else: dict = getstate() if dict: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/dis.py --- a/Lib/dis.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/dis.py Fri Feb 28 04:50:15 2014 +1100 @@ -22,10 +22,13 @@ Utility function to accept strings in functions that otherwise expect code objects """ - try: - c = compile(source, name, 'eval') - except SyntaxError: - c = compile(source, name, 'exec') + # PEP 463 automated translation: + c = (compile(source, name, 'eval') except SyntaxError: compile(source, name, 'exec')) + # try: + # c = compile(source, name, 'eval') + # except SyntaxError: + # c = compile(source, name, 'exec') + # End PEP 463 translation return c def dis(x=None, *, file=None): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/distutils/archive_util.py --- a/Lib/distutils/archive_util.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/distutils/archive_util.py Fri Feb 28 04:50:15 2014 +1100 @@ -32,10 +32,13 @@ """Returns a gid, given a group name.""" if getgrnam is None or name is None: return None - try: - result = getgrnam(name) - except KeyError: - result = None + # PEP 463 automated translation: + result = (getgrnam(name) except KeyError: None) + # try: + # result = getgrnam(name) + # except KeyError: + # result = None + # End PEP 463 translation if result is not None: return result[2] return None @@ -44,10 +47,13 @@ """Returns an uid, given a user name.""" if getpwnam is None or name is None: return None - try: - result = getpwnam(name) - except KeyError: - result = None + # PEP 463 automated translation: + result = (getpwnam(name) except KeyError: None) + # try: + # result = getpwnam(name) + # except KeyError: + # result = None + # End PEP 463 translation if result is not None: return result[2] return None @@ -157,12 +163,15 @@ zip_filename, base_dir) if not dry_run: - try: - zip = zipfile.ZipFile(zip_filename, "w", - compression=zipfile.ZIP_DEFLATED) - except RuntimeError: - zip = zipfile.ZipFile(zip_filename, "w", - compression=zipfile.ZIP_STORED) + # PEP 463 automated translation: + zip = (zipfile.ZipFile(zip_filename, 'w', compression=zipfile.ZIP_DEFLATED) except RuntimeError: zipfile.ZipFile(zip_filename, 'w', compression=zipfile.ZIP_STORED)) + # try: + # zip = zipfile.ZipFile(zip_filename, "w", + # compression=zipfile.ZIP_DEFLATED) + # except RuntimeError: + # zip = zipfile.ZipFile(zip_filename, "w", + # compression=zipfile.ZIP_STORED) + # End PEP 463 translation for dirpath, dirnames, filenames in os.walk(base_dir): for name in filenames: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/distutils/command/install.py --- a/Lib/distutils/command/install.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/distutils/command/install.py Fri Feb 28 04:50:15 2014 +1100 @@ -296,11 +296,14 @@ py_version = sys.version.split()[0] (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix') - try: - abiflags = sys.abiflags - except AttributeError: - # sys.abiflags may not be defined on all platforms. - abiflags = '' + # PEP 463 automated translation: + abiflags = (sys.abiflags except AttributeError: '') + # try: + # abiflags = sys.abiflags + # except AttributeError: + # # sys.abiflags may not be defined on all platforms. + # abiflags = '' + # End PEP 463 translation self.config_vars = {'dist_name': self.distribution.get_name(), 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/distutils/dist.py --- a/Lib/distutils/dist.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/distutils/dist.py Fri Feb 28 04:50:15 2014 +1100 @@ -707,10 +707,13 @@ klass = self.cmdclass.get(cmd) if not klass: klass = self.get_command_class(cmd) - try: - description = klass.description - except AttributeError: - description = "(no description available)" + # PEP 463 automated translation: + description = (klass.description except AttributeError: '(no description available)') + # try: + # description = klass.description + # except AttributeError: + # description = "(no description available)" + # End PEP 463 translation print(" %-*s %s" % (max_length, cmd, description)) @@ -772,10 +775,13 @@ klass = self.cmdclass.get(cmd) if not klass: klass = self.get_command_class(cmd) - try: - description = klass.description - except AttributeError: - description = "(no description available)" + # PEP 463 automated translation: + description = (klass.description except AttributeError: '(no description available)') + # try: + # description = klass.description + # except AttributeError: + # description = "(no description available)" + # End PEP 463 translation rv.append((cmd, description)) return rv @@ -877,15 +883,21 @@ if DEBUG: self.announce(" %s = %s (from %s)" % (option, value, source)) - try: - bool_opts = [translate_longopt(o) - for o in command_obj.boolean_options] - except AttributeError: - bool_opts = [] - try: - neg_opt = command_obj.negative_opt - except AttributeError: - neg_opt = {} + # PEP 463 automated translation: + bool_opts = ([translate_longopt(o) for o in command_obj.boolean_options] except AttributeError: []) + # try: + # bool_opts = [translate_longopt(o) + # for o in command_obj.boolean_options] + # except AttributeError: + # bool_opts = [] + # End PEP 463 translation + # PEP 463 automated translation: + neg_opt = (command_obj.negative_opt except AttributeError: {}) + # try: + # neg_opt = command_obj.negative_opt + # except AttributeError: + # neg_opt = {} + # End PEP 463 translation try: is_string = isinstance(value, str) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/email/_header_value_parser.py --- a/Lib/email/_header_value_parser.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/email/_header_value_parser.py Fri Feb 28 04:50:15 2014 +1100 @@ -1117,14 +1117,17 @@ # the best choice, but it is what the old algorithm did value = urllib.parse.unquote(value, encoding='latin-1') else: - try: - value = value.decode(charset, 'surrogateescape') - except LookupError: - # XXX: there should really be a custom defect for - # unknown character set to make it easy to find, - # because otherwise unknown charset is a silent - # failure. - value = value.decode('us-ascii', 'surrogateescape') + # PEP 463 automated translation: + value = (value.decode(charset, 'surrogateescape') except LookupError: value.decode('us-ascii', 'surrogateescape')) + # try: + # value = value.decode(charset, 'surrogateescape') + # except LookupError: + # # XXX: there should really be a custom defect for + # # unknown character set to make it easy to find, + # # because otherwise unknown charset is a silent + # # failure. + # value = value.decode('us-ascii', 'surrogateescape') + # End PEP 463 translation if utils._has_surrogates(value): param.defects.append(errors.UndecodableBytesDefect()) value_parts.append(value) @@ -1641,12 +1644,15 @@ raise errors.HeaderParseError( "expected atom but found '{}'".format(value)) if value.startswith('=?'): - try: - token, value = get_encoded_word(value) - except errors.HeaderParseError: - # XXX: need to figure out how to register defects when - # appropriate here. - token, value = get_atext(value) + # PEP 463 automated translation: + (token, value) = (get_encoded_word(value) except errors.HeaderParseError: get_atext(value)) + # try: + # token, value = get_encoded_word(value) + # except errors.HeaderParseError: + # # XXX: need to figure out how to register defects when + # # appropriate here. + # token, value = get_atext(value) + # End PEP 463 translation else: token, value = get_atext(value) atom.append(token) @@ -1685,12 +1691,15 @@ token, value = get_cfws(value) dot_atom.append(token) if value.startswith('=?'): - try: - token, value = get_encoded_word(value) - except errors.HeaderParseError: - # XXX: need to figure out how to register defects when - # appropriate here. - token, value = get_dot_atom_text(value) + # PEP 463 automated translation: + (token, value) = (get_encoded_word(value) except errors.HeaderParseError: get_dot_atom_text(value)) + # try: + # token, value = get_encoded_word(value) + # except errors.HeaderParseError: + # # XXX: need to figure out how to register defects when + # # appropriate here. + # token, value = get_dot_atom_text(value) + # End PEP 463 translation else: token, value = get_dot_atom_text(value) dot_atom.append(token) @@ -1939,10 +1948,13 @@ token[:0] = [leader] domain.append(token) return domain, value - try: - token, value = get_dot_atom(value) - except errors.HeaderParseError: - token, value = get_atom(value) + # PEP 463 automated translation: + (token, value) = (get_dot_atom(value) except errors.HeaderParseError: get_atom(value)) + # try: + # token, value = get_dot_atom(value) + # except errors.HeaderParseError: + # token, value = get_atom(value) + # End PEP 463 translation if leader is not None: token[:0] = [leader] domain.append(token) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/email/message.py --- a/Lib/email/message.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/email/message.py Fri Feb 28 04:50:15 2014 +1100 @@ -258,19 +258,25 @@ if utils._has_surrogates(payload): bpayload = payload.encode('ascii', 'surrogateescape') if not decode: - try: - payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace') - except LookupError: - payload = bpayload.decode('ascii', 'replace') + # PEP 463 automated translation: + payload = (bpayload.decode(self.get_param('charset', 'ascii'), 'replace') except LookupError: bpayload.decode('ascii', 'replace')) + # try: + # payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace') + # except LookupError: + # payload = bpayload.decode('ascii', 'replace') + # End PEP 463 translation elif decode: - try: - bpayload = payload.encode('ascii') - except UnicodeError: - # This won't happen for RFC compliant messages (messages - # containing only ASCII codepoints in the unicode input). - # If it does happen, turn the string into bytes in a way - # guaranteed not to fail. - bpayload = payload.encode('raw-unicode-escape') + # PEP 463 automated translation: + bpayload = (payload.encode('ascii') except UnicodeError: payload.encode('raw-unicode-escape')) + # try: + # bpayload = payload.encode('ascii') + # except UnicodeError: + # # This won't happen for RFC compliant messages (messages + # # containing only ASCII codepoints in the unicode input). + # # If it does happen, turn the string into bytes in a way + # # guaranteed not to fail. + # bpayload = payload.encode('raw-unicode-escape') + # End PEP 463 translation if not decode: return payload if cte == 'quoted-printable': @@ -355,10 +361,13 @@ # message is serialized. payload = self._payload if payload: - try: - payload = payload.encode('ascii', 'surrogateescape') - except UnicodeError: - payload = payload.encode(charset.output_charset) + # PEP 463 automated translation: + payload = (payload.encode('ascii', 'surrogateescape') except UnicodeError: payload.encode(charset.output_charset)) + # try: + # payload = payload.encode('ascii', 'surrogateescape') + # except UnicodeError: + # payload = payload.encode(charset.output_charset) + # End PEP 463 translation self._payload = charset.body_encode(payload) self.add_header('Content-Transfer-Encoding', cte) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/functools.py --- a/Lib/functools.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/functools.py Fri Feb 28 04:50:15 2014 +1100 @@ -681,10 +681,13 @@ try: impl = dispatch_cache[cls] except KeyError: - try: - impl = registry[cls] - except KeyError: - impl = _find_impl(cls, registry) + # PEP 463 automated translation: + impl = (registry[cls] except KeyError: _find_impl(cls, registry)) + # try: + # impl = registry[cls] + # except KeyError: + # impl = _find_impl(cls, registry) + # End PEP 463 translation dispatch_cache[cls] = impl return impl diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/http/client.py --- a/Lib/http/client.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/http/client.py Fri Feb 28 04:50:15 2014 +1100 @@ -980,16 +980,22 @@ nil, netloc, nil, nil, nil = urlsplit(url) if netloc: - try: - netloc_enc = netloc.encode("ascii") - except UnicodeEncodeError: - netloc_enc = netloc.encode("idna") + # PEP 463 automated translation: + netloc_enc = (netloc.encode('ascii') except UnicodeEncodeError: netloc.encode('idna')) + # try: + # netloc_enc = netloc.encode("ascii") + # except UnicodeEncodeError: + # netloc_enc = netloc.encode("idna") + # End PEP 463 translation self.putheader('Host', netloc_enc) else: - try: - host_enc = self.host.encode("ascii") - except UnicodeEncodeError: - host_enc = self.host.encode("idna") + # PEP 463 automated translation: + host_enc = (self.host.encode('ascii') except UnicodeEncodeError: self.host.encode('idna')) + # try: + # host_enc = self.host.encode("ascii") + # except UnicodeEncodeError: + # host_enc = self.host.encode("idna") + # End PEP 463 translation # As per RFC 273, IPv6 address should be wrapped with [] # when used as Host header diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/http/server.py --- a/Lib/http/server.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/http/server.py Fri Feb 28 04:50:15 2014 +1100 @@ -419,10 +419,13 @@ """ - try: - shortmsg, longmsg = self.responses[code] - except KeyError: - shortmsg, longmsg = '???', '???' + # PEP 463 automated translation: + (shortmsg, longmsg) = (self.responses[code] except KeyError: ('???', '???')) + # try: + # shortmsg, longmsg = self.responses[code] + # except KeyError: + # shortmsg, longmsg = '???', '???' + # End PEP 463 translation if message is None: message = shortmsg if explain is None: @@ -916,10 +919,13 @@ import pwd except ImportError: return -1 - try: - nobody = pwd.getpwnam('nobody')[2] - except KeyError: - nobody = 1 + max(x[2] for x in pwd.getpwall()) + # PEP 463 automated translation: + nobody = (pwd.getpwnam('nobody')[2] except KeyError: (1 + max((x[2] for x in pwd.getpwall())))) + # try: + # nobody = pwd.getpwnam('nobody')[2] + # except KeyError: + # nobody = 1 + max(x[2] for x in pwd.getpwall()) + # End PEP 463 translation return nobody @@ -1160,10 +1166,13 @@ if '=' not in query: cmdline.append(query) self.log_message("command: %s", subprocess.list2cmdline(cmdline)) - try: - nbytes = int(length) - except (TypeError, ValueError): - nbytes = 0 + # PEP 463 automated translation: + nbytes = (int(length) except (TypeError, ValueError): 0) + # try: + # nbytes = int(length) + # except (TypeError, ValueError): + # nbytes = 0 + # End PEP 463 translation p = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/AutoComplete.py --- a/Lib/idlelib/AutoComplete.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/AutoComplete.py Fri Feb 28 04:50:15 2014 +1100 @@ -176,10 +176,13 @@ two unrelated modules are being edited some calltips in the current module may be inoperative if the module was not the last to run. """ - try: - rpcclt = self.editwin.flist.pyshell.interp.rpcclt - except: - rpcclt = None + # PEP 463 automated translation: + rpcclt = (self.editwin.flist.pyshell.interp.rpcclt except BaseException: None) + # try: + # rpcclt = self.editwin.flist.pyshell.interp.rpcclt + # except: + # rpcclt = None + # End PEP 463 translation if rpcclt: return rpcclt.remotecall("exec", "get_the_completion_list", (what, mode), {}) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/CallTips.py Fri Feb 28 04:50:15 2014 +1100 @@ -92,10 +92,13 @@ To find methods, fetch_tip must be fed a fully qualified name. """ - try: - rpcclt = self.editwin.flist.pyshell.interp.rpcclt - except AttributeError: - rpcclt = None + # PEP 463 automated translation: + rpcclt = (self.editwin.flist.pyshell.interp.rpcclt except AttributeError: None) + # try: + # rpcclt = self.editwin.flist.pyshell.interp.rpcclt + # except AttributeError: + # rpcclt = None + # End PEP 463 translation if rpcclt: return rpcclt.remotecall("exec", "get_the_calltip", (expression,), {}) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/ClassBrowser.py --- a/Lib/idlelib/ClassBrowser.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/ClassBrowser.py Fri Feb 28 04:50:15 2014 +1100 @@ -126,10 +126,13 @@ self.name = name self.classes = classes self.file = file - try: - self.cl = self.classes[self.name] - except (IndexError, KeyError): - self.cl = None + # PEP 463 automated translation: + self.cl = (self.classes[self.name] except (IndexError, KeyError): None) + # try: + # self.cl = self.classes[self.name] + # except (IndexError, KeyError): + # self.cl = None + # End PEP 463 translation self.isfunction = isinstance(self.cl, pyclbr.Function) def GetText(self): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/Debugger.py --- a/Lib/idlelib/Debugger.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/Debugger.py Fri Feb 28 04:50:15 2014 +1100 @@ -162,10 +162,13 @@ # if info: type, value, tb = info - try: - m1 = type.__name__ - except AttributeError: - m1 = "%s" % str(type) + # PEP 463 automated translation: + m1 = (type.__name__ except AttributeError: ('%s' % str(type))) + # try: + # m1 = type.__name__ + # except AttributeError: + # m1 = "%s" % str(type) + # End PEP 463 translation if value is not None: try: m1 = "%s: %s" % (m1, str(value)) @@ -338,10 +341,13 @@ self.clear() for i in range(len(stack)): frame, lineno = stack[i] - try: - modname = frame.f_globals["__name__"] - except: - modname = "?" + # PEP 463 automated translation: + modname = (frame.f_globals['__name__'] except BaseException: '?') + # try: + # modname = frame.f_globals["__name__"] + # except: + # modname = "?" + # End PEP 463 translation code = frame.f_code filename = code.co_filename funcname = code.co_name diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/EditorWindow.py Fri Feb 28 04:50:15 2014 +1100 @@ -1062,10 +1062,13 @@ def load_extension(self, name): try: - try: - mod = importlib.import_module('.' + name, package=__package__) - except ImportError: - mod = importlib.import_module(name) + # PEP 463 automated translation: + mod = (importlib.import_module(('.' + name), package=__package__) except ImportError: importlib.import_module(name)) + # try: + # mod = importlib.import_module('.' + name, package=__package__) + # except ImportError: + # mod = importlib.import_module(name) + # End PEP 463 translation except ImportError: print("\nFailed to import extension: ", name) raise diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/IOBinding.py --- a/Lib/idlelib/IOBinding.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/IOBinding.py Fri Feb 28 04:50:15 2014 +1100 @@ -504,10 +504,13 @@ elif self.dirname: return self.dirname, "" else: - try: - pwd = os.getcwd() - except OSError: - pwd = "" + # PEP 463 automated translation: + pwd = (os.getcwd() except OSError: '') + # try: + # pwd = os.getcwd() + # except OSError: + # pwd = "" + # End PEP 463 translation return pwd, "" def asksavefile(self): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/PyShell.py Fri Feb 28 04:50:15 2014 +1100 @@ -1252,10 +1252,13 @@ def showprompt(self): self.resetoutput() - try: - s = str(sys.ps1) - except: - s = "" + # PEP 463 automated translation: + s = (str(sys.ps1) except BaseException: '') + # try: + # s = str(sys.ps1) + # except: + # s = "" + # End PEP 463 translation self.console.write(s) self.text.mark_set("insert", "end-1c") self.set_line_and_column() diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/ReplaceDialog.py --- a/Lib/idlelib/ReplaceDialog.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/ReplaceDialog.py Fri Feb 28 04:50:15 2014 +1100 @@ -25,14 +25,20 @@ def open(self, text): SearchDialogBase.open(self, text) - try: - first = text.index("sel.first") - except TclError: - first = None - try: - last = text.index("sel.last") - except TclError: - last = None + # PEP 463 automated translation: + first = (text.index('sel.first') except TclError: None) + # try: + # first = text.index("sel.first") + # except TclError: + # first = None + # End PEP 463 translation + # PEP 463 automated translation: + last = (text.index('sel.last') except TclError: None) + # try: + # last = text.index("sel.last") + # except TclError: + # last = None + # End PEP 463 translation first = first or text.index("insert") last = last or first self.show_hit(first, last) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/StackViewer.py --- a/Lib/idlelib/StackViewer.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/StackViewer.py Fri Feb 28 04:50:15 2014 +1100 @@ -61,10 +61,13 @@ def GetText(self): frame, lineno = self.info - try: - modname = frame.f_globals["__name__"] - except: - modname = "?" + # PEP 463 automated translation: + modname = (frame.f_globals['__name__'] except BaseException: '?') + # try: + # modname = frame.f_globals["__name__"] + # except: + # modname = "?" + # End PEP 463 translation code = frame.f_code filename = code.co_filename funcname = code.co_name diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/idlelib/TreeWidget.py --- a/Lib/idlelib/TreeWidget.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/idlelib/TreeWidget.py Fri Feb 28 04:50:15 2014 +1100 @@ -23,10 +23,13 @@ ICONDIR = "Icons" # Look for Icons subdirectory in the same directory as this module -try: - _icondir = os.path.join(os.path.dirname(__file__), ICONDIR) -except NameError: - _icondir = ICONDIR +# PEP 463 automated translation: +_icondir = (os.path.join(os.path.dirname(__file__), ICONDIR) except NameError: ICONDIR) +# try: +# _icondir = os.path.join(os.path.dirname(__file__), ICONDIR) +# except NameError: +# _icondir = ICONDIR +# End PEP 463 translation if os.path.isdir(_icondir): ICONDIR = _icondir elif not os.path.isdir(ICONDIR): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/imaplib.py --- a/Lib/imaplib.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/imaplib.py Fri Feb 28 04:50:15 2014 +1100 @@ -565,8 +565,11 @@ Returns server 'BYE' response. """ self.state = 'LOGOUT' - try: typ, dat = self._simple_command('LOGOUT') - except: typ, dat = 'NO', ['%s: %s' % sys.exc_info()[:2]] + # PEP 463 automated translation: + (typ, dat) = (self._simple_command('LOGOUT') except BaseException: ('NO', [('%s: %s' % sys.exc_info()[:2])])) + # try: typ, dat = self._simple_command('LOGOUT') + # except: typ, dat = 'NO', ['%s: %s' % sys.exc_info()[:2]] + # End PEP 463 translation self.shutdown() if 'BYE' in self.untagged_responses: return 'BYE', self.untagged_responses['BYE'] diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/importlib/__init__.py --- a/Lib/importlib/__init__.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/importlib/__init__.py Fri Feb 28 04:50:15 2014 +1100 @@ -115,10 +115,13 @@ """ if not module or not isinstance(module, types.ModuleType): raise TypeError("reload() argument must be module") - try: - name = module.__spec__.name - except AttributeError: - name = module.__name__ + # PEP 463 automated translation: + name = (module.__spec__.name except AttributeError: module.__name__) + # try: + # name = module.__spec__.name + # except AttributeError: + # name = module.__name__ + # End PEP 463 translation if sys.modules.get(name) is not module: msg = "module {} not in sys.modules" diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/importlib/_bootstrap.py Fri Feb 28 04:50:15 2014 +1100 @@ -496,19 +496,25 @@ rest, _, extension = bytecode_path.rpartition('.') if not rest or extension.lower()[-3:-1] != 'py': return bytecode_path - try: - source_path = source_from_cache(bytecode_path) - except (NotImplementedError, ValueError): - source_path = bytecode_path[:-1] + # PEP 463 automated translation: + source_path = (source_from_cache(bytecode_path) except (NotImplementedError, ValueError): bytecode_path[:(- 1)]) + # try: + # source_path = source_from_cache(bytecode_path) + # except (NotImplementedError, ValueError): + # source_path = bytecode_path[:-1] + # End PEP 463 translation return source_path if _path_isfile(source_path) else bytecode_path def _calc_mode(path): """Calculate the mode permissions for a bytecode file.""" - try: - mode = _path_stat(path).st_mode - except OSError: - mode = 0o666 + # PEP 463 automated translation: + mode = (_path_stat(path).st_mode except OSError: 438) + # try: + # mode = _path_stat(path).st_mode + # except OSError: + # mode = 0o666 + # End PEP 463 translation # We always ensure write access so we can update cached files # later even when the source files are read-only on Windows (#6074) mode |= 0o200 @@ -708,10 +714,13 @@ # We could use module.__class__.__name__ instead of 'module' in the # various repr permutations. - try: - name = module.__name__ - except AttributeError: - name = '?' + # PEP 463 automated translation: + name = (module.__name__ except AttributeError: '?') + # try: + # name = module.__name__ + # except AttributeError: + # name = '?' + # End PEP 463 translation try: filename = module.__file__ except AttributeError: @@ -867,10 +876,13 @@ if is_package is None: if hasattr(loader, 'is_package'): - try: - is_package = loader.is_package(name) - except ImportError: - is_package = None # aka, undefined + # PEP 463 automated translation: + is_package = (loader.is_package(name) except ImportError: None) + # try: + # is_package = loader.is_package(name) + # except ImportError: + # is_package = None # aka, undefined + # End PEP 463 translation else: # the default is_package = False @@ -962,26 +974,38 @@ except AttributeError: # loader will stay None. pass - try: - location = module.__file__ - except AttributeError: - location = None + # PEP 463 automated translation: + location = (module.__file__ except AttributeError: None) + # try: + # location = module.__file__ + # except AttributeError: + # location = None + # End PEP 463 translation if origin is None: if location is None: - try: - origin = loader._ORIGIN - except AttributeError: - origin = None + # PEP 463 automated translation: + origin = (loader._ORIGIN except AttributeError: None) + # try: + # origin = loader._ORIGIN + # except AttributeError: + # origin = None + # End PEP 463 translation else: origin = location - try: - cached = module.__cached__ - except AttributeError: - cached = None - try: - submodule_search_locations = list(module.__path__) - except AttributeError: - submodule_search_locations = None + # PEP 463 automated translation: + cached = (module.__cached__ except AttributeError: None) + # try: + # cached = module.__cached__ + # except AttributeError: + # cached = None + # End PEP 463 translation + # PEP 463 automated translation: + submodule_search_locations = (list(module.__path__) except AttributeError: None) + # try: + # submodule_search_locations = list(module.__path__) + # except AttributeError: + # submodule_search_locations = None + # End PEP 463 translation spec = ModuleSpec(name, loader, origin=origin) spec._set_fileattr = False if location is None else True @@ -1995,10 +2019,13 @@ package portions. Returns (loader, list-of-portions).""" is_namespace = False tail_module = fullname.rpartition('.')[2] - try: - mtime = _path_stat(self.path or _os.getcwd()).st_mtime - except OSError: - mtime = -1 + # PEP 463 automated translation: + mtime = (_path_stat((self.path or _os.getcwd())).st_mtime except OSError: (- 1)) + # try: + # mtime = _path_stat(self.path or _os.getcwd()).st_mtime + # except OSError: + # mtime = -1 + # End PEP 463 translation if mtime != self._path_mtime: self._fill_cache() self._path_mtime = mtime @@ -2038,12 +2065,15 @@ def _fill_cache(self): """Fill the cache of potential modules and packages for this directory.""" path = self.path - try: - contents = _os.listdir(path or _os.getcwd()) - except (FileNotFoundError, PermissionError, NotADirectoryError): - # Directory has either been removed, turned into a file, or made - # unreadable. - contents = [] + # PEP 463 automated translation: + contents = (_os.listdir((path or _os.getcwd())) except (FileNotFoundError, PermissionError, NotADirectoryError): []) + # try: + # contents = _os.listdir(path or _os.getcwd()) + # except (FileNotFoundError, PermissionError, NotADirectoryError): + # # Directory has either been removed, turned into a file, or made + # # unreadable. + # contents = [] + # End PEP 463 translation # We store two cached versions, to handle runtime changes of the # PYTHONCASEOK environment variable. if not sys.platform.startswith('win'): @@ -2401,11 +2431,14 @@ setattr(self_module, 'path_separators', ''.join(path_separators)) # Directly load the _thread module (needed during bootstrap). - try: - thread_module = _builtin_from_name('_thread') - except ImportError: - # Python was built without threads - thread_module = None + # PEP 463 automated translation: + thread_module = (_builtin_from_name('_thread') except ImportError: None) + # try: + # thread_module = _builtin_from_name('_thread') + # except ImportError: + # # Python was built without threads + # thread_module = None + # End PEP 463 translation setattr(self_module, '_thread', thread_module) # Directly load the _weakref module (needed during bootstrap). diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/inspect.py --- a/Lib/inspect.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/inspect.py Fri Feb 28 04:50:15 2014 +1100 @@ -1717,10 +1717,13 @@ program = "def foo" + clean_signature + ": pass" - try: - module = ast.parse(program) - except SyntaxError: - module = None + # PEP 463 automated translation: + module = (ast.parse(program) except SyntaxError: None) + # try: + # module = ast.parse(program) + # except SyntaxError: + # module = None + # End PEP 463 translation if not isinstance(module, ast.Module): raise ValueError("{!r} builtin has invalid signature".format(obj)) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/ipaddress.py --- a/Lib/ipaddress.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/ipaddress.py Fri Feb 28 04:50:15 2014 +1100 @@ -1506,13 +1506,16 @@ self.network_address = IPv4Address(self._ip_int_from_string(addr[0])) if len(addr) == 2: - try: - # Check for a netmask in prefix length form - self._prefixlen = self._prefix_from_prefix_string(addr[1]) - except NetmaskValueError: - # Check for a netmask or hostmask in dotted-quad form. - # This may raise NetmaskValueError. - self._prefixlen = self._prefix_from_ip_string(addr[1]) + # PEP 463 automated translation: + self._prefixlen = (self._prefix_from_prefix_string(addr[1]) except NetmaskValueError: self._prefix_from_ip_string(addr[1])) + # try: + # # Check for a netmask in prefix length form + # self._prefixlen = self._prefix_from_prefix_string(addr[1]) + # except NetmaskValueError: + # # Check for a netmask or hostmask in dotted-quad form. + # # This may raise NetmaskValueError. + # self._prefixlen = self._prefix_from_ip_string(addr[1]) + # End PEP 463 translation else: self._prefixlen = self._max_prefixlen self.netmask = IPv4Address(self._ip_int_from_prefix(self._prefixlen)) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/lib2to3/pgen2/pgen.py --- a/Lib/lib2to3/pgen2/pgen.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/lib2to3/pgen2/pgen.py Fri Feb 28 04:50:15 2014 +1100 @@ -327,10 +327,13 @@ def raise_error(self, msg, *args): if args: - try: - msg = msg % args - except: - msg = " ".join([msg] + list(map(str, args))) + # PEP 463 automated translation: + msg = ((msg % args) except BaseException: ' '.join(([msg] + list(map(str, args))))) + # try: + # msg = msg % args + # except: + # msg = " ".join([msg] + list(map(str, args))) + # End PEP 463 translation raise SyntaxError(msg, (self.filename, self.end[0], self.end[1], self.line)) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/lib2to3/pgen2/tokenize.py --- a/Lib/lib2to3/pgen2/tokenize.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/lib2to3/pgen2/tokenize.py Fri Feb 28 04:50:15 2014 +1100 @@ -367,10 +367,13 @@ indents = [0] while 1: # loop over lines in stream - try: - line = readline() - except StopIteration: - line = '' + # PEP 463 automated translation: + line = (readline() except StopIteration: '') + # try: + # line = readline() + # except StopIteration: + # line = '' + # End PEP 463 translation lnum = lnum + 1 pos, max = 0, len(line) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/logging/config.py --- a/Lib/logging/config.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/logging/config.py Fri Feb 28 04:50:15 2014 +1100 @@ -135,10 +135,13 @@ section = cp["handler_%s" % hand] klass = section["class"] fmt = section.get("formatter", "") - try: - klass = eval(klass, vars(logging)) - except (AttributeError, NameError): - klass = _resolve(klass) + # PEP 463 automated translation: + klass = (eval(klass, vars(logging)) except (AttributeError, NameError): _resolve(klass)) + # try: + # klass = eval(klass, vars(logging)) + # except (AttributeError, NameError): + # klass = _resolve(klass) + # End PEP 463 translation args = section["args"] args = eval(args, vars(logging)) h = klass(*args) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/logging/handlers.py --- a/Lib/logging/handlers.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/logging/handlers.py Fri Feb 28 04:50:15 2014 +1100 @@ -453,11 +453,14 @@ # once and then fstat'ing our new fd if we opened a new log stream. # See issue #14632: Thanks to John Mulligan for the problem report # and patch. - try: - # stat the file by path, checking for existence - sres = os.stat(self.baseFilename) - except FileNotFoundError: - sres = None + # PEP 463 automated translation: + sres = (os.stat(self.baseFilename) except FileNotFoundError: None) + # try: + # # stat the file by path, checking for existence + # sres = os.stat(self.baseFilename) + # except FileNotFoundError: + # sres = None + # End PEP 463 translation # compare file system stat with that of our stream file handle if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino: if self.stream is not None: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/multiprocessing/popen_forkserver.py --- a/Lib/multiprocessing/popen_forkserver.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/multiprocessing/popen_forkserver.py Fri Feb 28 04:50:15 2014 +1100 @@ -61,9 +61,12 @@ timeout = 0 if flag == os.WNOHANG else None if not wait([self.sentinel], timeout): return None - try: - self.returncode = forkserver.read_unsigned(self.sentinel) - except (OSError, EOFError): - # The process ended abnormally perhaps because of a signal - self.returncode = 255 + # PEP 463 automated translation: + self.returncode = (forkserver.read_unsigned(self.sentinel) except (OSError, EOFError): 255) + # try: + # self.returncode = forkserver.read_unsigned(self.sentinel) + # except (OSError, EOFError): + # # The process ended abnormally perhaps because of a signal + # self.returncode = 255 + # End PEP 463 translation return self.returncode diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/multiprocessing/process.py --- a/Lib/multiprocessing/process.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/multiprocessing/process.py Fri Feb 28 04:50:15 2014 +1100 @@ -23,10 +23,13 @@ # # -try: - ORIGINAL_DIR = os.path.abspath(os.getcwd()) -except OSError: - ORIGINAL_DIR = None +# PEP 463 automated translation: +ORIGINAL_DIR = (os.path.abspath(os.getcwd()) except OSError: None) +# try: +# ORIGINAL_DIR = os.path.abspath(os.getcwd()) +# except OSError: +# ORIGINAL_DIR = None +# End PEP 463 translation # # Public functions diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/multiprocessing/synchronize.py --- a/Lib/multiprocessing/synchronize.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/multiprocessing/synchronize.py Fri Feb 28 04:50:15 2014 +1100 @@ -131,10 +131,13 @@ return self._semlock._get_value() def __repr__(self): - try: - value = self._semlock._get_value() - except Exception: - value = 'unknown' + # PEP 463 automated translation: + value = (self._semlock._get_value() except Exception: 'unknown') + # try: + # value = self._semlock._get_value() + # except Exception: + # value = 'unknown' + # End PEP 463 translation return '' % value # @@ -147,10 +150,13 @@ SemLock.__init__(self, SEMAPHORE, value, value, ctx=ctx) def __repr__(self): - try: - value = self._semlock._get_value() - except Exception: - value = 'unknown' + # PEP 463 automated translation: + value = (self._semlock._get_value() except Exception: 'unknown') + # try: + # value = self._semlock._get_value() + # except Exception: + # value = 'unknown' + # End PEP 463 translation return '' % \ (value, self._semlock.maxvalue) @@ -239,11 +245,14 @@ self.release = self._lock.release def __repr__(self): - try: - num_waiters = (self._sleeping_count._semlock._get_value() - - self._woken_count._semlock._get_value()) - except Exception: - num_waiters = 'unknown' + # PEP 463 automated translation: + num_waiters = ((self._sleeping_count._semlock._get_value() - self._woken_count._semlock._get_value()) except Exception: 'unknown') + # try: + # num_waiters = (self._sleeping_count._semlock._get_value() - + # self._woken_count._semlock._get_value()) + # except Exception: + # num_waiters = 'unknown' + # End PEP 463 translation return '' % (self._lock, num_waiters) def wait(self, timeout=None): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/multiprocessing/util.py Fri Feb 28 04:50:15 2014 +1100 @@ -208,10 +208,13 @@ return self._key in _finalizer_registry def __repr__(self): - try: - obj = self._weakref() - except (AttributeError, TypeError): - obj = None + # PEP 463 automated translation: + obj = (self._weakref() except (AttributeError, TypeError): None) + # try: + # obj = self._weakref() + # except (AttributeError, TypeError): + # obj = None + # End PEP 463 translation if obj is None: return '' @@ -339,10 +342,13 @@ # Close fds except those specified # -try: - MAXFD = os.sysconf("SC_OPEN_MAX") -except Exception: - MAXFD = 256 +# PEP 463 automated translation: +MAXFD = (os.sysconf('SC_OPEN_MAX') except Exception: 256) +# try: +# MAXFD = os.sysconf("SC_OPEN_MAX") +# except Exception: +# MAXFD = 256 +# End PEP 463 translation def close_all_fds_except(fds): fds = list(fds) + [-1, MAXFD] diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/netrc.py --- a/Lib/netrc.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/netrc.py Fri Feb 28 04:50:15 2014 +1100 @@ -91,14 +91,20 @@ prop = os.fstat(fp.fileno()) if prop.st_uid != os.getuid(): import pwd - try: - fowner = pwd.getpwuid(prop.st_uid)[0] - except KeyError: - fowner = 'uid %s' % prop.st_uid - try: - user = pwd.getpwuid(os.getuid())[0] - except KeyError: - user = 'uid %s' % os.getuid() + # PEP 463 automated translation: + fowner = (pwd.getpwuid(prop.st_uid)[0] except KeyError: ('uid %s' % prop.st_uid)) + # try: + # fowner = pwd.getpwuid(prop.st_uid)[0] + # except KeyError: + # fowner = 'uid %s' % prop.st_uid + # End PEP 463 translation + # PEP 463 automated translation: + user = (pwd.getpwuid(os.getuid())[0] except KeyError: ('uid %s' % os.getuid())) + # try: + # user = pwd.getpwuid(os.getuid())[0] + # except KeyError: + # user = 'uid %s' % os.getuid() + # End PEP 463 translation raise NetrcParseError( ("~/.netrc file owner (%s) does not match" " current user (%s)") % (fowner, user), diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/nntplib.py --- a/Lib/nntplib.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/nntplib.py Fri Feb 28 04:50:15 2014 +1100 @@ -97,10 +97,13 @@ """Base class for all nntplib exceptions""" def __init__(self, *args): Exception.__init__(self, *args) - try: - self.response = args[0] - except IndexError: - self.response = 'No response given' + # PEP 463 automated translation: + self.response = (args[0] except IndexError: 'No response given') + # try: + # self.response = args[0] + # except IndexError: + # self.response = 'No response given' + # End PEP 463 translation class NNTPReplyError(NNTPError): """Unexpected [123]xx reply""" diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/ntpath.py --- a/Lib/ntpath.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/ntpath.py Fri Feb 28 04:50:15 2014 +1100 @@ -336,10 +336,13 @@ elif not 'HOMEPATH' in os.environ: return path else: - try: - drive = os.environ['HOMEDRIVE'] - except KeyError: - drive = '' + # PEP 463 automated translation: + drive = (os.environ['HOMEDRIVE'] except KeyError: '') + # try: + # drive = os.environ['HOMEDRIVE'] + # except KeyError: + # drive = '' + # End PEP 463 translation userhome = join(drive, os.environ['HOMEPATH']) if isinstance(path, bytes): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/optparse.py --- a/Lib/optparse.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/optparse.py Fri Feb 28 04:50:15 2014 +1100 @@ -210,10 +210,13 @@ self.parser = None self.indent_increment = indent_increment if width is None: - try: - width = int(os.environ['COLUMNS']) - except (KeyError, ValueError): - width = 80 + # PEP 463 automated translation: + width = (int(os.environ['COLUMNS']) except (KeyError, ValueError): 80) + # try: + # width = int(os.environ['COLUMNS']) + # except (KeyError, ValueError): + # width = 80 + # End PEP 463 translation width -= 2 self.width = width self.help_position = self.max_help_position = \ diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/os.py --- a/Lib/os.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/os.py Fri Feb 28 04:50:15 2014 +1100 @@ -606,10 +606,13 @@ with warnings.catch_warnings(): warnings.simplefilter("ignore", BytesWarning) - try: - path_list = env.get('PATH') - except TypeError: - path_list = None + # PEP 463 automated translation: + path_list = (env.get('PATH') except TypeError: None) + # try: + # path_list = env.get('PATH') + # except TypeError: + # path_list = None + # End PEP 463 translation if supports_bytes_environ: try: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/pdb.py --- a/Lib/pdb.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/pdb.py Fri Feb 28 04:50:15 2014 +1100 @@ -430,10 +430,13 @@ else: cmdlist.append(cmd) # Determine if we must stop - try: - func = getattr(self, 'do_' + cmd) - except AttributeError: - func = self.default + # PEP 463 automated translation: + func = (getattr(self, ('do_' + cmd)) except AttributeError: self.default) + # try: + # func = getattr(self, 'do_' + cmd) + # except AttributeError: + # func = self.default + # End PEP 463 translation # one of the resuming commands if func.__name__ in self.commands_resuming: self.commands_doprompt[self.commands_bnum] = False @@ -458,10 +461,13 @@ # Here comes a line number or a condition which we can't complete. return [] # First, try to find matching functions (i.e. expressions). - try: - ret = self._complete_expression(text, line, begidx, endidx) - except Exception: - ret = [] + # PEP 463 automated translation: + ret = (self._complete_expression(text, line, begidx, endidx) except Exception: []) + # try: + # ret = self._complete_expression(text, line, begidx, endidx) + # except Exception: + # ret = [] + # End PEP 463 translation # Then, try to complete file names as well. globs = glob.glob(text + '*') for fn in globs: @@ -641,12 +647,15 @@ try: lineno = int(arg) except ValueError: - try: - func = eval(arg, - self.curframe.f_globals, - self.curframe_locals) - except: - func = arg + # PEP 463 automated translation: + func = (eval(arg, self.curframe.f_globals, self.curframe_locals) except BaseException: arg) + # try: + # func = eval(arg, + # self.curframe.f_globals, + # self.curframe_locals) + # except: + # func = arg + # End PEP 463 translation try: if hasattr(func, '__func__'): func = func.__func__ @@ -800,10 +809,13 @@ the breakpoint is made unconditional. """ args = arg.split(' ', 1) - try: - cond = args[1] - except IndexError: - cond = None + # PEP 463 automated translation: + cond = (args[1] except IndexError: None) + # try: + # cond = args[1] + # except IndexError: + # cond = None + # End PEP 463 translation try: bp = self.get_bpbynumber(args[0].strip()) except IndexError: @@ -829,10 +841,13 @@ condition evaluates to true. """ args = arg.split() - try: - count = int(args[1].strip()) - except: - count = 0 + # PEP 463 automated translation: + count = (int(args[1].strip()) except BaseException: 0) + # try: + # count = int(args[1].strip()) + # except: + # count = 0 + # End PEP 463 translation try: bp = self.get_bpbynumber(args[0].strip()) except IndexError: @@ -862,10 +877,13 @@ clear all breaks at that line in that file. """ if not arg: - try: - reply = input('Clear all breaks? ') - except EOFError: - reply = 'no' + # PEP 463 automated translation: + reply = (input('Clear all breaks? ') except EOFError: 'no') + # try: + # reply = input('Clear all breaks? ') + # except EOFError: + # reply = 'no' + # End PEP 463 translation reply = reply.strip().lower() if reply in ('y', 'yes'): bplist = [bp for bp in bdb.Breakpoint.bpbynumber if bp] diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/pickle.py --- a/Lib/pickle.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/pickle.py Fri Feb 28 04:50:15 2014 +1100 @@ -483,10 +483,13 @@ rv = reduce(obj) else: # Check for a class with a custom metaclass; treat as regular class - try: - issc = issubclass(t, type) - except TypeError: # t is not a class (old Boost; see SF #502085) - issc = False + # PEP 463 automated translation: + issc = (issubclass(t, type) except TypeError: False) + # try: + # issc = issubclass(t, type) + # except TypeError: # t is not a class (old Boost; see SF #502085) + # issc = False + # End PEP 463 translation if issc: self.save_global(obj) return diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/pkgutil.py --- a/Lib/pkgutil.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/pkgutil.py Fri Feb 28 04:50:15 2014 +1100 @@ -139,11 +139,14 @@ yielded = {} import inspect - try: - filenames = os.listdir(importer.path) - except OSError: - # ignore unreadable directories like import does - filenames = [] + # PEP 463 automated translation: + filenames = (os.listdir(importer.path) except OSError: []) + # try: + # filenames = os.listdir(importer.path) + # except OSError: + # # ignore unreadable directories like import does + # filenames = [] + # End PEP 463 translation filenames.sort() # handle packages before same-named modules for fn in filenames: @@ -156,11 +159,14 @@ if not modname and os.path.isdir(path) and '.' not in fn: modname = fn - try: - dircontents = os.listdir(path) - except OSError: - # ignore unreadable directories like import does - dircontents = [] + # PEP 463 automated translation: + dircontents = (os.listdir(path) except OSError: []) + # try: + # dircontents = os.listdir(path) + # except OSError: + # # ignore unreadable directories like import does + # dircontents = [] + # End PEP 463 translation for fn in dircontents: subname = inspect.getmodulename(fn) if subname=='__init__': @@ -222,11 +228,14 @@ yielded = {} import inspect - try: - filenames = os.listdir(self.path) - except OSError: - # ignore unreadable directories like import does - filenames = [] + # PEP 463 automated translation: + filenames = (os.listdir(self.path) except OSError: []) + # try: + # filenames = os.listdir(self.path) + # except OSError: + # # ignore unreadable directories like import does + # filenames = [] + # End PEP 463 translation filenames.sort() # handle packages before same-named modules for fn in filenames: @@ -239,11 +248,14 @@ if not modname and os.path.isdir(path) and '.' not in fn: modname = fn - try: - dircontents = os.listdir(path) - except OSError: - # ignore unreadable directories like import does - dircontents = [] + # PEP 463 automated translation: + dircontents = (os.listdir(path) except OSError: []) + # try: + # dircontents = os.listdir(path) + # except OSError: + # # ignore unreadable directories like import does + # dircontents = [] + # End PEP 463 translation for fn in dircontents: subname = inspect.getmodulename(fn) if subname=='__init__': diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/platform.py --- a/Lib/platform.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/platform.py Fri Feb 28 04:50:15 2014 +1100 @@ -917,11 +917,14 @@ # else is given as default. if not bits: import struct - try: - size = struct.calcsize('P') - except struct.error: - # Older installations can only query longs - size = struct.calcsize('l') + # PEP 463 automated translation: + size = (struct.calcsize('P') except struct.error: struct.calcsize('l')) + # try: + # size = struct.calcsize('P') + # except struct.error: + # # Older installations can only query longs + # size = struct.calcsize('l') + # End PEP 463 translation bits = str(size*8) + 'bit' # Get data from the 'file' system command diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/pprint.py --- a/Lib/pprint.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/pprint.py Fri Feb 28 04:50:15 2014 +1100 @@ -84,10 +84,13 @@ self.obj = obj def __lt__(self, other): - try: - rv = self.obj.__lt__(other.obj) - except TypeError: - rv = NotImplemented + # PEP 463 automated translation: + rv = (self.obj.__lt__(other.obj) except TypeError: NotImplemented) + # try: + # rv = self.obj.__lt__(other.obj) + # except TypeError: + # rv = NotImplemented + # End PEP 463 translation if rv is NotImplemented: rv = (str(type(self.obj)), id(self.obj)) < \ diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/pydoc.py --- a/Lib/pydoc.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/pydoc.py Fri Feb 28 04:50:15 2014 +1100 @@ -385,10 +385,13 @@ def getdocloc(self, object): """Return the location of module docs or None""" - try: - file = inspect.getabsfile(object) - except TypeError: - file = '(built-in)' + # PEP 463 automated translation: + file = (inspect.getabsfile(object) except TypeError: '(built-in)') + # try: + # file = inspect.getabsfile(object) + # except TypeError: + # file = '(built-in)' + # End PEP 463 translation docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS) @@ -628,10 +631,13 @@ def docmodule(self, object, name=None, mod=None, *ignored): """Produce HTML documentation for a module object.""" name = object.__name__ # ignore the passed-in name - try: - all = object.__all__ - except AttributeError: - all = None + # PEP 463 automated translation: + all = (object.__all__ except AttributeError: None) + # try: + # all = object.__all__ + # except AttributeError: + # all = None + # End PEP 463 translation parts = name.split('.') links = [] for i in range(len(parts)-1): @@ -937,10 +943,13 @@ anchor, name, reallink) argspec = None if inspect.isroutine(object): - try: - signature = inspect.signature(object) - except (ValueError, TypeError): - signature = None + # PEP 463 automated translation: + signature = (inspect.signature(object) except (ValueError, TypeError): None) + # try: + # signature = inspect.signature(object) + # except (ValueError, TypeError): + # signature = None + # End PEP 463 translation if signature: argspec = str(signature) if realname == '': @@ -1174,10 +1183,13 @@ result = result + self.section('AUTHOR', str(object.__author__)) if hasattr(object, '__credits__'): result = result + self.section('CREDITS', str(object.__credits__)) - try: - file = inspect.getabsfile(object) - except TypeError: - file = '(built-in)' + # PEP 463 automated translation: + file = (inspect.getabsfile(object) except TypeError: '(built-in)') + # try: + # file = inspect.getabsfile(object) + # except TypeError: + # file = '(built-in)' + # End PEP 463 translation result = result + self.section('FILE', file) return result @@ -1256,10 +1268,13 @@ doc = getdoc(value) else: doc = None - try: - obj = getattr(object, name) - except AttributeError: - obj = homecls.__dict__[name] + # PEP 463 automated translation: + obj = (getattr(object, name) except AttributeError: homecls.__dict__[name]) + # try: + # obj = getattr(object, name) + # except AttributeError: + # obj = homecls.__dict__[name] + # End PEP 463 translation push(self.docother(obj, name, mod, maxlen=70, doc=doc) + '\n') return attrs @@ -1338,10 +1353,13 @@ argspec = None if inspect.isroutine(object): - try: - signature = inspect.signature(object) - except (ValueError, TypeError): - signature = None + # PEP 463 automated translation: + signature = (inspect.signature(object) except (ValueError, TypeError): None) + # try: + # signature = inspect.signature(object) + # except (ValueError, TypeError): + # signature = None + # End PEP 463 translation if signature: argspec = str(signature) if realname == '': @@ -2449,19 +2467,25 @@ title, content = html_getfile(url) elif op == "topic?key": # try topics first, then objects. - try: - title, content = html_topicpage(url) - except ValueError: - title, content = html_getobj(url) + # PEP 463 automated translation: + (title, content) = (html_topicpage(url) except ValueError: html_getobj(url)) + # try: + # title, content = html_topicpage(url) + # except ValueError: + # title, content = html_getobj(url) + # End PEP 463 translation elif op == "get?key": # try objects first, then topics. if url in ("", "index"): title, content = html_index() else: - try: - title, content = html_getobj(url) - except ValueError: - title, content = html_topicpage(url) + # PEP 463 automated translation: + (title, content) = (html_getobj(url) except ValueError: html_topicpage(url)) + # try: + # title, content = html_getobj(url) + # except ValueError: + # title, content = html_topicpage(url) + # End PEP 463 translation else: raise ValueError('bad pydoc url') else: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/shelve.py --- a/Lib/shelve.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/shelve.py Fri Feb 28 04:50:15 2014 +1100 @@ -145,10 +145,13 @@ pass # Catch errors that may happen when close is called from __del__ # because CPython is in interpreter shutdown. - try: - self.dict = _ClosedDict() - except (NameError, TypeError): - self.dict = None + # PEP 463 automated translation: + self.dict = (_ClosedDict() except (NameError, TypeError): None) + # try: + # self.dict = _ClosedDict() + # except (NameError, TypeError): + # self.dict = None + # End PEP 463 translation def __del__(self): if not hasattr(self, 'writeback'): diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/shutil.py --- a/Lib/shutil.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/shutil.py Fri Feb 28 04:50:15 2014 +1100 @@ -359,10 +359,13 @@ onerror(os.listdir, path, sys.exc_info()) for name in names: fullname = os.path.join(path, name) - try: - mode = os.lstat(fullname).st_mode - except OSError: - mode = 0 + # PEP 463 automated translation: + mode = (os.lstat(fullname).st_mode except OSError: 0) + # try: + # mode = os.lstat(fullname).st_mode + # except OSError: + # mode = 0 + # End PEP 463 translation if stat.S_ISDIR(mode): _rmtree_unsafe(fullname, onerror) else: @@ -548,10 +551,13 @@ """Returns a gid, given a group name.""" if getgrnam is None or name is None: return None - try: - result = getgrnam(name) - except KeyError: - result = None + # PEP 463 automated translation: + result = (getgrnam(name) except KeyError: None) + # try: + # result = getgrnam(name) + # except KeyError: + # result = None + # End PEP 463 translation if result is not None: return result[2] return None @@ -560,10 +566,13 @@ """Returns an uid, given a user name.""" if getpwnam is None or name is None: return None - try: - result = getpwnam(name) - except KeyError: - result = None + # PEP 463 automated translation: + result = (getpwnam(name) except KeyError: None) + # try: + # result = getpwnam(name) + # except KeyError: + # result = None + # End PEP 463 translation if result is not None: return result[2] return None @@ -1041,22 +1050,31 @@ The value returned is a named tuple of type os.terminal_size. """ # columns, lines are the working values - try: - columns = int(os.environ['COLUMNS']) - except (KeyError, ValueError): - columns = 0 + # PEP 463 automated translation: + columns = (int(os.environ['COLUMNS']) except (KeyError, ValueError): 0) + # try: + # columns = int(os.environ['COLUMNS']) + # except (KeyError, ValueError): + # columns = 0 + # End PEP 463 translation - try: - lines = int(os.environ['LINES']) - except (KeyError, ValueError): - lines = 0 + # PEP 463 automated translation: + lines = (int(os.environ['LINES']) except (KeyError, ValueError): 0) + # try: + # lines = int(os.environ['LINES']) + # except (KeyError, ValueError): + # lines = 0 + # End PEP 463 translation # only query if necessary if columns <= 0 or lines <= 0: - try: - size = os.get_terminal_size(sys.__stdout__.fileno()) - except (NameError, OSError): - size = os.terminal_size(fallback) + # PEP 463 automated translation: + size = (os.get_terminal_size(sys.__stdout__.fileno()) except (NameError, OSError): os.terminal_size(fallback)) + # try: + # size = os.get_terminal_size(sys.__stdout__.fileno()) + # except (NameError, OSError): + # size = os.terminal_size(fallback) + # End PEP 463 translation if columns <= 0: columns = size.columns if lines <= 0: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/socket.py --- a/Lib/socket.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/socket.py Fri Feb 28 04:50:15 2014 +1100 @@ -313,10 +313,13 @@ AF_UNIX if defined on the platform; otherwise, the default is AF_INET. """ if family is None: - try: - family = AF_UNIX - except NameError: - family = AF_INET + # PEP 463 automated translation: + family = (AF_UNIX except NameError: AF_INET) + # try: + # family = AF_UNIX + # except NameError: + # family = AF_INET + # End PEP 463 translation a, b = _socket.socketpair(family, type, proto) a = socket(family, type, proto, a.detach()) b = socket(family, type, proto, b.detach()) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/statistics.py --- a/Lib/statistics.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/statistics.py Fri Feb 28 04:50:15 2014 +1100 @@ -397,11 +397,14 @@ for obj in (x, interval): if isinstance(obj, (str, bytes)): raise TypeError('expected number but got %r' % obj) - try: - L = x - interval/2 # The lower limit of the median interval. - except TypeError: - # Mixed type. For now we just coerce to float. - L = float(x) - float(interval)/2 + # PEP 463 automated translation: + L = ((x - (interval / 2)) except TypeError: (float(x) - (float(interval) / 2))) + # try: + # L = x - interval/2 # The lower limit of the median interval. + # except TypeError: + # # Mixed type. For now we just coerce to float. + # L = float(x) - float(interval)/2 + # End PEP 463 translation cf = data.index(x) # Number of values below the median interval. # FIXME The following line could be more efficient for big lists. f = data.count(x) # Number of data points in the median interval. diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/subprocess.py --- a/Lib/subprocess.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/subprocess.py Fri Feb 28 04:50:15 2014 +1100 @@ -456,10 +456,13 @@ __del__ = Close __str__ = __repr__ -try: - MAXFD = os.sysconf("SC_OPEN_MAX") -except: - MAXFD = 256 +# PEP 463 automated translation: +MAXFD = (os.sysconf('SC_OPEN_MAX') except BaseException: 256) +# try: +# MAXFD = os.sysconf("SC_OPEN_MAX") +# except: +# MAXFD = 256 +# End PEP 463 translation # This lists holds Popen instances for which the underlying process had not # exited at the time its __del__ method got called: those processes are wait()ed diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/sunau.py --- a/Lib/sunau.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/sunau.py Fri Feb 28 04:50:15 2014 +1100 @@ -216,10 +216,13 @@ break else: self._info = '' - try: - self._data_pos = file.tell() - except (AttributeError, OSError): - self._data_pos = None + # PEP 463 automated translation: + self._data_pos = (file.tell() except (AttributeError, OSError): None) + # try: + # self._data_pos = file.tell() + # except (AttributeError, OSError): + # self._data_pos = None + # End PEP 463 translation def getfp(self): return self._file @@ -489,10 +492,13 @@ length = AUDIO_UNKNOWN_SIZE else: length = self._nframes * self._framesize - try: - self._form_length_pos = self._file.tell() - except (AttributeError, OSError): - self._form_length_pos = None + # PEP 463 automated translation: + self._form_length_pos = (self._file.tell() except (AttributeError, OSError): None) + # try: + # self._form_length_pos = self._file.tell() + # except (AttributeError, OSError): + # self._form_length_pos = None + # End PEP 463 translation _write_u32(self._file, length) self._datalength = length _write_u32(self._file, encoding) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/sysconfig.py --- a/Lib/sysconfig.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/sysconfig.py Fri Feb 28 04:50:15 2014 +1100 @@ -526,11 +526,14 @@ _CONFIG_VARS['installed_platbase'] = _BASE_EXEC_PREFIX _CONFIG_VARS['platbase'] = _EXEC_PREFIX _CONFIG_VARS['projectbase'] = _PROJECT_BASE - try: - _CONFIG_VARS['abiflags'] = sys.abiflags - except AttributeError: - # sys.abiflags may not be defined on all platforms. - _CONFIG_VARS['abiflags'] = '' + # PEP 463 automated translation: + _CONFIG_VARS['abiflags'] = (sys.abiflags except AttributeError: '') + # try: + # _CONFIG_VARS['abiflags'] = sys.abiflags + # except AttributeError: + # # sys.abiflags may not be defined on all platforms. + # _CONFIG_VARS['abiflags'] = '' + # End PEP 463 translation if os.name == 'nt': _init_non_posix(_CONFIG_VARS) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/tarfile.py --- a/Lib/tarfile.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/tarfile.py Fri Feb 28 04:50:15 2014 +1100 @@ -1325,10 +1325,13 @@ setattr(self, "size", int(value)) elif keyword in PAX_FIELDS: if keyword in PAX_NUMBER_FIELDS: - try: - value = PAX_NUMBER_FIELDS[keyword](value) - except ValueError: - value = 0 + # PEP 463 automated translation: + value = (PAX_NUMBER_FIELDS[keyword](value) except ValueError: 0) + # try: + # value = PAX_NUMBER_FIELDS[keyword](value) + # except ValueError: + # value = 0 + # End PEP 463 translation if keyword == "path": value = value.rstrip("/") setattr(self, keyword, value) @@ -2195,14 +2198,20 @@ """ if pwd and hasattr(os, "geteuid") and os.geteuid() == 0: # We have to be root to do so. - try: - g = grp.getgrnam(tarinfo.gname)[2] - except KeyError: - g = tarinfo.gid - try: - u = pwd.getpwnam(tarinfo.uname)[2] - except KeyError: - u = tarinfo.uid + # PEP 463 automated translation: + g = (grp.getgrnam(tarinfo.gname)[2] except KeyError: tarinfo.gid) + # try: + # g = grp.getgrnam(tarinfo.gname)[2] + # except KeyError: + # g = tarinfo.gid + # End PEP 463 translation + # PEP 463 automated translation: + u = (pwd.getpwnam(tarinfo.uname)[2] except KeyError: tarinfo.uid) + # try: + # u = pwd.getpwnam(tarinfo.uname)[2] + # except KeyError: + # u = tarinfo.uid + # End PEP 463 translation try: if tarinfo.issym() and hasattr(os, "lchown"): os.lchown(targetpath, u, g) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/telnetlib.py --- a/Lib/telnetlib.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/telnetlib.py Fri Feb 28 04:50:15 2014 +1100 @@ -658,10 +658,13 @@ port = 0 if sys.argv[2:]: portstr = sys.argv[2] - try: - port = int(portstr) - except ValueError: - port = socket.getservbyname(portstr, 'tcp') + # PEP 463 automated translation: + port = (int(portstr) except ValueError: socket.getservbyname(portstr, 'tcp')) + # try: + # port = int(portstr) + # except ValueError: + # port = socket.getservbyname(portstr, 'tcp') + # End PEP 463 translation tn = Telnet() tn.set_debuglevel(debuglevel) tn.open(host, port, timeout=0.5) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/threading.py --- a/Lib/threading.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/threading.py Fri Feb 28 04:50:15 2014 +1100 @@ -36,10 +36,13 @@ _set_sentinel = _thread._set_sentinel get_ident = _thread.get_ident ThreadError = _thread.error -try: - _CRLock = _thread.RLock -except AttributeError: - _CRLock = None +# PEP 463 automated translation: +_CRLock = (_thread.RLock except AttributeError: None) +# try: +# _CRLock = _thread.RLock +# except AttributeError: +# _CRLock = None +# End PEP 463 translation TIMEOUT_MAX = _thread.TIMEOUT_MAX del _thread diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/tkinter/__init__.py Fri Feb 28 04:50:15 2014 +1100 @@ -1219,16 +1219,22 @@ e.keysym = K e.keysym_num = getint_event(N) e.type = T - try: - e.widget = self._nametowidget(W) - except KeyError: - e.widget = W + # PEP 463 automated translation: + e.widget = (self._nametowidget(W) except KeyError: W) + # try: + # e.widget = self._nametowidget(W) + # except KeyError: + # e.widget = W + # End PEP 463 translation e.x_root = getint_event(X) e.y_root = getint_event(Y) - try: - e.delta = getint(D) - except ValueError: - e.delta = 0 + # PEP 463 automated translation: + e.delta = (getint(D) except ValueError: 0) + # try: + # e.delta = getint(D) + # except ValueError: + # e.delta = 0 + # End PEP 463 translation return (e,) def _report_exception(self): """Internal function.""" diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/tkinter/filedialog.py --- a/Lib/tkinter/filedialog.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/tkinter/filedialog.py Fri Feb 28 04:50:15 2014 +1100 @@ -207,10 +207,13 @@ def set_filter(self, dir, pat): if not os.path.isabs(dir): - try: - pwd = os.getcwd() - except OSError: - pwd = None + # PEP 463 automated translation: + pwd = (os.getcwd() except OSError: None) + # try: + # pwd = os.getcwd() + # except OSError: + # pwd = None + # End PEP 463 translation if pwd: dir = os.path.join(pwd, dir) dir = os.path.normpath(dir) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/tokenize.py --- a/Lib/tokenize.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/tokenize.py Fri Feb 28 04:50:15 2014 +1100 @@ -348,10 +348,13 @@ If no encoding is specified, then the default of 'utf-8' will be returned. """ - try: - filename = readline.__self__.name - except AttributeError: - filename = None + # PEP 463 automated translation: + filename = (readline.__self__.name except AttributeError: None) + # try: + # filename = readline.__self__.name + # except AttributeError: + # filename = None + # End PEP 463 translation bom_found = False encoding = None default = 'utf-8' @@ -477,10 +480,13 @@ encoding = "utf-8" yield TokenInfo(ENCODING, encoding, (0, 0), (0, 0), '') while True: # loop over lines in stream - try: - line = readline() - except StopIteration: - line = b'' + # PEP 463 automated translation: + line = (readline() except StopIteration: b'') + # try: + # line = readline() + # except StopIteration: + # line = b'' + # End PEP 463 translation if encoding is not None: line = line.decode(encoding) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/unittest/case.py --- a/Lib/unittest/case.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/unittest/case.py Fri Feb 28 04:50:15 2014 +1100 @@ -137,10 +137,13 @@ self.expected = expected self.test_case = test_case if callable_obj is not None: - try: - self.obj_name = callable_obj.__name__ - except AttributeError: - self.obj_name = str(callable_obj) + # PEP 463 automated translation: + self.obj_name = (callable_obj.__name__ except AttributeError: str(callable_obj)) + # try: + # self.obj_name = callable_obj.__name__ + # except AttributeError: + # self.obj_name = str(callable_obj) + # End PEP 463 translation else: self.obj_name = None if isinstance(expected_regex, (bytes, str)): @@ -169,10 +172,13 @@ def __exit__(self, exc_type, exc_value, tb): if exc_type is None: - try: - exc_name = self.expected.__name__ - except AttributeError: - exc_name = str(self.expected) + # PEP 463 automated translation: + exc_name = (self.expected.__name__ except AttributeError: str(self.expected)) + # try: + # exc_name = self.expected.__name__ + # except AttributeError: + # exc_name = str(self.expected) + # End PEP 463 translation if self.obj_name: self._raiseFailure("{} not raised by {}".format(exc_name, self.obj_name)) @@ -212,10 +218,13 @@ if exc_type is not None: # let unexpected exceptions pass through return - try: - exc_name = self.expected.__name__ - except AttributeError: - exc_name = str(self.expected) + # PEP 463 automated translation: + exc_name = (self.expected.__name__ except AttributeError: str(self.expected)) + # try: + # exc_name = self.expected.__name__ + # except AttributeError: + # exc_name = str(self.expected) + # End PEP 463 translation first_matching = None for m in self.warnings: w = m.message @@ -949,21 +958,27 @@ if len1 > len2: differing += ('\nFirst %s contains %d additional ' 'elements.\n' % (seq_type_name, len1 - len2)) - try: - differing += ('First extra element %d:\n%s\n' % - (len2, seq1[len2])) - except (TypeError, IndexError, NotImplementedError): - differing += ('Unable to index element %d ' - 'of first %s\n' % (len2, seq_type_name)) + # PEP 463 automated translation: + differing += (('First extra element %d:\n%s\n' % (len2, seq1[len2])) except (TypeError, IndexError, NotImplementedError): ('Unable to index element %d of first %s\n' % (len2, seq_type_name))) + # try: + # differing += ('First extra element %d:\n%s\n' % + # (len2, seq1[len2])) + # except (TypeError, IndexError, NotImplementedError): + # differing += ('Unable to index element %d ' + # 'of first %s\n' % (len2, seq_type_name)) + # End PEP 463 translation elif len1 < len2: differing += ('\nSecond %s contains %d additional ' 'elements.\n' % (seq_type_name, len2 - len1)) - try: - differing += ('First extra element %d:\n%s\n' % - (len1, seq2[len1])) - except (TypeError, IndexError, NotImplementedError): - differing += ('Unable to index element %d ' - 'of second %s\n' % (len1, seq_type_name)) + # PEP 463 automated translation: + differing += (('First extra element %d:\n%s\n' % (len1, seq2[len1])) except (TypeError, IndexError, NotImplementedError): ('Unable to index element %d of second %s\n' % (len1, seq_type_name))) + # try: + # differing += ('First extra element %d:\n%s\n' % + # (len1, seq2[len1])) + # except (TypeError, IndexError, NotImplementedError): + # differing += ('Unable to index element %d ' + # 'of second %s\n' % (len1, seq_type_name)) + # End PEP 463 translation standardMsg = differing diffMsg = '\n' + '\n'.join( difflib.ndiff(pprint.pformat(seq1).splitlines(), diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/unittest/loader.py --- a/Lib/unittest/loader.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/unittest/loader.py Fri Feb 28 04:50:15 2014 +1100 @@ -221,10 +221,13 @@ os.path.dirname((the_module.__file__))) except AttributeError: # look for namespace packages - try: - spec = the_module.__spec__ - except AttributeError: - spec = None + # PEP 463 automated translation: + spec = (the_module.__spec__ except AttributeError: None) + # try: + # spec = the_module.__spec__ + # except AttributeError: + # spec = None + # End PEP 463 translation if spec and spec.loader is None: if spec.submodule_search_locations is not None: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/unittest/main.py --- a/Lib/unittest/main.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/unittest/main.py Fri Feb 28 04:50:15 2014 +1100 @@ -230,14 +230,17 @@ if self.testRunner is None: self.testRunner = runner.TextTestRunner if isinstance(self.testRunner, type): - try: - testRunner = self.testRunner(verbosity=self.verbosity, - failfast=self.failfast, - buffer=self.buffer, - warnings=self.warnings) - except TypeError: - # didn't accept the verbosity, buffer or failfast arguments - testRunner = self.testRunner() + # PEP 463 automated translation: + testRunner = (self.testRunner(verbosity=self.verbosity, failfast=self.failfast, buffer=self.buffer, warnings=self.warnings) except TypeError: self.testRunner()) + # try: + # testRunner = self.testRunner(verbosity=self.verbosity, + # failfast=self.failfast, + # buffer=self.buffer, + # warnings=self.warnings) + # except TypeError: + # # didn't accept the verbosity, buffer or failfast arguments + # testRunner = self.testRunner() + # End PEP 463 translation else: # it is assumed to be a TestRunner instance testRunner = self.testRunner diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/unittest/mock.py Fri Feb 28 04:50:15 2014 +1100 @@ -1734,12 +1734,15 @@ return_calulator = _calculate_return_value.get(name) if return_calulator is not None: - try: - return_value = return_calulator(mock) - except AttributeError: - # XXXX why do we return AttributeError here? - # set it as a side_effect instead? - return_value = AttributeError(name) + # PEP 463 automated translation: + return_value = (return_calulator(mock) except AttributeError: AttributeError(name)) + # try: + # return_value = return_calulator(mock) + # except AttributeError: + # # XXXX why do we return AttributeError here? + # # set it as a side_effect instead? + # return_value = AttributeError(name) + # End PEP 463 translation method.return_value = return_value return diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/unittest/util.py --- a/Lib/unittest/util.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/unittest/util.py Fri Feb 28 04:50:15 2014 +1100 @@ -43,10 +43,13 @@ for s in args) def safe_repr(obj, short=False): - try: - result = repr(obj) - except Exception: - result = object.__repr__(obj) + # PEP 463 automated translation: + result = (repr(obj) except Exception: object.__repr__(obj)) + # try: + # result = repr(obj) + # except Exception: + # result = object.__repr__(obj) + # End PEP 463 translation if not short or len(result) < _MAX_LENGTH: return result return result[:_MAX_LENGTH] + ' [truncated]...' diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/urllib/parse.py Fri Feb 28 04:50:15 2014 +1100 @@ -921,10 +921,13 @@ if match: host, port = match.group(1, 2) if port: - try: - nport = int(port) - except ValueError: - nport = None + # PEP 463 automated translation: + nport = (int(port) except ValueError: None) + # try: + # nport = int(port) + # except ValueError: + # nport = None + # End PEP 463 translation return host, nport return host, defport diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/urllib/request.py --- a/Lib/urllib/request.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/urllib/request.py Fri Feb 28 04:50:15 2014 +1100 @@ -1370,12 +1370,15 @@ names = None def get_names(self): if FileHandler.names is None: - try: - FileHandler.names = tuple( - socket.gethostbyname_ex('localhost')[2] + - socket.gethostbyname_ex(socket.gethostname())[2]) - except socket.gaierror: - FileHandler.names = (socket.gethostbyname('localhost'),) + # PEP 463 automated translation: + FileHandler.names = (tuple((socket.gethostbyname_ex('localhost')[2] + socket.gethostbyname_ex(socket.gethostname())[2])) except socket.gaierror: (socket.gethostbyname('localhost'),)) + # try: + # FileHandler.names = tuple( + # socket.gethostbyname_ex('localhost')[2] + + # socket.gethostbyname_ex(socket.gethostname())[2]) + # except socket.gaierror: + # FileHandler.names = (socket.gethostbyname('localhost'),) + # End PEP 463 translation return FileHandler.names # not entirely sure what the rules are here @@ -2252,10 +2255,13 @@ """Return the IP addresses of the current host.""" global _thishost if _thishost is None: - try: - _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2]) - except socket.gaierror: - _thishost = tuple(socket.gethostbyname_ex('localhost')[2]) + # PEP 463 automated translation: + _thishost = (tuple(socket.gethostbyname_ex(socket.gethostname())[2]) except socket.gaierror: tuple(socket.gethostbyname_ex('localhost')[2])) + # try: + # _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2]) + # except socket.gaierror: + # _thishost = tuple(socket.gethostbyname_ex('localhost')[2]) + # End PEP 463 translation return _thishost _ftperrors = None diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/uuid.py --- a/Lib/uuid.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/uuid.py Fri Feb 28 04:50:15 2014 +1100 @@ -463,10 +463,13 @@ # 6 bytes returned by UuidCreateSequential are fixed, they don't appear # to bear any relationship to the MAC address of any network device # on the box. - try: - lib = ctypes.windll.rpcrt4 - except: - lib = None + # PEP 463 automated translation: + lib = (ctypes.windll.rpcrt4 except BaseException: None) + # try: + # lib = ctypes.windll.rpcrt4 + # except: + # lib = None + # End PEP 463 translation _UuidCreate = getattr(lib, 'UuidCreateSequential', getattr(lib, 'UuidCreate', None)) except: diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/warnings.py --- a/Lib/warnings.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/warnings.py Fri Feb 28 04:50:15 2014 +1100 @@ -183,11 +183,14 @@ filename = filename[:-1] else: if module == "__main__": - try: - filename = sys.argv[0] - except AttributeError: - # embedded interpreters don't have sys.argv, see bug #839151 - filename = '__main__' + # PEP 463 automated translation: + filename = (sys.argv[0] except AttributeError: '__main__') + # try: + # filename = sys.argv[0] + # except AttributeError: + # # embedded interpreters don't have sys.argv, see bug #839151 + # filename = '__main__' + # End PEP 463 translation if not filename: filename = module registry = globals.setdefault("__warningregistry__", {}) diff -r 59d37fbf71cd -r 6417a32c5df9 Lib/wave.py --- a/Lib/wave.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Lib/wave.py Fri Feb 28 04:50:15 2014 +1100 @@ -460,10 +460,13 @@ if not self._nframes: self._nframes = initlength // (self._nchannels * self._sampwidth) self._datalength = self._nframes * self._nchannels * self._sampwidth - try: - self._form_length_pos = self._file.tell() - except (AttributeError, OSError): - self._form_length_pos = None + # PEP 463 automated translation: + self._form_length_pos = (self._file.tell() except (AttributeError, OSError): None) + # try: + # self._form_length_pos = self._file.tell() + # except (AttributeError, OSError): + # self._form_length_pos = None + # End PEP 463 translation self._file.write(struct.pack('') + # try: + # line = self[first] + # except KeyError: + # line = "" + # End PEP 463 translation print(mark, chop(line)) def scanline(g): diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/scripts/ftpmirror.py --- a/Tools/scripts/ftpmirror.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/scripts/ftpmirror.py Fri Feb 28 04:50:15 2014 +1100 @@ -310,10 +310,13 @@ # Helper to remove a file or directory tree def remove(fullname): if os.path.isdir(fullname) and not os.path.islink(fullname): - try: - names = os.listdir(fullname) - except OSError: - names = [] + # PEP 463 automated translation: + names = (os.listdir(fullname) except OSError: []) + # try: + # names = os.listdir(fullname) + # except OSError: + # names = [] + # End PEP 463 translation ok = 1 for name in names: if not remove(os.path.join(fullname, name)): diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/scripts/treesync.py --- a/Tools/scripts/treesync.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/scripts/treesync.py Fri Feb 28 04:50:15 2014 +1100 @@ -107,14 +107,20 @@ process(s, m) def compare(slave, master): - try: - sf = open(slave, 'r') - except IOError: - sf = None - try: - mf = open(master, 'rb') - except IOError: - mf = None + # PEP 463 automated translation: + sf = (open(slave, 'r') except IOError: None) + # try: + # sf = open(slave, 'r') + # except IOError: + # sf = None + # End PEP 463 translation + # PEP 463 automated translation: + mf = (open(master, 'rb') except IOError: None) + # try: + # mf = open(master, 'rb') + # except IOError: + # mf = None + # End PEP 463 translation if not sf: if not mf: print("Neither master nor slave exists", master) diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/scripts/win_add2path.py --- a/Tools/scripts/win_add2path.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/scripts/win_add2path.py Fri Feb 28 04:50:15 2014 +1100 @@ -28,10 +28,13 @@ userscripts = None with winreg.CreateKey(HKCU, ENV) as key: - try: - envpath = winreg.QueryValueEx(key, PATH)[0] - except OSError: - envpath = DEFAULT + # PEP 463 automated translation: + envpath = (winreg.QueryValueEx(key, PATH)[0] except OSError: DEFAULT) + # try: + # envpath = winreg.QueryValueEx(key, PATH)[0] + # except OSError: + # envpath = DEFAULT + # End PEP 463 translation paths = [envpath] for path in (pythonpath, scripts, userscripts): diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/stringbench/stringbench.py --- a/Tools/stringbench/stringbench.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/stringbench/stringbench.py Fri Feb 28 04:50:15 2014 +1100 @@ -1459,10 +1459,13 @@ uni_total += uni_time except UnsupportedType: uni_time_s = "N/A" - try: - average = bytes_time/uni_time - except (TypeError, ZeroDivisionError): - average = 0.0 + # PEP 463 automated translation: + average = ((bytes_time / uni_time) except (TypeError, ZeroDivisionError): 0.0) + # try: + # average = bytes_time/uni_time + # except (TypeError, ZeroDivisionError): + # average = 0.0 + # End PEP 463 translation p("%s\t%s\t%.1f\t%s (*%d)" % ( bytes_time_s, uni_time_s, 100.*average, v.comment, v.repeat_count)) @@ -1470,10 +1473,13 @@ if bytes_total == uni_total == 0.0: p("That was zippy!") else: - try: - ratio = bytes_total/uni_total - except ZeroDivisionError: - ratio = 0.0 + # PEP 463 automated translation: + ratio = ((bytes_total / uni_total) except ZeroDivisionError: 0.0) + # try: + # ratio = bytes_total/uni_total + # except ZeroDivisionError: + # ratio = 0.0 + # End PEP 463 translation p("%.2f\t%.2f\t%.1f\t%s" % ( 1000*bytes_total, 1000*uni_total, 100.*ratio, "TOTAL")) diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/unicode/comparecodecs.py --- a/Tools/unicode/comparecodecs.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/unicode/comparecodecs.py Fri Feb 28 04:50:15 2014 +1100 @@ -31,14 +31,20 @@ # Check decoding for i in range(256): c = bytes([i]) - try: - u1 = c.decode(encoding1) - except UnicodeError: - u1 = '' - try: - u2 = c.decode(encoding2) - except UnicodeError: - u2 = '' + # PEP 463 automated translation: + u1 = (c.decode(encoding1) except UnicodeError: '') + # try: + # u1 = c.decode(encoding1) + # except UnicodeError: + # u1 = '' + # End PEP 463 translation + # PEP 463 automated translation: + u2 = (c.decode(encoding2) except UnicodeError: '') + # try: + # u2 = c.decode(encoding2) + # except UnicodeError: + # u2 = '' + # End PEP 463 translation if u1 != u2: print(' * decoding mismatch for 0x%04X: %-14r != %r' % \ (i, u1, u2)) diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/unicode/gencodec.py --- a/Tools/unicode/gencodec.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/unicode/gencodec.py Fri Feb 28 04:50:15 2014 +1100 @@ -60,10 +60,13 @@ if len(l) == 1: return int(l[0],16) for i in range(len(l)): - try: - l[i] = int(l[i],16) - except ValueError: - l[i] = MISSING_CODE + # PEP 463 automated translation: + l[i] = (int(l[i], 16) except ValueError: MISSING_CODE) + # try: + # l[i] = int(l[i],16) + # except ValueError: + # l[i] = MISSING_CODE + # End PEP 463 translation l = [x for x in l if x != MISSING_CODE] if len(l) == 1: return l[0] diff -r 59d37fbf71cd -r 6417a32c5df9 Tools/unicode/genwincodec.py --- a/Tools/unicode/genwincodec.py Fri Feb 28 04:30:49 2014 +1100 +++ b/Tools/unicode/genwincodec.py Fri Feb 28 04:50:15 2014 +1100 @@ -31,10 +31,13 @@ try: name = unicodedata.name(buf[0]) except ValueError: - try: - name = enc2uni[i][1] - except KeyError: - name = '' + # PEP 463 automated translation: + name = (enc2uni[i][1] except KeyError: '') + # try: + # name = enc2uni[i][1] + # except KeyError: + # name = '' + # End PEP 463 translation enc2uni[i] = (ord(buf[0]), name)