Browse Source

Use new style exception handling in a few more places.

Jelmer Vernooij 11 years ago
parent
commit
87303b1590
8 changed files with 24 additions and 24 deletions
  1. 2 2
      dulwich/client.py
  2. 1 1
      dulwich/config.py
  3. 7 7
      dulwich/file.py
  4. 1 1
      dulwich/index.py
  5. 8 8
      dulwich/object_store.py
  6. 1 1
      dulwich/patch.py
  7. 2 2
      dulwich/protocol.py
  8. 2 2
      dulwich/refs.py

+ 2 - 2
dulwich/client.py

@@ -582,7 +582,7 @@ class TCPGitClient(TraditionalGitClient):
             try:
                 s.connect(sockaddr)
                 break
-            except socket.error, err:
+            except socket.error as err:
                 if s is not None:
                     s.close()
                 s = None
@@ -897,7 +897,7 @@ class HttpGitClient(GitClient):
         req = urllib2.Request(url, headers=headers, data=data)
         try:
             resp = self._perform(req)
-        except urllib2.HTTPError, e:
+        except urllib2.HTTPError as e:
             if e.code == 404:
                 raise NotGitRepository()
             if e.code != 200:

+ 1 - 1
dulwich/config.py

@@ -359,7 +359,7 @@ class StackedConfig(Config):
         for path in paths:
             try:
                 cf = ConfigFile.from_path(path)
-            except (IOError, OSError), e:
+            except (IOError, OSError) as e:
                 if e.errno != errno.ENOENT:
                     raise
                 else:

+ 7 - 7
dulwich/file.py

@@ -26,7 +26,7 @@ def ensure_dir_exists(dirname):
     """Ensure a directory exists, creating if necessary."""
     try:
         os.makedirs(dirname)
-    except OSError, e:
+    except OSError as e:
         if e.errno != errno.EEXIST:
             raise
 
@@ -36,7 +36,7 @@ def fancy_rename(oldname, newname):
     if not os.path.exists(newname):
         try:
             os.rename(oldname, newname)
-        except OSError, e:
+        except OSError as e:
             raise
         return
 
@@ -45,17 +45,17 @@ def fancy_rename(oldname, newname):
         (fd, tmpfile) = tempfile.mkstemp(".tmp", prefix=oldname+".", dir=".")
         os.close(fd)
         os.remove(tmpfile)
-    except OSError, e:
+    except OSError as e:
         # either file could not be created (e.g. permission problem)
         # or could not be deleted (e.g. rude virus scanner)
         raise
     try:
         os.rename(newname, tmpfile)
-    except OSError, e:
+    except OSError as e:
         raise   # no rename occurred
     try:
         os.rename(oldname, newname)
-    except OSError, e:
+    except OSError as e:
         os.rename(tmpfile, newname)
         raise
     os.remove(tmpfile)
@@ -123,7 +123,7 @@ class _GitFile(object):
         try:
             os.remove(self._lockfilename)
             self._closed = True
-        except OSError, e:
+        except OSError as e:
             # The file may have been removed already, which is ok.
             if e.errno != errno.ENOENT:
                 raise
@@ -146,7 +146,7 @@ class _GitFile(object):
         try:
             try:
                 os.rename(self._lockfilename, self._filename)
-            except OSError, e:
+            except OSError as e:
                 # Windows versions prior to Vista don't support atomic renames
                 if e.errno != errno.EEXIST:
                     raise

+ 1 - 1
dulwich/index.py

