From: Zooko O'Whielacronx Date: Wed, 18 Apr 2007 03:14:26 +0000 (-0700) Subject: pyutil: fileutil.open_or_create() X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~80 X-Git-Url: https://git.rkrishnan.org/running.html?a=commitdiff_plain;h=723f4078a3b2dc299a5864c7e59a77d428ff6a66;p=tahoe-lafs%2Ftahoe-lafs.git pyutil: fileutil.open_or_create() --- diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py index ddb111ea..25ad9761 100644 --- a/src/allmydata/util/fileutil.py +++ b/src/allmydata/util/fileutil.py @@ -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+")