ok

Mini Shell

Direktori : /opt/imunify360/venv/lib64/python3.11/site-packages/daemon/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/daemon/__pycache__/daemon.cpython-311.pyc

�

?�Dg#����dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZ	eZe
Z
n#e$reZeZ
YnwxYweZGd�de��ZGd�dee��ZGd�d	ee��ZGd
�d��Zejejejfd�Zd
�Zd�Zd�Zd�Zd�Z d&d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(dZ)d�Z*d�Z+d�Z,d�Z-d'd �Z.d!�Z/d"�Z0d#�Z1d$�Z2d&d%�Z3dS)(z Daemon process behaviour.
    �)�absolute_import�unicode_literalsNc�(��eZdZdZ�fd�Zd�Z�xZS)�DaemonErrorz3 Base exception class for errors from this module. c�b��|���t��j|i|��dS�N)�_chain_from_context�super�__init__)�self�args�kwargs�	__class__s   ��D/opt/imunify360/venv/lib64/python3.11/site-packages/daemon/daemon.pyrzDaemonError.__init__&s7���� � �"�"�"������$�)�&�)�)�)�)�)�c�(�t|d���dS)NT)�as_cause)�0_chain_exception_from_existing_exception_context�rs rr	zDaemonError._chain_from_context+s��8���M�M�M�M�M�Mr)�__name__�
