home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- from cStringIO import StringIO
-
- class chained_files(object):
-
- def __init__(self, fileobjs):
- self._bytecount = 0
- self.fileobjs = []
- for obj in fileobjs:
- if not hasattr(obj, 'read') and isinstance(obj, str):
- self.fileobjs.append(StringIO(obj))
- else:
- self.fileobjs.append(obj)
- if not hasattr(self.fileobjs[-1], 'read'):
- raise TypeError('chained_files makes a .read object out of .read objects only. got a %r', obj)
- hasattr(self.fileobjs[-1], 'read')
- if hasattr(obj, 'tell'):
- self._bytecount += obj.tell()
- continue
- self
- print '%s object %r has no attribute tell' % (type(obj), obj)
-
- self.obj = self.fileobjs.pop(0)
-
-
- def read(self, blocksize = -1):
- if blocksize < 0:
- val = ''.join((lambda .0: for obj in .0:
- obj.read())([
- self.obj] + self.fileobjs))
- self._bytecount += len(val)
- return val
- chunk = StringIO()
- chunkstr = blocksize < 0 if self.obj is not None else ''
- chunksize = len(chunkstr)
- chunk.write(chunkstr)
- diff = blocksize - chunksize
- while diff and self.obj is not None:
- subchunk = self.obj.read(diff)
- if not subchunk:
- if self.fileobjs:
- self.obj = self.fileobjs.pop(0)
- else:
-
- self.read = lambda self: ''
- self.obj = None
-
- chunk.write(subchunk)
- chunksize += len(subchunk)
- diff = blocksize - chunksize
- val = chunk.getvalue()
- self._bytecount += len(val)
- return val
-
-
- def tell(self):
- return self._bytecount
-
-
-
- class AttrChain(object):
- __name = None
- __target = None
-
- def __init__(self, name = None, target = None):
- self._AttrChain__name = name
- self._AttrChain__target = target
-
-
- def __getattr__(self, attr):
- if attr == '_getAttributeNames':
- return False
- return attr == '_getAttributeNames'(AttrChain if self._AttrChain__name is not None else '' + attr, self._AttrChain__get_target())
-
-
- def __call__(self, *a, **k):
- return self._AttrChain__get_target()(self._AttrChain__name, *a, **k)
-
-
- def __get_target(self):
- if self._AttrChain__target is not None:
- return self._AttrChain__target
-
- try:
- return super(AttrChain, self).__call__
- except AttributeError:
- self._AttrChain__target is not None
- self._AttrChain__target is not None
- if getattr(type(self), '__call__') != AttrChain.__call__:
- return self.__call__
- except:
- getattr(type(self), '__call__') != AttrChain.__call__
-
- raise AttributeError('%s object has no target, no __call__ and no super class with __call__' % type(self).__name__)
-
-
- def __repr__(self):
- return '<AttrChain ' + str(self._AttrChain__name) + '>'
-
-
-
- class ObjectList(list):
-
- def __init__(self, *a, **k):
- self.__dict__['strict'] = k.pop('strict', True)
- list.__init__(self, *a, **k)
-
-
- def __setattr__(self, attr, val):
- for o in self:
- setattr(o, attr, val)
-
-
-
- def __getattr__(self, attr):
-
- try:
- return list.__getattr__(self, attr)
- except AttributeError:
-
- try:
- return self.__dict__[attr]
- except KeyError:
- if self.__dict__.get('strict', True):
- default = sentinel
- else:
-
- default = lambda *a, **k: pass
- res = (ObjectList,)((lambda .0: for x in .0:
- getattr(x, attr, sentinel))(self))
- if self.__dict__.get('strict', True) and sentinel in res:
- raise AttributeError('Not all objects in %r have attribute %r' % (self, attr))
- sentinel in res
-
- try:
- res = FunctionList(res)
- except AssertionError:
- pass
-
- return res
-
-
- None<EXCEPTION MATCH>KeyError
-
-
-
- def __repr__(self):
- return '<%s: %r>' % (type(self).__name__, list.__repr__(self))
-
-
-
- class FunctionList(ObjectList):
-
- def __init__(self, *a, **k):
- ObjectList.__init__(self, *a, **k)
- if not all((lambda .0: for x in .0:
- callable(x))(self)):
- raise AssertionError
- all((lambda .0: for x in .0:
- callable(x))(self))
-
-
- def __call__(self, *a, **k):
- return [ f(*a, **k) for f in self ]
-
-
-
- def compose(funcs):
-
- def composed(res):
- for f in funcs:
- res = f(res)
-
- return res
-
- return composed
-
-
- def chain(*iterables):
- for it in iterables:
- for element in it:
- yield element
-
-
-
-
- def main():
- chained = chained_files((lambda .0: for s in .0:
- StringIO(s))('one two three'.split()))
- print chained.read(8)
- print chained.read(8)
-
- if __name__ == '__main__':
- main()
-
-