• File: threadedprint.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/util/__pycache__/threadedprint.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 7.8 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

bN @sdZddlZddlZddlmZGdddejZdadaddZ	dd	Z
d
dZeaa
Gdd
d
ejZdadaddZdd	Z
ddZdS)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@steZdZdddZejfddZddZd	d
ZddZ	d
dZ
ddZddZdejfddZ
dejfddZdS)PrintCatcherNFcCsttdd|||gdks$td|r>|r8td|tj}|rL|j|_n$|rZ|j|_n|rh|j|_n|j	|_||_
||_||_i|_
dS)NcSs|dk	S)N)xrrI/opt/alt/python37/lib/python3.7/site-packages/paste/util/threadedprint.py<lambda>Gz'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)lenfilterAssertionErrorsysstdout
_writedefault_defaultfunc
_writefactory_writeparam_writeerror_default_factory_paramwriter	_catchers)selfdefaultfactoryparamwriterZleave_stdoutrrr__init__Es&



zPrintCatcher.__init__cCs>|}|j}||s(|||n||}||dS)N)getNamerhas_keyrwrite)rv
currentThreadnamecatcherscatcherrrrr\s

zPrintCatcher.writecGs:t}|j}||kr(|jj|n||j|dS)N)	threadingr!rrrseek)rargsr"r#rrrr&es
zPrintCatcher.seekcGs:t}|j}||kr(|jj|n||j|dS)N)r%r!rrrread)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 rrrrszPrintCatcher._writeerrorcCs |dkr|}||j|<dS)N)rr)rr$r"r!rrrregisters
zPrintCatcher.registercCs6|dkr|}|j|s*td||j|=dS)Nz2There is no PrintCatcher catcher for the thread %r)rrrr)rr"r!rrr
deregisters


zPrintCatcher.deregister)NNNF)__name__
__module____qualname__rr%r!rr&r(rrrrr)r*rrrrrCs
			rcKs4trtjtk	r0tjatf|at_tjatjadS)N)
_printcatcherr
r
_oldstdoutrr)r*)kwrrrinstalls
r1cCstrtt_daatatadS)N)r.r/r
rnot_installed_errorr)r*rrrr	uninstalls
r3cOsdstddS)NFzGthreadedprint has not yet been installed (call threadedprint.install()))r)r'r0rrrr2sr2c@sfeZdZdddZdejfddZddZdd	Zd
dZ	dd
Z
dejfddZdejfddZdS)StdinCatcherNcCsrttdd|||gdks$td|r2|j|_n$|r@|j|_n|rN|j|_n|j|_||_||_	||_
i|_dS)NcSs|dk	S)Nr)rrrrrrz'StdinCatcher.__init__.<locals>.<lambda>r	z<You can only provide one of default, factory, or paramwriter)r
rr_readdefaultr_readfactory
_readparam
_readerrorrrrr)rrrrrrrrs



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

zStdinCatcher.readcCs|j|dS)N)rr()rr"r9rrrr5szStdinCatcher._readdefaultcCs|||dS)N)rr()rr"r9rrrr6szStdinCatcher._readfactorycCs|||dS)N)Z_paramreader)rr"r9rrrr7szStdinCatcher._readparamcCsdstd|dS)NFz8There is no StdinCatcher output stream for the thread %r)r)rr"r9rrrr8szStdinCatcher._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*rrrrr4s
	r4cKs*ts&tjatf|at_tjatjadS)N)	
_stdincatcherr
stdin	_oldstdinr4r)register_stdinr*deregister_stdin)r0rrr
install_stdins
r?cCstr|t_da}taadS)N)r:r
r;not_installed_error_stdinr=r>)r<rrrr3scOsdstddS)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