__module__�__qualname__�__doc__rr	�
__classcell__)rs@rrr#sT�������=�=�*�*�*�*�*�
N�N�N�N�N�N�Nrrc��eZdZdZdS)�DaemonOSEnvironmentErrorzC Exception raised when daemon OS environment setup receives error. N�rrrr�rrrr/s������M�M�M�Mrrc��eZdZdZdS)�DaemonProcessDetachErrorz- Exception raised when process detach fails. Nrrrrr r 3s������7�7�7�7rr c�|�eZdZdZ														dd�Zed���Zd	�Zd
�Zd�Z	d�Z
d
�Zd�Zd�Z
d�ZdS)�
DaemonContextu. Context for turning the current program into a daemon process.

        A `DaemonContext` instance represents the behaviour settings and
        process context for the program when it becomes a daemon. The
        behaviour and environment is customised by setting options on the
        instance, before calling the `open` method.

        Each option can be passed as a keyword argument to the `DaemonContext`
        constructor, or subsequently altered by assigning to an attribute on
        the instance at any time prior to calling `open`. That is, for
        options named `wibble` and `wubble`, the following invocation::

            foo = daemon.DaemonContext(wibble=bar, wubble=baz)
            foo.open()

        is equivalent to::

            foo = daemon.DaemonContext()
            foo.wibble = bar
            foo.wubble = baz
            foo.open()

        The following options are defined.

        `files_preserve`
            :Default: ``None``

            List of files that should *not* be closed when starting the
            daemon. If ``None``, all open file descriptors will be closed.

            Elements of the list are file descriptors (as returned by a file
            object's `fileno()` method) or Python `file` objects. Each
            specifies a file that is not to be closed during daemon start.

        `chroot_directory`
            :Default: ``None``

            Full path to a directory to set as the effective root directory of
            the process. If ``None``, specifies that the root directory is not
            to be changed.

        `working_directory`
            :Default: ``'/'``

            Full path of the working directory to which the process should
            change on daemon start.

            Since a filesystem cannot be unmounted if a process has its
            current working directory on that filesystem, this should either
            be left at default or set to a directory that is a sensible “home
            directory” for the daemon while it is running.

        `umask`
            :Default: ``0``

            File access creation mask (“umask”) to set for the process on
            daemon start.

            A daemon should not rely on the parent process's umask value,
            which is beyond its control and may prevent creating a file with
            the required access mode. So when the daemon context opens, the
            umask is set to an explicit known value.

            If the conventional value of 0 is too open, consider setting a
            value such as 0o022, 0o027, 0o077, or another specific value.
            Otherwise, ensure the daemon creates every file with an
            explicit access mode for the purpose.

        `pidfile`
            :Default: ``None``

            Context manager for a PID lock file. When the daemon context opens
            and closes, it enters and exits the `pidfile` context manager.

        `detach_process`
            :Default: ``None``

            If ``True``, detach the process context when opening the daemon
            context; if ``False``, do not detach.

            If unspecified (``None``) during initialisation of the instance,
            this will be set to ``True`` by default, and ``False`` only if
            detaching the process is determined to be redundant; for example,
            in the case when the process was started by `init`, by `initd`, or
            by `inetd`.

        `signal_map`
            :Default: system-dependent

            Mapping from operating system signals to callback actions.

            The mapping is used when the daemon context opens, and determines
            the action for each signal's signal handler:

            * A value of ``None`` will ignore the signal (by setting the
              signal action to ``signal.SIG_IGN``).

            * A string value will be used as the name of an attribute on the
              ``DaemonContext`` instance. The attribute's value will be used
              as the action for the signal handler.

            * Any other value will be used as the action for the
              signal handler. See the ``signal.signal`` documentation
              for details of the signal handler interface.

            The default value depends on which signals are defined on the
            running system. Each item from the list below whose signal is
            actually defined in the ``signal`` module will appear in the
            default map:

            * ``signal.SIGTTIN``: ``None``

            * ``signal.SIGTTOU``: ``None``

            * ``signal.SIGTSTP``: ``None``

            * ``signal.SIGTERM``: ``'terminate'``

            Depending on how the program will interact with its child
            processes, it may need to specify a signal map that
            includes the ``signal.SIGCHLD`` signal (received when a
            child process exits). See the specific operating system's
            documentation for more detail on how to determine what
            circumstances dictate the need for signal handlers.

        `uid`
            :Default: ``os.getuid()``

        `gid`
            :Default: ``os.getgid()``

            The user ID (“UID”) value and group ID (“GID”) value to switch
            the process to on daemon start.

            The default values, the real UID and GID of the process, will
            relinquish any effective privilege elevation inherited by the
            process.

        `initgroups`
            :Default: ``False``

            If true, set the daemon process's supplementary groups as
            determined by the specified `uid`.

            This will require that the current process UID has
            permission to change the process's owning GID.

        `prevent_core`
            :Default: ``True``

            If true, prevents the generation of core files, in order to avoid
            leaking sensitive information from daemons run as `root`.

        `stdin`
            :Default: ``None``

        `stdout`
            :Default: ``None``

        `stderr`
            :Default: ``None``

            Each of `stdin`, `stdout`, and `stderr` is a file-like object
            which will be used as the new file for the standard I/O stream
            `sys.stdin`, `sys.stdout`, and `sys.stderr` respectively. The file
            should therefore be open, with a minimum of mode 'r' in the case
            of `stdin`, and mimimum of mode 'w+' in the case of `stdout` and
            `stderr`.

            If the object has a `fileno()` method that returns a file
            descriptor, the corresponding file will be excluded from being
            closed during daemon start (that is, it will be treated as though
            it were listed in `files_preserve`).

            If ``None``, the corresponding system stream is re-bound to the
            file named by `os.devnull`.

        N�/rFTc�l�||_||_||_||_|	|_|
|_||_||_|
|_|�tj
��}||_|�tj��}||_
||_|�t��}||_|�t#��}||_d|_dS)z Set up a new instance. NF)�chroot_directory�working_directory�umask�prevent_core�files_preserve�pidfile�stdin�stdout�stderr�os�getuid�uid�getgid�gid�
initgroups�"is_detach_process_context_required�detach_process�make_default_signal_map�
signal_map�_is_open)rr%r&r'r0r2r3r(r5r)r*r+r,r-r7s               rrzDaemonContext.__init__�s���$!1���!2�����
�(���,��������
��������;��)�+�+�C�����;��)�+�+�C����$����!�?�A�A�N�,�����0�2�2�J�$�����
�
�
rc��|jS)z- ``True`` if the instance is currently open. )r8rs r�is_openzDaemonContext.is_opens���}�rc���|jrdS|j�t|j��|jrt	��t|j��t|j��t|j
|j|j��|j
rt��|���}t!|��|���}t%|���t't(j|j��t't(j|j��t't(j|j��|j�|j���d|_t7|j��dS)u0 Become a daemon process.

            :return: ``None``.

            Open the daemon context, turning the current program into a daemon
            process. This performs the following steps:

            * If this instance's `is_open` property is true, return
              immediately. This makes it safe to call `open` multiple times on
              an instance.

            * If the `prevent_core` attribute is true, set the resource limits
              for the process to prevent any core dump from the process.

            * If the `chroot_directory` attribute is not ``None``, set the
              effective root directory of the process to that directory (via
              `os.chroot`).

              This allows running the daemon process inside a “chroot gaol”
              as a means of limiting the system's exposure to rogue behaviour
              by the process. Note that the specified directory needs to
              already be set up for this purpose.

            * Set the process owner (UID and GID) to the `uid` and `gid`
              attribute values.

              If the `initgroups` attribute is true, also set the process's
              supplementary groups to all the user's groups (i.e. those
              groups whose membership includes the username corresponding
              to `uid`).

            * Close all open file descriptors. This excludes those listed in
              the `files_preserve` attribute, and those that correspond to the
              `stdin`, `stdout`, or `stderr` attributes.

            * Change current working directory to the path specified by the
              `working_directory` attribute.

            * Reset the file access creation mask to the value specified by
              the `umask` attribute.

            * If the `detach_process` option is true, detach the current
              process into its own process group, and disassociate from any
              controlling terminal.

            * Set signal handlers as specified by the `signal_map` attribute.

            * If any of the attributes `stdin`, `stdout`, `stderr` are not
              ``None``, bind the system streams `sys.stdin`, `sys.stdout`,
              and/or `sys.stderr` to the files represented by the
              corresponding attributes. Where the attribute has a file
              descriptor, the descriptor is duplicated (instead of re-binding
              the name).

            * If the `pidfile` attribute is not ``None``, enter its context
              manager.

            * Mark this instance as open (for the purpose of future `open` and
              `close` calls).

            * Register the `close` method to be called during Python's exit
              processing.

            When the function returns, the running program is a daemon
            process.

            N��excludeT)r:r%�change_root_directoryr(�prevent_core_dump�change_file_creation_maskr'�change_working_directoryr&�change_process_ownerr0r2r3r5�detach_process_context�_make_signal_handler_map�set_signal_handlers�_get_exclude_file_descriptors�close_all_open_files�redirect_stream�sysr+r,r-r*�	__enter__r8�register_atexit_function�close)r�signal_handler_map�exclude_fdss   r�openzDaemonContext.opensM��H�<�	��F�� �,�!�$�"7�8�8�8���	 �����!�$�*�-�-�-� ��!7�8�8�8��T�X�t�x���A�A�A���	%�"�$�$�$�!�:�:�<�<���.�/�/�/��8�8�:�:���[�1�1�1�1���	�4�:�.�.�.���
�D�K�0�0�0���
�D�K�0�0�0��<�#��L�"�"�$�$�$���
� ���,�,�,�,�,rc�.�|���|S)z Context manager entry point. )rOrs rrJzDaemonContext.__enter__�s���	�	�����rc�l�|jsdS|j�|j�ddd��d|_dS)a Exit the daemon process context.

            :return: ``None``.

            Close the daemon context. This performs the following steps:

            * If this instance's `is_open` property is false, return
              immediately. This makes it safe to call `close` multiple times
              on an instance.

            * If the `pidfile` attribute is not ``None``, exit its context
              manager.

            * Mark this instance as closed (for the purpose of future `open`
              and `close` calls).

            NF)r:r*�__exit__r8rs rrLzDaemonContext.close�sB��$�|�	��F��<�#�
