sys.stdin.fileno

Here are the examples of the python api sys.stdin.fileno taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

200 Examples 7

Example 1

Project: django-windows-tools
Source File: winfcgi.py
View license
    def run(self):
        msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
        stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
        stdout = os.fdopen(sys.stdin.fileno(), 'wb', 0)

        conn = Connection(stdin, stdout, self)
        try:
            conn.run()
        except Exception as e:
            logging.exception(e)
            raise

Example 2

Project: django-windows-tools
Source File: winfcgi.py
View license
    def run(self):
        msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
        stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
        stdout = os.fdopen(sys.stdin.fileno(), 'wb', 0)

        conn = Connection(stdin, stdout, self)
        try:
            conn.run()
        except Exception as e:
            logging.exception(e)
            raise

Example 3

Project: tile-generator
Source File: opsmgr.py
View license
def ssh_interactive(tty):
	while True:
		rlist, wlist, xlist = select.select([sys.stdin.fileno(), tty], [], [])
		if sys.stdin.fileno() in rlist:
			input = os.read(sys.stdin.fileno(), 1024)
			if len(input) == 0:
				break
			else:
				os.write(tty, input)
				os.fsync(tty)
		elif tty in rlist:
			output = os.read(tty, 1024)
			if len(output) == 0:
				break
			sys.stdout.write(output)
			sys.stdout.flush()
	os.close(tty)

Example 4

Project: reviewboard
Source File: rbssh.py
View license
    def process_stdin(self, channel):
        """Read data from stdin and send it over the channel."""
        logging.debug('!! process_stdin\n')

        try:
            buf = os.read(sys.stdin.fileno(), 1)
        except OSError:
            buf = None

        if not buf:
            logging.debug('!! stdin empty\n')
            return False

        channel.send(buf)

        return True

Example 5

Project: push
Source File: cli.py
View license
def read_character():
    "Read a single character from the terminal without echoing it."
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setcbreak(fd)
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

Example 6

Project: 217gdb
Source File: ui.py
View license
def get_term_size():
    try:
        height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))
    except:
        height = 60
        width = 80
    return (height, width)

Example 7

Project: Sick-Beard-TPB
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 8

Project: wfuzz
Source File: getch.py
View license
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 9

Project: qfc
Source File: readchar.py
View license
def read_char_no_blocking():
    ''' Read a character in nonblocking mode, if no characters are present in the buffer, return an empty string '''
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    old_flags = fcntl.fcntl(fd, fcntl.F_GETFL)
    try:
        tty.setraw(fd, termios.TCSADRAIN)
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK)
        return sys.stdin.read(1)
    except IOError as e:
        ErrorNumber = e[0]
        # IOError with ErrorNumber 11(35 in Mac)  is thrown when there is nothing to read(Resource temporarily unavailable)
        if (sys.platform.startswith("linux") and ErrorNumber != 11) or (sys.platform == "darwin" and ErrorNumber != 35):
            raise
        return ""
    finally:
        fcntl.fcntl(fd, fcntl.F_SETFL, old_flags)
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)

Example 10

Project: pyload
Source File: Getch.py
View license
    def __call__(self):
        import sys
        import tty
        import termios

        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 11

Project: term2048
Source File: keypress.py
View license
    def __getKey():
        """Return a key pressed by the user"""
        try:
            tty.setcbreak(sys.stdin.fileno())
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            ch = sys.stdin.read(1)
            return ord(ch) if ch else None
        finally:
            termios.tcsetattr(__fd, termios.TCSADRAIN, __old)

Example 12

Project: django-nonrel
Source File: autoreload.py
View license
def ensure_echo_on():
    if termios:
        fd = sys.stdin.fileno()
        attr_list = termios.tcgetattr(fd)
        if not attr_list[3] & termios.ECHO:
            attr_list[3] |= termios.ECHO
            termios.tcsetattr(fd, termios.TCSANOW, attr_list)

Example 13

Project: pwndbg
Source File: ui.py
View license
def banner(title):
    title = title.upper()
    try:
        _height, width = struct.unpack('hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234'))
    except:
        width = 80
    width -= 2
    return C.banner(("[{:%s^%ss}]" % (config.banner_separator, width)).format(title))

Example 14

Project: headphones
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 15

Project: cgstudiomap
Source File: shell.py
View license
    def console(self, local_vars):
        if not os.isatty(sys.stdin.fileno()):
            exec sys.stdin in local_vars
        else:
            if 'env' not in local_vars:
                print('No environment set, use `odoo.py shell -d dbname`'
                      ' to get one.')
            for i in sorted(local_vars):
                print('%s: %s' % (i, local_vars[i]))
            logging.disable(logging.CRITICAL)
            Console(locals=local_vars).interact()

