From: Zooko O'Whielacronx Date: Wed, 17 Dec 2008 00:37:45 +0000 (-0700) Subject: pyutil: assertutil: copy in simplified assertutil from pyutil X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/flags/...?a=commitdiff_plain;h=5fb44a3e798082d99b50216a29e84a430e17f2ee;p=tahoe-lafs%2Ftahoe-lafs.git pyutil: assertutil: copy in simplified assertutil from pyutil --- diff --git a/src/allmydata/util/assertutil.py b/src/allmydata/util/assertutil.py index acd234ff..021c3e62 100644 --- a/src/allmydata/util/assertutil.py +++ b/src/allmydata/util/assertutil.py @@ -1,6 +1,6 @@ # Copyright (c) 2003-2008 Zooko Wilcox-O'Hearn # mailto:zooko@zooko.com -# http://zooko.com/ +# http://zooko.com # Permission is hereby granted, free of charge, to any person obtaining a # copy of this work to deal in this work without restriction (including the # rights to use, modify, distribute, sublicense, and/or sell copies) @@ -27,33 +27,24 @@ def _assert(___cond=False, *___args, **___kwargs): raise AssertionError, "".join(msgbuf) - return False - def precondition(___cond=False, *___args, **___kwargs): - try: - if ___cond: - return True - msgbuf=["precondition", ] - if ___args or ___kwargs: - msgbuf.append(": ") - if ___args: - msgbuf.append("%s %s" % tuple(map(hr, (___args[0], type(___args[0]),)))) - msgbuf.extend([", %s %s" % tuple(map(hr, (arg, type(arg),))) for arg in ___args[1:]]) - if ___kwargs: - msgbuf.append(", %s: %s %s" % ((___kwargs.items()[0][0],) + tuple(map(hr, (___kwargs.items()[0][1], type(___kwargs.items()[0][1]),))))) - else: - if ___kwargs: - msgbuf.append("%s: %s %s" % ((___kwargs.items()[0][0],) + tuple(map(hr, (___kwargs.items()[0][1], type(___kwargs.items()[0][1]),))))) - msgbuf.extend([", %s: %s %s" % tuple(map(hr, (k, v, type(v),))) for k, v in ___kwargs.items()[1:]]) - except: - import logging - logging.exception("assertutil.precondition(): INTERNAL ERROR in allmydata.util.assertutil.") - raise + if ___cond: + return True + msgbuf=["precondition", ] + if ___args or ___kwargs: + msgbuf.append(": ") + if ___args: + msgbuf.append("%s %s" % tuple(map(hr, (___args[0], type(___args[0]),)))) + msgbuf.extend([", %s %s" % tuple(map(hr, (arg, type(arg),))) for arg in ___args[1:]]) + if ___kwargs: + msgbuf.append(", %s: %s %s" % ((___kwargs.items()[0][0],) + tuple(map(hr, (___kwargs.items()[0][1], type(___kwargs.items()[0][1]),))))) + else: + if ___kwargs: + msgbuf.append("%s: %s %s" % ((___kwargs.items()[0][0],) + tuple(map(hr, (___kwargs.items()[0][1], type(___kwargs.items()[0][1]),))))) + msgbuf.extend([", %s: %s %s" % tuple(map(hr, (k, v, type(v),))) for k, v in ___kwargs.items()[1:]]) raise AssertionError, "".join(msgbuf) - return False - def postcondition(___cond=False, *___args, **___kwargs): if ___cond: return True @@ -71,6 +62,3 @@ def postcondition(___cond=False, *___args, **___kwargs): msgbuf.extend([", %s: %s %s" % tuple(map(hr, (k, v, type(v),))) for k, v in ___kwargs.items()[1:]]) raise AssertionError, "".join(msgbuf) - - return False -