�L�!�!�$��d�3�3�3���
�
�
rc�.�|���dS)z Context manager exit point. N)rL)r�exc_type�	exc_value�	tracebacks    rrRzDaemonContext.__exit__�s���
�
�����rc�L�td�|�����}|�)a� Signal handler for end-process signals.

            :param signal_number: The OS signal number received.
            :param stack_frame: The frame object at the point the
                signal was received.
            :return: ``None``.

            Signal handler for the ``signal.SIGTERM`` signal. Performs the
            following step:

            * Raise a ``SystemExit`` exception explaining the signal.

            z'Terminating on signal {signal_number!r})�
signal_number)�
SystemExit�format)rrX�stack_frame�	exceptions    r�	terminatezDaemonContext.terminate�s6���9�@�@�"/�A�1�1�2�2�	��rc�"�|j}|�g}|�d�|j|j|jhD����t��}|D]A}|��t
|��}|�|�|���,|�|���B|S)ac Get the set of file descriptors to exclude closing.

            :return: A set containing the file descriptors for the
                files to be preserved.

            The file descriptors to be preserved are those from the
            items in `files_preserve`, and also each of `stdin`,
            `stdout`, and `stderr`. For each item:

            * If the item is ``None``, omit it from the return set.

            * If the item's `fileno` method returns a value, include
              that value in the return set.

            * Otherwise, include the item verbatim in the return set.
            Nc3�:K�|]}t|d���|V��dS)�filenoN)�hasattr)�.0�items  r�	<genexpr>z>DaemonContext._get_exclude_file_descriptors.<locals>.<genexpr>�sF����,�,���4��*�*�,��,�,�,�,�,�,r)r)�extendr+r,r-�set�_get_file_descriptor�add)rr)�exclude_descriptorsrc�file_descriptors     rrFz+DaemonContext._get_exclude_file_descriptors�s���"�,���!��N����,�,�"&�*�d�k�4�;�!G�,�,�,�	,�	,�	,�"�e�e��"�	.�	.�D��|��2�4�8�8�O��*�#�'�'��8�8�8�8�#�'�'��-�-�-�-�"�"rc�x�|�
