diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-22 19:10:33 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-08-22 19:10:33 +0900 |
commit | 2c300e209d3842ae7cd6dd57c942d6bca8986948 (patch) | |
tree | 88d98737d43354eb47d16833dcf911dc02d0449f /sphinx/util/osutil.py | |
parent | c6cb0b667fb9a01e2c72d2cf06927a6600ad5edf (diff) | |
download | sphinx-git-2c300e209d3842ae7cd6dd57c942d6bca8986948.tar.gz |
Refactor FileAvoidWrite
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index a78eeb98c..df3e03431 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -262,18 +262,12 @@ class FileAvoidWrite(object): old_content = None try: - old_f = open(self._path, r_mode) - except IOError: - pass - else: - try: + with open(self._path, r_mode) as old_f: old_content = old_f.read() if old_content == buf: return - except IOError: - pass - finally: - old_f.close() + except IOError: + pass with open(self._path, w_mode) as f: f.write(buf) |