[Digicool-CVS] CVS: Packages/ZTUtils - Iterator.py:1.2
Evan Simpson
evan@zope.com
Tue, 7 Aug 2001 16:53:54 -0400
Update of /cvs-repository/Packages/ZTUtils
In directory cvs.zope.org:/tmp/cvs-serv7171
Modified Files:
Iterator.py
Log Message:
Add Roman numeral conversion to Iterators based on Tino's algorithm.
=== Packages/ZTUtils/Iterator.py 1.1 => 1.2 ===
__version__='$Revision$'[11:-2]
+import string
+
class Iterator:
'''Simple Iterator class'''
@@ -123,6 +125,20 @@
def Letter(self):
return self.letter(base=ord('A'))
+ def Roman(self, rnvalues=(
+ (1000,'M'),(900,'CM'),(500,'D'),(400,'CD'),
+ (100,'C'),(90,'XC'),(50,'L'),(40,'XL'),
+ (10,'X'),(9,'IX'),(5,'V'),(4,'IV'),(1,'I')) ):
+ n = self.index + 1
+ s = ''
+ for v, r in rnvalues:
+ rct, n = divmod(n, v)
+ s = s + r * rct
+ return s
+
+ def roman(self, lower=string.lower):
+ return lower(self.Roman())
+
def start(self): return self.nextIndex == 1
def end(self):
@@ -135,3 +151,4 @@
def length(self):
return len(self.seq)
+