Example 16

Project: playitagainsam
Source File: util.py
View license
    def __init__(self, fd=None):
        if fd is None:
            fd = sys.stdin.fileno()
        elif hasattr(fd, "fileno"):
            fd = fd.fileno()
        self.fd = fd

Example 17

Project: moviegrabber
Source File: webtest.py
View license
    def getchar():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 18

Project: Ultros
Source File: console.py
View license
    def __call__(self):
        import sys
        import tty
        import termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 19

Project: bup
Source File: ftp-cmd.py
View license
def inputiter():
    if os.isatty(sys.stdin.fileno()):
        while 1:
            try:
                yield raw_input('bup> ')
            except EOFError:
                print ''  # Clear the line for the terminal's next prompt
                break
    else:
        for line in sys.stdin:
            yield line

Example 20

View license
    def handle_SIGHUP(self):
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 21

Project: pyusb
Source File: vcp_terminal.py
View license
    def __call__(self):
        import sys
        import tty
        import termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 22

Project: playerpiano
Source File: piano.py
View license
@contextlib.contextmanager
def frob_tty():
    """massage the terminal to not echo characters & the like"""
    stdin_fd = sys.stdin.fileno()
    old_mask = termios.tcgetattr(stdin_fd)
    new = old_mask[:]
    LFLAGS = 3
    new[LFLAGS] &= ~termios.ECHO
    termios.tcsetattr(stdin_fd, termios.TCSADRAIN, new)
    tty.setraw(stdin_fd)
    try:
        yield
    finally:
        # restore the terminal to its original state
        termios.tcsetattr(stdin_fd, termios.TCSADRAIN, old_mask)

Example 23

View license
def readchar():
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    if ch == '0x03':
        raise KeyboardInterrupt
    return ch

Example 24

Project: pyserial
Source File: miniterm.py
View license
        def __init__(self):
            super(Console, self).__init__()
            self.fd = sys.stdin.fileno()
            # an additional pipe is used in getkey, so that the cancel method
            # can abort the waiting getkey method
            self.pipe_r, self.pipe_w = os.pipe()
            self.old = termios.tcgetattr(self.fd)
            atexit.register(self.cleanup)
            if sys.version_info < (3, 0):
                self.enc_stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin)
            else:
                self.enc_stdin = sys.stdin

Example 25

Project: SoCo
Source File: analyse_ws.py
View license
def getch():
    """ Read a single character non-echoed and return it. Recipe from:
    http://code.activestate.com/recipes/
    134892-getch-like-unbuffered-character-reading-from-stdin/
    """
    filedescriptor = sys.stdin.fileno()
    old_settings = termios.tcgetattr(filedescriptor)
    if PLATFORM == 'win32':
        character = msvcrt.getch()
    else:
        try:
            tty.setraw(sys.stdin.fileno())
            character = sys.stdin.read(1)
        finally:
            termios.tcsetattr(filedescriptor, termios.TCSADRAIN, old_settings)
    return character

Example 26

Project: babel
Source File: download_import_cldr.py
View license
def get_terminal_width():
    try:
        import fcntl
        import termios
        import struct
        fd = sys.stdin.fileno()
        cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
        return cr[1]
    except Exception:
        return 80

Example 27

Project: HTPC-Manager
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 28

Project: nzbToMedia
Source File: input.py
View license
	def getch():
		fd = sys.stdin.fileno()
		old = termios.tcgetattr(fd)
		try:
			tty.setraw(fd)
			return sys.stdin.read(1)
		finally:
			termios.tcsetattr(fd, termios.TCSADRAIN, old)

Example 29

Project: GoAtThrottleUp
Source File: webtest.py
View license
    def getchar():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 30

Project: pattern
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 31

Project: getline
Source File: __linux_impl.py
View license
    def __init__(self, histfile=None):
        self.histfile = histfile
        self.fd = sys.stdin.fileno()
        self.curpos = [0, 0, 0]
        self.history = self.__loadhist()
        self.__init()

Example 32

Project: qb
Source File: buzzer.py
View license
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
            sys.stdin.flush()
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 33

Project: odoo-development
Source File: getch.py
View license
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 34

Project: marker
Source File: readchar.py
View license
def read_char():
    ''' Read a character '''
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(fd, termios.TCSADRAIN)
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch

Example 35

