관리-도구
편집 파일: outputcapture.cpython-311.pyc
� �܋f� � �V � d dl Z d dlZd dlmZ d dlmZ d dlmZ G d� de� � Z dS )� N)�StringIO)� TemporaryFile)�comparec � � e Zd ZdZdZdZddededefd�Zd � Zd � Z d� Z d� Zd � Ze defd�� � Zddededefd�ZdS )� OutputCapturea� A context manager for capturing output to the :any:`sys.stdout` and :any:`sys.stderr` streams. :param separate: If ``True``, ``stdout`` and ``stderr`` will be captured separately and their expected values must be passed to :meth:`~OutputCapture.compare`. :param fd: If ``True``, the underlying file descriptors will be captured, rather than just the attributes on :mod:`sys`. This allows you to capture things like subprocesses that write directly to the file descriptors, but is more invasive, so only use it when you need it. :param strip_whitespace: When ``True``, which is the default, leading and training whitespace is trimmed from both the expected and actual values when comparing. .. note:: If ``separate`` is passed as ``True``, :attr:`OutputCapture.captured` will be an empty string. NFT�separate�fd�strip_whitespacec �0 � || _ || _ || _ d S �N)r r r )�selfr r r s �k/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/testfixtures/outputcapture.py�__init__zOutputCapture.__init__# s � � �� ���� 0����� c �" � | j r:t � � | _ t � � | _ t � � | _ n9t � � | _ t � � | _ t � � | _ | � � � | S r )r r �output�stdout�stderrr �enable�r s r � __enter__zOutputCapture.__enter__( sb � ��7� %�'�/�/�D�K�'�/�/�D�K�'�/�/�D�K�K�"�*�*�D�K�"�*�*�D�K�"�*�*�D�K���� � � ��r c �. � | � � � d S r )�disable)r �argss r �__exit__zOutputCapture.__exit__4 s � ��������r c �* � | j ri| j t j f| j t j ffD ]@\ }}t j ||� � � � � t j |� � �AdS | j t _ | j t _ dS )z,Disable the output capture if it is enabled.N) r �original_stdout�sysr �original_stderrr �os�dup2�fileno�close)r �original�currents r r zOutputCapture.disable7 s� � ��7� .��%�s�z�2��%�s�z�2�&� #� #�!��'� ���'�.�.�"2�"2�3�3�3����"�"�"�"� #� #� �-�C�J��-�C�J�J�Jr c �0 � | j ��| j rkt j t j � � � � � | _ t j t j � � � � � | _ n"t j | _ t j | _ | j r�| j r�t j | j � � � t j � � � � � t j | j � � � t j � � � � � dS | j t _ | j t _ dS | j r�t j | j � � � t j � � � � � t j | j � � � t j � � � � � dS | j xt _ t _ dS )z,Enable the output capture if it is disabled.N)r r r �dupr r r"