U
    ÎÕb+ÿ ã                   @   sV  d Z dZdZddlmZ zddlmZ W n  ek
rH   ddlmZ Y nX ddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl!Z!ddl"m#Z# ddl$m%Z% dd	l&m'Z' dd
l&m(Z) ddl*m+Z+ ddl,m-Z-m.Z. ej/d dkZ0ej/d Z1ej/d dkoŒe1dkZ2e0rÚddl&m3Z3 e3Z4ddl&m5Z6 e6Z7ddl8m9Z9m:Z: e;e<dƒsdd„ Z=n@ddl&m5Z7 ddl&m3Z4 ddl6m>Z6 ddl:m9Z9m:Z: ddl3m3Z3 zddl?m@ZA W n" ek
rL   ddlBm@ZA Y nX de C¡  D¡ krlede ƒ‚e+ƒ pvdZEe C¡ dkZFejG HejG IeJ¡¡ZKeLZMeNeOejP Qdd¡ƒƒZReNeOejP Qdd¡ƒƒZSe T¡ ZUe;edƒræd d!„ ZVnd"d!„ ZVe0reWZXeYZZeYZ[eOZ\e]e^eZƒ ƒƒZ_e;ed#ƒZ`dZadZbd$Zcd%Zde`rJeSsJG d&d'„ d'eeƒZfnG d(d'„ d'eeƒZfd)d*„ ZgdÉd+d,„ZhG d-d.„ d.eiƒZjG d/d0„ d0ekƒZlG d1d2„ d2eiƒZmG d3d4„ d4emƒZnG d5d6„ d6eiƒZoe]ejpejqejrejsejtejuejvejwejxejyejzfƒZ{G d7d8„ d8e|ƒZ}e ~d9¡Zi Z€ed:d;„ ej‚ ƒ¡ D ƒƒZ„d<d=„ Z…d>d?„ Z†ejZ‡G d@dA„ dAeˆƒZ‰dBdC„ Zee_dDdE„ ZŠdÊdFdG„Z‹dHdI„ ZŒdËdJdK„ZG dLdM„ dMeeƒZŽdÌdNdO„ZG dPdQ„ dQeeƒZdRdS„ Z‘dTdU„ Z’dVdW„ Z“dXdY„ Z”dZd[„ Z•d\d]„ Z–d^d_„ Z—d`da„ Z˜dbdc„ Z™ddde„ Zšdfdg„ Z›G dhdi„ dieeƒZœdjdk„ ZdÍdmdn„Zždodp„ ZŸdqdr„ Z dsdt„ Z¡dudv„ Z¢dwdx„ Z£dydz„ Z¤G d{d|„ d|eeƒZ¥d}d~„ Z¦dÎdd€„Z§dd‚„ Z¨dƒd„„ Z©G d…d†„ d†eiƒZªG d‡dˆ„ dˆeiƒZ«d‰dŠ„ Z¬d‹dŒ„ Z­ddŽ„ Z®dd„ Z¯d‘d’„ Z°d“d”„ Z±d•d–„ Z²G d—d˜„ d˜eeƒZ³d™dš„ Z´d›dœ„ Zµddž„ Z¶dŸd „ Z·d¡d¢„ Z¸d£d¤„ Z¹G d¥d¦„ d¦eeƒZºG d§d¨„ d¨eeƒZ»d©dª„ Z¼e¼eUƒd«d¬„ ƒZ½e#d­d®„ ƒZ¾G d¯d°„ d°eƒZ¿G d±d²„ d²eeƒZÀG d³d´„ d´e.ƒZÁeLdµ ZÂeÁeÂƒZÃeÃejÄeÂ< eÃd¶ƒd·d¶„ ƒZÅeÃd¸ƒd¹d¸„ ƒZÆeÃdºƒd»dº„ ƒZÇd¼d½„ ZÈG d¾d¿„ d¿e.ƒZÉdÀdÁ„ ZÊdÂdÃ„ ZËdÄdÅ„ ZÌG dÆdÇ„ dÇeeƒZÍeLdÈkr8e¿eÎƒ ƒZÏeÈeÏƒ neÉejÄeL ƒejÄeL< eËƒ  dS )Ïz
http://amoffat.github.io/sh/
z1.14.3zhttps://github.com/amoffat/shé    )Údeque)ÚMappingN©Úcontextmanager)Úpartial)ÚUnsupportedOperation)Úopen)Úgetpreferredencoding)ÚGeneratorTypeÚ
ModuleTypeé   é   é   é   )ÚStringIO)ÚBytesIO)ÚEmptyÚQueueÚcallablec                 C   s
   t | dƒS )NÚ__call__)Úhasattr©Úob© r   úX/var/www/pilapila.net/web_application_project/mywebapp/lib/python3.8/site-packages/sh.pyr   Q   s    )Ú
OutputType)ÚquoteZwindowszƒsh %s is currently only supported on linux and osx. please install pbs 0.110 (http://pypi.python.org/pypi/pbs) for windows support.zUTF-8)ZAIXÚDarwinZSH_TESTS_RUNNINGÚ0ZSH_TESTS_USE_SELECTÚgetfullargspecc                 C   s   t t | ¡jƒS ©N)ÚlenÚinspectr   Úargs©Úfnr   r   r   Úget_num_argsy   s    r&   c                 C   s   t t | ¡jƒS r    )r!   r"   Ú
getargspecr#   r$   r   r   r   r&   |   s    Úpollé   é   c                   @   st   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚPollerc                 C   s   t  ¡ | _i | _i | _d S r    )Úselectr(   Ú_pollÚ	fd_lookupÚ	fo_lookup©Úselfr   r   r   Ú__init__”   s    
úPoller.__init__c                 C   s   t | jƒdkS ©Nr   ©r!   r.   r0   r   r   r   Ú__nonzero__š   s    úPoller.__nonzero__c                 C   s
   t | jƒS r    r5   r0   r   r   r   Ú__len__   s    úPoller.__len__c                 C   s@   t |dƒr(| ¡ }|| j|< || j|< n|| j|< || j|< d S ©NÚfileno©r   r;   r.   r/   ©r1   ÚfÚfdr   r   r   Ú_set_fileobject    s    


zPoller._set_fileobjectc                 C   s8   t |dƒr$| ¡ }| j|= | j|= n| j|= | j|= d S r:   r<   r=   r   r   r   Ú_remove_fileobject©   s    

zPoller._remove_fileobjectc                 C   s   | j  |¡S r    )r/   Úget©r1   r>   r   r   r   Ú_get_file_descriptor²   s    zPoller._get_file_descriptorc                 C   s   | j  |¡S r    )r.   rB   )r1   r?   r   r   r   Ú_get_file_objectµ   s    zPoller._get_file_objectc                 C   s&   |   |¡ |  |¡}| j ||¡ d S r    )r@   rD   r-   Úregister)r1   r>   Úeventsr?   r   r   r   Ú	_register¸   s    

úPoller._registerc                 C   s   |   |tjtjB ¡ d S r    )rH   r,   ÚPOLLINÚPOLLPRIrC   r   r   r   Úregister_read¾   s    úPoller.register_readc                 C   s   |   |tj¡ d S r    )rH   r,   ÚPOLLOUTrC   r   r   r   Úregister_writeÁ   s    úPoller.register_writec                 C   s   |   |tjtjB tjB ¡ d S r    )rH   r,   ÚPOLLERRÚPOLLHUPÚPOLLNVALrC   r   r   r   Úregister_errorÄ   s    úPoller.register_errorc                 C   s$   |   |¡}| j |¡ |  |¡ d S r    )rD   r-   Ú
unregisterrA   r=   r   r   r   rV   Ç   s    
úPoller.unregisterc                 C   s®   |d k	r|d9 }| j  |¡}g }|D ]„\}}|  |¡}|tjtjB @ rV| |tf¡ q$|tj@ rp| |t	f¡ q$|tj
@ rŠ| |tf¡ q$|tjtjB @ r$| |tf¡ q$|S )Niè  )r-   r(   rE   r,   rJ   rK   ÚappendÚPOLLER_EVENT_READrN   ÚPOLLER_EVENT_WRITErR   ÚPOLLER_EVENT_HUPrQ   rS   ÚPOLLER_EVENT_ERROR)r1   ÚtimeoutÚchangesÚresultsr?   rG   r>   r   r   r   r(   Ì   s    


úPoller.pollN)Ú__name__Ú
__module__Ú__qualname__r2   r6   r8   r@   rA   rD   rE   rH   rL   rO   rT   rV   r(   r   r   r   r   r+   “   s   		r+   c                   @   sd   e Zd Zdd„ Zdd„ Zdd„ Zedd„ ƒZed	d
„ ƒZdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )r+   c                 C   s   g | _ g | _g | _d S r    )ÚrlistÚwlistÚxlistr0   r   r   r   r2   ß   s    r3   c                 C   s"   t | jƒt | jƒ t | jƒ dkS r4   ©r!   rd   re   rf   r0   r   r   r   r6   ä   s    r7   c                 C   s   t | jƒt | jƒ t | jƒ S r    rg   r0   r   r   r   r8   ç   s    r9   c                 C   s   | |kr|  | ¡ d S r    )rX   ©r>   rG   r   r   r   rH   ê   s    rI   c                 C   s   | |kr|  | ¡ d S r    )Úremoverh   r   r   r   Ú_unregisterï   s    zPoller._unregisterc                 C   s   |   || j¡ d S r    )rH   rd   rC   r   r   r   rL   ô   s    rM   c                 C   s   |   || j¡ d S r    )rH   re   rC   r   r   r   rO   ÷   s    rP   c                 C   s   |   || j¡ d S r    )rH   rf   rC   r   r   r   rT   ú   s    rU   c                 C   s.   |   || j¡ |   || j¡ |   || j¡ d S r    )rj   rd   re   rf   rC   r   r   r   rV   ý   s    rW   c                 C   sl   t   | j| j| j|¡\}}}g }|D ]}| |tf¡ q$|D ]}| |tf¡ q<|D ]}| |tf¡ qT|S r    )r,   rd   re   rf   rX   rY   rZ   r\   )r1   r]   Ú_inÚ_outZ_errr_   r>   r   r   r   r(     s    r`   N)ra   rb   rc   r2   r6   r8   ÚstaticmethodrH   rj   rL   rO   rT   rV   r(   r   r   r   r   r+   Þ   s   

c                 C   s¬   d}t rLt| tƒrq¨t| ƒ} zt| tƒ} W q¨ tk
rH   t| |ƒ} Y q¨X n\zt| tƒ} W n tk
rv   t| ƒ} Y nX z|  t¡} W n  tk
r¦   |  |d¡} Y nX | S )z  takes anything and attempts to return a py2 string or py3 bytes.  this
    is typically used when creating command + arguments to be executed via
    os.exec* Úutf8Úreplace)	ÚIS_PY3Ú
isinstanceÚbytesÚstrÚDEFAULT_ENCODINGÚUnicodeEncodeErrorÚunicodeÚ	TypeErrorÚencode)ÚsÚfallback_encodingr   r   r   Úencode_to_py3bytes_or_py2str  s$    
r{   c                 C   s4   g }|   d¡D ]}d| | }| |¡ qd |¡S )NÚ
ú )ÚsplitrX   Újoin)ÚtextÚnumÚlinesÚliner   r   r   Ú_indent_text2  s
    r„   c                   @   s   e Zd Zdd„ ZdS )ÚForkExceptionc                 C   s    d}|t |ƒ }t | |¡ d S )Nz.

Original exception:
===================