tj}n*t|t��r|}t	||��}n|}|S)a� Make the signal handler for a specified target object.

            :param target: A specification of the target for the
                handler; see below.
            :return: The value for use by `signal.signal()`.

            If `target` is ``None``, return ``signal.SIG_IGN``. If `target`
            is a text string, return the attribute of this instance named
            by that string. Otherwise, return `target` itself.

            )�signal�SIG_IGN�
isinstance�
basestring�getattr)r�target�result�names    r�_make_signal_handlerz"DaemonContext._make_signal_handler�sD���>��^�F�F�
��
�
+�
+�	��D��T�4�(�(�F�F��F��
rc�l��t�fd��j���D����}|S)a* Make the map from signals to handlers for this instance.

            :return: The constructed signal map for this instance.

            Construct a map from signal numbers to handlers for this
            context instance, suitable for passing to
            `set_signal_handlers`.

            c3�L�K�|]\}}|��|��fV��dSr)rt)rbrXrqrs   �rrdz9DaemonContext._make_signal_handler_map.<locals>.<genexpr>�sV�����"H�"H�+�]�F��� 9� 9�&� A� A�B�"H�"H�"H�"H�"H�"Hr)�dictr7�items)rrMs` rrDz&DaemonContext._make_signal_handler_map�sZ���"�"H�"H�"H�"H�/3��/D�/D�/F�/F�"H�"H�"H�H�H��"�!r)Nr#rNNFTNNNNNNN)rrrrr�propertyr:rOrJrLrRr]rFrtrDrrrr"r"7s�������q�q�j"�!�������������,�,�,�,�\����X��c-�c-�c-�J���
���8������&"#�"#�"#�H���,
"�
"�
"�
"�
"rr"c	�l�td�td�|||hD����D����}|S)a� Get the set of file descriptors for the process streams.

        :stdin: The input stream for the process (default:
            `sys.stdin`).
        :stdout: The ouput stream for the process (default:
            `sys.stdout`).
        :stderr: The diagnostic stream for the process (default:
            `sys.stderr`).
        :return: A `set` of each file descriptor (integer) for the
            streams.

        The standard streams are the files `sys.stdin`, `sys.stdout`,
        `sys.stderr`.

        Streams might in some circumstances be non-file objects.
        Include in the result only those streams that actually have a
        file descriptor (as returned by the `fileno` method).
        c3�K�|]}|�|V��	dSrr)rb�fds  rrdz.get_stream_file_descriptors.<locals>.<genexpr>s4��������~�
��~�~�~�	�rc3�4K�|]}t|��V��dSr)rg)rb�streams  rrdz.get_stream_file_descriptors.<locals>.<genexpr>s>����7�7��%�V�,�,�7�7�7�7�7�7r)rf)r+r,r-�file_descriptorss    r�get_stream_file_descriptorsr�se��.����7�7�$�f�f�5�7�7�7�7�7�������
�rc�v�d}t|d��r&	|���}n#t$rYnwxYw|S)a� Get the file descriptor, if the object has one.

        :param obj: The object expected to be a file-like object.
        :return: The file descriptor iff the file supports it; otherwise
            ``None``.

        The object may be a non-file object. It may also be a
        file-like object with no support for a file descriptor. In
        either case, return ``None``.
        Nr`)rar`�
ValueError)�objrjs  rrgrg$sW���O��s�H����	�!�j�j�l�l�O�O���	�	�	��D�	�����s�)�
6�6c��	tj|��dS#t$r*}td�|�����}|�d}~wwxYw)z� Change the working directory of this process.

        :param directory: The target directory path.
        :return: ``None``.

        z*Unable to change working directory ({exc})��excN)r.�chdir�	ExceptionrrZ��	directoryr��errors   rrArA:sf���
�������������(�<�C�C��C�L�L�N�N��������������
A�%A�Ac���	tj|��tj|��dS#t$r*}t	d�|�����}|�d}~wwxYw)a6 Change the root directory of this process.

        :param directory: The target directory path.
        :return: ``None``.

        Set the current working directory, then the process root directory,
        to the specified `directory`. Requires appropriate OS privileges
        for this process.

        z'Unable to change root directory ({exc})r�N)r.r��chrootr�rrZr�s   rr>r>Isv���
������
�	�)�����������(�9�@�@�S�@�I�I�K�K�����������s�(,�
A �%A�A c��	tj|��dS#t$r*}td�|�����}|�d}~wwxYw)z� Change the file creation mask for this process.

        :param mask: The numeric file creation mask to set.
        :return: ``None``.

        z+Unable to change file creation mask ({exc})r�N)r.r'r�rrZ)�maskr�r�s   rr@r@]sa���
�������������(�=�D�D��D�M�M�O�O�����������r�c�<�tj|��}|j}|S)z) Get the username for the specified UID. )�pwd�getpwuid�pw_name)r0�passwd_entry�usernames   r�get_username_for_uidr�ls���<��$�$�L��#�H��OrFc�<�	t|��}n#t$rd}YnwxYw	|rtj||��ntj|��tj|��dS#t$r*}td�|�����}|�d}~wwxYw)a Change the owning UID, GID, and groups of this process.

        :param uid: The target UID for the daemon process.
        :param gid: The target GID for the daemon process.
        :param initgroups: If true, initialise the supplementary
            groups of the process.
        :return: ``None``.

        Sets the owning GID and UID of the process (in that order, to
        avoid permission errors) to the specified `gid` and `uid`
        values.

        If `initgroups` is true, the supplementary groups of the
        process are also initialised, with those corresponding to the
        username for the target UID.

        All these operations require appropriate OS privileges. If
        permission is denied, a ``DaemonOSEnvironmentError`` is
        raised.

        Fz&Unable to change process owner ({exc})r�N)	r��KeyErrorr.r3�setgid�setuidr�rrZ)r0r2r3r�r�r�s      rrBrBts���,�'��,�,���������
�
�
�����	��	��M�(�C�(�(�(�(��I�c�N�N�N�
�	�#�����������(�8�?�?�C�?�H�H�J�J�����������s$��!�!�AA'�'
B�1%B�Bc���tj}	tj|��n7#t$r*}t	d�|�����}|�d}~wwxYwd}tj||��dS)z� Prevent this process from generating a core dump.

        :return: ``None``.

        Set the soft and hard limits for core dump size to zero. On Unix,
        this entirely prevents the process from creating core dump.

        z:System does not support RLIMIT_CORE resource limit ({exc})r�N�rr)�resource�RLIMIT_CORE�	getrlimitr�rrZ�	setrlimit)�
core_resourcer�r��
core_limits    rr?r?�s����(�M��	��=�)�)�)�)������(��!�6�c�6�?�?�,�,��������	�����J���}�j�1�1�1�1�1s�#�
A�%A�Ac�b�d�}|d���tj��|d���dS)u~ Detach the process context from parent and session.

        :return: ``None``.

        Detach from the parent process and session group, allowing the
        parent to exit while this process continues running.

        Reference: “Advanced Programming in the Unix Environment”,
        section 13.3, by W. Richard Stevens, published 1993 by
        Addison-Wesley.

        c���	tj��}|dkrtjd��dSdS#t$r+}t	d�||�����}|�d}~wwxYw)a Fork a child process, then exit the parent process.

            :param error_message: Message for the exception in case of a
                detach failure.
            :return: ``None``.
            :raise DaemonProcessDetachError: If the fork fails.

            rz){message}: [{exc.errno:d}] {exc.strerror})�messager�N)r.�fork�_exit�OSErrorr rZ)�
error_message�pidr�r�s    r�fork_then_exit_parentz5detach_process_context.<locals>.fork_then_exit_parent�s���	��'�)�)�C��Q�w�w����������w���	�	�	�,�?�F�F� -�3�G�8�8�9�9�E��K�����		���s�-3�
A(�&A#�#A(zFailed first fork)r�zFailed second forkN)r.�setsid)r�s rrCrC�sN�����&��(;�<�<�<�<��I�K�K�K���(<�=�=�=�=�=�=rc�@�d}d}tj��|krd}|S)z� Determine whether the current process is started by `init`.

        :return: ``True`` iff the parent process is `init`; otherwise
            ``False``.

        The `init` process is the one with process ID of 1.

        F�T)r.�getppid)rr�init_pids  r�is_process_started_by_initr��s)���F��H�	�z�|�|�x������Mrc�2�d}	tj|tjtj��}|�tjtj��d}n<#tj$r*}|jd}|tj
krnd}Yd}~nd}~wwxYw|S)a1 Determine whether the file descriptor is a socket.

        :param fd: The file descriptor to interrogate.
        :return: ``True`` iff the file descriptor is a socket; otherwise
            ``False``.

        Query the socket type of `fd`. If there is no error, the file is a
        socket.

        FTrN)�socket�fromfd�AF_INET�SOCK_RAW�
getsockopt�
SOL_SOCKET�SO_TYPEr�r
�errno�ENOTSOCK)r|rr�file_socketr��	exc_errnos     r�	is_socketr��s����F�
��m�B�����H�H�����v�0�&�.�A�A�A������<�����H�Q�K�	����&�&���F���������������Ms�AA�B�* B�Bc�h�d}tj���}t|��rd}|S)a� Determine whether the current process is started by the superserver.

        :return: ``True`` if this process was started by the internet
            superserver; otherwise ``False``.

        The internet superserver creates a network socket, and
        attaches it to the standard streams of the child process. If
        that is the case for this process, return ``True``, otherwise
        ``False``.

        FT)rI�	__stdin__r`r�)rr�stdin_fds  r�!is_process_started_by_superserverr�
