summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/utils.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-09 14:27:56 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-09 14:27:56 -0500
commit246557f31b1be5d73419434e2f05f7a7653de592 (patch)
tree91790049f6bf7d142f677c72623d5256ebdf0cf8 /src/lib/Server/Reports/utils.py
parent227690fca43d08f1c6cc9d19afc1013fe8f3eec0 (diff)
downloadbcfg2-246557f31b1be5d73419434e2f05f7a7653de592.tar.gz
bcfg2-246557f31b1be5d73419434e2f05f7a7653de592.tar.bz2
bcfg2-246557f31b1be5d73419434e2f05f7a7653de592.zip
Reports: PY3K compatibility fix for PEP 3114
Quoted from PEP 3114: The iterator protocol in Python 2.x consists of two methods: __iter__() called on an iterable object to yield an iterator, and next() called on an iterator object to yield the next item in the sequence. Using a for loop to iterate over an iterable object implicitly calls both of these methods. This PEP proposes that the next method be renamed to __next__, consistent with all the other protocols in Python in which a method is implicitly called as part of a language-level protocol, and that a built-in function named next be introduced to invoke __next__ method, consistent with the manner in which other protocols are explicitly invoked. Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Server/Reports/utils.py')
-rwxr-xr-xsrc/lib/Server/Reports/utils.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/Server/Reports/utils.py b/src/lib/Server/Reports/utils.py
index 6010f366b..04fdbf985 100755
--- a/src/lib/Server/Reports/utils.py
+++ b/src/lib/Server/Reports/utils.py
@@ -1,10 +1,25 @@
"""Helper functions for reports"""
from django.conf.urls.defaults import *
import re
+import sys
"""List of filters provided by filteredUrls"""
filter_list = ('server', 'state')
+def increment(self):
+ """Return the next object from our array and fetch from the
+ database when needed"""
+ if self.block_count + self.count - self.step == self.max:
+ raise StopIteration
+ if self.block_count == 0 or self.count == self.step:
+ # Without list() this turns into LIMIT 1 OFFSET x queries
+ self.data = list(self.obj.all()[self.block_count: \
+ (self.block_count + self.step)])
+ self.block_count += self.step
+ self.count = 0
+ self.count += 1
+ return self.data[self.count - 1]
+
class BatchFetch(object):
"""Fetch Django objects in smaller batches to save memory"""
@@ -20,19 +35,12 @@ class BatchFetch(object):
def __iter__(self):
return self
- def __next__(self):
- """Return the next object from our array and fetch from the
- database when needed"""
- if self.block_count + self.count - self.step == self.max:
- raise StopIteration
- if self.block_count == 0 or self.count == self.step:
- # Without list() this turns into LIMIT 1 OFFSET x queries
- self.data = list(self.obj.all()[self.block_count: \
- (self.block_count + self.step)])
- self.block_count += self.step
- self.count = 0
- self.count += 1
- return self.data[self.count - 1]
+ if sys.hexversion > 0x03000000:
+ def __next__(self):
+ return increment(self)
+ else:
+ def next(self):
+ return increment(self)
def generateUrls(fn):