%s
)r„   Ú	Exceptionr2   )r1   Úorig_excÚtmplÚmsgr   r   r   r2   ;  s    zForkException.__init__N©ra   rb   rc   r2   r   r   r   r   r…   :  s   r…   c                   @   s   e Zd ZdZdd„ ZdS )ÚErrorReturnCodeMetaaˆ   a metaclass which provides the ability for an ErrorReturnCode (or
    derived) instance, imported from one sh module, to be considered the
    subclass of ErrorReturnCode from another module.  this is mostly necessary
    in the tests, where we do assertRaises, but the ErrorReturnCode that the
    program we're testing throws may not be the same class that we pass to
    assertRaises
    c                 C   s*   t dd„ |jD ƒƒ}| j|kp(|j| jkS )Nc                 S   s   g | ]
}|j ‘qS r   )ra   )Ú.0Úbr   r   r   Ú
<listcomp>Q  s     z9ErrorReturnCodeMeta.__subclasscheck__.<locals>.<listcomp>)ÚsetÚ	__bases__ra   )r1   ÚoÚother_basesr   r   r   Ú__subclasscheck__P  s    z%ErrorReturnCodeMeta.__subclasscheck__N)ra   rb   rc   Ú__doc__r“   r   r   r   r   r‹   G  s   r‹   c                       s.   e Zd ZeZdZdd„ Zd‡ fdd„	Z‡  ZS )ÚErrorReturnCodeiî  c                 C   s   | j | j| j| j| jffS r    )Ú	__class__Úfull_cmdÚstdoutÚstderrÚtruncater0   r   r   r   Ú
__reduce__n  s    zErrorReturnCode.__reduce__Tc                    sÞ   || _ || _|| _|| _| j}|rV|d | j… }t| jƒt|ƒ }|rV|d|  ¡ 7 }| j}|r”|d | j… }t| jƒt|ƒ }|r”|d|  ¡ 7 }tdƒ}	|	j| j | 	t
d¡| 	t
d¡d}
tsÊt|
ƒ}
tt| ƒ |
¡ d S )Nz"... (%d more, please see e.stdout)z"... (%d more, please see e.stderr)z6

  RAN: {cmd}

  STDOUT:
{stdout}

  STDERR:
{stderr}ro   )Úcmdr˜   r™   )r—   r˜   r™   rš   Útruncate_capr!   rx   rv   ÚformatÚdecodert   rp   r{   Úsuperr•   r2   )r1   r—   r˜   r™   rš   Ú
exc_stdoutÚ	out_deltaÚ
exc_stderrÚ	err_deltaÚmsg_tmplr‰   ©r–   r   r   r2   q  s2    

ýzErrorReturnCode.__init__)T)	ra   rb   rc   r‹   Ú__metaclass__r   r›   r2   Ú__classcell__r   r   r¦   r   r•   U  s   r•   c                   @   s   e Zd ZdS )ÚSignalExceptionN©ra   rb   rc   r   r   r   r   r©   –  s   r©   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚTimeoutExceptionzx the exception thrown when a command is killed because a specified
    timeout (via _timeout or .wait(timeout)) was hit c                    s   || _ || _tt| ƒ ¡  d S r    )Ú	exit_coder—   r    r†   r2   )r1   r¬   r—   r¦   r   r   r2   ž  s    zTimeoutException.__init__)ra   rb   rc   r”   r2   r¨   r   r   r¦   r   r«   š  s   r«   c                   @   s   e Zd ZdS )ÚCommandNotFoundNrª   r   r   r   r   r­   ¶  s   r­   z6(ErrorReturnCode|SignalException)_((\d+)|SIG[a-zA-Z]+)c                 C   s$   g | ]\}}t  d |¡r||f‘qS )zSIG[a-zA-Z]+)ÚreÚmatch©rŒ   ÚkÚvr   r   r   rŽ   ½  s      rŽ   c                 C   s”   d}z
t |  W S  tk
rŽ   t | ¡}|rŠ| d¡}| d¡}|dkrzzt|ƒ }W q‚ tk
rv   tt|ƒ }Y q‚X nt|ƒ}t	|ƒ}Y nX |S )a   takes an exception name, like:

        ErrorReturnCode_1
        SignalException_9
        SignalException_SIGHUP

    and returns the corresponding exception.  this is primarily used for
    importing exceptions from sh into user code, for instance, to capture those
    exceptions Nr   r   r©   )
Úrc_exc_cacheÚKeyErrorÚrc_exc_regexr¯   ÚgroupÚintÚ
ValueErrorÚgetattrÚsignalÚ
get_rc_exc)ÚnameÚexcÚmÚbaseÚrc_or_sig_nameÚrcr   r   r   Úget_exc_from_nameÀ  s     



rÂ   c                 C   sl   z
t |  W S  tk
r   Y nX | dkr6d|  }t}ntt| ƒ }d| }t}t||fd| iƒ}|t | < |S )aI   takes a exit code or negative signal number and produces an exception
    that corresponds to that return code.  positive return codes yield
    ErrorReturnCode exception, negative return codes yield SignalException

    we also cache the generated exception so that only one signal of that type
    exists, preserving identity r   zErrorReturnCode_%dÚSignalException_r¬   )r³   r´   r•   ÚSIGNAL_MAPPINGÚabsr©   r‹   )rÁ   r¼   r¿   Úsignamer½   r   r   r   r»   à  s    
r»   c                   @   s   e Zd Zdd„ ZdS )ÚGlobResultsc                 C   s   || _ t | |¡ d S r    )ÚpathÚlistr2   )r1   rÈ   r_   r   r   r   r2     s    zGlobResults.__init__NrŠ   r   r   r   r   rÇ     s   rÇ   c                 O   s   t | t| f|ž|Žƒ}|S r    )rÇ   Ú	_old_glob)rÈ   r#   ÚkwargsÚexpandedr   r   r   Úglob  s    rÍ   c                 C   s   t j t j | ¡¡S r    )ÚosrÈ   ÚabspathÚ
expanduser)rÈ   r   r   r   Úcanonicalize  s    rÑ   c           
      C   s¤   dd„ }d}t j | ¡\}}|r6t| ƒ} || ƒr | }njg }t|ttfƒrT| |¡ n t j 	dd¡ t j
¡}| |¡ |D ]&}t j t|ƒ| ¡}	||	ƒrx|	} q qx|S )a-   takes a program name or full path, plus an optional collection of search
    paths, and returns the full path of the requested executable.  if paths is
    specified, it is the entire list of search paths, and the PATH env is not
    used at all.  otherwise, PATH env is used to look for the program c                 S   s.   t j | ¡o,t  | t j¡o,t j t j | ¡¡S r    )rÎ   rÈ   ÚexistsÚaccessÚX_OKÚisfileÚrealpath)Ú	file_pathr   r   r   Úis_exe#  s
    ÿþz_which.<locals>.is_exeNÚPATHÚ )rÎ   rÈ   r~   rÑ   rq   ÚtuplerÉ   ÚextendÚenvironrB   Úpathsepr   )
ÚprogramÚpathsrØ   Ú
found_pathÚfpathÚfnameÚpaths_to_searchÚ	env_pathsrÈ   Úexe_filer   r   r   Ú_which  s$    
rç   c                 C   s0   t | ƒ}|s,d| kr$t |  dd¡ƒ}|s,d S |S )NÚ_ú-)rç   ro   )rß   rÈ   r   r   r   Úresolve_command_pathF  s    rê   c                 C   s,   t | ƒ}d }|r(t|ƒ}|r(|jf |Ž}|S r    )rê   ÚCommandÚbake)r¼   Ú
baked_argsrÈ   rœ   r   r   r   Úresolve_commandT  s    rî   c                   @   sV   e Zd ZdZddd„Zdd„ Zedd„ ƒZd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚLoggeraG   provides a memory-inexpensive logger.  a gotcha about python's builtin
    logger is that logger objects are never garbage collected.  if you create a
    thousand loggers with unique names, they'll sit there in memory until your
    script is done.  with sh, it's easy to create loggers with unique names if
    we want our loggers to include our command arguments.  for example, these
    are all unique loggers:

            ls -l
            ls -l /tmp
            ls /tmp

    so instead of creating unique loggers, and without sacrificing logging
    output, we use this class, which maintains as part of its state, the logging
    "context", which will be the very unique name.  this allows us to get a
    logger with a very general name, eg: "command", and have a unique name
    appended to it via the context, eg: "ls -l /tmp" Nc                 C   s*   || _ t dt|f ¡| _|  |¡| _d S )Nz%s.%s)r¼   ÚloggingÚ	getLoggerÚSH_LOGGER_NAMEÚlogÚsanitize_contextÚcontext)r1   r¼   rõ   r   r   r   r2   p  s    zLogger.__init__c                 G   s   | j rd| j |f }|| S )Nz%s: %s©rõ   ©r1   r‰   Úar   r   r   Ú_format_msgu  s    zLogger._format_msgc                 C   s   | r|   dd¡} | pdS )Nú%z%%rÚ   )ro   rö   r   r   r   rô   z  s    zLogger.sanitize_contextc                 C   s&   | j d | }| jd | }t||ƒS )NÚ.)r¼   rõ   rï   )r1   r¼   rõ   Únew_nameÚnew_contextr   r   r   Ú	get_child€  s    zLogger.get_childc                 G   s   | j  | j|f|žŽ ¡ d S r    )ró   Úinforù   r÷   r   r   r   rÿ   …  s    zLogger.infoc                 G   s   | j  | j|f|žŽ ¡ d S r    )ró   Údebugrù   r÷   r   r   r   r   ˆ  s    zLogger.debugc                 G   s   | j  | j|f|žŽ ¡ d S r    )ró   Úerrorrù   r÷   r   r   r   r  ‹  s    zLogger.errorc                 G   s   | j  | j|f|žŽ ¡ d S r    )ró   Ú	exceptionrù   r÷   r   r   r   r  Ž  s    zLogger.exception)N)ra   rb   rc   r”   r2   rù   rm   rô   rþ   rÿ   r   r  r  r   r   r   r   rï   ^  s   

rï   c                 C   s   |rd| |f }nd|  }|S )Nz<Command %r, pid %d>ú<Command %r>r   )rœ   Ú	call_argsÚpidry   r   r   r   Údefault_logger_str’  s    r  c                   @   sÖ   e Zd ZdZedƒZdd„ Zd.dd„Zdd	„ Zd
d„ Z	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZeZdd„ Zdd„ Zdd„ Zd d!„ ZdZd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ ZdS )/ÚRunningCommandaÊ   this represents an executing Command object.  it is returned as the
    result of __call__() being executed on a Command instance.  this creates a
    reference to a OProc instance, which is a low-level wrapper around the
    process that was exec'd

    this is the class that gets manipulated the most by user code, and so it
    implements various convenience methods and logical mechanisms for the
    underlying process.  for example, if a user tries to access a
    backgrounded-process's stdout/err, the RunningCommand object is smart enough
    to know to wait() on the process to finish first.  and when the process
    finishes, RunningCommand is smart enough to translate exit codes to
    exceptions. )rº   Ú	terminateÚkillÚ
kill_groupÚsignal_groupr  ÚsidÚpgidÚcttyÚinput_thread_excÚoutput_thread_excÚbg_thread_excc                    sà  |d ‰ d  ‡ fdd„|D ƒ¡| _|| _|| _d| _d| _d}d}d| _|d r`d}tƒ  | ¡ |d	 sx|d
 sx|d r|d}|d rˆd}|d r–t	j
}|d }|r°t|| ƒ|d< t	j
}	|d
 dksÎ|d
 dkrÖt	j
}	n|d
 dkrèt	j}	|d dks|d dkrt	j
}	n|d dkr t	j}	d| _|rÜ|d p8t}
|
| j|ƒ}td|ƒ| _| j d¡ |rjd| _t ¡ }|$ t	| | j||||| j|	|ƒ	| _W 5 Q R X |
| j|| jjƒ}| j |¡| j_| j d¡ |rÜ|  ¡  dS )z^
            cmd is a list, where each element is encoded as bytes (PY3) or str (PY2)
        Úencodingr}   c                    s   g | ]}t | ˆ d ¡ƒ‘qS ©Úignore)Úshlex_quoterŸ   ©rŒ   Úarg©Úencr   r   rŽ   Ç  s     z+RunningCommand.__init__.<locals>.<listcomp>NFTÚwithÚpipedÚiterÚiter_noblockÚbgÚ
err_to_outÚdoneÚoutÚerrÚlog_msgÚcommandzstarting processzprocess started)r   Úranr  rœ   ÚprocessÚ_waited_until_completionÚ_stopped_iterationÚget_prepend_stackrX   ÚOProcÚSTDOUTr   ÚSTDERRÚ_spawned_and_waitedr  rï   ró   r   Ú	threadingÚLockr  rô   rõ   rÿ   Úwait)r1   rœ   r  Ústdinr˜   r™   Úshould_waitÚspawn_processÚdone_callbackÚpipeÚlog_str_factoryÚ
logger_strÚprocess_assign_lockr   r  r   r2   ¹  sd      ÿzRunningCommand.__init__Nc                 C   sÐ   | j sÌ|dk	rxd}d}d}d}|dk r.tdƒ‚||kr`| j ¡ \}}|r`t |¡ ||7 }q.q`q.|rptd| jƒ‚d| _ n| j ¡ }d| _ | jj	r t| | jƒ‚n |  
|¡ | jjrÀ| jjj ¡  | j d¡ | S )aË   waits for the running command to finish.  this is called on all
        running commands, eventually, except for ones that run in the background

        if timeout is a number, it is the number of seconds to wait for the process to resolve. otherwise block on wait.

        this function can raise a TimeoutException, either because of a `_timeout` on the command itself as it was
        launched, or because of a timeout passed into this method.
        Nr   çš™™™™™¹?Fztimeout cannot be negativeTzprocess completed)r'  ÚRuntimeErrorr&  Úis_aliveÚtimeÚsleepr«   r%  r0  Ú	timed_outÚhandle_command_exit_codeÚ_stdin_processr$  ró   r   )r1   r]   Ú
