File: //usr/lib/python3/dist-packages/pexpect/__pycache__/utils.cpython-38.pyc
U
�C
[� � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZze W n ek
rR ejZY nX ej d dkrje
fZnee
fZdd� Z
d
dd�Zdd� Zdd d
�Zddd�ZdS )� N� c C sh t j�| �}t j�|�sdS t �|�j}tj�d�rZt � � dkrZt
|tjtjB tj
B @ �S t �|t j�S )z�Checks that path is an executable regular file, or a symlink towards one.
This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``.
FZsunosr )�os�path�realpath�isfile�stat�st_mode�sys�platform�
startswith�getuid�bool�S_IXUSR�S_IXGRP�S_IXOTH�access�X_OK)r Zfpath�mode� r �//usr/lib/python3/dist-packages/pexpect/utils.py�is_executable_file s
���r c C sv t j�| �dkrt| �r| S |dkr*t j}|�d�}|s>t j}|�t j�}|D ]"}t j� || �}t|�rN| S qNdS )z�This takes a given filename; tries to find it in the environment path;
then checks if it is executable. This returns the full path to the filename
if found and executable. Otherwise this returns None.� N�PATH)
r r �dirnamer �environ�get�defpath�split�pathsep�join)�filename�env�pZpathlistr Zffr r r �which0 s
r# c
C s g }d}d}d}d}d}d}|}| D ]�} ||ks8||kr�| dkrF|}q�| dkrT|}q�| d krb|}q�| � � r�||krtq�|�|� d}|}q�|| }|}q$||kr�|| }|}q$||kr�| dkr�|}q�|| }q$||kr$| d kr�|}q$|| }q$|dkr�|�|� |S )
a This splits a command line into a list of arguments. It splits arguments
on spaces, but handles embedded quotes, doublequotes, and escaped
characters. It's impossible to do this with a regular expression, so I
wrote a little state machine to parse the command line. r r � � r � �\�'�")�isspace�append)
Zcommand_line�arg_list�argZstate_basicZ state_escZstate_singlequoteZstate_doublequoteZstate_whitespace�state�cr r r �split_command_lineE sL
r0 c C s� |dk rt � � | }zt�| |||�W S tk
r� t�� d }|jd tjkr~|dk r�|t � � }|dk r�g g g f Y S n� Y qX qdS )z�This is a wrapper around select.select() that ignores signals. If
select.select raises a select.error exception and errno is an EINTR
error then it is ignored. Mainly this is used to ignore sigwinch
(terminal resize). Nr$ r )�time�select�InterruptedErrorr �exc_info�args�errno�EINTR)ZiwtdZowtdZewtd�timeout�end_time�errr r r �select_ignore_interrupts� s r; c C s� |dk rt � � | }t�� }| D ]$}|�|tjtjB tjB tjB � q z.|dkrTdn|d }|�|�}dd� |D �W S tk
r� t �
� d }|jd tj
kr�|dk r�|t � � }|dk r�g Y S n� Y qFX qFdS )zOSimple wrapper around poll to register file descriptors and
ignore signals.Ni� c S s g | ]\}}|�qS r r )�.0Zafd�_r r r �
<listcomp>� s z*poll_ignore_interrupts.<locals>.<listcomp>r$ r )r1 r2 Zpoll�registerZPOLLINZPOLLPRIZPOLLHUPZPOLLERRr3 r r4 r5 r6 r7 )Zfdsr8 r9 Zpoller�fdZ
timeout_msZresultsr: r r r �poll_ignore_interrupts� s"