:zm] V d dl Z d dlZd dlmZ d dlmZ d dlmZ G d de Z dS ) N)StringIO) TemporaryFile)comparec e Zd ZdZdZdZddededefdZd Zd Z d Z d Zd Ze defd ZddededefdZdS ) 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. NFTseparatefdstrip_whitespacec 0 || _ || _ || _ d S N)r r r )selfr r r s l/builddir/build/BUILD/cloudlinux-venv-1.0.10/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 outputstdoutstderrr enabler s r __enter__zOutputCapture.__enter__( sb 7 %'//DK'//DK'//DKK"**DK"**DK"**DK 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_stdoutsysr original_stderrr osdup2filenoclose)r originalcurrents r r zOutputCapture.disable7 s 7 .%sz2%sz2& # #!' '.."2"2333"""" # # -CJ-CJJJr c 0 | j | j rkt j t j | _ t j t j | _ n"t j | _ t j | _ | j r| j rt j | j t j t j | j t j dS | j t _ | j t _ dS | j rt 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" r r r r! r r s r r zOutputCapture.enableE sx 'w 2')vcj.?.?.A.A'B'B$')vcj.?.?.A.A'B'B$$'*z$'*z$= 6w )**,,cj.?.?.A.ABBB**,,cj.?.?.A.ABBBBB![ ![ w 6**,,cj.?.?.A.ABBB**,,cj.?.?.A.ABBBBB*.+5 SZZZr c | j r;| d | S | S )Nr )r seekreaddecodegetvalue)r streams r _readzOutputCapture._read\ sE 7 %KKNNN;;=='')))??$$$r returnc 6 | | j S )z?A property containing any output that has been captured so far.)r. r r s r capturedzOutputCapture.capturedc s zz$+&&&r expectedr r c i }i }d|| j fd|| | j fd|| | j ffD ]E\ }}}| j r(| }| }||k r |||<