waited_forÚ	sleep_amtÚaliver¬   r   r   r   r0    s4    	



zRunningCommand.waitc                 C   s   | j  ¡ d S )zO returns whether or not we're still alive. this call has side-effects on OProc r   )r&  r;  r0   r   r   r   r;  Y  s    zRunningCommand.is_alivec                 C   sB   | j }t||d |d ƒ}|r>|| j| jj| jj|d ƒ}|‚dS )z› here we determine if we had an exception, or an error code that we
        weren't expecting to see.  if we did, we create and raise an exception
        Úok_coder  Útruncate_excN)r  Úget_exc_exit_code_would_raiser%  r&  r˜   r™   )r1   ÚcodeÚcaÚ	exc_classr½   r   r   r   r?  ]  s
    z'RunningCommand.handle_command_exit_codec                 C   s   |   ¡  | jjS r    )r0  r&  r˜   r0   r   r   r   r˜   g  s    zRunningCommand.stdoutc                 C   s   |   ¡  | jjS r    )r0  r&  r™   r0   r   r   r   r™   l  s    zRunningCommand.stderrc                 C   s   |   ¡  | jjS r    )r0  r&  r¬   r0   r   r   r   r¬   q  s    zRunningCommand.exit_codec                 C   s   t t| ƒƒS r    )r!   rs   r0   r   r   r   r8   v  s    zRunningCommand.__len__c                 C   s   dS )zí we don't actually do anything here because anything that should have
        been done would have been done in the Command.__call__ call.
        essentially all that has to happen is the command be pushed on the
        prepend stack. Nr   r0   r   r   r   Ú	__enter__y  s    zRunningCommand.__enter__c                 C   s   | S r    r   r0   r   r   r   Ú__iter__€  s    zRunningCommand.__iter__c                 C   s¦   | j rtƒ ‚z| jj d| jd ¡}W n( tk
rN   | jd rJtj Y S Y qX |dkrl|  	¡  d| _ tƒ ‚z| 
| jd | jd ¡W S  tk
rž   | Y S X qdS )z4 allow us to iterate over the output of our command TÚiter_poll_timer  Nr  Údecode_errors)r(  ÚStopIterationr&  Ú_pipe_queuerB   r  r   ÚerrnoÚEWOULDBLOCKr0  rŸ   ÚUnicodeDecodeError©r1   Úchunkr   r   r   Únextƒ  s    
zRunningCommand.nextc                 C   s   | j d rtƒ rtƒ  ¡  d S )Nr  )r  r)  Úpop©r1   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__ž  s    zRunningCommand.__exit__c                 C   s$   t r|  ¡ S t| ƒ | jd ¡S dS )úY in python3, should return unicode.  in python2, should return a
        string of bytes r  N)rp   Ú__unicode__rv   rx   r  r0   r   r   r   Ú__str__¢  s    zRunningCommand.__str__c                 C   s:   | j r&| jr&| j | jd | jd ¡S tr.dS tdƒS dS )zj a magic method defined for python2.  calling unicode() on a
        RunningCommand object will call this r  rM  rÚ   N)r&  r˜   rŸ   r  rp   rv   r0   r   r   r   r]  ª  s
    zRunningCommand.__unicode__c                 C   s   t | ƒt |ƒkS r    )rv   ©r1   Úotherr   r   r   Ú__eq__´  s    zRunningCommand.__eq__c                 C   s   |t | ƒkS r    ©rs   )r1   Úitemr   r   r   Ú__contains__¹  s    zRunningCommand.__contains__c                 C   s>   || j kr | jrt| j|ƒS t‚|tkr6tt| ƒ|ƒS t‚d S r    )Ú_OProc_attr_whitelistr&  r¹   ÚAttributeErrorÚ_unicode_methodsrv   )r1   Úpr   r   r   Ú__getattr__¼  s    
zRunningCommand.__getattr__c                 C   sF   z
t | ƒW S  tk
r@   | jr4| jr4t| jƒ Y S tdƒ Y S X dS )r\  rÚ   N)rs   rR  r&  r˜   Úreprr0   r   r   r   Ú__repr__Ï  s    
zRunningCommand.__repr__c                 C   s   t t| ƒ ¡ ƒS r    )Úlongrs   Ústripr0   r   r   r   Ú__long__Ú  s    zRunningCommand.__long__c                 C   s   t t| ƒ ¡ ƒS r    )Úfloatrs   rm  r0   r   r   r   Ú	__float__Ý  s    zRunningCommand.__float__c                 C   s   t t| ƒ ¡ ƒS r    )r·   rs   rm  r0   r   r   r   Ú__int__à  s    zRunningCommand.__int__)N)ra   rb   rc   r”   r   re  r2   r0  r;  r?  Úpropertyr˜   r™   r¬   r8   rJ  rK  rU  Ú__next__r[  r^  r]  ra  Ú__hash__rd  ri  rk  rn  rp  rq  r   r   r   r   r  š  s8   ]
C




r  c                 C   s   t | tƒpt| dƒS )NÚ
__fspath__)rq   Ú
basestringr   )r!  r   r   r   Úoutput_redirect_is_filenameä  s    rw  c                  C   s   t j} t| dƒsg | _| jS )NÚ_prepend_stack)rë   Úthread_localr   rx  )Útlr   r   r   r)  è  s    
r)  c           	      C   s`   t |  ¡ ƒ}g }|D ]F}t|ƒr:|}|| |ƒ}| |¡ q|\}}| |¡r| ||f¡ q|S r    )r   Úkeysr   rÜ   Ú
issupersetrX   )	Úpassed_kwargsÚmerged_kwargsÚinvalid_listÚs1Úinvalid_argsÚelemr%   ÚretÚ	error_msgr   r   r   Úspecial_kwarg_validatorï  s    

r…  c                 C   sT   t | dd ƒ}d }|r6z
|ƒ }W qP tk
r2   Y qPX nt| ttfƒrP| dkrP| }|S )Nr;   r   )r¹   r   rq   r·   rl  )r   Úfileno_methr;   r   r   r   Ú
get_fileno  s    
r‡  c                 C   s   t | ƒd k	S r    )r‡  r   r   r   r   Úob_is_fd_based  s    rˆ  c                 C   s"   t | ƒ}d}|dk	rt |¡}|S )z: checks if an object (like a file-like object) is a tty.  FN)r‡  rÎ   Úisatty)r   r;   Úis_ttyr   r   r   Ú	ob_is_tty  s
    
r‹  c                 C   s*   t | ƒ}d}|r&t |¡}t |j¡}|S ©NF)r‡  rÎ   ÚfstatÚstatÚS_ISFIFOÚst_mode)r   r;   Úis_pipeÚfd_statr   r   r   Ú
ob_is_pipe#  s    
r“  c                 C   sr   d}g }|D ]>\}}|| krt |  |d ¡ƒrd||f }| ||f|f¡ q|d rn|d rd|d sn| d¡ |S )N))Útty_inÚin)Útty_outr!  zN`_%s` is a TTY already, so so it doesn't make sense to set up a TTY with `_%s`Ú
unify_ttysr”  r–  ))r—  r”  r–  zC`_tty_in` and `_tty_out` must both be True if `_unify_ttys` is True)r‹  rB   rX   )r}  r~  ÚpairsÚinvalidÚtty_typeÚstdr  r   r   r   Útty_in_validator,  s    
rœ  c                 C   sF   g }d}t dƒ}t |  ¡ ƒ| }d| krB| d rB|rB| d|f¡ |S )z3 fg is not valid with basically every other option z”_fg is invalid with nearly every other option, see warning and workaround here:

    https://amoffat.github.io/sh/sections/special_arguments.html#fg)ÚenvÚfgÚcwdrž  )r   r{  rX   )r}  r~  r™  r‰   Ú	whitelistÚ	offendingr   r   r   Úfg_validator@  s    r¢  c           
      C   s   g }|   dd¡}|   dd¡}|   dd¡}|   dd¡}t|ƒ}t|ƒ}d}	|rj|dk	rj| d|	jddf¡ |rŒ|dk	rŒ| d	|	jddf¡ |S )
a=   a validator to prevent a user from saying that they want custom
    buffering when they're using an in/out object that will be os.dup'ed to the
    process, and has its own buffering.  an example is a pipe or a tty.  it
    doesn't make sense to tell them to have a custom buffering, since the os
    controls this. r•  Nr!  Ú
in_bufsizeÚout_bufsizezICan't specify an {target} bufsize if the {target} target is a pipe or TTY)r•  r£  )Útarget)r!  r¤  )rB   rˆ  rX   rž   )
r}  r~  r™  Úin_obÚout_obÚin_bufÚout_bufÚ	in_no_bufÚ
out_no_bufr"  r   r   r   Úbufsize_validatorP  s    r¬  c                 C   s–   g }|   dd¡}|dkr|S t|tƒs>| dd |¡f¡ |S | d  ¡ D ]F\}}t|tƒsp| dd |¡f¡ t|tƒsJ| dd ||¡f¡ qJ|S )z« a validator to check that env is a dictionary and that all environment variable
    keys and values are strings. Otherwise, we would exit with a confusing exit code 255. r  Nzenv must be dict-like. Got {!r}zenv key {!r} must be a strz(value {!r} of env key {!r} must be a str)rB   rq   r   rX   rž   Úitemsrs   )r}  r~  r™  r  r±   r²   r   r   r   Úenv_validatorl  s    


r®  c                +   @   sî   e Zd ZdZe ¡ Zdddddddddddddddddddd	d
dddeddej	ddddddddddddde
ƒ dœ*Zdddddeeeef	Zd)dd„Zdd„ Zedd„ ƒZdd„ Zdd„ Zdd„ ZdZdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ ZdS )*rë   a   represents an un-run system program, like "ls" or "cd".  because it
    represents the program itself (and not a running instance of it), it should
    hold very little state.  in fact, the only state it does hold is baked
    arguments.

    when a Command object is called, the result that is returned is a
    RunningCommand object, which represents the Command put into an execution
    state. FTNr   r   i  0 r9  ú=z--Ústrict)é   éP   )*rž  r  Úbg_excr  r•  r!  r"  r  r£  r¤  Úerr_bufsizeÚinternal_bufsizer  r  r  r  rL  rD  rŸ  Úlong_sepÚlong_prefixr”  r–  r—  r  rM  r]   Útimeout_signalÚno_outÚno_errÚno_pipeÚteer   Útty_sizerE  Ú
preexec_fnÚuidÚnew_sessionÚarg_preprocessr#  Ú	close_fdsÚpass_fds))r"  r  z"Stderr is already being redirected))r  r  z3You cannot iterate when this command is being piped))r  r»  z;Using a pipe doesn't make sense if you've disabled the pipe))r¹  r  z4You cannot iterate over output if there is no output))rÂ  rÃ  z0Passing `pass_fds` forces `close_fds` to be Truec                 C   sT   t ||ƒ}tdƒ| _d| _g | _i | _t| ƒ| _|s<t|ƒ‚t|ƒ| _t| ƒ| _d S )NrÚ   F)	rç   r{   Ú_pathÚ_partialÚ_partial_baked_argsÚ_partial_call_argsrs   ra   r­   )r1   rÈ   Úsearch_pathsÚfoundr   r   r   r2     s    



zCommand.__init__c                 C   sd   t tj| ƒ}d }| d¡r$||ƒ}n(|dkr6|dƒ}n| d¡rL|d d… }|d kr`|dƒ|ƒ}|S )Nrè   rì   éÿÿÿÿ)r   ÚobjectÚ__getattribute__Ú
startswithÚendswith)r1   r¼   Úget_attrÚvalr   r   r   rÌ  (  s    



zCommand.__getattribute__c           
      C   sª   |   ¡ } i }tj ¡ D ]*\}}d| }|| kr| | ||< | |= qtj  ¡ }| |¡ t||tjƒ}|r¢g }|D ]\}}	| d||	f ¡ qpd |¡}t	d| ƒ‚|| fS )zÑ takes kwargs that were passed to a command's __call__ and extracts
        out the special keyword arguments, we return a tuple of special keyword
        args, and kwargs that will go to the exec'ed command rè   z  %r: %sr|   zInvalid special arguments:

