관리-도구
편집 파일: logcapture.cpython-38.pyc
U )�e�$ � @ s� d Z ddlZddlmZ ddlZddlmZ ddlmZmZm Z zddl mZ W n ek rp ddl mZ Y nX e� e�ZG dd� de�ZG d d � d e�ZG dd� de�ZdS ) a This plugin captures logging statements issued during test execution. When an error or failure occurs, the captured log messages are attached to the running test in the test.capturedLogging attribute, and displayed with the error failure output. It is enabled by default but can be turned off with the option ``--nologcapture``. You can filter captured logging statements with the ``--logging-filter`` option. If set, it specifies which logger(s) will be captured; loggers that do not match will be passed. Example: specifying ``--logging-filter=sqlalchemy,myapp`` will ensure that only statements logged via sqlalchemy.engine, myapp or myapp.foo.bar logger will be logged. You can remove other installed logging handlers with the ``--logging-clear-handlers`` option. � N)�Handler)�Plugin)�anyp�ln�safe_str)�StringIOc @ sL e Zd Zdd� Zdd� Zee�Zdd� Zdd� Zee�Zd d � Zdd� Z d S )� FilterSetc C s | � |�\| _| _d S �N)� _partition� inclusive� exclusive)�selfZfilter_components� r �E/opt/hc_python/lib/python3.8/site-packages/nose/plugins/logcapture.py�__init__! s zFilterSet.__init__c C sD g g }}| D ],}|� d�r0|�|dd � � q|�|� q||fS )N�-� )� startswith�append)� componentsr r � componentr r r r % s zFilterSet._partitionc C s | sdS | � |�o| �|� S )z-returns whether this record should be printedT)�_allow�_deny�r �recordr r r �allow/ s zFilterSet.allowc s � fdd�}t ttt|| ���S )zNreturn the bool of whether `record` starts with any item in `matchers`c s � | kp� � | d �S )N�.)r )�key�r r r �record_matches_key: s z0FilterSet._any_match.<locals>.record_matches_key)r �bool�list�map)Zmatchersr r r r r � _any_match7 s zFilterSet._any_matchc C s | j s dS | �| j |�S )NT)r r# r r r r r ? s zFilterSet._allowc C s | j s dS | �| j |�S )NF)r r# r r r r r D s zFilterSet._denyN) �__name__� __module__�__qualname__r r �staticmethodr r# r r r r r r r s r c @ sD e Zd Zdd� Zdd� Zdd� Zdd� Zd d � Zdd� Zd d� Z dS )�MyMemoryHandlerc C s4 t �| � t�||�}| �|� t|�| _g | _d S r )r r �logging� Formatter�setFormatterr � filterset�buffer)r � logformat� logdatefmt�filters�fmtr r r r K s zMyMemoryHandler.__init__c C s | j �| �|�� d S r )r- r �formatr r r r �emitQ s zMyMemoryHandler.emitc C s d S r r �r r r r �flushS s zMyMemoryHandler.flushc C s g | _ d S r )r- r4 r r r �truncateU s zMyMemoryHandler.truncatec C s | j �|j�rt�| |�S d S r )r, r �namer �filterr r r r r8 W s zMyMemoryHandler.filterc C s | j �� }|d= |S )N�lock)�__dict__�copy�r �stater r r �__getstate__Z s zMyMemoryHandler.__getstate__c C s | j �|� t�� | _d S r )r: �update� threading�RLockr9 r<