
uGLc           @   s5  y e  e Wn3 e e f k
 rA e Z  d  e f d     YZ n Xd   Z e d g  Z e d g  Z e d g  Z	 e d g  Z
 d d d	 d
 d f \ Z Z Z Z Z d d d f \ Z Z Z d d d d f \ Z Z Z Z i d e 6d e 6d e 6d e 6d e 6Z d e f d     YZ d e f d     YZ e d  Z e d  Z d e f d     YZ d  e f d!     YZ  e! d" k r1d# d$ l" Z" e    Z# e" j$ j% d% e# j&  e" j$ j% d& e# j'    e" j$ j% d' e# j(    e" j$ j% d( e# j)    e" j$ j% d) e# j*    e" j$ j% d* e#  n  d$ S(+   t	   bytearrayc           B   sG   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   d j  |   S(   Nt    (   t   join(   t   self(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __str__   s    c         C   s   d d j  |   S(   Ns   bytearray(%r)R   (   R   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __repr__   s    c         C   s<   t  | t  r" t j |  |  n t j |  t |   d  S(   N(   t
   isinstancet   strt   listt   appendt   chr(   R   t   item(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR	      s    c         C   s"   x | D] } |  j  |  q W|  S(   N(   R	   (   R   t   othert   byte(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __iadd__   s    c         C   s   t  t j |  | |   S(   N(   R    R   t   __getslice__(   R   t   it   j(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR   #   s    c         C   s?   t  | t  r% t t j |  |   St t j |  |   Sd  S(   N(   R   t   sliceR    R   t   __getitem__t   ord(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR   &   s    c         C   s.   t  | t  r t |  } n  t j |  |  S(   N(   R   t
   basestringR    R   t   __eq__(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR   ,   s    (	   t   __name__t
   __module__R   R   R	   R   R   R   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR       s   						c         C   s1   t    } x |  D] } | j |  q Wt |  S(   s"   convert a sequence to a bytes type(   R    R	   t   bytes(   t   seqt   bR   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   to_bytes3   s    	i   i   i   i
   t   Nt   Et   Ot   Mt   Si   g      ?i   i   i   i   i   t   Nonet   Event   Oddt   Markt   Spacet   SerialExceptionc           B   s   e  Z d  Z RS(   s.   Base class for serial port related exceptions.(   R   R   t   __doc__(    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR'   O   s   t   SerialTimeoutExceptionc           B   s   e  Z d  Z RS(   s    Write timeouts give an exception(   R   R   R(   (    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR)   S   s   s   Write timeouts)   Attempting to use a port that is not opent   FileLikec           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d e d  Z d e d	  Z d d
  Z d d  Z d   Z d d  Z d   Z RS(   s  An abstract file like class.

    This class implements readline and readlines based on read and
    writelines based on write.
    This class is used to provide the above functions for to Serial
    port objects.

    Note that when the serial port was opened with _NO_ timeout that
    readline blocks until it sees a newline (or the specified size is
    reached) and that readlines would never return and therefore
    refuses to work (it raises an exception in this case)!
    c         C   s   t  |  _ d  S(   N(   t   Truet   closed(   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __init__i   s    c         C   s   t  |  _ d  S(   N(   R+   R,   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   closel   s    c         C   s   y |  j    Wn n Xd S(   s   Destructor.  Calls close().N(   R.   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __del__p   s    c         C   s"   x | D] } |  j  |  q Wd  S(   N(   t   write(   R   t   sequencet   line(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   writelines|   s    c         C   s   d S(   s   flush of file like objectsN(    (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   flush   s    c         C   s   |  j    } | s t  n  | S(   N(   t   readlinet   StopIteration(   R   R2   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   next   s     	c         C   s   |  S(   N(    (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   __iter__   s    c         C   s   t  |  } t   } xd t r{ |  j d  } | rw | | 7} | | | k rR Pn  | d k	 rx t  |  | k rx Pqx q Pq Wt |  S(   sk   read a line which is terminated with end-of-line (eol) character
        ('
' by default) or until timeout.i   N(   t   lenR    R+   t   readR"   R   (   R   t   sizet   eolt   leneolR2   t   c(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR5      s    		
c         C   sr   |  j  d k r t d   n  g  } xG t rm |  j d |  } | ri | j |  | d | k rj Pqj q' Pq' W| S(   sA   read a list of lines, until timeout.
        sizehint is ignored.s8   Serial port MUST have enabled timeout for this function!R<   iN(   t   timeoutR"   t
   ValueErrorR+   R5   R	   (   R   t   sizehintR<   t   linesR2   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   readlines   s    	c         c   s,   x% t  r' |  j   } | s Pn  | Vq Wd S(   sw   Read lines, implemented as generator. It will raise StopIteration on
        timeout (empty read). sizehint is ignored.N(   R+   R5   (   R   RA   R2   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   xreadlines   s
    	 i    c         C   s   t  d   d  S(   Ns   file is not seekable(   t   IOError(   R   t   post   whence(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   seek   s    c         C   s   t  d   d  S(   Ns   file is not seekable(   RE   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   tell   s    c         C   s   t  d   d  S(   Ns   file is not seekable(   RE   (   R   t   n(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   truncate   s    c         C   s   t  S(   N(   t   False(   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   isatty   s    N(   R   R   R(   R-   R.   R/   R3   R4   R7   R8   R"   t   LFR5   RC   RD   RH   RI   RK   RM   (    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR*   [   s   								t
   SerialBasec           B   s  e  Z d  Z dX Z e e e e f Z e	 e
 e e e f Z e e e f Z dY d e e	 e dY e e dY e dY d  Z d    Z d!   Z d"   Z d#   Z d$   Z d%   Z d&   Z e e e d' d( Z d)   Z d*   Z  e e  e d' d+ Z! d,   Z" d-   Z# e e# e" d' d. Z$ d/   Z% d0   Z& e e& e% d' d1 Z' d2   Z( d3   Z) e e) e( d' d4 Z* d5   Z+ d6   Z, e e, e+ d' d7 Z- d8   Z. d9   Z/ e e/ e. d' d: Z0 d;   Z1 d<   Z2 e e2 e1 d' d= Z3 d>   Z4 d?   Z5 e e5 e4 d' d@ Z6 dY dA  Z7 dB   Z8 e e8 e7 dC  Z9 dD   Z: dE   Z; e e; e: d' dF Z< dZ Z= dQ   Z> dR   Z? dS   Z@ dT   ZA dU   ZB dV   ZC dW   ZD RS([   sb   Serial port base class. Provides __init__ function and properties to
       get/set port settings.i2   iK   in   i   i   i   i,  iX  i  i  i`	  i  i%  i K  i   i   i  i  i  i  i  i  i@B i  i` i i%& i- ig5 i 	= c         C   s   t  |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ d |  _ d |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ | |  _ |
 |  _ | |  _ | d k	 r |  j   n  d S(   s   Initialize comm port object. If a port is given, then the port will be
           opened immediately. Otherwise a Serial port object in closed state
           is returned.N(   RL   t   _isOpenR"   t   _portt	   _baudratet	   _bytesizet   _parityt	   _stopbitst   _timeoutt   _writeTimeoutt   _xonxofft   _rtsctst   _dsrdtrt   _interCharTimeoutt   portt   baudratet   bytesizet   parityt   stopbitsR?   t   writeTimeoutt   xonxofft   rtsctst   dsrdtrt   interCharTimeoutt   open(   R   R\   R]   R^   R_   R`   R?   Rb   Rc   Ra   Rd   Re   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR-      s2    																							c         C   s   |  j  S(   s   Check if the port is opened.(   RP   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   isOpen  s    c         C   s&   g  |  j  D] } t |  | f ^ q
 S(   N(   t	   BAUDRATESR   (   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getSupportedBaudrates  s    c         C   s&   g  |  j  D] } t |  | f ^ q
 S(   N(   t	   BYTESIZESR   (   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getSupportedByteSizes  s    c         C   s&   g  |  j  D] } t |  | f ^ q
 S(   N(   t   STOPBITSR   (   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getSupportedStopbits  s    c         C   s$   g  |  j  D] } t | | f ^ q
 S(   N(   t   PARITIESt   PARITY_NAMES(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getSupportedParities  s    c         C   s   |  j  } | r |  j   n  | d k	 rX t | t  rC | |  _ qa |  j |  |  _ n	 d |  _ | |  _ |  j |  _ | r |  j	   n  d S(   sh   Change the port. The attribute portstr is set to a string that
           contains the name of the port.N(
   RP   R.   R"   R   R   t   portstrt   makeDeviceNameRQ   t   nameRf   (   R   R\   t   was_open(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setPort  s    	 		 c         C   s   |  j  S(   s   Get the current port setting. The value that was passed on init or using
           setPort() is passed back. See also the attribute portstr which contains
           the name of the port as a string.(   RQ   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getPort.  s    t   docs   Port settingc         C   sT   y t  |  |  _ Wn$ t k
 r9 t d | f   n X|  j rP |  j   n  d S(   s   Change baud rate. It raises a ValueError if the port is open and the
        baud rate is not possible. If the port is closed, then the value is
        accepted and the exception is raised when the port is opened.s   Not a valid baudrate: %rN(   t   intRR   t	   TypeErrorR@   RP   t   _reconfigurePort(   R   R]   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setBaudrate7  s    	 c         C   s   |  j  S(   s"   Get the current baud rate setting.(   RR   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getBaudrateB  s    s   Baud rate settingc         C   sH   | |  j  k r% t d | f   n  | |  _ |  j rD |  j   n  d S(   s   Change byte size.s   Not a valid byte size: %rN(   Rj   R@   RS   RP   Rz   (   R   R^   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setByteSizeI  s
     		 c         C   s   |  j  S(   s"   Get the current byte size setting.(   RS   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getByteSizeO  s    s   Byte size settingc         C   sH   | |  j  k r% t d | f   n  | |  _ |  j rD |  j   n  d S(   s   Change parity setting.s   Not a valid parity: %rN(   Rn   R@   RT   RP   Rz   (   R   R_   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   setParityV  s
     		 c         C   s   |  j  S(   s   Get the current parity setting.(   RT   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   getParity\  s    s   Parity settingc         C   sH   | |  j  k r% t d | f   n  | |  _ |  j rD |  j   n  d S(   s   Change stop bits size.s   Not a valid stop bit size: %rN(   Rl   R@   RU   RP   Rz   (   R   R`   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setStopbitsc  s
     		 c         C   s   |  j  S(   s"   Get the current stop bits setting.(   RU   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getStopbitsi  s    s   Stop bits settingc         C   s   | d k	 rd y | d Wn$ t k
 r> t d | f   n X| d k  rd t d | f   qd n  | |  _ |  j r |  j   n  d S(   s   Change timeout setting.i   s   Not a valid timeout: %ri    N(   R"   Ry   R@   RV   RP   Rz   (   R   R?   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   setTimeoutp  s     		 c         C   s   |  j  S(   s    Get the current timeout setting.(   RV   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   getTimeout{  s    s   Timeout setting for read()c         C   s   | d k	 ra | d k  r. t d | f   n  y | d Wqa t k
 r] t d |   qa Xn  | |  _ |  j r |  j   n  d S(   s   Change timeout setting.i    s   Not a valid timeout: %ri   N(   R"   R@   Ry   RW   RP   Rz   (   R   R?   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setWriteTimeout  s     		 c         C   s   |  j  S(   s    Get the current timeout setting.(   RW   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getWriteTimeout  s    s   Timeout setting for write()c         C   s#   | |  _  |  j r |  j   n  d S(   s   Change XON/XOFF setting.N(   RX   RP   Rz   (   R   Rb   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   setXonXoff  s    		 c         C   s   |  j  S(   s!   Get the current XON/XOFF setting.(   RX   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt
   getXonXoff  s    s   XON/XOFF settingc         C   s#   | |  _  |  j r |  j   n  d S(   s$   Change RTS/CTS flow control setting.N(   RY   RP   Rz   (   R   Rc   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   setRtsCts  s    		 c         C   s   |  j  S(   s-   Get the current RTS/CTS flow control setting.(   RY   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   getRtsCts  s    s   RTS/CTS flow control settingc         C   s>   | d k r |  j |  _ n	 | |  _ |  j r: |  j   n  d S(   s#   Change DsrDtr flow control setting.N(   R"   RY   RZ   RP   Rz   (   R   Rd   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   setDsrDtr  s
    		 c         C   s   |  j  S(   s-   Get the current DSR/DTR flow control setting.(   RZ   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt	   getDsrDtr  s    s   DSR/DTR flow control settingc         C   s   | d k	 r^ | d k  r+ t d |   n  y | d Wq^ t k
 rZ t d |   q^ Xn  | |  _ |  j r} |  j   n  d S(   s'   Change inter-character timeout setting.i    s   Not a valid timeout: %ri   N(   R"   R@   Ry   R[   RP   Rz   (   R   Re   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   setInterCharTimeout  s     		 c         C   s   |  j  S(   s0   Get the current inter-character timeout setting.(   R[   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getInterCharTimeout  s    s*   Inter-character timeout setting for read()R]   R^   R_   R`   Rb   Rd   Rc   R?   Ra   Re   c         C   s3   t  g  |  j D] } | t |  d |  f ^ q  S(   sQ   Get current port settings as a dictionary. For use with
        applySettingsDictt   _(   t   dictt	   _SETTINGSt   getattr(   R   t   key(    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   getSettingsDict  s    c         C   sL   xE |  j  D]: } | | t |  d |  k r
 t |  | | |  q
 q
 Wd S(   s   apply stored settings from a dictionary returned from
        getSettingsDict. it's allowed to delete keys from the dictionary. these
        values will simply left unchanged.R   N(   R   R   t   setattr(   R   t   dR   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   applySettingsDict  s    c         C   sV   d |  j  j t |   |  j |  j |  j |  j |  j |  j |  j	 |  j
 |  j |  j f S(   sA   String representation of the current port settings and its state.s}   %s<id=0x%x, open=%s>(port=%r, baudrate=%r, bytesize=%r, parity=%r, stopbits=%r, timeout=%r, xonxoff=%r, rtscts=%r, dsrdtr=%r)(   t	   __class__R   t   idRP   Rq   R]   R^   R_   R`   R?   Rb   Rc   Rd   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyR     s    		c         C   s   t  S(   N(   R+   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   readable  s    c         C   s   t  S(   N(   R+   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   writable  s    c         C   s   t  S(   N(   RL   (   R   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   seekable  s    c         C   s   |  j  t |   } t |  } y | | | *WnP t k
 r } d d  l } t | | j  sh |  n  | j d |  | | *n X| S(   NiR   (   R:   R9   Ry   t   arrayR   (   R   R   t   dataRJ   t   errR   (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   readinto  s    	(   i2   iK   in   i   i   i   i,  iX  i  i  i`	  i  i%  i K  i   i   i  i  i  i  i  i  i@B i  i` i i%& i- ig5 i 	= N(
   s   baudrates   bytesizes   paritys   stopbitss   xonxoffs   dsrdtrs   rtsctss   timeouts   writeTimeouts   interCharTimeout(E   R   R   R(   Rh   t   FIVEBITSt   SIXBITSt	   SEVENBITSt	   EIGHTBITSRj   t   PARITY_NONEt   PARITY_EVENt
   PARITY_ODDt   PARITY_MARKt   PARITY_SPACERn   t   STOPBITS_ONEt   STOPBITS_ONE_POINT_FIVEt   STOPBITS_TWORl   R"   RL   R-   Rg   Ri   Rk   Rm   Rp   Ru   Rv   t   propertyR\   R{   R|   R]   R}   R~   R^   R   R   R_   R   R   R`   R   R   R?   R   R   Ra   R   R   Rb   R   R   Rc   R   R   Rd   R   R   Re   R   R   R   R   R   R   R   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyRO      s      #																								
			 		
				t   __main__iNs   port name:  %s
s   baud rates: %s
s   byte sizes: %s
s   parities:   %s
s   stop bits:  %s
s   %s
(+   R   R    t	   NameErrort   AttributeErrorR   R   R   t   XONt   XOFFt   CRRN   R   R   R   R   R   R   R   R   R   R   R   R   Ro   RE   R'   R)   t   writeTimeoutErrorR@   t   portNotOpenErrort   objectR*   RO   R   t   syst   st   stdoutR0   Rq   Ri   Rk   Rp   Rm   (    (    (    s5   /usr/lib/python2.7/dist-packages/serial/serialutil.pyt   <module>	   sF    	$
l @	