%s
)
Úcopyrë   Ú
_call_argsr­  Úupdater…  Ú_kwarg_validatorsrX   r   rw   )
rË   r  ÚpargÚdefaultÚkeyÚmerged_argsÚinvalid_kwargsÚexc_msgÚkwargr„  r   r   r   Ú_extract_call_args>  s"    


zCommand._extract_call_argsc           
   	   O   sÐ   t | ƒ| jƒ}d|_|  |¡\}}|}tj ¡ D ]8\}}z|| |krL||= W q0 tk
rf   Y q0Y q0X q0|j 	| j¡ |j 	|¡ |j
 | j
¡ | d| jd ¡}| d| jd ¡}	|j
 t||||	ƒ¡ |S )NTr¶  r·  )ÚtyperÄ  rÅ  rÜ  rë   rÒ  r­  r´   rÇ  rÓ  rÆ  rÜ   rB   Úcompile_args)
r1   r#   rË   r%   r  Úpruned_call_argsr±   r²   ÚsepÚprefixr   r   r   rì   [  s"    
zCommand.bakec                 C   s   t r|  ¡ S |  ¡  t¡S dS )r\  N)rp   r]  rx   rt   r0   r   r   r   r^  q  s    zCommand.__str__c                 C   s   t | ƒt |ƒkS r    rb  r_  r   r   r   ra  y  s    zCommand.__eq__c                 C   s   dt | ƒ S )r\  r  rb  r0   r   r   r   rk  ~  s    zCommand.__repr__c                 C   s2   d  dd„ | jD ƒ¡}|r"d| }| j t¡| S )zY a magic method defined for python2.  calling unicode() on a
        self will call this r}   c                 s   s   | ]}|  t¡V  qd S r    ©rŸ   rt   )rŒ   rc  r   r   r   Ú	<genexpr>†  s     z&Command.__unicode__.<locals>.<genexpr>)r   rÆ  rÄ  rŸ   rt   )r1   rí   r   r   r   r]  ƒ  s    zCommand.__unicode__c                 C   s   | dd d S )NT)Ú_withr   r0   r   r   r   rJ  ‹  s    zCommand.__enter__c                 C   s   t ƒ  ¡  d S r    )r)  rV  rW  r   r   r   r[  Ž  s    zCommand.__exit__c              	   O   sl  |  ¡ }t|ƒ}g }tj  ¡ }tƒ D ]0}|j  ¡ }| dd ¡ | |¡ | |j	¡ q$| 
| j¡ | j dd ¡}|r‚|||ƒ\}}|  |¡\}}| | j¡ | |¡ |d d krºd|d< t|d dd ƒsØ|d g|d< |d }	|r&| d¡}
t|
tƒr|
jd r|
j}	n|
jj}	n| d|
¡ t|||d |d	 ƒ}| j| }|}| |¡ |d
 r|d pnt ¡ }t|ƒD |d d kržt tj|d |¡}nt tj|d ||d ¡}W 5 Q R X t||d |d ƒ}|rtrød dd„ |D ƒ¡}n
d |¡}||dd|d ƒ}|‚d S |d }t |ƒr<t!t"|ƒdƒ}|d }t |ƒr\t!t"|ƒdƒ}t|||	||ƒS )Nr  rÁ  rD  r   rK  r•  r  r¶  r·  rž  rŸ  r  r}   c                 S   s   g | ]}|  td ¡‘qS r  râ  r  r   r   r   rŽ   ã  s     z$Command.__call__.<locals>.<listcomp>ó    rE  r!  Úwbr"  )#rÑ  rÉ   rë   rÒ  r)  r  rV  rÓ  rÜ   rœ   rX   rÄ  rÇ  rB   rÜ  r¹   rq   r  r&  rO  ÚinsertrÞ  rÆ  rÎ   ÚgetcwdÚpushdÚspawnvÚP_WAITÚspawnverF  rp   r   rw  r   rs   )r1   r#   rË   rœ   r  ÚprependÚ
pcall_argsÚpreprocessorÚextracted_call_argsr1  Ú	first_argÚprocessed_argsÚ
split_argsÚ
final_argsrŸ  r¬   rI  r%  r½   r˜   r™   r   r   r   r   ‘  sj    










$


zCommand.__call__)N)ra   rb   rc   r”   r.  Úlocalry  rt   rº   ÚSIGKILLr   rÒ  rœ  r¬  r®  r¢  rÔ  r2   rÌ  rm   rÜ  rì   r^  ra  rt  rk  r]  rJ  r[  r   r   r   r   r   rë   ‚  sˆ   Žx÷

rë   c                 C   s¤   g }t }| D ]‚}t|ttfƒrNt|tƒr4|s4|jg}|D ]}| ||ƒ¡ q8qt|tƒrn|t|||dd7 }q|dksŽ|dkr€q| ||ƒ¡ q|t|||ƒ7 }|S )aŸ   takes args and kwargs, as they were passed into the command instance
    being executed with __call__, and compose them into a flat list that
    will eventually be fed into exec.  example:

    with this call:

        sh.ls("-l", "/tmp", color="never")

    this function receives

        args = ['-l', '/tmp']
        kwargs = {'color': 'never'}

    and produces

        ['-l', '/tmp', '--color=never']

    T)ÚrawNF)	r{   rq   rÉ   rÛ   rÇ   rÈ   rX   ÚdictÚaggregate_keywords)rø   rË   rà  rá  rò  rx   r  Úsub_argr   r   r   rÞ  ÷  s    
rÞ  Fc           	      C   sâ   g }t }|  ¡ D ]Ì\}}t|ƒdkrV|dk	rÜ| |d| ƒ¡ |dk	rÜ| ||ƒ¡ q|sf| dd¡}|dkr‚| ||| ƒ¡ q|dkrŒq|dksœ|dkr¾| ||| ƒ¡ | ||ƒ¡ q|d||||f ƒ}| |¡ q|S )	a   take our keyword arguments, and a separator, and compose the list of
    flat long (and short) arguments.  example

        {'color': 'never', 't': True, 'something': True} with sep '='

    becomes

        ['--color=never', '-t', '--something']

    the `raw` argument indicates whether or not we should leave the argument
    name alone, or whether we should replace "_" with "-".  if we pass in a
    dictionary, like this:

        sh.command({"some_option": 12})

    then `raw` gets set to True, because we want to leave the key as-is, to
    produce:

        ['--some_option=12']

    but if we just use a command's kwargs, `raw` is False, which means this:

        sh.command(some_option=12)

    becomes:

        ['--some-option=12']

    essentially, using kwargs is a convenience, but it lacks the ability to
    put a '-' in the name, so we do the replacement of '_' to '-' for you.
    but when you really don't want that to happen, you should use a
    dictionary instead with the exact names you want
    r   Fré   Trè   Nr}   z%s%s%s%s)r{   r­  r!   rX   ro   )	Úkeywordsrà  rá  r÷  Ú	processedrx   r±   r²   r  r   r   r   rù  $  s(    #rù  c                    s0   ‡ ‡fdd„}t j|||d}d|_| ¡  |S )Nc               
      sB   zˆ| |Ž W n. t k
r< } zˆ  |¡ ‚ W 5 d }~X Y nX d S r    )r†   Úput)ÚrgsrË   Úe©Ú	exc_queuer%   r   r   Úwrapg  s
    
z"_start_daemon_thread.<locals>.wrap)r¥  r¼   r#   T)r.  ÚThreadÚdaemonÚstart)r%   r¼   r  rø   r  Úthreadr   r   r   Ú_start_daemon_threadf  s
    r  c                 C   s8   |\}}t tddƒ}t d||dd¡}t | ||¡ dS )zU set the terminal size of a tty file descriptor.  borrowed logic
    from pexpect.py Ú
