def __exit__(self, exc_type, exc_val, exc_tb):
     sys.stdout.finalize()
     sys.stderr.finalize()
     printed = (getattr(sys.stdout, 'printed', False) or
                getattr(sys.stderr, 'printed', False))
     # Reprompt if anything had printed out
     if printed:
         pythonaddins._WriteStringToPythonWindow(u"",
                                                 reprompt_when_done=True)
     sys.stdout = self._stdout
     sys.stderr = self._stderr
 def __exit__(self, exc_type, exc_val, exc_tb):
     sys.stdout.finalize()
     sys.stderr.finalize()
     printed = (getattr(sys.stdout, 'printed', False)
                or getattr(sys.stderr, 'printed', False))
     # Reprompt if anything had printed out
     if printed:
         pythonaddins._WriteStringToPythonWindow(u"",
                                                 reprompt_when_done=True)
     sys.stdout = self._stdout
     sys.stderr = self._stderr
 def finalize(self, reprompt=False):
     self._reprompt = reprompt
     if self._buffer and isinstance(self._buffeer, unicode):
         pythonaddins._WriteStringToPythonWindow(self._buffer,
                                      reprompt_when_done=self._reprompt,
                                      is_error=self._stderr)
         self._wroteout = True
         self.write(self.buffer)
     elif self._reprompt:
         pythonaddins._WriteStringToPythonWindow(u"",
                                      reprompt_when_done=True,
                                      is_error=self._stderr)
 def finalize(self, reprompt=False):
     self._reprompt = reprompt
     if self._buffer and isinstance(self._buffeer, unicode):
         pythonaddins._WriteStringToPythonWindow(
             self._buffer,
             reprompt_when_done=self._reprompt,
             is_error=self._stderr)
         self._wroteout = True
         self.write(self.buffer)
     elif self._reprompt:
         pythonaddins._WriteStringToPythonWindow(u"",
                                                 reprompt_when_done=True,
                                                 is_error=self._stderr)
 def write(self, *args, **kwargs):
     try:
         self._buffer += u' '.join(a.decode("utf-8", "replace")
                                     if isinstance(a, basestring)
                                     else unicode(repr(a))
                                   for a in args)
     except:
         pass
     if self._buffer:
         self._wroteout = True
     if '\n' in self._buffer:
         outstring, self._buffer = self._buffer.rsplit('\n', 1)
         try:
             outstring = (outstring.replace('\r\n', '\n')
                                   .replace('\n', '\r\n'))
             pythonaddins._WriteStringToPythonWindow(outstring,
                                          reprompt_when_done=self._reprompt,
                                          is_error=self._stderr)
         except:
             return self._wrapped_stream.write(*args, **kwargs)
 def write(self, *args, **kwargs):
     try:
         self._buffer += u' '.join(
             a.decode("utf-8", "replace"
                      ) if isinstance(a, basestring) else unicode(repr(a))
             for a in args)
     except:
         pass
     if self._buffer:
         self._wroteout = True
     if '\n' in self._buffer:
         outstring, self._buffer = self._buffer.rsplit('\n', 1)
         try:
             outstring = (outstring.replace('\r\n',
                                            '\n').replace('\n', '\r\n'))
             pythonaddins._WriteStringToPythonWindow(
                 outstring,
                 reprompt_when_done=self._reprompt,
                 is_error=self._stderr)
         except:
             return self._wrapped_stream.write(*args, **kwargs)
 def printfunc(message, error=False):
     try:
         pythonaddins._WriteStringToPythonWindow(message, True, True, error)
     except:
         print message
 def printfunc(message, error=False):
     try:
         pythonaddins._WriteStringToPythonWindow(message, True, True, error)
     except:
         print message