view MoinMoin/util/StringIOClosing.py @ 2657:080673c3e60a

Now nameless items can also be downloaded and removed unnecessary blank spaces in items/content.py
author Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
date Sun, 06 Jul 2014 09:25:31 +0530
parents f83b66646d75
children
line wrap: on
line source
from StringIO import StringIO as StringIOBase


class StringIO(StringIOBase):
    """
    same as StringIO from stdlib, but enhanced with a context manager, so it
    can be used within a "with" statement and gets automatically closed when
    the with-block is left. The standard "file" object behaves that way, so
    a StringIO "file emulation" should behave the same.
    """
    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, exc_tb):
        self.close()