s6���F��}�#�#�%�%�H���������Mrc�F�d}t��st��rd}|S)a� Determine whether detaching the process context is required.

        :return: ``False`` iff the process is already detached;
            otherwise ``True``.

        The process environment is interrogated for the following:

        * Process was started by `init`; or

        * Process was started by `inetd`.

        If any of the above are true, the process is deemed to be already
        detached.

        TF)r�r�)rrs rr4r4"s/�� �F�!�#�#��'H�'J�'J�����Mrc���	tj|��dS#t$rG}|jtjkrn&td�||�����}|�Yd}~dSd}~wwxYw)z� Close a file descriptor if already open.

        :param fd: The file descriptor to close.
        :return: ``None``.

        Close the file descriptor `fd`, suppressing an error in the
        case the file was not open.

        z.Failed to close file descriptor {fd:d} ({exc}))r|r�N)r.rL�EnvironmentErrorr��EBADFrrZ)r|r�r�s   r�close_file_descriptor_if_openr�9s���
�
��������������9���#�#��,�D�K�K��3�L�(�(�)�)�E��K�
�D�D�D�D�D��������s��
A)�<A$�$A)ic�z�tjtj��\}}|}|tjkrt}|S)uz Get the maximum number of open file descriptors for this process.

        :return: The number (integer) to use as the maximum number of open
            files for this process.

        The maximum is the process hard resource limit of maximum number of
        open file descriptors. If the limit is “infinity”, a default value
        of ``MAXFD`` is returned.

        )r�r��
