3 \Ќ @spddlZddlZddlZddlZddlZddlZddlZddlZyddlZ ddl Z Wne k rldZ YnXddl m Z mZdZejZdad*ddZddZd d Zd d Zd dZddZddZddZejdejZddZGdddeZ Gddde!e Z"Gddde#e Z$Gddde%e Z&Gd d!d!eZ'Gd"d#d#e'Z(e(Z)d$d%Z*edfd&d'Z+d(d)Z,dS)+N)ThreadingTCPServerStreamRequestHandleriF#Tc Csddl}t||jr|}n*|j|}t|dr:|j|n |j|t|}tj z t t ||}t |||Wdtj XdS)Nrreadline) configparser isinstanceZRawConfigParserZ ConfigParserhasattrZ read_fileread_create_formatterslogging _acquireLock_clearExistingHandlers_install_handlers_install_loggers _releaseLock)ZfnameZdefaultsdisable_existing_loggersrcp formattershandlersr&/usr/lib64/python3.6/logging/config.py fileConfig8s       rc Csp|jd}|jd}t|}xN|D]F}|d|}yt||}Wq"tk rft|t||}Yq"Xq"W|S)N.r)splitpop __import__getattrAttributeError)nameusedfoundnrrr_resolveZs    r!cCstdd|S)NcSs|jS)N)strip)xrrrisz_strip_spaces..)map)Zalistrrr _strip_spaceshsr&c Cs|dd}t|siS|jd}t|}i}x~|D]v}d|}|j|dddd}|j|dddd}|j|d dd d}tj}||jd } | rt| }||||} | ||<q4W|S) Nrkeys,z formatter_%sformatT)rawfallbackdatefmtstyle%class)lenrr&getr Formatterr!) rZflistrZformZsectnameZfsZdfsZstlc class_namefrrrr ks$     r c CsD|dd}t|siS|jd}t|}i}g}x|D]}|d|}|d}|jdd}yt|tt}Wn ttfk rt |}YnX|d} t| tt} || } d |kr|d } | j | t|r| j ||t |tj jr|jd d} t| r|j| | f| ||<q8Wx |D]\} } | j|| q$W|S) Nrr'r(z handler_%sr/ formatterargsleveltarget)r0rr&r1evalvarsr r NameErrorr!setLevel setFormatter issubclassr MemoryHandlerappendZ setTarget)rrhlistrZfixupshandsectionklassfmtr8hr9r:trrrr s>         r cCsHtj}x<|D]4}|jj|}||kr:tj|_g|_d|_q ||_q WdS)NT) r rootmanager loggerDictZNOTSETr9r propagatedisabled)existing child_loggersdisable_existingrJlogloggerrrr_handle_existing_loggerss   rTcCs,|dd}|jd}ttdd|}|jd|d}tj}|}d|kr^|d}|j|x |jddD]}|j|qnW|d } t | r| jd} t | } x| D]} |j || qWt|j j j} | jg} x>|D]4}|d |}|d } |jd d d}tj| }| | kr| j| d }| d}t |}t | }x<||kr| |d||krt| j| ||d 7}qFW| j| d|kr|d}|j|x"|jddD]}|j|qW||_d|_|d } t | r| jd} t | } x| D]} |j || qWqWt| | |dS)Nloggersr'r(cSs|jS)N)r")r#rrrr$sz"_install_loggers..rJZ logger_rootr9rz logger_%squalnamerM)r+rr)rlistr%remover rJr>r removeHandlerr0r& addHandlerrKrLr'sortZgetint getLoggerindexrBrMrNrT)rrrQZllistrErJrRr9rHrCrDrOrPZqnrMrSiprefixedpflen num_existingrrrrsd                rcCs.tjjtjtjddtjdd=dS)N)r _handlersclearZshutdownZ _handlerListrrrrr s r z^[a-z_][a-z0-9_]*$cCstj|}|std|dS)Nz!Not a valid Python identifier: %rT) IDENTIFIERmatch ValueError)smrrr valid_idents  rjc@seZdZdddZddZdS)ConvertingMixinTcCsB|jj|}||k r>|r |||<t|tttfkr>||_||_|S)N) configuratorconverttypeConvertingDictConvertingListConvertingTupleparentkey)selfrsvaluereplaceresultrrrconvert_with_key$s  z ConvertingMixin.convert_with_keycCs0|jj|}||k r,t|tttfkr,||_|S)N)rlrmrnrorprqrr)rtrurwrrrrm0s   zConvertingMixin.convertN)T)__name__ __module__ __qualname__rxrmrrrrrk!s rkc@s(eZdZddZdddZd ddZdS) rocCstj||}|j||S)N)dict __getitem__rx)rtrsrurrrr}Es zConvertingDict.__getitem__NcCstj|||}|j||S)N)r|r1rx)rtrsdefaultrurrrr1IszConvertingDict.getcCstj|||}|j||ddS)NF)rv)r|rrx)rtrsr~rurrrrMszConvertingDict.pop)N)N)ryrzr{r}r1rrrrrroBs roc@seZdZddZdddZdS) rpcCstj||}|j||S)N)rXr}rx)rtrsrurrrr}Ss zConvertingList.__getitem__rWcCstj||}|j|S)N)rXrrm)rtidxrurrrrWs zConvertingList.popN)r)ryrzr{r}rrrrrrpQsrpc@seZdZddZdS)rqcCstj||}|j||ddS)NF)rv)tupler}rx)rtrsrurrrr}]s zConvertingTuple.__getitem__N)ryrzr{r}rrrrrq[srqc@seZdZejdZejdZejdZejdZejdZ dddZ e e Z d d Zd d Zd dZddZddZddZddZdS)BaseConfiguratorz%^(?P[a-z]+)://(?P.*)$z ^\s*(\w+)\s*z^\.\s*(\w+)\s*z^\[\s*(\w+)\s*\]\s*z^\d+$ ext_convert cfg_convert)ZextZcfgcCst||_||j_dS)N)roconfigrl)rtrrrr__init__vs zBaseConfigurator.__init__c Cs|jd}|jd}y`|j|}xP|D]H}|d|7}yt||}Wq&tk rl|j|t||}Yq&Xq&W|Stk rtjdd\}}td||f}|||_ |_ |YnXdS)NrrrWzCannot resolve %r: %s) rrimporterrr ImportErrorsysexc_inforg __cause__ __traceback__) rtrhrrrZfragetbvrrrresolvezs"      zBaseConfigurator.resolvecCs |j|S)N)r)rtrurrrrszBaseConfigurator.ext_convertc Cs|}|jj|}|dkr&td|n||jd}|j|jd}x|r|jj|}|rp||jd}nd|jj|}|r|jd}|jj|s||}n2yt |}||}Wnt k r||}YnX|r||jd}qJtd||fqJW|S)NzUnable to convert %rrzUnable to convert %r at %r) WORD_PATTERNrfrgendrgroups DOT_PATTERN INDEX_PATTERN DIGIT_PATTERNint TypeError)rtrurestridrr rrrrs2       zBaseConfigurator.cfg_convertcCst|t r&t|tr&t|}||_nt|t rLt|trLt|}||_n|t|t rrt|trrt|}||_nVt|tr|j j |}|r|j }|d}|j j |d}|r|d}t||}||}|S)Nprefixsuffix)rror|rlrprXrqrstrCONVERT_PATTERNrf groupdictvalue_convertersr1r)rtrurirrZ converterrrrrrms*     zBaseConfigurator.convertcsrjd}t|s|j|}jdd}tfddD}|f|}|rnx |jD]\}}t|||qVW|S)Nz()rcs g|]}t|r||fqSr)rj).0k)rrr sz5BaseConfigurator.configure_custom..)rcallablerr|itemssetattr)rtrr3propskwargsrwrrur)rrconfigure_customs    z!BaseConfigurator.configure_customcCst|trt|}|S)N)rrXr)rtrurrras_tuples zBaseConfigurator.as_tupleN)ryrzr{recompilerrrrrr staticmethodrrrrrrrmrrrrrrrbs     "rc@sZeZdZddZddZddZddZd d Zd d ZdddZ dddZ dddZ dS)DictConfiguratorcCs|j}d|krtd|ddkr2td|d|jdd}i}tjz|r|jd|}x|D]}|tjkrtd|qfy6tj|}||}|jd d}|r|jtj|Wqft k r} ztd || fWYdd} ~ XqfXqfW|jd |} xZ| D]R}y|j || |d Wn4t k rP} ztd || fWYdd} ~ XnXqW|jdd} | ry|j | d Wn0t k r} ztd| WYdd} ~ XnXn:|jdd } t |jd|} xZ| D]R}y|j | || |<Wn4t k r"} ztd|| fWYdd} ~ XnXqW|jd|}xZ|D]R}y|j||||<Wn4t k r} ztd|| fWYdd} ~ XnXq _checkLevel Exceptionconfigure_loggerconfigure_rootr configure_formatterconfigure_filtersortedconfigure_handlerrrrBrJrXrKrLr'r\r^r0rYrTr)rtrrZ EMPTY_DICTrrhandlerZhandler_configr9rrUrJrQrrZdeferredrOrPr_r`rarbrrr configures        "  $    $  $   $  $      $ zDictConfigurator.configurec Csd|krr|d}y|j|}Wqtk rn}z4dt|kr>|jd|d<||d<|j|}WYdd}~XqXnP|jdd}|jdd}|jdd}|jdd}|stj} nt|} | |||}|S) Nz()z'format'r)rGr,r-r.r/)rrrrr1r r2r!) rtrfactoryrwterGZdfmtr-cnamer3rrrrs&      z$DictConfigurator.configure_formattercCs.d|kr|j|}n|jdd}tj|}|S)Nz()rr7)rr1r ZFilter)rtrrwrrrrrs    z!DictConfigurator.configure_filtercCs^xX|D]P}y|j|jd|Wqtk rT}ztd||fWYdd}~XqXqWdS)NrzUnable to add filter %r: %s)Z addFilterrrrg)rtZfiltererrr5rrrr add_filterss  zDictConfigurator.add_filtersc/st}jdd}|r^y|jd|}Wn2tk r\}ztd||fWYdd}~XnXjdd}jdd}dkrjd}t|s|j|}|}njd} |j| } t| tj j odkrHy>|jd d} t | tj sj |td | d<Wn8tk rD}ztd d|fWYdd}~XnXnZt| tj jrvd krv|jd d <n,t| tj jrd kr|jd d <| }jdd} tfddD} y|f| }WnLtk r"}z.dt|kr| jd| d<|f| }WYdd}~XnX|r4|j||dk rN|jtj||r`|j||| rx"| jD]\}}t|||qpW|S)Nr6rzUnable to set formatter %r: %sr9rz()r/r:rztarget not configured yetz#Unable to set target handler %r: %sZmailhostZaddressrcs g|]}t|r||fqSr)rj)rr)rrrrsz6DictConfigurator.configure_handler..z'stream'streamZstrm)r|rrrrgrrr@r rrArZHandlerupdaterZ SMTPHandlerrZ SysLogHandlerrr?r>rrrr)rtrZ config_copyr6rr9rr3rrrFZthrrrwrrrur)rrrsl          $      z"DictConfigurator.configure_handlercCs^xX|D]P}y|j|jd|Wqtk rT}ztd||fWYdd}~XqXqWdS)NrzUnable to add handler %r: %s)r[rrrg)rtrSrrHrrrr add_handlerss  zDictConfigurator.add_handlersFcCs|jdd}|dk r$|jtj||sx |jddD]}|j|q8W|jdd}|rf|j|||jdd}|r|j||dS)Nr9rr)r1r>r rrrZrr)rtrSrrr9rHrrrrrcommon_logger_configs    z%DictConfigurator.common_logger_configcCs6tj|}|j||||jdd}|dk r2||_dS)NrM)r r]rr1rM)rtrrrrSrMrrrrs   z!DictConfigurator.configure_loggercCstj}|j|||dS)N)r r]r)rtrrrJrrrrszDictConfigurator.configure_rootN)F)F)F) ryrzr{rrrrrrrrrrrrrrs ?  rcCst|jdS)N)dictConfigClassr)rrrr dictConfig srcsPts tdGdddt}Gdddt}Gfdddtj||||S)Nz listen() needs threading to workc@seZdZddZdS)z#listen..ConfigStreamHandlercSsHy|j}|jd}t|dkrtjd|d}|jj|}x&t||krd||j|t|}q@W|jjdk r~|jj|}|dk r|jd}yddl}|j |}t |WnHt k rt j |}y t|Wnt k rtjYnXYnX|jjr|jjjWn2tk rB}z|jtkr2WYdd}~XnXdS)Nz>Lrzutf-8)Z connectionZrecvr0structZunpackserververifydecodejsonloadsrrioStringIOr traceback print_excreadysetOSErrorerrno RESET_ERROR)rtZconnchunkZslenrrfilerrrrhandleBs6           z*listen..ConfigStreamHandler.handleN)ryrzr{rrrrrConfigStreamHandler;src@s,eZdZdZdedddfddZddZdS)z$listen..ConfigSocketReceiverrWZ localhostNcSs>tj|||f|tjd|_tjd|_||_||_dS)NrrW) rrr r abortrtimeoutrr)rthostportrrrrrrrpsz-listen..ConfigSocketReceiver.__init__cSsfddl}d}xJ|sV|j|jjggg|j\}}}|r>|jtj|j}tjqW|jj dS)Nr) selectZsocketfilenorZhandle_requestr r rrclose)rtrrZrdwrZexrrrserve_until_stoppedzs z8listen..ConfigSocketReceiver.serve_until_stopped)ryrzr{Zallow_reuse_addressDEFAULT_LOGGING_CONFIG_PORTrrrrrrConfigSocketReceiveris rcs&eZdZfddZddZZS)zlisten..Servercs4t|j||_||_||_||_tj|_dS)N) superrrcvrhdlrrr threadingZEventr)rtrrrr)Server __class__rrrs zlisten..Server.__init__cSsZ|j|j|j|j|jd}|jdkr0|jd|_|jjtj|a tj |j dS)N)rrrrrrW) rrrrrZserver_addressrr r _listenerrr)rtrrrrruns     zlisten..Server.run)ryrzr{rr __classcell__r)r)rrrsr)threadNotImplementedErrorrrrZThread)rrrrr)rrlisten%s .rc Cs*tjztrdt_daWdtjXdS)NrW)r r rrrrrrr stopListenings r)NT)-rrr Zlogging.handlersrrrr_threadrrrZ socketserverrrrZ ECONNRESETrrrr!r&r r rTrr rIrerjobjectrkr|rorXrprrqrrrrrrrrrrsN   "#W! 9|