TIOCSWINSZigt€ÚHHHHr   N)r¹   ÚtermiosÚstructÚpackÚfcntlÚioctl)r?   Ú	rows_colsÚrowsÚcolsÚwinsizery   r   r   r   Ú
setwinsizet  s    r  c                    s¸   d}d}ˆ }t ˆ tƒr&tˆ jƒ}ˆ j}t |¡r>d}t|ƒ}n"t |¡rRt|ƒ}nd}t|j	ƒ}|| | }d‰|dkr|d‰|dkrŽ| j
f‰n|dkr¦| j
t | ¡f‰‡ ‡fdd„}|S )a`   here we're constructing a closure for our streamreader callback.  this
    is used in the case that we pass a callback into _out or _err, meaning we
    want to our callback to handle each bit of output

    we construct the closure based on how many arguments it takes.  the reason
    for this is to make it as easy as possible for people to use, without
    limiting them.  a new user will assume the callback takes 1 argument (the
    data).  as they get more advanced, they may want to terminate the process,
    or pass some stdin back, and will realize that they can pass a callback of
    more args r   r   r   r   r   c                    s0   ˆ}t |ƒdkr"ˆd ˆd ƒ f}ˆ | f|žŽ S )Nr   r   r   )r!   )rT  rø   ©ÚhandlerÚhandler_argsr   r   r%   ¶  s    z+construct_streamreader_callback.<locals>.fn)rq   r   r!   r#   Úfuncr"   Úismethodr&   Ú
isfunctionr   r1  ÚweakrefÚref)r&  r  Úimplied_argÚpartial_argsÚhandler_to_inspectÚnum_argsÚnet_argsr%   r   r  r   Úconstruct_streamreader_callback~  s.    







r!  c                 C   sB   d }| |k}|  t k}|r.|  tjkr.d}d}|r6|r>t| ƒ}|S )NFT)Ú#SIGNALS_THAT_SHOULD_THROW_EXCEPTIONrº   ÚSIGPIPEr»   )r¬   Úok_codesÚ
sigpipe_okr½   ÚsuccessÚbad_sigr   r   r   rF  Á  s    
rF  c                 C   s:   t  | ¡rt  | ¡ } nt  | ¡r.t  | ¡} ntdƒ‚| S )z= this should only ever be called once for each child process zUnknown child exit status!)rÎ   ÚWIFSIGNALEDÚWTERMSIGÚ	WIFEXITEDÚWEXITSTATUSr:  ©r¬   r   r   r   Úhandle_process_exit_codeÒ  s    

r-  c              
   O   sV   d}z| ||Ž}W qR t k
rL } z|jtjkr:W Y ¢
qn‚ W 5 d}~X Y qX qRq|S )z2 a helper for making system calls immune to EINTR N)ÚOSErrorrP  ÚEINTR)Úsyscallr#   rË   rƒ  rÿ  r   r   r   Úno_interruptà  s    
r1  c                   @   sØ   e Zd ZdZdZdZdZdd„ Zdd„ Ze	d	d
„ ƒZ
e	dd„ ƒZe	dd„ ƒZdd„ Zdd„ Zdd„ Ze	dd„ ƒZe	dd„ ƒZdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/S )0r*  a$   this class is instantiated by RunningCommand for a command to be exec'd.
    it handles all the nasty business involved with correctly setting up the
    input/output to the child process.  it gets its name for subprocess.Popen
    (process open) but we're calling ours OProc (open process) )é   r²  rÊ  éþÿÿÿc
           9         s6  |ˆ_ |ˆ_ˆj‰ ˆ d dk	rPt ¡ dkr2tdƒ‚ˆ d }
t ˆ d ¡}|j}nd\}
}ˆ d rhdˆ d< dˆ_t	|ƒ}t	|ƒ}t	|ƒ}ˆ d	 d
k}ˆ d	 dk}ˆ d o´ˆ d o´ˆ d }|rt
 ¡ \ˆ_ˆ_t ˆj¡ˆ_t ˆj¡ˆ_t ˆj¡ˆ_t ˆj¡ˆ_n:t|tƒr6|jd r6|jˆ_dˆ_|ˆ_nJ|rTt t|ƒ¡ˆ_dˆ_n,ˆ d rpt
 ¡ \ˆ_ˆ_nt ¡ \ˆ_ˆ_|r¤|s¤t t|ƒ¡ˆ_dˆ_n,ˆ d rÀt
 ¡ \ˆ_ˆ_nt ¡ \ˆ_ˆ_|tjkr|rð|sðdˆ_nt ˆj¡ˆ_t ˆj¡ˆ_n4|r2|s2t t|ƒ¡ˆ_dˆ_nt ¡ \ˆ_ˆ_ˆ d }dˆ_|rxˆj}|dkrlˆj}t |¡ˆ_ˆ d }ˆ d oŒ|}dˆ_|r¨t ˆj¡ˆ_t ¡ }|r¾t ¡  t ¡ \}}t ¡ \}}trêt ¡ \}}nd\}}dˆ_dˆ_ t !¡ ˆ_"ˆj"dkrLtr:t #|d¡ t $|¡ t $|¡ t% %|t%j&¡}|t%j'O }t% %|t%j(|¡ znˆ d dkr„t) )t)j*t)j+¡ t) )t)j,t)j-¡ |r¤t .¡  nt /¡  t 0d¡}t 1d¡} d|| f  2t3¡}!t 4||!¡ ˆ d r |s |s t5 6ˆj¡ ˆjrt $ˆj¡ ˆjr(t $ˆj¡ ˆjr<t $ˆj¡ t $|¡ t $|¡ ˆ d }"|"rht 7|"¡ t 8ˆjd¡ t 8ˆjd¡ t 8ˆjd¡ |r¶t 9t d¡tj:¡}#t $|#¡ ˆ d rÔ|sÔt;dˆ d ƒ ˆ d dk	röt <|¡ t =|
¡ ˆ d }$t>|$ƒr|$ƒ  ˆ d }%ˆ d r$d}%|%ršt?ddd|fƒ}&|& @ˆ d ¡ t Ad¡}'t?dd„ |'D ƒƒ|& }'|'D ],}(zt $|(¡ W n tBk
r”   Y nX qlˆ d dkrºt C|d |¡ nt D|d |ˆ d ¡ W nt   tE F¡  2dd¡})zJzt 4||)¡ W n4 tHk
r0 }* ztIjJ 4d |* ¡ W 5 d}*~*X Y nX W 5 t Gd¡ X Y nX næ|rZt K¡  t $ˆj¡ t $ˆj¡ t $ˆj¡ tr®t $|¡ t 4|tLdƒ 2t3¡¡ t $|¡ t $|¡ t #|d!¡}+t $|¡ |+ræ|+ Mt3¡}+tN|+ƒ‚t $|¡ t #|d"¡ Mt3¡ Od#¡\}} t $|¡ tP|ƒˆ_tP| ƒˆ_ dˆ_QtR R¡ ˆ_S|ˆ_Tdˆ_U|ˆ_Vt>ˆ d$ ƒrnˆjVdkrntWƒ ˆ_VtWƒ ˆ_XtY Z¡ ˆ_[t\ˆ d% d&ˆ_]t\ˆ d% d&ˆ_^ˆ d rÀ|sÀt;ˆjˆ d ƒ | _d't`ˆƒ¡ˆ_aˆja bd(¡ ˆ d r |s tc dˆj¡},|,d)  tcje M  < tc fˆjtcjg|,¡ dˆ_hˆjr`ˆja _d*d+¡}-ti|-ˆjˆjVˆ d, ˆ d- ˆ d ƒˆ_hd}.|tjkr€ˆ d. s€ˆjX}.ˆ d/  o˜|p˜|dk}/ˆ d d0k}0ˆ d d1k}1dˆ_j|0	sˆj	rt>|ƒrÚtkˆ|ƒ}tlˆja _d2d3¡ˆj|ˆj]ˆ d4 ˆ d- ˆ d5 |.|/d6	ˆ_jnˆj	r&t $ˆj¡ dˆ_m|tjk		rÔ|	sÔ|1	sÔˆj	rÔd}2|tjnk	rlˆ d. 	slˆjX}2ˆ d7  	oŒˆ d	 d1k	pŒ|dk}3t>|ƒ	r¢tkˆ|ƒ}tltod2ƒˆj|ˆj^ˆ d8 ˆ d- ˆ d5 |2|3d6	ˆ_mnˆj	rèt $ˆj¡ ‡ ‡fd9d:„}4dˆ_pdˆ_qˆ d; 
r6tY r¡ ˆ_ptY sˆ d; ˆjpj?¡ˆ_qˆjq t¡  d}5ˆj ju
s`ˆ d< 
r`‡‡fd=d>„}6|6}5tY r¡ ˆ_vd?ˆj" }7tWdƒˆ_wtxty|7ˆjw|4ˆjp|5ˆjzˆjvƒˆ_{dˆ_|tWdƒˆ_}ˆjh
rè| }8d@ˆj" }7txt~|7ˆj}ˆjaˆjhˆjzˆjv|8ƒˆ_|tY r¡ ˆ_tWdƒˆ_€dAˆj" }7txt|7ˆj€ˆjaˆjjˆjmˆjpˆjzˆjvˆjƒ
ˆ_‚dS )BaG  
            cmd is the full list of arguments that will be exec'd.  it includes the program name and all its arguments.

            stdin, stdout, stderr are what the child will use for standard input/output/err.

            call_args is a mapping of all the special keyword arguments to apply to the child process.
        r¿  Nr   z$UID setting requires root privileges)NNr  Fr–  r¼  )Tr!  r"  r”  r—  rÀ  r   r  Tz%d,%drŸ  r   r½  r¾  rÂ  rÃ  z/dev/fdc                 s   s   | ]}t |ƒV  qd S r    )r·   )rŒ   r?   r   r   r   rã    s     z!OProc.__init__.<locals>.<genexpr>r  rn   r  éÿ   z
FATAL SH ERROR: %s
i   é   ú,r!  rµ  ©Úmaxlenr&  zstarted processr   Ústreamwriterr1  r£  r  r»  r¹  )r!  T)r"  Ústreamreaderr˜   r¤  rM  )Ú	save_datarº  r´  c                      s   dˆ_ ˆ ˆ d ¡ d S )NTr¸  )r>  rº   r   )rH  r1   r   r   Ú
timeout_fnÇ  s    z"OProc.__init__.<locals>.timeout_fnr]   r³  c              
      s(   ˆ  ˆj  | ¡W  5 Q R £ S Q R X d S r    )r$  r?  r,  )r8  r1   r   r   r%   Û  s    zOProc.__init__.<locals>.fnzbackground thread for pid %dzSTDIN thread for pid %dzSTDOUT/ERR thread for pid %d)ƒr$  r  rÎ   Úgetuidr:  ÚpwdÚgetpwuidÚpw_gidr@  rˆ  ÚptyÚopenptyÚ_stdin_parent_fdÚ_stdin_child_fdÚdupÚ_stdout_parent_fdÚ_stdout_child_fdÚ_stderr_parent_fdÚ_stderr_child_fdrq   r*  Ú_pipe_fdr‡  r5  r+  r  ÚttynameÚgcÚ	isenabledÚdisableÚIS_MACOSr  r  Úforkr  ÚreadÚcloser  ÚF_GETFDÚ
FD_CLOEXECÚF_SETFDrº   ÚSIGHUPÚSIG_IGNr#  ÚSIG_DFLÚsetsidÚsetpgrpÚgetsidÚgetpgidrx   rt   ÚwriteÚttyÚsetrawÚchdirÚdup2r   ÚO_RDWRr  ÚsetgidÚsetuidr   r   rÓ  Úlistdirr.  ÚexecvÚexecveÚ	tracebackÚ
format_excÚ_exitr†   Úsysr™   Úenablers   rŸ   r…   r~   r·   r>  r<  Ústartedrœ   r¬   r1  r   rO  r.  r/  Ú
_wait_lockr   Ú_stdoutÚ_stderrrþ   rj  ró   r   r
  Ú	tcgetattrÚECHOÚ	tcsetattrÚTCSANOWÚ_stdin_streamÚStreamWriterÚ_stdout_streamr!  ÚStreamReaderÚ_stderr_streamr,  rï   Ú_timeout_eventÚ_timeout_timerÚEventÚTimerr  r-  Ú_quit_threadsÚ_bg_thread_exc_queuer  Úbackground_threadr;  Ú_background_threadÚ_input_threadÚ_input_thread_exc_queueÚinput_threadÚ_stop_output_eventÚ_output_thread_exc_queueÚoutput_threadÚ_output_thread)9r1   r$  Ú
parent_logrœ   r1  r˜   r™   r  r5  r8  Ú
target_uidÚpwrecÚ
target_gidÚstdin_is_fd_basedÚstdout_is_fd_basedÚstderr_is_fd_basedÚtee_outÚtee_errÚ
single_ttyr  Ú	fd_to_userÀ  Ú
needs_cttyÚ
gc_enabledÚsession_pipe_readÚsession_pipe_writeÚexc_pipe_readÚexc_pipe_writeÚclose_pipe_readÚclose_pipe_writeÚflagsr  r  ÚpayloadrŸ  Útmp_fdr¾  rÂ  rÃ  Úinherited_fdsr?   Útbrÿ  Úfork_excÚattrró   Ústdout_pipeÚsave_stdoutÚpipe_outÚpipe_errÚstderr_pipeÚsave_stderrr<  Úhandle_exit_coder%   Úthread_nameÚclose_before_termr   )rH  r8  r1   r   r2   þ  s>   







	











	&










  ÿ

    û
 "

     ü



	


    ü	

    ü


     ûzOProc.__init__c                 C   s   d| j | jd d… f S )Nz<Process %d %r>iô  )r  rœ   r0   r   r   r   rk  	  s    zOProc.__repr__c                 C   s.   d }z| j  d¡}W n tk
r(   Y nX |S rŒ  )r†  rB   r   ©r1   r½   r   r   r   r  	  s    zOProc.output_thread_excc                 C   s.   d }z| j  d¡}W n tk
r(   Y nX |S rŒ  )rƒ  rB   r   r¬  r   r   r   r  	  s    zOProc.input_thread_excc                 C   s.   d }z| j  d¡}W n tk
r(   Y nX |S rŒ  )r  rB   r   r¬  r   r   r   r  !	  s    zOProc.bg_thread_excc                 C   s   | j j |¡ d S r    )ru  Ústream_buffererÚchange_buffering©r1   Úbufr   r   r   Úchange_in_bufsize*	  s    zOProc.change_in_bufsizec                 C   s   | j j |¡ d S r    )rw  r­  r®  r¯  r   r   r   Úchange_out_bufsize-	  s    zOProc.change_out_bufsizec                 C   s   | j j |¡ d S r    )ry  r­  r®  r¯  r   r   r   Úchange_err_bufsize0	  s    zOProc.change_err_bufsizec                 C   s   d  | jd ¡ | j¡S ©NrÚ   r  )rx   r  r   ro  r0   r   r   r   r˜   3	  s    zOProc.stdoutc                 C   s   d  | jd ¡ | j¡S r´  )rx   r  r   rp  r0   r   r   r   r™   7	  s    zOProc.stderrc                 C   s   t  | j¡S )z» return the CURRENT group id of the process. this differs from
        self.pgid in that this reflects the current state of the process, where
        self.pgid is the group id at launch )rÎ   r\  r  r0   r   r   r   Úget_pgid;	  s    zOProc.get_pgidc                 C   s   t  | j¡S )z½ return the CURRENT session id of the process. this differs from
        self.sid in that this reflects the current state of the process, where
        self.sid is the session id at launch )rÎ   r[  r  r0   r   r   r   Úget_sidA	  s    zOProc.get_sidc                 C   s"   | j  d|¡ t |  ¡ |¡ d S )Nzsending signal %d to group)ró   r   rÎ   Úkillpgrµ  ©r1   Úsigr   r   r   r  G	  s    zOProc.signal_groupc                 C   s    | j  d|¡ t | j|¡ d S )Nzsending signal %d)ró   r   rÎ   r	  r  r¸  r   r   r   rº   K	  s    zOProc.signalc                 C   s   | j  d¡ |  tj¡ d S )Nzkilling group)ró   r   r  rº   rö  r0   r   r   r   r
  O	  s    zOProc.kill_groupc                 C   s   | j  d¡ |  tj¡ d S )NÚkilling)ró   r   rº   rö  r0   r   r   r   r	  S	  s    z
OProc.killc                 C   s   | j  d¡ |  tj¡ d S )NÚterminating)ró   r   rº   ÚSIGTERMr0   r   r   r   r  W	  s    zOProc.terminatec                 C   sÜ   | j dk	rd| j fS | j d¡}|sB| j dk	r8d| j fS d| j fS d}zxzBttj| jtj	ƒ\}}|| jkrˆt
|ƒ| _ d}d| j fW W ¢:S W n" tk
r¬   d| j f Y W ¢S X d| j fW ¢S W 5 | j ¡  |rÖ|  ¡  X dS )zÄ polls if our child process has completed, without blocking.  this
        method has side-effects, such as setting our exit_code, if we happen to
        see our child exit while this is running NFT)r¬   rn  ÚacquireÚreleaseÚ_process_just_endedr1  rÎ   Úwaitpidr  ÚWNOHANGr-  r.  )r1   ÚacquiredÚwitnessed_endr  r¬   r   r   r   r;  [	  s(    







zOProc.is_alivec                 C   sV   | j r| j  ¡  | jd }|r:| j| jd k}||| jƒ | jrR| jsRt | j¡ d S )Nr   rD  )r{  Úcancelr  r¬   rC  ru  rÎ   rR  )r1   r4  r&  r   r   r   r¿  Š	  s    

zOProc._process_just_endedc              	   C   sŠ   | j  d¡ | j` | j  d¡ d}| jdkr^| j  d¡ ttj| jdƒ\}}t|ƒ| _d}n| j  d| j¡ W 5 Q R X | j	|d	 | jS )
z: waits for the process to complete, handles the exit code z*acquiring wait lock to wait for completionzgot wait lockFNz!exit code not set, waiting on pidr   Tz+exit code already set (%d), no need to wait)rÃ  )
ró   r   rn  r¬   r1  rÎ   rÀ  r  r-  Ú_process_exit_cleanup)r1   rÃ  r  r¬   r   r   r   r0  š	  s    

