Ñò ô†³Kc@s¼dZddkZddkZddklZdeifd„ƒYZdada d„Z d„Z d„Z e a ad eifd „ƒYZdadad „Zd „Z d „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„Zeid„Zd„Zd„Z d„Z d„Z d„Z d„Z d eid„Zd eid „ZRS( cCsÕttd„|||gƒƒdjp td‚|o#| ptd|‚ti}n|o|i|_n;|o|i|_n$|o|i|_n |i |_||_ ||_ ||_ h|_ dS(NcSs |dj S(N(tNone(tx((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pytGsis<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(tselftdefaulttfactoryt paramwritert leave_stdout((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyt__init__Es&       cCsW|ƒiƒ}|i}|i|ƒp|i||ƒn||}|i|ƒdS(N(tgetNameRthas_keyR twrite(Rtvt currentThreadtnametcatcherstcatcher((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR\s   cGsQtiƒiƒ}|i}||jo|ii|Œn||i|ŒdS(N(t threadingRRRRtseek(RtargsRR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR"es   cGsQtiƒiƒ}|i}||jo|ii|Œn||i|ŒdS(N(R!RRRRtread(RR#RR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR$ns   cCs|ii|ƒdS(N(RR(RRR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR wscCs|i|ƒi|ƒdS(N(RR(RRR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR zscCs|i||ƒdS(N(R(RRR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR }scCstptd|‚dS(Ns8There is no PrintCatcher output stream for the thread %r(tFalseR(RRR((s</usr/lib/python2.6/site-packages/paste/util/threadedprint.pyR€s cCs1|djo|ƒiƒ}n||i|=s   P    8