Example #1
0
class SubclassableCStringIO(object):
    """A wrapper around cStringIO to allow for subclassing"""
    __csio = None
    def __init__(self, *a, **kw):
        from cStringIO import StringIO
        self.__csio = StringIO(*a, **kw)
    def __iter__(self):
        return self.__csio.__iter__()
    def next(self):
        return self.__csio.next()
    def close(self):
        return self.__csio.close()
    def isatty(self):
        return self.__csio.isatty()
    def seek(self, pos, mode=0):
        return self.__csio.seek(pos, mode)
    def tell(self):
        return self.__csio.tell()
    def read(self, n=-1):
        return self.__csio.read(n)
    def readline(self, length=None):
        return self.__csio.readline(length)
    def readlines(self, sizehint=0):
        return self.__csio.readlines(sizehint)
    def truncate(self, size=None):
        return self.__csio.truncate(size)
    def write(self, s):
        return self.__csio.write(s)
    def writelines(self, list):
        return self.__csio.writelines(list)
    def flush(self):
        return self.__csio.flush()
    def getvalue(self):
        return self.__csio.getvalue()
Example #2
0
class SubclassableCStringIO(object):
    """
    A wrapper around cStringIO to allow for subclassing.
    """
    __csio = None

    def __init__(self, *a, **kw):
        from cStringIO import StringIO
        self.__csio = StringIO(*a, **kw)

    def __iter__(self):
        return self.__csio.__iter__()

    def next(self):
        return self.__csio.next()

    def close(self):
        return self.__csio.close()

    def isatty(self):
        return self.__csio.isatty()

    def seek(self, pos, mode=0):
        return self.__csio.seek(pos, mode)

    def tell(self):
        return self.__csio.tell()

    def read(self, n=-1):
        return self.__csio.read(n)

    def readline(self, length=None):
        return self.__csio.readline(length)

    def readlines(self, sizehint=0):
        return self.__csio.readlines(sizehint)

    def truncate(self, size=None):
        return self.__csio.truncate(size)

    def write(self, s):
        return self.__csio.write(s)

    def writelines(self, list):
        return self.__csio.writelines(list)

    def flush(self):
        return self.__csio.flush()

    def getvalue(self):
        return self.__csio.getvalue()
class ReadOnlyStream(object):
    def __init__(self, name, str=''):
        self._sio=StringIO(str)
        self.closed=0
        self.mode='r'
        self.name=name

    def read(self, n=-1):
        return self._sio.read(n)

    def readline(self, length=None):
        return self._sio.readline(length)

    def readlines(self, sizehint=0):
        return self._sio.readlines(sizehint)

    def close(self):
        self._sio.close()
        self.closed=1

    def flush(self):
        raise VFSException, "unsupported operation: flush"

    def isatty(self):
        return self._sio.isatty()

    def seek(self, pos, mode=0):
        self._sio.seek(pos, mode)

    def tell(self):
        return self._sio.tell()

    def truncate(self, size=None):
        raise VFSException, "unsupported operation: truncate"

    def write(self, s):
        raise VFSException, "unsupported operation: write"

    def writelines(self, list):
        raise VFSException, "unsupported operation: writelines"

    def __iter__(self):
        return self._sio.__iter__()