z
OProc.waitc                 C   s^   | j  ¡  | jr| j ¡  t d| jj¡}| ¡  | j ¡  | 	¡  | j
 ¡  |rZ|  ¡  d S )Ng       @)r~  r   r‚  r   r.  r}  r…  r  rˆ  rÄ  r  r¿  )r1   rÃ  Útimerr   r   r   rÅ  ¯	  s    



zOProc._process_exit_cleanupN)ra   rb   rc   r”   Ú_default_window_sizer+  r,  r2   rk  rr  r  r  r  r±  r²  r³  r˜   r™   rµ  r¶  r  rº   r
  r	  r  r;  r¿  r0  rÅ  r   r   r   r   r*  ò  sD       




/r*  c                 C   s¬   d}d}t ƒ }| |¡ |r‚|r‚| d¡}|D ]F\}	}
|
ttB @ r.|  d|¡ | ¡ }|r.| |¡ |r.| ¡  d}q.|ƒ \}}q|rœ| 	d¡ |ƒ \}}q‚|s¨| ¡  dS )z® this is run in a separate thread.  it writes into our process's
    stdin (a streamwriter) and waits the process to end AND everything that
    can be written to be written FTr   z%r ready for more inputN)
r+   rO   r(   rZ   r[   r   r]  rV   rR  r0  )ró   r1  r;  Úquit_threadr«  ÚclosedrC  ÚpollerÚchangedr?   rG   r   rè   r   r   r   r„  È	  s*    



r„  c                 C   s   |   |¡}tr|  ¡ }|S r    )r0  ÚIS_PY26Úis_set)Úevr]   Ú	triggeredr   r   r   Ú
event_waité	  s    
rÐ  c                 C   sZ   |r$|  ¡ s$t|dƒ}|r| ƒ  q$q|rVtsVd}d}|rN| d¡ |ƒ \}}q4||ƒ dS )z handles the timeout logic r9  TNr   )rÍ  rÐ  ÚRUNNING_TESTSr0  )r<  Útimeout_eventr©  r;  rÈ  r>  rC  r¬   r   r   r   r€  ð	  s    
	
r€  c                 C   sÚ   t ƒ }|dk	r| |¡ |dk	r*| |¡ |ršt|jdƒ}|D ]@\}	}
|
ttB @ rv|  d|	¡ |	 ¡ }|r~| |	¡ q>|
t	@ r>q>|rŽ| 
¡ rŽqš| 
¡ r*qšq*|ƒ \}}|r¾| d¡ |ƒ \}}q¤|rÊ| ¡  |rÖ| ¡  dS )z™ this function is run in a separate thread.  it reads from the
    process's stdout stream (a streamreader), and waits for it to claim that
    its done Nr9  z%r ready to be read fromr   )r+   rL   r1  r(   rY   r[   r   rQ  rV   r\   rÍ  r0  rR  )ró   r˜   r™   rÒ  r;  rÈ  Ústop_output_eventrÊ  rË  r>   rG   r   rC  rè   r   r   r   r‡  
  s6    



r‡  c                   @   s   e Zd ZdS )ÚDoneReadingForeverNrª   r   r   r   r   rÔ  >
  s   rÔ  c                   @   s   e Zd ZdS )ÚNotYetReadyToReadNrª   r   r   r   r   rÕ  B
  s   rÕ  c                 C   sê   t | tƒrd}t| ƒ}nÊt| ƒr.d}t| ƒ}n´t| dƒrFd}t| ƒ}nœt | tƒr^d}t| ƒ}n„t | t	ƒrvd}t| ƒ}nlt | t
ƒr’d}tt| ƒƒ}nP| dkr¬d	}d
d„ }|}n6zt| ƒ}W n tk
rÔ   tdƒ‚Y nX d}t|ƒ}||fS )a    given some kind of input object, return a function that knows how to
    read chunks of that input object.

    each reader function should return a chunk and raise a DoneReadingForever
    exception, or return None, when there's no more data to read

    NOTE: the function returned does not need to care much about the requested
    buffering type (eg, unbuffered vs newline-buffered).  the StreamBufferer
    will take care of that.  these functions just need to return a
    reasonably-sized chunk of data. Úqueuer   rQ  zfile descriptorÚstringrr   Ú	generatorNÚNonec                   S   s   t ‚d S r    ©rÔ  r   r   r   r   Úraise_n
  s    z+determine_how_to_read_input.<locals>.raise_zunknown input objectzgeneral iterable)rq   r   Úget_queue_chunk_readerr   Úget_callable_chunk_readerr   Úget_file_chunk_readerrv  Úget_iter_string_readerrr   r
   Úget_iter_chunk_readerr  rw   r†   )Ú	input_objr#  Ú	get_chunkrÛ  Úitr   r   r   Údetermine_how_to_read_inputF
  s:    









rä  c                    s   ‡ fdd„}|S )Nc                     s:   zˆ   dd¡} W n tk
r(   t‚Y nX | d kr6t‚| S )NTr9  )rB   r   rÕ  rÔ  ©rT  ©r1  r   r   r%   €
  s    
z"get_queue_chunk_reader.<locals>.fnr   ©r1  r%   r   ræ  r   rÜ  
  s    	rÜ  c                    s   ‡ fdd„}|S )Nc                     s.   z
ˆ ƒ } W n t k
r    ‚ Y nX | s*t ‚| S r    rÚ  )Údataræ  r   r   r%   
  s    
z%get_callable_chunk_reader.<locals>.fnr   rç  r   ræ  r   rÝ  Œ
  s    rÝ  c                    s,   d‰ ‡ ‡fdd„t dtˆƒˆ ƒD ƒ}t|ƒS )a-   return an iterator that returns a chunk of a string every time it is
    called.  notice that even though bufsize_type might be line buffered, we're
    not doing any line buffering here.  that's because our StreamBufferer
    handles all buffering.  we just need to return a reasonable-sized chunk. r5  c                 3   s   | ]}ˆ||ˆ  … V  qd S r    r   ©rŒ   Úi©Úbufsizer1  r   r   rã  ¡
  s     z)get_iter_string_reader.<locals>.<genexpr>r   )Úranger!   rà  )r1  Úiter_strr   rë  r   rß  ›
  s     rß  c                    s   ‡ fdd„}|S )Nc                     s:   zt rˆ  ¡ } nˆ  ¡ } | W S  tk
r4   t‚Y nX d S r    )rp   rs  rU  rN  rÔ  rå  ræ  r   r   r%   ¦
  s    
z!get_iter_chunk_reader.<locals>.fnr   rç  r   ræ  r   rà  ¥
  s    
rà  c                    s   d‰ ‡ ‡fdd„}|S )Nr5  c                     sœ   d} t r.zˆ ¡  W n tk
r,   d} Y nX | r€tˆdƒr€tƒ }| ˆ¡ | d¡}d}|D ]\}}|ttB @ r^d}q^|s€t	‚ˆ 
ˆ ¡}|s”t‚n|S d S )NTFr;   r9  )rp   r;   r   r   r+   rL   r(   rY   r[   rÕ  rQ  rÔ  )Úis_real_filerÊ  rË  Úreadyr?   rG   rT  rë  r   r   r%   ¶
  s(    



z!get_file_chunk_reader.<locals>.fnr   rç  r   rë  r   rÞ  ³
  s    rÞ  c                 C   s$   | dkrd}n| dkrd}n| }|S )a   for a given bufsize type, return the actual bufsize we will read.
    notice that although 1 means "newline-buffered", we're reading a chunk size
    of 1024.  this is because we have to read something.  we let a
    StreamBufferer instance handle splitting our chunk on newlines r   r5  r   r   )Úbf_typerì  r   r   r   Úbufsize_type_to_bufsize×
  s    rò  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )rv  zÇ StreamWriter reads from some input (the stdin param) and writes to a fd
    (the stream param).  the stdin may be a Queue, a callable, something with
    the "read" method, a string, or an iterable c                 C   sL   || _ || _|| _|| _|| _t|| jƒ| _t|ƒ\| _}| j 	d|¡ d S )Nzparsed stdin as a %s)
Ústreamr1  ró   r  r”  ÚStreamBuffererr­  rä  râ  r   )r1   ró   ró  r1  Úbufsize_typer  r”  r#  r   r   r   r2   ï
  s    zStreamWriter.__init__c                 C   s   | j S ©zI defining this allows us to do poll on an instance of this
        class ©ró  r0   r   r   r   r;   ü
  s    zStreamWriter.filenoc              	   C   sD  z|   ¡ }|dkrt‚W n˜ tk
r   | j d¡ | jrŠzt | j¡d tj }W n   t	dƒ 
¡ }Y nX t | j|¡ t | j|¡ Y dS  tk
r°   | j d¡ Y dS X trÌt|tƒsÌ| 
| j¡}| j |¡D ]f}| j dt|ƒ|dd	… ¡ | j d
¡ zt | j|¡ W qØ tk
r<   | j d¡ Y  dS X qØdS )z­ attempt to get a chunk of data to write to our child process's
        stdin, then write it.  the return value answers the questions "are we
        done writing forever?" Nzdone readingr   r)   Tzreceived no dataFúgot chunk size %d: %ré   zwriting chunk to processzOSError writing stdin chunk)râ  rÔ  ró   r   r”  r
  rq  ró  ÚVEOFÚchrrx   rÎ   r]  rÕ  rp   rq   rr   r  r­  r&  r!   r.  )r1   rT  ÚcharÚ
proc_chunkr   r   r   r]    s6    zStreamWriter.writec                 C   sn   | j  d¡ | j ¡ }| j  dt|ƒ|d d… ¡ z|rFt | j|¡ W n tk
r\   Y nX t 	| j¡ d S )Nzclosing, but flushing firstúgot chunk size %d to flush: %rrù  )
ró   r   r­  Úflushr!   rÎ   r]  ró  r.  rR  rS  r   r   r   rR  >  s    
zStreamWriter.closeN)ra   rb   rc   r”   r2   r;   r]  rR  r   r   r   r   rv  ê
  s
   =rv  c              	   C   s¸   t | ƒrt| ||ƒ\}}n–t| ttfƒr6t| ƒ\}}nzt| ttfƒrVt| ||ƒ\}}nZt	| dƒrnt
| ƒ\}}nBzt| ƒ} W n( ttfk
r¢   dd„ }dd„ }Y nX t| ƒ\}}||fS )Nr]  c                 S   s   dS rŒ  r   rå  r   r   r   r&  _  rå  z-determine_how_to_feed_output.<locals>.processc                   S   s   d S r    r   r   r   r   r   Úfinish`  rå  z,determine_how_to_feed_output.<locals>.finish)r   Úget_callback_chunk_consumerrq   Ú	cStringIOÚiocStringIOÚget_cstringio_chunk_consumerr   Ú
ioStringIOÚget_stringio_chunk_consumerr   Úget_file_chunk_consumerr·   r¸   rw   Úget_fd_chunk_consumer©r  r  rM  r&  r   r   r   r   Údetermine_how_to_feed_outputL  s    
r
  c                 C   s   t | ddd} t| ƒS )NÚwF)Úclosefd)Úfdopenr  ©r  r   r   r   r  g  s    r  c                    s`   t ˆdd ƒr‡fdd„‰ ndd„ ‰ tˆdƒr4ˆj‰ndd„ ‰‡ ‡‡fdd	„}‡fd
