%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python27/lib/python2.7/site-packages/paste/util/
Upload File :
Create Path :
Current File : //opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyc

�
b�Nc@s�dZddlZddlZddlmZdejfd��YZdada	d�Z
d�Zd�Zea
ad	ejfd
��YZdadad�Zd�Zd
�ZdS(s�
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.

i����N(t	filemixintPrintCatchercBs�eZd
d
d
ed�Zejd�Zd�Zd�Z	d�Z
d�Zd�Zd�Z
d
ejd�Zd
ejd	�ZRS(cCs�ttd�|||g��dks3td��|r\|sPtd|��tj}n|rq|j|_n6|r�|j|_n!|r�|j|_n|j	|_||_
||_||_i|_
dS(NcSs
|dk	S(N(tNone(tx((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt<lambda>Gsis<You can only provide one of default, factory, or paramwriters:You cannot pass in both default (%r) and leave_stdout=True(tlentfiltertAssertionErrortsyststdoutt
_writedefaultt_defaultfunct
_writefactoryt_writeparamt_writeerrort_defaultt_factoryt_paramwritert	_catchers(tselftdefaulttfactorytparamwritertleave_stdout((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt__init__Es&	

			cCsU|�j�}|j}|j|�s:|j||�n||}|j|�dS(N(tgetNameRthas_keyRtwrite(Rtvt
currentThreadtnametcatcherstcatcher((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR\s	
cGsOtj�j�}|j}||kr:|jj|�n||j|�dS(N(t	threadingRRRRtseek(RtargsRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR"es
	cGsOtj�j�}|j}||kr:|jj|�n||j|�dS(N(R!RRRRtread(RR#RR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR$ns
	cCs|jj|�dS(N(RR(RRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR
wscCs|j|�j|�dS(N(RR(RRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyRzscCs|j||�dS(N(R(RRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR
}scCststd|��dS(Ns8There is no PrintCatcher output stream for the thread %r(tFalseR(RRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR�s	cCs/|dkr|�j�}n||j|<dS(N(RRR(RR RR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pytregister�scCsN|dkr|�j�}n|jj|�s@td|��|j|=dS(Ns2There is no PrintCatcher catcher for the thread %r(RRRRR(RRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt
deregister�s

N(t__name__t
__module__RR%RR!RRR"R$R
RR
RR&R'(((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyRCs										cKsKtstjtk	rGtjat|�at_tjatjandS(N(t
_printcatcherRR	t
_oldstdoutRR&R'(tkw((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pytinstall�s
		cCs,tr(tt_daatatandS(N(R*R+RR	Rtnot_installed_errorR&R'(((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt	uninstall�s
	
cOststd��dS(NsGthreadedprint has not yet been installed (call threadedprint.install())(R%R(R#R,((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR.�s	tStdinCatchercBsteZdddd�Zdejd�Zd�Zd�Zd�Z	d�Z
dejd�Zdejd�ZRS(	cCs�ttd�|||g��dks3td��|rH|j|_n6|r]|j|_n!|rr|j|_n|j|_||_||_	||_
i|_dS(NcSs
|dk	S(N(R(R((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR�sis<You can only provide one of default, factory, or paramwriter(RRRt_readdefaultRt_readfactoryt
_readparamt
_readerrorRRRR(RRRR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR�s				cCsR|�j�}|j}|j|�s7|j||�S||}|j|�SdS(N(RRRRR$(RtsizeRRRR ((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR$�s	
cCs|jj|�dS(N(RR$(RRR5((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR1�scCs|j|�j|�dS(N(RR$(RRR5((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR2�scCs|j||�dS(N(t_paramreader(RRR5((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR3�scCststd|��dS(Ns8There is no StdinCatcher output stream for the thread %r(R%R(RRR5((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR4�s	cCs/|dkr|�j�}n||j|<dS(N(RRR(RR RR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR&�scCsN|dkr|�j�}n|jj|�s@td|��|j|=dS(Ns2There is no StdinCatcher catcher for the thread %r(RRRRR(RR RR((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR'�s

N(
R(R)RRR!RR$R1R2R3R4R&R'(((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR0�s					cKs;ts7tjat|�at_tjatjandS(N(	t
_stdincatcherRtstdint	_oldstdinR0R&tregister_stdinR'tderegister_stdin(R,((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt
install_stdin�s
		cCs*tr&|t_da}taandS(N(R7RR8Rtnot_installed_error_stdinR:R;(R9((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR/�s	
cOststd��dS(NsWthreadedprint has not yet been installed for stdin (call threadedprint.install_stdin())(R%R(R#R,((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyR=�s	(t__doc__R!Rt
paste.utilRt	FileMixinRRR*R+R-R/R.R&R'R0R7R9R<R=(((sI/opt/alt/python27/lib/python2.7/site-packages/paste/util/threadedprint.pyt<module>=s P			
8		

Zerion Mini Shell 1.0