egXdZddlmZddlmZmZddlmZmZddl Z dgZ GddeZ y) aThis is like :mod:`pexpect`, but it will work with any file descriptor that you pass it. You are responsible for opening and close the file descriptor. This allows you to use Pexpect with sockets and named pipes (FIFOs). .. note:: socket.fileno() does not give a readable file descriptor on windows. Use :mod:`pexpect.socket_pexpect` for cross-platform socket support PEXPECT LICENSE This license is approved by the OSI and FSF as GPL-compatible. http://opensource.org/licenses/isc-license.txt Copyright (c) 2012, Noah Spurrier PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ) SpawnBase)ExceptionPexpectTIMEOUT)select_ignore_interruptspoll_ignore_interruptsNfdspawnc\eZdZdZ d dZdZdZd dZdZdZ dZ d Z d fd Z xZ S)r zThis is like pexpect.spawn but allows you to supply your own open file descriptor. For example, you could use it to read through a file looking for patterns, or to control a modem or serial device. c t|tdk7rt|dr|j}t|tdk7r td t j |d|_d|_tj|||||||||_ d|_ d|_ d|z|_| |_y#t $r tdwxYw) zThis takes a file descriptor (an int) or an object that support the fileno() method (returning an int). All Python file-like objects support fileno(). rfilenozdThe fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.z/The fd argument is not a valid file descriptor.N)encoding codec_errorsFz)typehasattrr rosfstatOSErrorargscommandr__init__child_fdown_fdclosednameuse_poll) selffdrtimeoutmaxreadsearchwindowsizelogfiler rrs 3/usr/lib/python3/dist-packages/pexpect/fdpexpect.pyrzfdspawn.__init__(s 8tAw 72x#8B 8tAw "$JK K V HHRL  4'3CW$,< I   *R/    V"#TU U Vs B==Cc|jdk(ry|jtj|jd|_d|_y)zClose the file descriptor. Calling this method a second time does nothing, but if the file descriptor was closed elsewhere, :class:`OSError` will be raised. NT)rflushrcloserrs r"r&z fdspawn.closeCs: ==B      cr|jdk(ry tj|jy#YyxYw)zThis checks if the file descriptor is still valid. If :func:`os.fstat` does not raise an exception then we assume it is alive. r$FT)rrrr's r"isalivezfdspawn.isaliveQs5 ==B   HHT]] # s26ctd)z1Deprecated and invalid. Just raises an exception.z.This method is not valid for file descriptors.)r)rforces r" terminatezfdspawn.terminate]sOPPr(c|j|}|j|d|jj|d}t j |j |S)z+Write to fd, return number of bytes writtensendF)final)_coerce_send_string_log_encoderencoderwriter)rsbs r"r/z fdspawn.senddsN  $ $Q ' !V MM % 0xx q))r(c`|j|}|j||jzS)zAWrite to fd with trailing newline, return number of bytes written)r1r/lineseprr6s r"sendlinezfdspawn.sendlinels*  $ $Q 'yyT\\)**r(c&|j|y)zWrite to fd, return NoneN)r/r:s r"r5z fdspawn.writeqs  ! r(c4|D]}|j|y)z+Call self.write() for each item in sequenceN)r5)rsequencer6s r" writelineszfdspawn.writelinesus A JJqM r(ctjdk(rf|dk(r |j}|jg}g}g}|jr t ||}nt ||||\}}}|j|vr tdtt|+|S)a Read from the file descriptor and return the result as a string. The read_nonblocking method of :class:`SpawnBase` assumes that a call to os.read will not block (timeout parameter is ignored). This is not the case for POSIX file-like objects such as sockets and serial ports. Use :func:`select.select`, timeout is implemented conditionally for POSIX systems. :param int size: Read at most *size* bytes. :param int timeout: Wait timeout seconds for file descriptor to be ready to read. When -1 (default), use self.timeout. When 0, poll. :return: String containing the bytes read posixr$zTimeout exceeded.) rrrrrrrrsuperr read_nonblocking)rsizerrlistwlistxlist __class__s r"rCzfdspawn.read_nonblockingzs 77g "},,]]OEEE}}.ug>&>5%'#ue}}E)122Wd4T::r()NiNNNstrictF)F)rr$)__name__ __module__ __qualname____doc__rr&r*r-r/r;r5r?rC __classcell__)rHs@r"r r #sE>SWOT!6  Q*+  ;;r() rN spawnbaser exceptionsrrutilsrrr__all__r r(r"rUs-6!1C +u;iu;r(