{fc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z yddl Z ddlZWnek reZ nXddlmZmZdZejZeaeedZdZdZdZd Zd Zd Zej d ej!Z"d Z#de$fdYZ%de&e%fdYZ'de(e%fdYZ)de*e%fdYZ+de$fdYZ,de,fdYZ-e-Z.dZ/edZ0dZ1dS(s Configuration functions for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! iN(tThreadingTCPServertStreamRequestHandleriF#cCsddl}|j|}t|dr:|j|n |j|t|}tjz7tjjtj 2t ||}t |||Wdtj XdS(sD Read the logging configuration from a ConfigParser-format file. This can be called several times from an application, allowing an end user the ability to select from various pre-canned configurations (if the developer provides a mechanism to present the choices and load the chosen configuration). iNtreadline( t ConfigParserthasattrtreadfptreadt_create_formatterstloggingt _acquireLockt _handlerstcleart _handlerListt_install_handlerst_install_loggerst _releaseLock(tfnametdefaultstdisable_existing_loggersRtcpt formattersthandlers((s&/usr/lib64/python2.7/logging/config.pyt fileConfig<s     cCs|jd}|jd}t|}x\|D]T}|d|}yt||}Wq1tk rt|t||}q1Xq1W|S(s)Resolve a dotted name to a global object.t.i(tsplittpopt __import__tgetattrtAttributeError(tnametusedtfoundtn((s&/usr/lib64/python2.7/logging/config.pyt_resolve[s    cCstd|S(NcSs |jS(N(tstrip(tx((s&/usr/lib64/python2.7/logging/config.pytjt(tmap(talist((s&/usr/lib64/python2.7/logging/config.pyt _strip_spacesiscCs t|tr|S|jdS(Nsutf-8(t isinstancetstrtencode(ts((s&/usr/lib64/python2.7/logging/config.pyt_encodedlsc Cs|jdd}t|s"iS|jd}t|}i}x|D]}d|}|j|}d|kr|j|dd}nd }d|kr|j|dd}nd }tj}d|kr|j|d} | rt| }qn|||} | ||s  R|cBs#eZdZdZddZRS(sA converting list wrapper.cCs"tj||}|j||S(N(R[RR(RRR((s&/usr/lib64/python2.7/logging/config.pyROsicCstj||}|j|S(N(R[RRy(RtidxR((s&/usr/lib64/python2.7/logging/config.pyRSs(RRRRR(((s&/usr/lib64/python2.7/logging/config.pyR|Ms R}cBseZdZdZRS(sA converting tuple wrapper.cCs(tj||}|j||dtS(NR(ttupleRRR(RRR((s&/usr/lib64/python2.7/logging/config.pyRYs(RRRR(((s&/usr/lib64/python2.7/logging/config.pyR}WstBaseConfiguratorcBseZdZejdZejdZejdZejdZejdZ idd6dd 6Z e Z d Z d Zd Zd ZdZdZdZRS(sI The configurator base class which defines some useful defaults. s%^(?P[a-z]+)://(?P.*)$s ^\s*(\w+)\s*s^\.\s*(\w+)\s*s^\[\s*(\w+)\s*\]\s*s^\d+$t ext_converttextt cfg_converttcfgcCs@t||_||j_tttjkr<t|_ndS(N(R{tconfigRxRzRttypest FunctionTypetimporter(RR((s&/usr/lib64/python2.7/logging/config.pyt__init__rs c Cs|jd}|jd}yy|j|}x_|D]W}|d|7}yt||}Wq7tk r|j|t||}q7Xq7W|SWnVtk rtjd\}}td||f}|||_ |_ |nXdS(s` Resolve strings to objects using standard import and attribute syntax. RiisCannot resolve %r: %sN( RRRRRt ImportErrortsystexc_infoRst __cause__t __traceback__( RR,RRRtfragtettbtv((s&/usr/lib64/python2.7/logging/config.pytresolve|s"    cCs |j|S(s*Default converter for the ext:// protocol.(R(RR((s&/usr/lib64/python2.7/logging/config.pyRscCsO|}|jj|}|dkr7td|n||j}|j|jd}x|rJ|jj|}|r||jd}n|jj|}|r|jd}|j j|s||}qyt |}||}Wqt k r||}qXn|r1||j}qatd||fqaW|S(s*Default converter for the cfg:// protocol.sUnable to convert %risUnable to convert %r at %rN( t WORD_PATTERNRrR6RstendRtgroupst DOT_PATTERNt INDEX_PATTERNt DIGIT_PATTERNtintt TypeError(RRtrestRutdRR ((s&/usr/lib64/python2.7/logging/config.pyRs2     cCs/t|t r7t|tr7t|}||_nt|t rnt|trnt|}||_nt|t rt|trt|}||_nt|tr+|j j |}|r+|j }|d}|j j |d}|r(|d}t||}||}q(q+n|S(s Convert values to an appropriate type. dicts, lists and tuples are replaced by their converting alternatives. Strings are checked to see if they have a conversion format and are converted if they do. tprefixtsuffixN(R)R{RRxR|R[R}Rt basestringtCONVERT_PATTERNRrt groupdicttvalue_convertersR3R6R(RRRuRRt converterR((s&/usr/lib64/python2.7/logging/config.pyRys*         c Cs|jd}t|d rUttdrUt|tjkrU|j|}n|jdd}tg|D]"}t|rq|||f^qq}||}|rx-|j D]\}}t |||qWn|S(s1Configure an object with a user-supplied factory.s()t__call__t ClassTypeRN( RRRRzRRR6RRvtitemstsetattr( RRR>tpropstktkwargsRRR((s&/usr/lib64/python2.7/logging/config.pytconfigure_customs45 cCs"t|trt|}n|S(s0Utility function which converts lists to tuples.(R)R[R(RR((s&/usr/lib64/python2.7/logging/config.pytas_tuples(RRRtretcompileRRRRRRRRRRRRRyRR(((s&/usr/lib64/python2.7/logging/config.pyR^s"    "  tDictConfiguratorcBsheZdZdZdZdZdZdZdZe dZ e dZ e d Z RS( s] Configure logging using a dictionary-like object to describe the configuration. cCs|j}d|kr$tdn|ddkrKtd|dn|jdt}i}tjzz|r|jd|}x|D]}|tjkrtd|qyLtj|}||}|jdd}|r|j tj |nWqt k r.} td || fqXqW|jd |} xU| D]M}y|j || |t WqLt k r} td || fqLXqLW|jd d} | ry|j| t Wqt k r} td | qXqn|jdt } tjjtj2|jd|} xU| D]M}y|j| || |RtcnameRRtthRRRR((s&/usr/lib64/python2.7/logging/config.pyRsb 4     5 cCs]xV|D]N}y|j|jd|Wqtk rT}td||fqXqWdS(s.Add handlers to a logger from a list of names.RsUnable to add handler %r: %sN(R^RRRs(RRlRRTR((s&/usr/lib64/python2.7/logging/config.pyt add_handlerss  cCs|jdd}|dk r7|jtj|n|sx|jD]}|j|qHW|jdd}|r|j||n|jdd}|r|j||qndS(sU Perform configuration which is common to root and non-root loggers. RCRRN( R3R6RHRRRR]RR(RRlRRRCRTRR((s&/usr/lib64/python2.7/logging/config.pytcommon_logger_configs cCsPtj|}|j||||jdd}|dk rL||_ndS(s.Configure a non-root logger from a dictionary.RZN(RRcRR3R6RZ(RRRRRlRZ((s&/usr/lib64/python2.7/logging/config.pyR s  cCs#tj}|j|||dS(s*Configure a root logger from a dictionary.N(RRcR(RRRRW((s&/usr/lib64/python2.7/logging/config.pyRs ( RRRRRRRRRRRRR(((s&/usr/lib64/python2.7/logging/config.pyRs   :   cCst|jdS(s%Configure logging using a dictionary.N(tdictConfigClassR(R((s&/usr/lib64/python2.7/logging/config.pyt dictConfigscsptstdndtfdY}dtfdY}dtjffdY|||S(sW Start up a socket server on the specified port, and listen for new configurations. These will be sent as a file suitable for processing by fileConfig(). Returns a Thread object on which you can call start() to start the server, and which you can join() when appropriate. To stop the server, call stopListening(). s listen() needs threading to worktConfigStreamHandlercBseZdZdZRS(s Handler for a logging configuration request. It expects a completely new logging configuration and uses fileConfig to install it. c Ssiddl}y+|j}|jd}t|dkr6tjd|d}|jj|}x3t||kr||j|t|}qdWy)ddl}|j|}t|WnQt j |}yt |Wqt t fk rqtjqXnX|jjr6|jjjq6nWn+tjk rd}|jtkreqenXdS(s Handle a request. Each request is expected to be a 4-byte length, packed using struct.pack(">L", n), followed by the config file. Uses fileConfig() to do the grunt work. iNis>Li(ttempfilet connectiontrecvR4tstructtunpacktjsontloadsRt cStringIOtStringIORtKeyboardInterruptt SystemExitt tracebackt print_exctservertreadytsettsocketterrorterrnot RESET_ERROR( RRtconntchunktslenRRtfileR((s&/usr/lib64/python2.7/logging/config.pythandle1s4  !  (RRRR(((s&/usr/lib64/python2.7/logging/config.pyR*stConfigSocketReceivercBs2eZdZdZdedddZdZRS(sD A simple TCP socket-based logging config receiver. it localhostcSsLtj|||f|tjd|_tjd|_||_dS(Nii(RRRR tabortRttimeoutR(RthosttportRR((s&/usr/lib64/python2.7/logging/config.pyR^s     cSsddl}d}xj|s~|j|jjggg|j\}}}|r^|jntj|j}tjqW|jj dS(Nii( tselectRtfilenoRthandle_requestRR RRtclose(RRRtrdtwrtex((s&/usr/lib64/python2.7/logging/config.pytserve_until_stoppedgs     N(RRRtallow_reuse_addresstDEFAULT_LOGGING_CONFIG_PORTR6RR (((s&/usr/lib64/python2.7/logging/config.pyRWs tServercs eZfdZdZRS(csAt|j||_||_||_tj|_dS(N(tsuperRtrcvrthdlrRt threadingtEventR(RRRR(R(s&/usr/lib64/python2.7/logging/config.pyRws    cSs~|jd|jd|jd|j}|jdkrI|jd|_n|jjtj|atj |j dS(NRRRii( RRRRtserver_addressRRR t _listenerRR (RR((s&/usr/lib64/python2.7/logging/config.pytrun~s    (RRRR((R(s&/usr/lib64/python2.7/logging/config.pyRus(tthreadtNotImplementedErrorRRRtThread(RRR((Rs&/usr/lib64/python2.7/logging/config.pytlistens -cCs8tjztr%dt_danWdtjXdS(sN Stop the listening server which was created with a call to listen(). iN(RR RRR6R(((s&/usr/lib64/python2.7/logging/config.pyt stopListenings    (2RRRtioRtlogging.handlerstosRRRRRRRRRR6t SocketServerRRR t ECONNRESETRRRtRR!R(R-RR RRtIRqRvtobjectRwRR{R[R|RR}RRRRRR(((s&/usr/lib64/python2.7/logging/config.pytsR                     + \ ! .  o