Changeset 157
- Timestamp:
- Fri Dec 2 14:24:35 2005
- Files:
-
- trunk/xix/utils/python.py (modified) (diff)
- trunk/xix/utils/io.py (modified) (diff)
- trunk/runtests.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/xix/utils/python.py
r142 r157 234 234 return ret 235 235 236 class CurriedCallable: 237 """Example Usage: 236 238 239 >>> def addThree(a, b, c=4): 240 ... return a + b + c 241 ... 242 >>> curried = CurriedCallable(addThree, 2, 3) 243 >>> print curried() 244 9 245 >>> curried = CurriedCallable(addThree, 2, 3, c=5) 246 >>> print curried() 247 10 248 249 Supplying an additional argument to curried: 250 251 >>> curried = CurriedCallable(addThree, 2, 3) 252 >>> print curried(c=20) 253 25 254 255 """ 256 257 def __init__(self, func, *pargs, **kwargs): 258 self.func = func 259 self.pargs = list(pargs) 260 self.kwargs = dict(kwargs) 261 262 263 def __call__(self, *pargs, **kwargs): 264 kws = dict(self.kwargs) 265 kws.update(dict(kwargs)) 266 args = self.pargs + list(pargs) 267 return self.func(*args, **kws) 237 268 238 269 __all__ = _setAll([], locals(), 'os', 'inspect', 'implements', 'IModuleWrapper') -
trunk/xix/utils/io.py
r143 r157 6 6 7 7 from cStringIO import StringIO 8 import sys8 import fileinput 8 8 9 9 __author__ = 'Drew Smathers' … … 13 13 14 14 15 class AggregateFileInput: 16 """Similar to AggregateFile except much faster and only iteration is 17 supported 18 """ 19 20 def __init__(self, files): 21 self.files = files 22 23 def __iterfiles(self): 24 last = '' 25 for line in fileinput.input(self.files): 26 if line[-1] != '\n': 27 last = line 28 else: 29 yield last + line 30 last = '' 31 32 def __iter__(self): 33 return self.__iterfiles() 34 35 def readlines(self): 36 # alias 37 return self.__iterfiles() 38 15 39 class AggregateFile: 16 40 """A file-like object that aggregates multiple files into one … … 18 42 and consist of read, readline, seek, and tell. 19 43 20 And what a pain in the ass it was!44 TODO: optimizations 20 44 """ 21 45 -
trunk/runtests.py
r143 r157 22 22 import xix.utils.rules 23 23 import xix.utils.python 24 import xix.utils.timetool 24 25 import xix.xixxml.xmlbuilder 25 26 from tests import doctests … … 47 48 suite.addTest(doctest.DocTestSuite(xix.xixxml.xmlbuilder)) 48 49 suite.addTest(doctest.DocTestSuite(xix.utils.python)) 50 suite.addTest(doctest.DocTestSuite(xix.utils.timetool)) 49 51 suite.addTest(doctest.DocTestSuite(doctests.utils.config)) 50 52 suite.addTest(doctest.DocTestSuite(doctests.utils.python))
