%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/paste/util/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/paste/util/__pycache__/threadedprint.cpython-37.pyc

B

b�N �@s�dZddlZddlZddlmZGdd�dej�Zdadadd�Z	dd	�Z
d
d�Zeaa
Gdd
�d
ej�Zdadadd�Zdd	�Z
dd�ZdS)a�
threadedprint.py
================

:author: Ian Bicking
:date: 12 Jul 2004

Multi-threaded printing; allows the output produced via print to be
separated according to the thread.

To use this, you must install the catcher, like::

    threadedprint.install()

The installation optionally takes one of three parameters:

default
    The default destination for print statements (e.g., ``sys.stdout``).
factory
    A function that will produce the stream for a thread, given the
    thread's name.
paramwriter
    Instead of writing to a file-like stream, this function will be
    called like ``paramwriter(thread_name, text)`` for every write.

The thread name is the value returned by
``threading.currentThread().getName()``, a string (typically something
like Thread-N).

You can also submit file-like objects for specific threads, which will
override any of these parameters.  To do this, call ``register(stream,
[threadName])``.  ``threadName`` is optional, and if not provided the
stream will be registered for the current thread.

If no specific stream is registered for a thread, and no default has
been provided, then an error will occur when anything is written to
``sys.stdout`` (or printed).

Note: the stream's ``write`` method will be called in the thread the
text came from, so you should consider thread safety, especially if
multiple threads share the same writer.

Note: if you want access to the original standard out, use
``sys.__stdout__``.

You may also uninstall this, via::

    threadedprint.uninstall()

TODO
----

* Something with ``sys.stderr``.
* Some default handlers.  Maybe something that hooks into `logging`.
* Possibly cache the results of ``factory`` calls.  This would be a
  semantic change.

�N)�	filemixinc@steZdZddd�Zejfdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdejfdd�Z
dejfdd�ZdS)�PrintCatcherNFcCs�ttdd�|||g��dks$td��|r>|r8td|��tj}|rL|j|_n$|rZ|j|_n|rh|j|_n|j	|_||_
||_||_i|_
dS)NcSs|dk	S)N�)�xrr�I/opt/alt/python37/lib/python3.7/site-packages/paste/util/threadedprint.py�<lambda>G�z'PrintCatcher.__init__.<locals>.<lambda>�z<You can only provide one of default, factory, or paramwriterz:You cannot pass in both default (%r) and leave_stdout=True)�len�filter�AssertionError�sys�stdout�
_writedefault�_defaultfunc�
_writefactory�_writeparam�_writeerror�_default�_factory�_paramwriter�	_catchers)�self�default�factory�paramwriterZleave_stdoutrrr�__init__Es&



zPrintCatcher.__init__cCs>|���}|j}|�|�s(|�||�n||}|�|�dS)N)�getNamer�has_keyr�write)r�v�
currentThread�name�catchers�catcherrrrr\s

zPrintCatcher.writecGs:t����}|j}||kr(|jj|�n||j|�dS)N)�	threadingr!rrr�seek)r�argsr"r#rrrr&es
zPrintCatcher.seekcGs:t����}|j}||kr(|jj|�n||j|�dS)N)r%r!rrr�read)rr'r"r#rrrr(ns
zPrintCatcher.readcCs|j�|�dS)N)rr)rr"r rrrrwszPrintCatcher._writedefaultcCs|�|��|�dS)N)rr)rr"r rrrrzszPrintCatcher._writefactorycCs|�||�dS)N)r)rr"r rrrr}szPrintCatcher._writeparamcCsdstd|��dS)NFz8There is no PrintCatcher output stream for the thread %r)r)rr"r rrrr�szPrintCatcher._writeerrorcCs |dkr|���}||j|<dS)N)rr)rr$r"r!rrr�register�s
zPrintCatcher.registercCs6|dkr|���}|j�|�s*td|��|j|=dS)Nz2There is no PrintCatcher catcher for the thread %r)rrrr)rr"r!rrr�
deregister�s


zPrintCatcher.deregister)NNNF)�__name__�
__module__�__qualname__rr%r!rr&r(rrrrr)r*rrrrrCs
			rcKs4trtjtk	r0tjatf|�at_tjatjadS)N)�
_printcatcherr
r�
_oldstdoutrr)r*)�kwrrr�install�s
r1cCstrtt_daatatadS)N)r.r/r
r�not_installed_errorr)r*rrrr�	uninstall�s
r3cOsdstd��dS)NFzGthreadedprint has not yet been installed (call threadedprint.install()))r)r'r0rrrr2�sr2c@sfeZdZddd�Zdejfdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dejfdd�Zdejfdd�ZdS)�StdinCatcherNcCsrttdd�|||g��dks$td��|r2|j|_n$|r@|j|_n|rN|j|_n|j|_||_||_	||_
i|_dS)NcSs|dk	S)Nr)rrrrr�rz'StdinCatcher.__init__.<locals>.<lambda>r	z<You can only provide one of default, factory, or paramwriter)r
rr�_readdefaultr�_readfactory�
_readparam�
_readerrorrrrr)rrrrrrrr�s



zStdinCatcher.__init__cCs<|���}|j}|�|�s&|�||�S||}|�|�SdS)N)rrrrr()r�sizer!r"r#r$rrrr(�s

zStdinCatcher.readcCs|j�|�dS)N)rr()rr"r9rrrr5�szStdinCatcher._readdefaultcCs|�|��|�dS)N)rr()rr"r9rrrr6�szStdinCatcher._readfactorycCs|�||�dS)N)Z_paramreader)rr"r9rrrr7�szStdinCatcher._readparamcCsdstd|��dS)NFz8There is no StdinCatcher output stream for the thread %r)r)rr"r9rrrr8�szStdinCatcher._readerrorcCs |dkr|���}||j|<dS)N)rr)rr$r"r!rrrr)�s
zStdinCatcher.registercCs6|dkr|���}|j�|�s*td|��|j|=dS)Nz2There is no StdinCatcher catcher for the thread %r)rrrr)rr$r"r!rrrr*�s


zStdinCatcher.deregister)NNN)
r+r,r-rr%r!r(r5r6r7r8r)r*rrrrr4�s
	r4cKs*ts&tjatf|�at_tjatjadS)N)	�
_stdincatcherr
�stdin�	_oldstdinr4r)�register_stdinr*�deregister_stdin)r0rrr�
install_stdin�s
r?cCstr|t_da}taadS)N)r:r
r;�not_installed_error_stdinr=r>)r<rrrr3�scOsdstd��dS)NFzWthreadedprint has not yet been installed for stdin (call threadedprint.install_stdin()))r)r'r0rrrr@�sr@)�__doc__r%r
Z
paste.utilrZ	FileMixinrr.r/r1r3r2r)r*r4r:r<r?r@rrrr�<module>=s P8

Zerion Mini Shell 1.0