def StringIO():
    """Add support for 'with' statement to StringIO - http://bugs.python.org/issue1286
    """
    try:
        from cStringIO import StringIO
    except ImportError:
        from StringIO import StringIO
        
    sio = StringIO()
    
    try:
        yield sio
    finally:
        sio.close()
Add support for 'with' statement to StringIO - http://bugs.python.org/issue1286
    
recipes/Python/576650_with_statement_for_StringIO/recipe-576650.py