RLIMIT_NOFILE�
RLIM_INFINITY�MAXFD)�__�
hard_limitrrs   r�get_maximum_file_descriptorsr�Ss9�� �)�(�*@�A�A��R��
�F��X�+�+�+����Mrc��t��}ttd|�����|��}|S)a� Get the collection of candidate file descriptors.

        :param exclude: A collection of file descriptors that should
            be excluded from the return set.
        :return: The collection (a `set`) of file descriptors that are
            candidates for files that may be open in this process.

        Determine the set of all `int` values that could be open file
        descriptors in this process. A file descriptor is a candidate
        if it is within the range (0, `maxfd`), excluding those
        integers in the `exclude` collection.

        The `maxfd` value is determined from the standard library
        `resource` module.
        r)r�rf�range�
difference)r=�maxfd�
candidatess   r�_get_candidate_file_descriptorsr�gs8�� 
)�*�*�E��U�1�e�_�_�%�%�0�0��9�9�J��rc���tt|����}g��fd�}|r!t|��t|��dzfnd}|dd�D]-}|dz}|d|kr|d|f}�||��||f}�.||���S)a� Get the collection of candidate file descriptor ranges.

        :param exclude: A collection of file descriptors that should
            be excluded from the return ranges.
        :return: The collection (a `list`) of ranges that contain the
            file descriptors that are candidates for files that may be
            open in this process.

        Determine the ranges of all the candidate file descriptors.
        Each range is a pair of `int` values (`low`, `high`).

        A value is a candidate if it could be an open file descriptor
        in this process, excluding those integers in the `exclude`
        collection.
        c�L��|\}}||kr��|��dSdSr)�append)�candidate_range�low�high�rangess   �r�append_range_if_neededzE_get_candidate_file_descriptor_ranges.<locals>.append_range_if_needed�s4���%���d��$�J�J��M�M�/�*�*�*�*�*�
