[Python-modules-commits] r11605 - in packages/python-whisper/trunk/debian (3 files)
statik-guest at users.alioth.debian.org
statik-guest at users.alioth.debian.org
Sun Feb 7 03:46:21 UTC 2010
Date: Sunday, February 7, 2010 @ 03:46:19
Author: statik-guest
Revision: 11605
Add a patch that converts assertions to exceptions.
This patch has been forwarded upstream and tagged.
Added:
packages/python-whisper/trunk/debian/patches/
packages/python-whisper/trunk/debian/patches/cleanup-assertions
packages/python-whisper/trunk/debian/patches/series
Added: packages/python-whisper/trunk/debian/patches/cleanup-assertions
===================================================================
--- packages/python-whisper/trunk/debian/patches/cleanup-assertions (rev 0)
+++ packages/python-whisper/trunk/debian/patches/cleanup-assertions 2010-02-07 03:46:19 UTC (rev 11605)
@@ -0,0 +1,90 @@
+Description: Convert some asserts to exceptions instead.
+Forwarded: https://code.launchpad.net/~statik/graphite/cleanup-assertions/+merge/18780
+Author: Elliot Murphy <elliot at ubuntu.com>
+Last-Update: 2010-02-06
+=== modified file 'whisper/whisper.py'
+--- whisper/whisper.py 2009-11-02 06:47:51 +0000
++++ whisper/whisper.py 2010-02-07 03:26:22 +0000
+@@ -53,6 +53,23 @@
+
+ debug = startBlock = endBlock = lambda *a,**k: None
+
++
++class WhisperException(Exception):
++ """Base class for whisper exceptions."""
++
++
++class InvalidConfiguration(WhisperException):
++ """Invalid configuration."""
++
++
++class InvalidTimeInterval(WhisperException):
++ """Invalid time interval."""
++
++
++class TimestampNotCovered(WhisperException):
++ """Timestamp not covered by any archives in this database."""
++
++
+ def enableDebug():
+ global open, debug, startBlock, endBlock
+ class open(file):
+@@ -136,21 +153,28 @@
+ xFilesFactor specifies the fraction of data points in a propagation interval that must have known values for a propagation to occur
+ """
+ #Validate archive configurations...
+- assert archiveList, "You must specify at least one archive configuration!"
++ if not archiveList:
++ raise InvalidConfiguration("You must specify at least one archive configuration!")
+ archiveList.sort(key=lambda a: a[0]) #sort by precision (secondsPerPoint)
+ for i,archive in enumerate(archiveList):
+ if i == len(archiveList) - 1: break
+ next = archiveList[i+1]
+- assert archive[0] < next[0],\
+- "You cannot configure two archives with the same precision %s,%s" % (archive,next)
+- assert (next[0] % archive[0]) == 0,\
+- "Higher precision archives' precision must evenly divide all lower precision archives' precision %s,%s" % (archive[0],next[0])
++ if archive[0] < next[0]:
++ raise InvalidConfiguration("You cannot configure two archives "
++ "with the same precision %s,%s" % (archive,next))
++ if (next[0] % archive[0]) == 0:
++ raise InvalidConfiguration("Higher precision archives' precision "
++ "must evenly divide all lower precision archives' precision %s,%s" \
++ % (archive[0],next[0]))
+ retention = archive[0] * archive[1]
+ nextRetention = next[0] * next[1]
+- assert nextRetention > retention,\
+- "Lower precision archives must cover larger time intervals than higher precision archives %s,%s" % (archive,next)
++ if nextRetention > retention:
++ raise InvalidConfiguration("Lower precision archives must cover "
++ "larger time intervals than higher precision archives %s,%s" \
++ % (archive,next))
+ #Looks good, now we create the file and write the header
+- assert not os.path.exists(path), "File %s already exists!" % path
++ if os.path.exists(path):
++ raise InvalidConfiguration("File %s already exists!" % path)
+ fh = open(path,'wb')
+ if LOCK: fcntl.flock( fh.fileno(), fcntl.LOCK_EX )
+ lastUpdate = struct.pack( timestampFormat, int(time.time()) )
+@@ -251,7 +275,9 @@
+ if timestamp is None: timestamp = now
+ timestamp = int(timestamp)
+ diff = now - timestamp
+- assert diff < header['maxRetention'] and diff >= 0, "Timestamp not covered by any archives in this database"
++ if diff < header['maxRetention']:
++ raise TimestampNotCovered("Timestamp not covered by any archives in "
++ "this database.")
+ for i,archive in enumerate(header['archives']): #Find the highest-precision archive that covers timestamp
+ if archive['retention'] < diff: continue
+ lowerArchives = header['archives'][i+1:] #We'll pass on the update to these lower precision archives later
+@@ -445,7 +471,8 @@
+ if fromTime < oldestTime:
+ fromTime = oldestTime
+
+- assert fromTime < untilTime, "Invalid time interval"
++ if fromTime < untilTime:
++ raise InvalidTimeInterval("Invalid time interval")
+ if untilTime > now:
+ untilTime = now
+ if untilTime < fromTime:
+
Added: packages/python-whisper/trunk/debian/patches/series
===================================================================
--- packages/python-whisper/trunk/debian/patches/series (rev 0)
+++ packages/python-whisper/trunk/debian/patches/series 2010-02-07 03:46:19 UTC (rev 11605)
@@ -0,0 +1 @@
+cleanup-assertions
More information about the Python-modules-commits
mailing list