Project: deltaic
Source File: __init__.py
View license
    def __init__(self, settings):
        self._spool_dir = settings['archive-spool']
        self._tar = settings.get('archive-tar-path', 'tar')
        self._gpg = settings.get('archive-gpg-path', 'gpg2')
        self._gpg_recipients = settings.get('archive-gpg-recipients')
        self._gpg_signing_key = settings.get('archive-gpg-signing-key')

        self._gpg_env = dict(os.environ)
        try:
            # Required for GPG passphrase prompting
            self._gpg_env['GPG_TTY'] = os.ttyname(sys.stdin.fileno())
        except OSError:
            # stdin is not a tty
            pass

        self.encryption = 'gpg' if self._gpg_recipients else 'none'

Example 36

Project: pgctl
Source File: timestamp.py
View license
def main():
    import sys
    import io
    infile = io.open(sys.stdin.fileno(), buffering=0, mode='rb')
    outfile = io.open(sys.stdout.fileno(), buffering=0, mode='wb')
    prepend_timestamps(infile, outfile)

Example 37

Project: pysh
Source File: evaluator.py
View license
  def tofile(self, fd):
    if fd == sys.stdin.fileno():
      return sys.stdin
    if fd == sys.stdout.fileno():
      return sys.stdout
    if fd in self.all_r:
      mode = 'r'
    elif fd in self.all_w:
      mode = 'w'
    else:
      raise Exception('Unknown file descriptor: ' + str(fd))
    if fd in self.files:
      return self.files[fd]
    f = os.fdopen(fd, mode)
    self.files[fd] = f
    return f

Example 38

Project: evolutionary-circuits
Source File: getch.py
View license
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 39

Project: zstack-utility
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 40

Project: PySixel
Source File: cellsize.py
View license
    def __set_raw(self):
        fd = sys.stdin.fileno()
        backup = termios.tcgetattr(fd)
        try:
            new = termios.tcgetattr(fd)
            new[0] = 0  # c_iflag = 0
            new[3] = 0  # c_lflag = 0
            new[3] = new[3] & ~(termios.ECHO | termios.ICANON)
            termios.tcsetattr(fd, termios.TCSANOW, new)
        except Exception:
            termios.tcsetattr(fd, termios.TCSANOW, backup)
        return backup

Example 41

Project: mavelous
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 42

Project: Cyprium
Source File: ui.py
View license
    @classmethod
    def _getch_unix(cl, echo=False):
        import tty
        import termios
        _fd = sys.stdin.fileno()
        _old_settings = termios.tcgetattr(_fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(_fd, termios.TCSADRAIN, _old_settings)
        if echo:
            cl.cprint(ch, end="")
        return ch

Example 43

Project: Sick-Beard
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 44

Project: funcparserlib
Source File: json.py
View license
def main():
    logging.basicConfig(level=logging.DEBUG)
    try:
        stdin = os.fdopen(sys.stdin.fileno(), 'rb')
        input = stdin.read().decode(ENCODING)
        tree = loads(input)
        print pformat(tree)
    except (NoParseError, LexerError), e:
        msg = (u'syntax error: %s' % e).encode(ENCODING)
        print >> sys.stderr, msg
        sys.exit(1)

Example 45

Project: aioconsole
Source File: stream.py
View license
@asyncio.coroutine
def create_standard_streams(stdin, stdout, loop):
    try:
        sys.stdin.fileno(), sys.stdout.fileno()
    except io.UnsupportedOperation:
        reader = NonFileStreamReader(stdin, loop=loop)
        writer = NonFileStreamWriter(stdout, loop=loop)
    else:
        future = open_pipe_connection(stdin, stdout, loop=loop)
        reader, writer = yield from future
    return reader, writer

Example 46

Project: TACTIC
Source File: logtest.py
View license
    def getchar():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 47

View license
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 48

Project: CouchPotatoV1
Source File: plugins.py
View license
    def handle_SIGHUP(self):
        """Restart if daemonized, else exit."""
        if os.isatty(sys.stdin.fileno()):
            # not daemonized (may be foreground or background)
            self.bus.log("SIGHUP caught but not daemonized. Exiting.")
            self.bus.exit()
        else:
            self.bus.log("SIGHUP caught while daemonized. Restarting.")
            self.bus.restart()

Example 49

Project: fixofx
Source File: webtest.py
View license
    def getchar():
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

Example 50

Project: sfepy
Source File: getch.py
View license
    def __call__(self):
        tty, sys, select = self.mods

        fd = sys.stdin.fileno()
        old = tty.tcgetattr(fd)
        tty.setcbreak(fd, tty.TCSANOW)
        try:
            return sys.stdin.read(1)
        finally:
            tty.tcsetattr(fd, tty.TCSAFLUSH, old)