�Jrr�r�Nr)�sortedr��min)r=�candidates_listr��
this_ranger|r�r�s      @r�%_get_candidate_file_descriptor_rangesr�|s���� �<�W�E�E�F�F�O�
�F�+�+�+�+�+��	'��_�	�	��O� 4� 4�q� 8�:�:� &���a�b�b�!�	$�	$���A�v���a�=�B���$�Q�-��.�J�J�
#�"�:�.�.�.��d��J�J���:�&�&�&��Mrc�R�|D]#}tj|d|d���$dS)u^ Close file descriptors described by `ranges`.

        :param ranges: A sequence of tuples `(low, high)`, each
            describing a range of file descriptors to close.
        :return: ``None``.

        Attempt to close each open file descriptor – starting from
        `low` and ending before `high` – from each range in `ranges`.
        rr�N)r.�
closerange)r�r�s  r�_close_file_descriptor_rangesr��s:���*�*��
�
�e�A�h��a��)�)�)�)�*�*rc�f�|�t��}t|���}t|���dS)a; Close all open file descriptors.

        :param exclude: Collection of file descriptors to skip when closing
            files.
        :return: ``None``.

        Closes every file descriptor (if open) of this process. If
        specified, `exclude` is a set of file descriptors to *not*
        close.
        Nr<)r�)rfr�r�)r=�	fd_rangess  rrGrG�s9�����%�%��5�g�F�F�F�I�!��3�3�3�3�3�3rc���|�*tjtjtj��}n|���}tj||�����dS)a} Redirect a system stream to a specified file.

        :param standard_stream: A file object representing a standard I/O
            stream.
        :param target_stream: The target file object for the redirected
            stream, or ``None`` to specify the null device.
        :return: ``None``.

        `system_stream` is a standard system stream such as
        ``sys.stdout``. `target_stream` is an open file object that
        should replace the corresponding system stream object.

        If `target_stream` is ``None``, defaults to opening the
        operating system's null device and using its file descriptor.

        N)r.rO�devnull�O_RDWRr`�dup2)�
system_stream�
target_stream�	target_fds   rrHrH�sV��"���G�B�J��	�2�2�	�	�!�(�(�*�*�	��G�I�}�+�+�-�-�.�.�.�.�.rc�j�ddddd�}td�|���D����}|S)z� Make the default signal map for this system.

        :return: A mapping from signal number to handler object.

        The signals available differ by system. The map will not contain
        any signals not defined on the running system.

        Nr])�SIGTSTP�SIGTTIN�SIGTTOU�SIGTERMc3�tK�|]3\}}tt|���tt|��|fV��4dSr)rarlrp)rbrsrqs   rrdz*make_default_signal_map.<locals>.<genexpr>�sY����&�&���v��v�t�$�$�&�
�V�T�
"�
"�F�+�&�&�&�&�&�&r)rwrx)�name_mapr7s  rr6r6�s[�����"�	��H��&�&�"*�.�.�"2�"2�&�&�&�&�&�J�
�rc�d�|���D]\}}tj||���dS)a Set the signal handlers as specified.

        :param signal_handler_map: A map from signal number to handler
            object.
        :return: ``None``.

        See the `signal` module for details on signal numbers and signal
        handlers.

        N)rxrl)rMrX�handlers   rrErE�sC��%7�$<�$<�$>�$>�.�.� ����
�m�W�-�-�-�-�.�.rc�.�tj|��dS)z� Register a function for processing at program exit.

        :param func: A callable function expecting no arguments.
        :return: ``None``.

        The function `func` is registered for a call with no arguments
        at program exit.

        N)�atexit�register)�funcs rrKrKs���O�D�����rc�d�tj��\}}}|r||_n||_||_dS)a, Decorate the specified exception with the existing exception context.

        :param exc: The exception instance to decorate.
        :param as_cause: If true, the existing context is declared to be
            the cause of the exception.
        :return: ``None``.

        :PEP:`344` describes syntax and attributes (`__traceback__`,
        `__context__`, `__cause__`) for use in exception chaining.

        Python 2 does not have that syntax, so this function decorates
        the exception with values from the current exception context.

        N)rI�exc_info�	__cause__�__context__�
__traceback__)r�r�existing_exc_type�existing_exc�existing_tracebacks     rrrs?��=@�L�N�N�9���&8��'�$��
�
�&���*�C���r)Fr)4r�
__future__rrr�r�r.r�r�rlr�rIro�unicode�	NameError�str�type�
__metaclass__r�rr�rr r"r+r,r-r�rgrAr>r@r�rBr?rCr�r�r�r4r�r�r�r�r�r�rGrHr6rErKrrrr�<module>r
s����;�:�:�:�:�:�:�:�
�
�
�
�����	�	�	�	�
�
�
�
�����
�
�
�
�
�
�
�
�
�
�
�
���J��G�G�������J��G�G�G�����
�
�	N�	N�	N�	N�	N�)�	N�	N�	N�N�N�N�N�N�{�G�N�N�N�8�8�8�8�8�{�G�8�8�8�K"�K"�K"�K"�K"�K"�K"�K"�^�i��z��z�����>���,������(������%�%�%�%�P2�2�2�4#>�#>�#>�L���$���>���*���.���.	
�����(���*'�'�'�T*�*�*�4�4�4�4�"/�/�/�0���..�.�.�
�
�
�+�+�+�+�+�+s�1�	=�=

Zerion Mini Shell 1.0