Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/util.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 | c2ec81891502 |
children | d5ac3bebaf2a |
comparison
equal
deleted
inserted
replaced
25659:d60678a567a9 | 25660:328739ea70c3 |
---|---|
814 os.symlink(os.readlink(src), dest) | 814 os.symlink(os.readlink(src), dest) |
815 else: | 815 else: |
816 try: | 816 try: |
817 shutil.copyfile(src, dest) | 817 shutil.copyfile(src, dest) |
818 shutil.copymode(src, dest) | 818 shutil.copymode(src, dest) |
819 except shutil.Error, inst: | 819 except shutil.Error as inst: |
820 raise Abort(str(inst)) | 820 raise Abort(str(inst)) |
821 | 821 |
822 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): | 822 def copyfiles(src, dst, hardlink=None, progress=lambda t, pos: None): |
823 """Copy a directory tree using hardlinks if possible.""" | 823 """Copy a directory tree using hardlinks if possible.""" |
824 num = 0 | 824 num = 0 |
913 checkosfilename = platform.checkosfilename | 913 checkosfilename = platform.checkosfilename |
914 | 914 |
915 def makelock(info, pathname): | 915 def makelock(info, pathname): |
916 try: | 916 try: |
917 return os.symlink(info, pathname) | 917 return os.symlink(info, pathname) |
918 except OSError, why: | 918 except OSError as why: |
919 if why.errno == errno.EEXIST: | 919 if why.errno == errno.EEXIST: |
920 raise | 920 raise |
921 except AttributeError: # no symlink in os | 921 except AttributeError: # no symlink in os |
922 pass | 922 pass |
923 | 923 |
926 os.close(ld) | 926 os.close(ld) |
927 | 927 |
928 def readlock(pathname): | 928 def readlock(pathname): |
929 try: | 929 try: |
930 return os.readlink(pathname) | 930 return os.readlink(pathname) |
931 except OSError, why: | 931 except OSError as why: |
932 if why.errno not in (errno.EINVAL, errno.ENOSYS): | 932 if why.errno not in (errno.EINVAL, errno.ENOSYS): |
933 raise | 933 raise |
934 except AttributeError: # no symlink in os | 934 except AttributeError: # no symlink in os |
935 pass | 935 pass |
936 fp = posixfile(pathname) | 936 fp = posixfile(pathname) |
1143 if emptyok: | 1143 if emptyok: |
1144 return temp | 1144 return temp |
1145 try: | 1145 try: |
1146 try: | 1146 try: |
1147 ifp = posixfile(name, "rb") | 1147 ifp = posixfile(name, "rb") |
1148 except IOError, inst: | 1148 except IOError as inst: |
1149 if inst.errno == errno.ENOENT: | 1149 if inst.errno == errno.ENOENT: |
1150 return temp | 1150 return temp |
1151 if not getattr(inst, 'filename', None): | 1151 if not getattr(inst, 'filename', None): |
1152 inst.filename = name | 1152 inst.filename = name |
1153 raise | 1153 raise |
1202 | 1202 |
1203 def makedirs(name, mode=None, notindexed=False): | 1203 def makedirs(name, mode=None, notindexed=False): |
1204 """recursive directory creation with parent mode inheritance""" | 1204 """recursive directory creation with parent mode inheritance""" |
1205 try: | 1205 try: |
1206 makedir(name, notindexed) | 1206 makedir(name, notindexed) |
1207 except OSError, err: | 1207 except OSError as err: |
1208 if err.errno == errno.EEXIST: | 1208 if err.errno == errno.EEXIST: |
1209 return | 1209 return |
1210 if err.errno != errno.ENOENT or not name: | 1210 if err.errno != errno.ENOENT or not name: |
1211 raise | 1211 raise |
1212 parent = os.path.dirname(os.path.abspath(name)) | 1212 parent = os.path.dirname(os.path.abspath(name)) |
1229 parent = os.path.dirname(os.path.abspath(name)) | 1229 parent = os.path.dirname(os.path.abspath(name)) |
1230 if parent != name: | 1230 if parent != name: |
1231 ensuredirs(parent, mode, notindexed) | 1231 ensuredirs(parent, mode, notindexed) |
1232 try: | 1232 try: |
1233 makedir(name, notindexed) | 1233 makedir(name, notindexed) |
1234 except OSError, err: | 1234 except OSError as err: |
1235 if err.errno == errno.EEXIST and os.path.isdir(name): | 1235 if err.errno == errno.EEXIST and os.path.isdir(name): |
1236 # someone else seems to have won a directory creation race | 1236 # someone else seems to have won a directory creation race |
1237 return | 1237 return |
1238 raise | 1238 raise |
1239 if mode is not None: | 1239 if mode is not None: |