@@ -423,7 +423,7 @@ def build_index_from_tree(prefix, index_path, object_store, tree_id,
             src_path = object_store[entry.sha].as_raw_string()
             try:
                 os.symlink(src_path, full_path)
-            except OSError, e:
+            except OSError as e:
                 if e.errno == errno.EEXIST:
                     os.unlink(full_path)
                     os.symlink(src_path, full_path)

+ 8 - 8
dulwich/object_store.py

@@ -421,7 +421,7 @@ class DiskObjectStore(PackBasedObjectStore):
         try:
             f = GitFile(os.path.join(self.path, "info", "alternates"),
                     'rb')
-        except (OSError, IOError), e:
+        except (OSError, IOError) as e:
             if e.errno == errno.ENOENT:
                 return []
             raise
@@ -444,7 +444,7 @@ class DiskObjectStore(PackBasedObjectStore):
         """
         try:
             os.mkdir(os.path.join(self.path, "info"))
-        except OSError, e:
+        except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
         alternates_path = os.path.join(self.path, "info/alternates")
@@ -452,7 +452,7 @@ class DiskObjectStore(PackBasedObjectStore):
         try:
             try:
                 orig_f = open(alternates_path, 'rb')
-            except (OSError, IOError), e:
+            except (OSError, IOError) as e:
                 if e.errno != errno.ENOENT:
                     raise
             else:
@@ -478,7 +478,7 @@ class DiskObjectStore(PackBasedObjectStore):
                 if name.startswith("pack-") and name.endswith(".pack"):
                     filename = os.path.join(self.pack_dir, name)
                     pack_files.append((os.stat(filename).st_mtime, filename))
-        except OSError, e:
+        except OSError as e:
             if e.errno == errno.ENOENT:
                 return []
             raise
@@ -497,7 +497,7 @@ class DiskObjectStore(PackBasedObjectStore):
     def _pack_cache_stale(self):
         try:
             return os.stat(self.pack_dir).st_mtime > self._pack_cache_time
-        except OSError, e:
+        except OSError as e:
             if e.errno == errno.ENOENT:
                 return True
             raise
@@ -517,7 +517,7 @@ class DiskObjectStore(PackBasedObjectStore):
         path = self._get_shafile_path(sha)
         try:
             return ShaFile.from_path(path)
-        except (OSError, IOError), e:
+        except (OSError, IOError) as e:
             if e.errno == errno.ENOENT:
                 return None
             raise
@@ -663,7 +663,7 @@ class DiskObjectStore(PackBasedObjectStore):
         dir = os.path.join(self.path, obj.id[:2])
         try:
             os.mkdir(dir)
-        except OSError, e:
+        except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
         path = os.path.join(dir, obj.id[2:])
@@ -679,7 +679,7 @@ class DiskObjectStore(PackBasedObjectStore):
     def init(cls, path):
         try:
             os.mkdir(path)
-        except OSError, e:
+        except OSError as e:
             if e.errno != errno.EEXIST:
                 raise
         os.mkdir(os.path.join(path, "info"))

+ 1 - 1
dulwich/patch.py

@@ -52,7 +52,7 @@ def write_commit_patch(f, commit, contents, progress, version=None):
         import subprocess
         p = subprocess.Popen(["diffstat"], stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE)
-    except (ImportError, OSError), e:
+    except (ImportError, OSError):
         pass # diffstat not available?
     else:
         (diffstat, _) = p.communicate(contents)

+ 2 - 2
dulwich/protocol.py

@@ -109,7 +109,7 @@ class Protocol(object):
             if self.report_activity:
                 self.report_activity(size, 'read')
             return read(size-4)
-        except socket.error, e:
+        except socket.error as e:
             raise GitProtocolError(e)
 
     def eof(self):
@@ -160,7 +160,7 @@ class Protocol(object):
             self.write(line)
             if self.report_activity:
                 self.report_activity(len(line), 'write')
-        except socket.error, e:
+        except socket.error as e:
             raise GitProtocolError(e)
 
     def write_file(self):

+ 2 - 2
dulwich/refs.py

@@ -442,7 +442,7 @@ class DiskRefsContainer(RefsContainer):
             path = os.path.join(self.path, 'packed-refs')
             try:
                 f = GitFile(path, 'rb')
-            except IOError, e:
+            except IOError as e:
                 if e.errno == errno.ENOENT:
                     return {}
                 raise
@@ -504,7 +504,7 @@ class DiskRefsContainer(RefsContainer):
                     return header + f.read(40 - len(SYMREF))
             finally:
                 f.close()
-        except IOError, e:
+        except IOError as e:
             if e.errno == errno.ENOENT:
                 return None
             raise