d„}||fS )Nr  c                    s   |   ˆ j¡S r    )rŸ   r  rå  r  r   r   rx   n  rå  z'get_file_chunk_consumer.<locals>.encodec                 S   s   | S r    r   rå  r   r   r   rx   p  rå  rÿ  c                   S   s   d S r    r   r   r   r   r   rÿ  u  rå  z&get_file_chunk_consumer.<locals>.flushc                    s   ˆ  ˆ | ƒ¡ ˆƒ  dS rŒ  ©r]  rå  ©rx   rÿ  r  r   r   r&  w  s    z(get_file_chunk_consumer.<locals>.processc                      s
   ˆ ƒ  d S r    r   r   )rÿ  r   r   r   ~  s    z'get_file_chunk_consumer.<locals>.finish)r¹   r   rÿ  ©r  r&  r   r   r  r   r  l  s    
r  c                    s    ‡ ‡‡fdd„}dd„ }||fS )Nc                    s.   z|   ˆˆ ¡} W n tk
r$   Y nX ˆ| ƒS r    )rŸ   rR  rå  ©rM  r  r  r   r   r&  …  s
    z,get_callback_chunk_consumer.<locals>.processc                   S   s   d S r    r   r   r   r   r   r   Ž  s    z+get_callback_chunk_consumer.<locals>.finishr   r	  r   r  r   r  „  s    	r  c                    s   ‡ fdd„}dd„ }||fS )Nc                    s   ˆ   | ¡ dS rŒ  r  rå  r  r   r   r&  •  s    
z-get_cstringio_chunk_consumer.<locals>.processc                   S   s   d S r    r   r   r   r   r   r   ™  s    z,get_cstringio_chunk_consumer.<locals>.finishr   r  r   r  r   r  ”  s    r  c                    s    ‡ ‡‡fdd„}dd„ }||fS )Nc                    s   ˆ  |  ˆˆ ¡¡ dS rŒ  )r]  rŸ   rå  r  r   r   r&     s    z,get_stringio_chunk_consumer.<locals>.processc                   S   s   d S r    r   r   r   r   r   r   ¤  s    z+get_stringio_chunk_consumer.<locals>.finishr   r	  r   r  r   r  Ÿ  s    r  c                   @   s:   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )rx  zV reads from some output (the stream) and sends what it just read to the
    handler.  NTc
           
      C   st   || _ || _|	| _|| _|| _d | _|r4t |¡| _|| _t	|| j| jƒ| _
t|ƒ| _t|||ƒ\| _| _d| _d S rŒ  )ró  Úbufferr;  r  rM  Ú
pipe_queuer  r  ró   rô  r­  rò  rì  r
  Úprocess_chunkÚfinish_chunk_processorÚshould_quit)
r1   ró   ró  r  r  rõ  r  rM  r  r;  r   r   r   r2   ®  s    

ÿ
zStreamReader.__init__c                 C   s   | j S rö  r÷  r0   r   r   r   r;   Ä  s    zStreamReader.filenoc                 C   sf   | j  ¡ }| j dt|ƒ|d d… ¡ |r4|  |¡ |  ¡  | jrV| jrV|  ¡  	d ¡ t
 | j¡ d S )Nrþ  rù  )r­  rÿ  ró   r   r!   Úwrite_chunkr  r  r;  rý  rÎ   rR  ró  rS  r   r   r   rR  É  s    

zStreamReader.closec                 C   sR   | j s|  |¡| _ | jrN| j |¡ | jrN| j d|d d… ¡ |  ¡  |¡ d S )Nzputting chunk onto pipe: %rrù  )	r  r  r;  r  rX   r  ró   r   rý  rS  r   r   r   r  Ö  s    zStreamReader.write_chunkc              
   C   s    zt tj| j| jƒ}W n8 tk
rN } z| j d|j¡ W Y ¢dS d }~X Y nX |sd| j d¡ dS | j dt	|ƒ|d d… ¡ | j
 |¡D ]}|  |¡ qŒd S )Nzgot errno %d, done readingTzgot no chunk, done readingrø  rù  )r1  rÎ   rQ  ró  rì  r.  ró   r   rP  r!   r­  r&  r  )r1   rT  rÿ  r   r   r   rQ  ã  s    zStreamReader.read)NT)	ra   rb   rc   r”   r2   r;   rR  r  rQ  r   r   r   r   rx  ª  s     ÿ
rx  c                   @   s6   e Zd ZdZedfdd„Zdd„ Zdd„ Zd	d
„ ZdS )rô  aµ   this is used for feeding in chunks of stdout/stderr, and breaking it up
    into chunks that will actually be put into the internal buffers.  for
    example, if you have two processes, one being piped to the other, and you
    want that, first process to feed lines of data (instead of the chunks
    however they come in), OProc will use an instance of this class to chop up
    the data and feed it as lines to be sent down the pipe r°  c                 C   s<   || _ g | _d| _|| _|| _d| _t ¡ | _t	dƒ| _
d S )Nr   Fr­  )rÝ  r  Ún_buffer_countr  rM  Ú_use_up_buffer_firstr.  ÚRLockÚ_buffering_lockrï   ró   )r1   Úbuffer_typer  rM  r   r   r   r2   ü  s    
zStreamBufferer.__init__c              	   C   sX   | j  d¡ | j ¡  | j  d¡ z|dkr2d| _|| _W 5 | j ¡  | j  d¡ X d S )Nz/acquiring buffering lock for changing bufferingz)got buffering lock for changing bufferingz.released buffering lock for changing bufferingr   T)ró   r   r  r½  r¾  r  rÝ  )r1   Únew_typer   r   r   r®    s    


zStreamBufferer.change_bufferingc           	   
   C   sÚ  | j  d| j¡ | j ¡  | j  d| j¡ zŒ| jdkrp| jrdd| _| j}g | _| |¡ |W ¢XS |gW ¢LS | jdkrg }d 	| j
¡}| |¡}|dkr qî|d |d … }| jrÒd	 | j¡| }g | _d| _||d d … }| |¡ qŒ|r| j |¡ |  jt|ƒ7  _|W ¢¢S g }| jt|ƒ | j }|dkrˆd
 	| j
¡ | j¡| }|d | j… }|| jd … }| |¡ g | _d| _n"| j |¡ |  jt|ƒ7  _q®q|W ¢S W 5 | j ¡  | j  d| j¡ X d S )Nz9acquiring buffering lock to process chunk (buffering: %d)z3got buffering lock to process chunk (buffering: %d)z<released buffering lock for processing chunk (buffering: %d)r   Fr   r|   rÊ  rå  rÚ   )ró   r   rÝ  r  r½  r¾  r  r  rX   rx   r  Úfindr   r  r!   )	r1   rT  Úto_writeÚtotal_to_writeÚnlÚnewlineÚchunk_to_writeÚoveragerƒ  r   r   r   r&    sX    







zStreamBufferer.processc              	   C   sb   | j  d¡ | j ¡  | j  d¡ z"d | j¡ | j¡}g | _|W ¢S | j ¡  | j  d¡ X d S )Nz,acquiring buffering lock for flushing bufferz&got buffering lock for flushing bufferz+released buffering lock for flushing bufferrÚ   )	ró   r   r  r½  r¾  rx   r  r   r  )r1   rƒ  r   r   r   rÿ  `  s    

zStreamBufferer.flushN)	ra   rb   rc   r”   rt   r2   r®  r&  rÿ  r   r   r   r   rô  ô  s
   Arô  c                    s   ‡ fdd„}|S )Nc                    s   t ˆ ƒ‰ t ‡ ‡fdd„ƒ}|S )Nc               
   ?   s0   ˆ" ˆ | |Ž d V  W 5 Q R X W 5 Q R X d S r    r   )r#   rË   )r%   Úlockr   r   Úwrapped2q  s    z,with_lock.<locals>.wrapped.<locals>.wrapped2r   )r%   r'  ©r&  r$   r   Úwrappedn  s    zwith_lock.<locals>.wrappedr   )r&  r)  r   r(  r   Ú	with_lockm  s    r*  c              	   c   s.   t  ¡ }t  | ¡ z
dV  W 5 t  |¡ X dS )z§ pushd changes the actual working directory for the duration of the
    context, unlike the _cwd arg this will work with other built-ins such as
    sh.glob correctly N)rÎ   rè  r`  )rÈ   Ú	orig_pathr   r   r   ré  |  s
    

ré  c                  K   s,   d  dd„ |  ¡ D ƒ¡}tdj|dƒ‚dS )z\ allows us to temporarily override all the special keyword parameters in
    a with context r6  c                 S   s   g | ]\}}d ||f ‘qS )z%s=%rr   r°   r   r   r   rŽ   Ž  s     z_args.<locals>.<listcomp>zÞ

sh.args() has been deprecated because it was never thread safe.  use the
following instead:

    sh2 = sh({kwargs})
    sh2.your_command()

or

    sh2 = sh({kwargs})
    from sh2 import your_command
    your_command()

)rË   N)r   r­  ÚDeprecationWarningrž   )rË   Ú
kwargs_strr   r   r   Ú_args‰  s    òr.  c                       s@   e Zd ZdZedƒZd
‡ fdd„	Zdd„ Zeddd	„ƒZ	‡  Z
S )ÚEnvironmenta“   this allows lookups to names that aren't found in the global scope to be
    searched for as a program name.  for example, if "ls" isn't found in this
    module's scope, we consider it a system program and try to find it.

    we use a dict instead of just a regular object as the base class because the
    exec() statement used in the run_repl requires the "globals" argument to be a
    dictionary )rë   r  r­   rt   rÔ  r•   rÕ  r©   r…   r«   rô  Ú__project_url__Ú__version__Ú__file__r.  ré  rÍ   ÚcontribNc                    s"   t t| ƒ ¡  || _|pi | _dS )z½ baked_args are defaults for the 'sh' execution context.  for
        example:

            tmp = sh(_out=StringIO())

        'out' would end up in here as an entry in the baked_args dict N)r    rø  r2   Úglobsrí   )r1   r4  rí   r¦   r   r   r2   Ã  s    zEnvironment.__init__c                 C   sÄ   |dkrd}|| j kr | j| S |dkr6t d¡ g S t|ƒ}|rF|S | d¡r^| d¡r^t‚|dkrjtS t	|| j
ƒ}|r~|S t| d| d ƒ}|r–|S ztj| W S  tk
r¶   Y nX t|ƒ‚d S )Nr#   r.  Ú__all__zJCannot import * from sh. Please import sh or import programs individually.Ú__ÚcdÚb_)r   r4  ÚwarningsÚwarnrÂ   rÍ  rÎ  rf  ÚCdrî   rí   r¹   rÎ   rÝ   r´   r­   )r1   r±   r½   rœ   Úbuiltinr   r   r   Ú__getitem__Î  s2    


zEnvironment.__getitem__c                 C   s
   t | |ƒS r    )rç   )rß   rà   r   r   r   Úb_which  s    zEnvironment.b_which)N)N)ra   rb   rc   r”   r   r   r2   r=  rm   r>  r¨   r   r   r¦   r   r/  ¡  s   8r/  c                       s.   e Zd Zd‡ fdd„	Zdd„ Zdd„ Z‡  ZS )	r;  Nc                    s4   t t| ƒ | ¡}t ¡ |_t |p,tj d¡¡ |S )Nú~)	r    r;  Ú__new__rÎ   rè  Úold_pathr`  rÈ   rÐ   )ÚclsrÈ   Úresr¦   r   r   r@    s    
