# Path: evergreen/io/stream.py
# class BaseStream(AbstractBaseStream):
#     """Base class for streams implemented using pyuv Stream objects as the underlying mechanism
#     """
# 
#     def __init__(self):
#         super(BaseStream, self).__init__()
#         self._read_result = Result()
#         self._shutdown_result = Result()
#         self._pending_writes = 0
#         self._flush_event = Event()
#         self._flush_event.set()
# 
#     def flush(self):
#         self._check_closed()
#         self._flush_event.wait()
# 
#     def _read(self, n):
#         with self._read_result:
#             try:
#                 self._handle.start_read(self.__read_cb)
#             except self.error_cls:
#                 self.close()
#                 raise
#             try:
#                 data = self._read_result.get()
#             except self.error_cls as e:
#                 self.close()
#                 if e.args[0] != errno.EOF:
#                     raise
#             else:
#                 self._read_buffer.feed(data)
# 
#     def _write(self, data):
#         try:
#             self._handle.write(data, self.__write_cb)
#         except self.error_cls:
#             self.close()
#             raise
#         if self._pending_writes == 0:
#             self._flush_event.clear()
#         self._pending_writes += 1
#         return self._handle.write_queue_size == 0
# 
#     def _shutdown(self):
#         with self._shutdown_result:
#             self._handle.shutdown(self.__shutdown_cb)
#             self._shutdown_result.get()
# 
#     def _close(self):
#         self._handle.close()
# 
#     def __read_cb(self, handle, data, error):
#         self._handle.stop_read()
#         if error is not None:
#             self._read_result.set_exception(self.error_cls(error, pyuv.errno.strerror(error)))
#         else:
#             self._read_result.set_value(data)
# 
#     def __write_cb(self, handle, error):
#         self._pending_writes -= 1
#         if self._pending_writes == 0:
#             self._flush_event.set()
#         if error is not None:
#             log.debug('write failed: %d %s', error, pyuv.errno.strerror(error))
#             evergreen.current.loop.call_soon(self.close)
# 
#     def __shutdown_cb(self, handle, error):
#         if error is not None:
#             self._shutdown_result.set_exception(self.error_cls(error, pyuv.errno.strerror(error)))
#         else:
#             self._shutdown_result.set_value(None)


import atexit
import os
import pyuv
import sys
import evergreen
from evergreen.io.stream import BaseStream
#
# This file is part of Evergreen. See the NOTICE for more information.
#



__all__ = ['TTYStream', 'TTYError', 'StdinStream', 'StdoutStream', 'StderrStream']


# Reset terminal settings on program exit
atexit.register(pyuv.TTY.reset_mode)


TTYError = pyuv.error.TTYError



# Path: evergreen/io/stream.py
# class BaseStream(AbstractBaseStream):
#     """Base class for streams implemented using pyuv Stream objects as the underlying mechanism
#     """
# 
#     def __init__(self):
#         super(BaseStream, self).__init__()
#         self._read_result = Result()
#         self._shutdown_result = Result()
#         self._pending_writes = 0
#         self._flush_event = Event()
#         self._flush_event.set()
# 
#     def flush(self):
#         self._check_closed()
#         self._flush_event.wait()
# 
#     def _read(self, n):
#         with self._read_result:
#             try:
#                 self._handle.start_read(self.__read_cb)
#             except self.error_cls:
#                 self.close()
#                 raise
#             try:
#                 data = self._read_result.get()
#             except self.error_cls as e:
#                 self.close()
#                 if e.args[0] != errno.EOF:
#                     raise
#             else:
#                 self._read_buffer.feed(data)
# 
#     def _write(self, data):
#         try:
#             self._handle.write(data, self.__write_cb)
#         except self.error_cls:
#             self.close()
#             raise
#         if self._pending_writes == 0:
#             self._flush_event.clear()
#         self._pending_writes += 1
#         return self._handle.write_queue_size == 0
# 
#     def _shutdown(self):
#         with self._shutdown_result:
#             self._handle.shutdown(self.__shutdown_cb)
#             self._shutdown_result.get()
# 
#     def _close(self):
#         self._handle.close()
# 
#     def __read_cb(self, handle, data, error):
#         self._handle.stop_read()
#         if error is not None:
#             self._read_result.set_exception(self.error_cls(error, pyuv.errno.strerror(error)))
#         else:
#             self._read_result.set_value(data)
# 
#     def __write_cb(self, handle, error):
#         self._pending_writes -= 1
#         if self._pending_writes == 0:
#             self._flush_event.set()
#         if error is not None:
#             log.debug('write failed: %d %s', error, pyuv.errno.strerror(error))
#             evergreen.current.loop.call_soon(self.close)
# 
#     def __shutdown_cb(self, handle, error):
#         if error is not None:
#             self._shutdown_result.set_exception(self.error_cls(error, pyuv.errno.strerror(error)))
#         else:
#             self._shutdown_result.set_value(None)


# Path: evergreen/io/tty.py
import atexit
import os
import pyuv
import sys
import evergreen
from evergreen.io.stream import BaseStream

#
# This file is part of Evergreen. See the NOTICE for more information.
#



__all__ = ['TTYStream', 'TTYError', 'StdinStream', 'StdoutStream', 'StderrStream']


# Reset terminal settings on program exit
atexit.register(pyuv.TTY.reset_mode)


TTYError = pyuv.error.TTYError



class TTYStream(BaseStream):