]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
pyutil: fileutil.open_or_create()
authorZooko O'Whielacronx <zooko@zooko.com>
Wed, 18 Apr 2007 03:14:26 +0000 (20:14 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Wed, 18 Apr 2007 03:14:26 +0000 (20:14 -0700)
src/allmydata/util/fileutil.py

index ddb111eaf6973aadaa89e276e79fc5d8c1aaa899..25ad9761f8636a56759bd0aec6e2332082abfc65 100644 (file)
@@ -178,3 +178,9 @@ def remove_if_possible(f):
         remove(f)
     except:
         pass
+
+def open_or_create(fname, binarymode=True):
+    try:
+        return open(fname, binarymode and "r+b" or "r+")
+    except EnvironmentError:
+        return open(fname, binarymode and "w+b" or "w+")