ž ­ÿf#‹c @s÷dZddlZddlZddlZddlZddlZddlZddlZddlZyddl Z ddl Z Wne k rœe Z YnXddlmZmZdZejdkrÑdZndZe ae edd „Zd d „Zd d „Zdd„Zdd„Zdd„Zdd„ZejdejƒZdd„Z Gdd„de!ƒZ"Gdd„de#ƒZ$Gdd„de%ƒZ&Gdd „d e'ƒZ(Gd!d"„d"e(ƒZ)e)Z*d#d$„Z+ed%d&„Z,d'd(„Z-dS()u 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-2013 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! iN(uThreadingTCPServeruStreamRequestHandleriF#uwin32iF'ihc Cs¯ddl}|j|ƒ}t|dƒr:|j|ƒn |j|ƒt|ƒ}tjƒz@tjj ƒtj dd…=t ||ƒ}t |||ƒWdtj ƒXdS(uD 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). iNureadline(u configparseru ConfigParseruhasattru read_fileureadu_create_formattersuloggingu _acquireLocku _handlersuclearu _handlerListu_install_handlersu_install_loggersu _releaseLock(ufnameudefaultsudisable_existing_loggersu configparserucpu formattersuhandlers((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu fileConfig5s     u fileConfigc CsŽ|jdƒ}|jdƒ}t|ƒ}x]|D]U}|d|}yt||ƒ}Wq1tk r…t|ƒt||ƒ}Yq1Xq1W|S(u)Resolve a dotted name to a global object.u.i(usplitupopu __import__ugetattruAttributeError(unameuusedufoundun((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu_resolveTs    u_resolvecCstdd„|ƒS(NcSs |jƒS(N(ustrip(ux((u3/opt/alt/python33/lib64/python3.3/logging/config.pyucsu_strip_spaces..(umap(ualist((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu _strip_spacesbsu _strip_spacesc Csä|dd}t|ƒsiS|jdƒ}t|ƒ}i}xž|D]–}d|}|j|ddd dd ƒ}|j|ddd dd ƒ}tj}||jd ƒ}|rÃt|ƒ}n|||ƒ} | ||}|d|}|d}|jddƒ}yt|ttƒƒ}Wn$ttfk r»t |ƒ}YnX|d} t| ttƒƒ} || Œ} d |kr|d } | j tj | ƒnt|ƒr4| j ||ƒnt |tjjƒr€|jd dƒ} t| ƒr€|j| | fƒq€n| ||          u_install_handlerscCsdtj}xT|D]L}|jj|}||krStj|_g|_d|_q||_ qWdS(uå When (re)configuring logging, handle loggers which were in the previous configuration but are not in the new configuration. There's no point deleting them as other threads may continue to hold references to them; and by disabling them, you stop them doing any logging. However, don't disable children of named loggers, as that's probably not what was intended by the user. Also, allow existing loggers to NOT be disabled if disable_existing is false. NT( uloggingurootumanageru loggerDictuNOTSETuleveluhandlersuTrueu propagateudisabled(uexistingu child_loggersudisable_existingurootulogulogger((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu_handle_existing_loggerss      u_handle_existing_loggerscCsñ|dd}|jdƒ}ttdd„|ƒƒ}|jdƒ|d}tj}|}d|kr‹|d}|jtj|ƒnx(|jd d …D]}|j |ƒqŸW|d } t | ƒr | jdƒ} t | ƒ} x"| D]} |j || ƒqîWnt|j jjƒƒ} | jƒg} x¦|D]ž}|d |}|d } |jd ddƒ}tj| ƒ}| | kr| j| ƒd}| d}t |ƒ}t | ƒ}xH||kr| |d |…|krû| j| |ƒn|d7}qÁW| j| ƒnd|krF|d}|jtj|ƒnx(|jd d …D]}|j |ƒqZW||_d|_|d } t | ƒr;| jdƒ} t | ƒ} x"| D]} |j || ƒq»Wq;q;Wt| | |ƒd S(uCreate and install loggersuloggersukeysu,cSs |jƒS(N(ustrip(ux((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu¸su"_install_loggers..urootu logger_rootulevelNuhandlersu logger_%suqualnameu propagateufallbackiu.i(usplitulistumapuremoveuloggingurootusetLevelu _levelNamesuhandlersu removeHandlerulenu _strip_spacesu addHandlerumanageru loggerDictukeysusortugetintu getLoggeruindexuappendu propagateudisabledu_handle_existing_loggers(ucpuhandlersudisable_existingullistusectionurootuloguleveluhuhlistuhanduexistingu child_loggersuqnu propagateuloggeruiuprefixedupflenu num_existing((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu_install_loggers²sd                         u_install_loggersu^[a-z_][a-z0-9_]*$cCs,tj|ƒ}|s(td|ƒ‚ndS(Nu!Not a valid Python identifier: %rT(u IDENTIFIERumatchu ValueErroruTrue(usum((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu valid_ident su valid_identcBsD|EeZdZdZdd„Zddd„Zddd„ZdS( uConvertingDictu A converting dictionary wrapper.cCsqtj||ƒ}|jj|ƒ}||k rm|||[a-z]+)://(?P.*)$u ^\s*(\w+)\s*u^\.\s*(\w+)\s*u^\[\s*(\w+)\s*\]\s*u^\d+$u ext_convertuextu cfg_convertucfgcCst|ƒ|_||j_dS(N(uConvertingDictuconfigu configurator(uselfuconfig((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu__init__wsuBaseConfigurator.__init__c Csü|jdƒ}|jdƒ}yz|j|ƒ}x`|D]X}|d|7}yt||ƒ}Wq7tk rŽ|j|ƒt||ƒ}Yq7Xq7W|SWn]tk r÷tjƒdd…\}}td||fƒ}|||_ |_ |‚YnXdS(u` Resolve strings to objects using standard import and attribute syntax. u.iiNuCannot resolve %r: %s( usplitupopuimporterugetattruAttributeErroru ImportErrorusysuexc_infou ValueErroru __cause__u __traceback__( uselfusunameuusedufoundufragueutbuv((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuresolve{s"    uBaseConfigurator.resolvecCs |j|ƒS(u*Default converter for the ext:// protocol.(uresolve(uselfuvalue((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu ext_convert’suBaseConfigurator.ext_convertc Cs\|}|jj|ƒ}|dkr7td|ƒ‚n!||jƒd…}|j|jƒd}xñ|rW|jj|ƒ}|rœ||jƒd}nƒ|jj|ƒ}|r|jƒd}|j j|ƒsã||}qyt |ƒ}||}Wqt k r||}YqXn|r>||jƒd…}qgtd||fƒ‚qgW|S(u*Default converter for the cfg:// protocol.uUnable to convert %rNiuUnable to convert %r at %r( u WORD_PATTERNumatchuNoneu ValueErroruenduconfigugroupsu DOT_PATTERNu INDEX_PATTERNu DIGIT_PATTERNuintu TypeError(uselfuvalueurestumuduidxun((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu cfg_convert–s2     uBaseConfigurator.cfg_convertcCs/t|tƒ r7t|tƒr7t|ƒ}||_nôt|tƒ rnt|tƒrnt|ƒ}||_n½t|tƒ r¥t|tƒr¥t|ƒ}||_n†t|tƒr+|j j |ƒ}|r+|j ƒ}|d}|j j |dƒ}|r(|d}t||ƒ}||ƒ}q(q+n|S(ué 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. uprefixusuffixN(u isinstanceuConvertingDictudictu configuratoruConvertingListulistuConvertingTupleutupleustruCONVERT_PATTERNumatchu groupdictuvalue_convertersugetuNoneugetattr(uselfuvalueumuduprefixu converterusuffix((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuconvert¸s*         uBaseConfigurator.convertcs¤ˆjdƒ}t|ƒs-|j|ƒ}nˆjddƒ}t‡fdd†ˆDƒƒ}||}|r x-|jƒD]\}}t|||ƒq}Wn|S(u1Configure an object with a user-supplied factory.u()u.cs,g|]"}t|ƒr|ˆ|f‘qS((u valid_ident(u.0uk(uconfig(u3/opt/alt/python33/lib64/python3.3/logging/config.pyu Ûs u5BaseConfigurator.configure_custom..N(upopucallableuresolveuNoneudictuitemsusetattr(uselfuconfigucupropsukwargsuresultunameuvalue((uconfigu3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_customÔs  u!BaseConfigurator.configure_customcCs"t|tƒrt|ƒ}n|S(u0Utility function which converts lists to tuples.(u isinstanceulistutuple(uselfuvalue((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuas_tupleâsuBaseConfigurator.as_tupleN(u__name__u __module__u __qualname__u__doc__ureucompileuCONVERT_PATTERNu WORD_PATTERNu DOT_PATTERNu INDEX_PATTERNu DIGIT_PATTERNuvalue_convertersu staticmethodu __import__uimporteru__init__uresolveu ext_convertu cfg_convertuconvertuconfigure_customuas_tuple(u __locals__((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuBaseConfiguratorcs"      "  uBaseConfiguratorcBs|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z ddd„Z ddd„Z ddd„Z dS(uDictConfiguratoru] Configure logging using a dictionary-like object to describe the configuration. cCsQ|j}d|kr$tdƒ‚n|ddkrKtd|dƒ‚n|jddƒ}i}tjƒzÒ|r+|jd|ƒ}xº|D]²}|tjkr·td|ƒ‚qyLtj|}||}|jdd ƒ}|r|j tj |ƒƒnWqt k r@} ztd || fƒ‚WYd d } ~ XqXqW|jd |ƒ} xg| D]_}y|j || |dƒWq^t k r¼} ztd || fƒ‚WYd d } ~ Xq^Xq^W|jd d ƒ} | r>y|j| dƒWq(t k r$} ztd| ƒ‚WYd d } ~ Xq(Xq>n|jddƒ} tjjƒtjd d …=|jd|ƒ} xg| D]_}y|j| |ƒ| |y|j| ƒWq>t k r:} ztd| ƒ‚WYd d } ~ Xq>XnWd tj"ƒXd S(uDo the configuration.uversionu$dictionary doesn't specify a versioniuUnsupported version: %su incrementaluhandlersuNo handler found with name %rulevelu"Unable to configure handler %r: %sNuloggersu!Unable to configure logger %r: %surootu#Unable to configure root logger: %sudisable_existing_loggersu formattersu$Unable to configure formatter %r: %sufiltersu!Unable to configure filter %r: %sutarget not configured yetu.FT(#uconfigu ValueErrorupopuFalseuloggingu _acquireLockugetu _handlersuNoneusetLevelu _checkLevelu Exceptionuconfigure_loggeruTrueuconfigure_rootuclearu _handlerListuconfigure_formatteruconfigure_filterusorteduconfigure_handlerunameustruappendurootulistumanageru loggerDictukeysusortuindexulenuremoveu_handle_existing_loggersu _releaseLock(uselfuconfigu incrementalu EMPTY_DICTuhandlersunameuhandleruhandler_configulevelueuloggersurootudisable_existingu formattersufiltersudeferreduexistingu child_loggersuiuprefixedupflenu num_existing((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu configureîsÖ       ' '#  ' ' '  '       ' $uDictConfigurator.configurecCsçd|kr˜|d}y|j|ƒ}Wqãtk r”}zIdt|ƒkrV‚n|jdƒ|d<||d<|j|ƒ}WYdd}~XqãXnK|jddƒ}|jddƒ}|jddƒ}tj|||ƒ}|S( u(Configure a formatter from a dictionary.u()u'format'uformatufmtNudatefmtustyleu%(uconfigure_customu TypeErrorustrupopugetuNoneuloggingu Formatter(uselfuconfigufactoryuresultuteufmtudfmtustyle((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_formatters   %u$DictConfigurator.configure_formattercCsCd|kr|j|ƒ}n!|jddƒ}tj|ƒ}|S(u%Configure a filter from a dictionary.u()unameu(uconfigure_customugetulogginguFilter(uselfuconfiguresultuname((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_filter¤s  u!DictConfigurator.configure_filtercCsoxh|D]`}y|j|jd|ƒWqtk rf}ztd||fƒ‚WYdd}~XqXqWdS(u/Add filters to a filterer from a list of names.ufiltersuUnable to add filter %r: %sN(u addFilteruconfigu Exceptionu ValueError(uselfufiltererufiltersufue((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu add_filters­s  uDictConfigurator.add_filtersc.stˆƒ}ˆjddƒ}|rzy|jd|}Wqztk rv}ztd||fƒ‚WYdd}~XqzXnˆjddƒ}ˆjddƒ}dˆkràˆjdƒ}t|ƒs×|j|ƒ}n|}nQˆjdƒ} |j| ƒ} t| t j j ƒrµd ˆkrµyQ|jd ˆd } t | t j ƒseˆj|ƒtd ƒ‚n| ˆd Üs u6DictConfigurator.configure_handler..u'stream'ustreamustrm(udictupopuNoneuconfigu Exceptionu ValueErrorucallableuresolveu issubclassulogginguhandlersu MemoryHandleru isinstanceuHandleruupdateu TypeErroru SMTPHandleruas_tupleu SysLogHandlerustru setFormatterusetLevelu _checkLevelu add_filters(uselfuconfigu config_copyu formatterueulevelufiltersucufactoryucnameuklassuthukwargsuresultute((uconfigu3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_handlerµsd &     *   u"DictConfigurator.configure_handlercCsoxh|D]`}y|j|jd|ƒWqtk rf}ztd||fƒ‚WYdd}~XqXqWdS(u.Add handlers to a logger from a list of names.uhandlersuUnable to add handler %r: %sN(u addHandleruconfigu Exceptionu ValueError(uselfuloggeruhandlersuhue((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu add_handlersðs  uDictConfigurator.add_handlerscCsÅ|jddƒ}|dk r7|jtj|ƒƒn|sÁx(|jdd…D]}|j|ƒqQW|jddƒ}|r“|j||ƒn|jddƒ}|rÁ|j||ƒqÁndS(uU Perform configuration which is common to root and non-root loggers. ulevelNuhandlersufilters( ugetuNoneusetLeveluloggingu _checkLeveluhandlersu removeHandleru add_handlersu add_filters(uselfuloggeruconfigu incrementaluleveluhuhandlersufilters((u3/opt/alt/python33/lib64/python3.3/logging/config.pyucommon_logger_configøs u%DictConfigurator.common_logger_configcCsPtj|ƒ}|j|||ƒ|jddƒ}|dk rL||_ndS(u.Configure a non-root logger from a dictionary.u propagateN(uloggingu getLoggerucommon_logger_configugetuNoneu propagate(uselfunameuconfigu incrementaluloggeru propagate((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_logger s  u!DictConfigurator.configure_loggercCs#tjƒ}|j|||ƒdS(u*Configure a root logger from a dictionary.N(uloggingu getLoggerucommon_logger_config(uselfuconfigu incrementaluroot((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuconfigure_roots uDictConfigurator.configure_rootNF(u__name__u __module__u __qualname__u__doc__u configureuconfigure_formatteruconfigure_filteru add_filtersuconfigure_handleru add_handlersuFalseucommon_logger_configuconfigure_loggeruconfigure_root(u __locals__((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuDictConfiguratorès Ÿ   ; uDictConfiguratorcCst|ƒjƒdS(u%Configure logging using a dictionary.N(udictConfigClassu configure(uconfig((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu dictConfigsu dictConfigcsptstdƒ‚nGdd„dtƒ}Gdd„dtƒ}G‡fdd†dtjƒ‰ˆ|||ƒS(uW 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(). u listen() needs threading to workcBs&|EeZdZdZdd„ZdS(u#listen..ConfigStreamHandleru¤ Handler for a logging configuration request. It expects a completely new logging configuration and uses fileConfig to install it. c Ss£y=|j}|jdƒ}t|ƒdkr<tjd|ƒd}|jj|ƒ}x3t|ƒ|krŠ||j|t|ƒƒ}qXW|jdƒ}y)ddl}|j|ƒ}t|ƒWnTt j |ƒ}yt |ƒWn,t t fk r‚YntjƒYnXYnX|jjr<|jjjƒq<nWn_tjk rž}z<t|jtƒsm‚n|jd}|tkrŒ‚nWYdd}~XnXdS(uè 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. iu>Liuutf-8N(u connectionurecvulenustructuunpackudecodeujsonuloadsu dictConfiguiouStringIOu fileConfiguKeyboardInterruptu SystemExitu tracebacku print_excuserverureadyusetusocketuerroru isinstanceuargsutupleu RESET_ERROR( uselfuconnuchunkuslenujsonudufileueuerrcode((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuhandle2s: !    u*listen..ConfigStreamHandler.handleN(u__name__u __module__u __qualname__u__doc__uhandle(u __locals__((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuConfigStreamHandler+suConfigStreamHandlercBsD|EeZdZdZdZdedddd„Zdd„ZdS( u$listen..ConfigSocketReceiveruD A simple TCP socket-based logging config receiver. iu localhostcSsLtj|||f|ƒtjƒd|_tjƒd|_||_dS(Nii(uThreadingTCPServeru__init__uloggingu _acquireLockuabortu _releaseLockutimeoutuready(uselfuhostuportuhandleruready((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu__init__cs     u-listen..ConfigSocketReceiver.__init__cSsddl}d}xj|s~|j|jjƒggg|jƒ\}}}|r^|jƒntjƒ|j}tjƒqW|jj ƒdS(Ni( uselectusocketufilenoutimeoutuhandle_requestuloggingu _acquireLockuabortu _releaseLockuclose(uselfuselectuaborturduwruex((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuserve_until_stoppedls     u8listen..ConfigSocketReceiver.serve_until_stoppedN( u__name__u __module__u __qualname__u__doc__uallow_reuse_addressuDEFAULT_LOGGING_CONFIG_PORTuNoneu__init__userve_until_stopped(u __locals__((u3/opt/alt/python33/lib64/python3.3/logging/config.pyuConfigSocketReceiver\s uConfigSocketReceivercs5|EeZdZ‡‡fdd†Zdd„Z‡S(ulisten..ServercsAtˆ|ƒjƒ||_||_||_tjƒ|_dS(N(usuperu__init__urcvruhdlruportu threadinguEventuready(uselfurcvruhdlruport(uServeru __class__(u3/opt/alt/python33/lib64/python3.3/logging/config.pyu__init__|s    ulisten..Server.__init__cSs~|jd|jd|jd|jƒ}|jdkrI|jd|_n|jjƒtjƒ|atj ƒ|j ƒdS(Nuportuhandlerureadyii( urcvruportuhdlrureadyuserver_addressusetuloggingu _acquireLocku _listeneru _releaseLockuserve_until_stopped(uselfuserver((u3/opt/alt/python33/lib64/python3.3/logging/config.pyurunƒs    ulisten..Server.run(u__name__u __module__u __qualname__u__init__urun(u __locals__(uServer(u __class__u3/opt/alt/python33/lib64/python3.3/logging/config.pyuServerzsuServer(uthreaduNotImplementedErroruStreamRequestHandleruThreadingTCPServeru threadinguThread(uportuConfigStreamHandleruConfigSocketReceiver((uServeru3/opt/alt/python33/lib64/python3.3/logging/config.pyulistens 1ulistenc Cs8tjƒztr%dt_danWdtjƒXdS(uN Stop the listening server which was created with a call to listen(). iN(uloggingu _acquireLocku _listeneruabortuNoneu _releaseLock(((u3/opt/alt/python33/lib64/python3.3/logging/config.pyu stopListening‘s    u stopListening(.u__doc__usysuloggingulogging.handlersusocketustructu tracebackureuiou_threaduthreadu threadingu ImportErroruNoneu socketserveruThreadingTCPServeruStreamRequestHandleruDEFAULT_LOGGING_CONFIG_PORTuplatformu RESET_ERRORu _listeneruTrueu fileConfigu_resolveu _strip_spacesu_create_formattersu_install_handlersu_handle_existing_loggersu_install_loggersucompileuIu IDENTIFIERu valid_identudictuConvertingDictulistuConvertingListutupleuConvertingTupleuobjectuBaseConfiguratoruDictConfiguratorudictConfigClassu dictConfigulistenu stopListening(((u3/opt/alt/python33/lib64/python3.3/logging/config.pyus@T         #  V % …ÿ0 s