class Foo(object):
            """A proxy for NoCloseStringIO.

            Disconnects the network after the second write.
            """
            def __init__(self):
                self.buf = NoCloseStringIO()
                self.writes = 0

            def write(self, data):
                """Write data to the buffer."""
                rv = self.buf.write(data)
                self.writes += 1
                if self.writes == 2:
                    outer_self.main.event_q.push('SYS_NET_DISCONNECTED')
                    outer_self.main.event_q.push('SYS_NET_CONNECTED')
                return rv

            def __getattr__(self, attr):
                return getattr(self.buf, attr)
        class Foo(object):
            """A proxy for NoCloseStringIO.

            Disconnects the network after the second write.
            """
            def __init__(self):
                self.buf = NoCloseStringIO()
                self.writes = 0

            def write(self, data):
                """Write data to the buffer."""
                rv = self.buf.write(data)
                self.writes += 1
                if self.writes == 2:
                    outer_self.main.event_q.push('SYS_NET_DISCONNECTED')
                    outer_self.main.event_q.push('SYS_NET_CONNECTED')
                return rv

            def __getattr__(self, attr):
                return getattr(self.buf, attr)
 def write(self, data):
     """Cancel the request, and then go on and write."""
     outer_self.aq.cancel_download(request.ROOT, self.file_id)
     NoCloseStringIO.write(self, data)
 def write(self, data):
     """Cancel the request, and then go on and write."""
     outer_self.aq.cancel_download(request.ROOT, self.file_id)
     NoCloseStringIO.write(self, data)