MCPcopy Create free account
hub / github.com/pexpect/pexpect / __init__

Method __init__

pexpect/fdpexpect.py:40–65  ·  view source on GitHub ↗

This takes a file descriptor (an int) or an object that support the fileno() method (returning an int). All Python file-like objects support fileno().

(self, fd, args=None, timeout=30, maxread=2000, searchwindowsize=None,
                  logfile=None, encoding=None, codec_errors='strict', use_poll=False)

Source from the content-addressed store, hash-verified

38 for patterns, or to control a modem or serial device. '''
39
40 def __init__ (self, fd, args=None, timeout=30, maxread=2000, searchwindowsize=None,
41 logfile=None, encoding=None, codec_errors='strict', use_poll=False):
42 '''This takes a file descriptor (an int) or an object that support the
43 fileno() method (returning an int). All Python file-like objects
44 support fileno(). '''
45
46 if type(fd) != type(0) and hasattr(fd, 'fileno'):
47 fd = fd.fileno()
48
49 if type(fd) != type(0):
50 raise ExceptionPexpect('The fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.')
51
52 try: # make sure fd is a valid file descriptor
53 os.fstat(fd)
54 except OSError:
55 raise ExceptionPexpect('The fd argument is not a valid file descriptor.')
56
57 self.args = None
58 self.command = None
59 SpawnBase.__init__(self, timeout, maxread, searchwindowsize, logfile,
60 encoding=encoding, codec_errors=codec_errors)
61 self.child_fd = fd
62 self.own_fd = False
63 self.closed = False
64 self.name = '<file descriptor %d>' % fd
65 self.use_poll = use_poll
66
67 def close (self):
68 """Close the file descriptor.

Callers

nothing calls this directly

Calls 2

ExceptionPexpectClass · 0.85
filenoMethod · 0.80

Tested by

no test coverage detected