z
Cd.__new__c                 C   s   d S r    r   r0   r   r   r   rJ    s    zCd.__enter__c                 C   s   t  | j¡ d S r    )rÎ   r`  rA  rW  r   r   r   r[    s    zCd.__exit__)N)ra   rb   rc   r@  rJ  r[  r¨   r   r   r¦   r   r;    s   r;  c                   @   s   e Zd Zedd„ ƒZdS )ÚContribc                    s   ‡ ‡fdd„}|S )Nc                    s"   t ‡ ‡fdd„ƒ}tˆˆ|ƒ ˆ S )Nc                    s    t ˆƒ}|stˆƒ‚ˆ |ƒ}|S r    )rî   r­   )r1   rœ   Únew_cmd)r%   r¼   r   r   Ú
cmd_getter  s
    z6Contrib.__call__.<locals>.wrapper1.<locals>.cmd_getter)rr  Úsetattr)r%   rF  ©rB  r¼   r$   r   Úwrapper1  s    	z"Contrib.__call__.<locals>.wrapper1r   )rB  r¼   rI  r   rH  r   r     s    zContrib.__call__N)ra   rb   rc   Úclassmethodr   r   r   r   r   rD    s   rD  z.contribÚgitc                 C   s   | j dd}|S )z, most git commands play nicer without a TTY F)Ú_tty_out)rì   )Úorigrœ   r   r   r   rK  2  s    Úsudoc                    s6   dt  ¡  ‰ ‡ fdd„‰‡fdd„}| jd|d}|S )z{ a nicer version of sudo that uses getpass to ask for a password, or
    allows the first argument to be a string password z[sudo] password for %s: c                  3   s   t j ˆ dd } | V  d S )N©Úpromptr|   ©Úgetpass)ÚpwrO  r   r   r1  @  s    zsudo.<locals>.stdinc                    s:   |  dd ¡}|d krˆ ƒ }n| d¡d }||d< | |fS )NÚpasswordr|   rk   )rV  Úrstrip)rø   rË   rT  Úpass_getterræ  r   r   r&  D  s    zsudo.<locals>.processz-S)Ú_arg_preprocess)rR  Úgetuserrì   ©rM  r&  rœ   r   )rP  r1  r   rN  9  s
    Ússhc                    sF   G dd„ dt ƒ‰G ‡fdd„dt ƒ‰ ‡ fdd„}| jddd|d	}|S )
z- An ssh command for automatic password login c                   @   s(   e Zd Zdd„ Zdd„ Zedd„ ƒZdS )zssh.<locals>.SessionContentc                 S   s.   t dd| _t dd| _g | _d| _d| _d S )NiPÃ  r7  iˆ  rÚ   )r   Úcharsr‚   Ú
line_charsÚ	last_lineÚcur_charr0   r   r   r   r2   X  s
    z$ssh.<locals>.SessionContent.__init__c                 S   sJ   |dkr(| j }|| _| j |¡ g | _n| j |¡ | j |¡ || _d S ©Nr|   )Úcur_liner]  r‚   rX   r\  r[  r^  )r1   rü  rƒ   r   r   r   Úappend_char_  s    z'ssh.<locals>.SessionContent.append_charc                 S   s   d  | j¡}|S )NrÚ   )r   r\  )r1   rƒ   r   r   r   r`  k  s    z$ssh.<locals>.SessionContent.cur_lineN)ra   rb   rc   r2   ra  rr  r`  r   r   r   r   ÚSessionContentW  s   rb  c                       s    e Zd Z‡ fdd„Zdd„ ZdS )zssh.<locals>.SSHInteractc                    s0   || _ || _|| _|| _ˆ ƒ | _d| _d| _d S rŒ  )Úprompt_matchrV  Úout_handlerÚlogin_successÚcontentÚ
pw_enteredr&  )r1   rc  rV  rd  re  ©rb  r   r   r2   q  s    z!ssh.<locals>.SSHInteract.__init__c                 S   sf   | j  |¡ | jr&| js&|  | j ¡| _| jr:|  | j |¡S |  | j ¡rb|  ¡ }| |d ¡ d| _d S )Nr|   T)	rf  ra  rg  r&  re  rd  rc  rV  rý  )r1   rü  r1  rT  r   r   r   r   |  s    z!ssh.<locals>.SSHInteract.__call__N)ra   rb   rc   r2   r   r   rh  r   r   ÚSSHInteractp  s   ri  c                    sŽ   |  d¡}|  dd ¡‰ |  dd ¡}|  dd ¡}d‰|d krBdd„ }ˆ d krX‡fdd	„}n‡ fd
d	„}|d krtdd„ }ˆ||||ƒ|d< | |fS )NÚinteractrT  re  rP  zPlease enter SSH password: c                 S   s   | j  d¡S )Nz
password: )r`  rÎ  ©rf  r   r   r   rc  ’  rå  z*ssh.<locals>.process.<locals>.prompt_matchc                      s   t j ˆ dS )NrO  rQ  r   rO  r   r   rV  •  rå  z)ssh.<locals>.process.<locals>.pass_getterc                      s
   ˆ   d¡S r_  )rU  r   )rT  r   r   rV  —  rå  c                 S   s   dS )NTr   rk  r   r   r   re  š  rå  z+ssh.<locals>.process.<locals>.login_successrl   )rV  )rø   rË   Úreal_out_handlerre  rc  rV  )ri  )rT  rP  r   r&  Š  s    
zssh.<locals>.processr   T)Ú_out_bufsizeÚ_tty_inÚ_unify_ttysrW  )rË  rì   rY  r   )ri  rb  r   rZ  S  s
    c              	   C   s”   d}t |jtdƒ ztdƒ}W n ttfk
r<   Y qˆY nX ztt|ddƒ| | ƒ W q tk
rn   Y qˆY q   t t	 
¡ ƒ Y qX qt dƒ d S )Nz3
>> sh v{version}
>> https://github.com/amoffat/sh
)Úversionzsh> z<dummy>ÚsinglerÚ   )Úprintrž   r1  Ú	raw_inputr¸   ÚEOFErrorÚexecÚcompileÚ
SystemExitrh  ri  )r  Úbannerrƒ   r   r   r   Úrun_repl£  s    
ry  c                       s.   e Zd Zd‡ fdd„	Zdd„ Zdd„ Z‡  ZS )	ÚSelfWrapperNc           	         s¾   t t| ƒjt|dd ƒt|dd ƒd dD ]}t| |t||d ƒƒ q(g | _|| _tj 	¡ }|rˆt 
|¡\}}|d  	¡ |d< |d  |¡ ttjtj|ƒ}tƒ  	¡ }||tj< t||d| _d S )Nra   r”   )r¼   Údoc)Ú__builtins__r2  Ú__package__rÒ  )rí   )r    rz  r2   r¹   rG  Ú__path__Ú_SelfWrapper__self_modulerë   Ú__dict__rÑ  rÜ  rÓ  rÝ  ra   r   Úglobalsr/  Ú_SelfWrapper__env)	r1   Úself_modulerí   r¢  Ú	cls_attrsr  rè   Úcommand_clsr4  r¦   r   r   r2   ¾  s"    


þ


zSelfWrapper.__init__c                 C   s
   | j | S r    )r‚  )r1   r¼   r   r   r   ri  Û  s    zSelfWrapper.__getattr__c                 K   s  | j j ¡ }| |¡ |  | j|¡}t ¡ d }z|d d  ¡ }W nP t	k
r”   |d dks||d dkrŽt
 ¡  ¡ dkrŽ|d jjd }n‚ Y nTX t |¡}z|jd jd j}W n0 tk
ræ   t|jd tjƒsàtdƒ‚‚ Y nX |tkrütd	t ƒ‚tj |d
¡ |S )z€ returns a new SelfWrapper object, where all commands spawned from it
        have the baked_args kwargs set on them by default r   r)   r   )z<stdin>z<string>z<module>ÚpypyrÊ  z6A new execution context must be assigned to a variablez0Cannot use the name '%s' as an execution contextN)r‚  rí   rÑ  rÓ  r–   r  r"   Ústackrm  rw   ÚplatformÚpython_implementationÚlowerÚf_codeÚco_namesÚastÚparseÚbodyÚtargetsÚidr†   rq   ÚAssignr:  ra   rk  ÚmodulesrV  )r1   rË   rí   Únew_modÚparentrG  Úmodule_nameÚparsedr   r   r   r   Þ  s2    


ÿÿ
zSelfWrapper.__call__)N)ra   rb   rc   r2   ri  r   r¨   r   r   r¦   r   rz  ½  s   rz  c                 C   s   | j jdkS )z8 helper for checking if a filename is in importlib guts z<frozen importlib._bootstrap>)r‹  Úco_filename)Úframer   r   r   Úin_importlib  s    rš  c                     sF   dd„ ‰ t ‡ fdd„tjD ƒƒ} | s@ttjgd}tj d|¡ |  S )z˜ registers our fancy importer that can let us import from a module name,
    like:

        import sh
        tmp = sh()
        from tmp import ls
    c                 S   s,   z| j jtjkW S  tk
r&   Y dS X d S rŒ  )r–   ra   ÚModuleImporterFromVariablesrf  )Úimporter_clsr   r   r   Útest  s    zregister_importer.<locals>.testc                    s   g | ]}ˆ |ƒrd ‘qS )Tr   ré  ©r  r   r   rŽ   #  s      z%register_importer.<locals>.<listcomp>)Úrestrict_tor   )Úanyrk  Ú	meta_pathr›  rz  ra   rç  )Úalready_registeredÚimporterr   rž  r   Úregister_importer  s    	r¤  c                 C   s   |j  | |j | d ¡¡}|S r    )Úf_localsrB   Ú	f_globals)r¼   r™  Úmodr   r   r   Úfetch_module_from_frame,  s    r¨  c                   @   s6   e Zd ZdZddd„Zddd„Zddd„Zd	d
„ ZdS )r›  zÃ a fancy importer that allows us to import from a variable that was
    recently set in either the local or global scope, like this:

        sh2 = sh(_timeout=3)
        from sh2 import ls

    Nc                 C   s   t |p
t ƒ ƒ| _d S r    )r   rŸ  )r1   rŸ  r   r   r   r2   :  s    z$ModuleImporterFromVariables.__init__c                 C   sd   t  ¡ j}|r |jjdkr |j}|r4t|ƒr4|j}q |s<dS t||ƒ}|sNdS |jj| j	kr`dS | S )a   mod_fullname doubles as the name of the VARIABLE holding our new sh
        context.  for example:

            derp = sh()
            from derp import ls

        here, mod_fullname will be "derp".  keep that in mind as we go through
        the rest of this function Ú	find_specN)
r"   ÚcurrentframeÚf_backr‹  Úco_namerš  r¨  r–   ra   rŸ  )r1   Úmod_fullnamerÈ   Úparent_frameÚmoduler   r   r   Úfind_module=  s    


z'ModuleImporterFromVariables.find_modulec                 C   s.   ddl m} |  ||¡}|dk	r*|||ƒS dS )zF find_module() is deprecated since Python 3.4 in favor of find_spec() r   )Ú
ModuleSpecN)Úimportlib.machineryr±  r°  )r1   ÚfullnamerÈ   r¥  r±  rÉ  r   r   r   r©  d  s    z%ModuleImporterFromVariables.find_specc                 C   s8   t  ¡ j}t|ƒr|j}q
t||ƒ}|tj|< | |_|S r    )r"   rª  r«  rš  r¨  rk  r“  Ú
__loader__)r1   r­  r®  r¯  r   r   r   Úload_modulek  s    


z'ModuleImporterFromVariables.load_module)N)N)NN)ra   rb   rc   r”   r2   r°  r©  rµ  r   r   r   r   r›  1  s
   

'
r›  Ú__main__)r)   )N)N)N)F)N)Ðr”   r1  r0  Úcollectionsr   Úcollections.abcr   ÚImportErrorr  rP  r  rL  rR  rÍ   Úglob_moduler"   rð   rÎ   rˆ  rA  r>  r®   r,   rº   rŽ  r  rk  r
  r.  r<  rh  r^  r9  r  Ú
contextlibr   Ú	functoolsr   Úior   r   r  Úlocaler	   Útypesr
   r   Úversion_inforp   Ú	MINOR_VERrÌ  r   r  r   r  r  rÖ  r   r   r   r|  r   r   Úshlexr   r  ZpipesÚsystemrŠ  rt   rO  rÈ   ÚdirnamerÖ   r2  ÚTHIS_DIRra   rò   Úboolr·   rÝ   rB   rÑ  ÚFORCE_USE_SELECTr  Ú
PUSHD_LOCKr&   Úinputrs  rs   rv   rv  rl  r   Údirrg  ÚHAS_POLLrY   rZ   r[   r\   rË  r+   r{   r„   r†   r…   rÝ  r‹   r•   r©   r«   ÚSIGABRTÚSIGBUSÚSIGFPEÚSIGILLÚSIGINTrö  r#  ÚSIGQUITÚSIGSEGVr¼  ÚSIGSYSr"  rf  r­   rv  rµ   r³   rø  r€  r­  rÄ   rÂ   r»   rÊ   rÉ   rÇ   rÑ   rç   rê   rî   rï   r  r  rw  r)  r…  r‡  rˆ  r‹  r“  rœ  r¢  r¬  r®  rë   rÞ  rù  r  r  r!  rF  r-  r1  r*  r„  rÐ  r€  r‡  rÔ  rÕ  rä  rÜ  rÝ  rß  rà  rÞ  rò  rv  r
  r  r  r  r  r  rx  rô  r*  ré  r.  r/  r;  rD  Úmod_namer3  r“  rK  rN  rZ  ry  rz  rš  r¤  r¨  r›  r  r  r   r   r   r   Ú<module>   s–  

þ

K0$
A
õ
 (
)

4
  L		  w-
B
C     [!
29
$bJy

j



OQL


