B @`0@s,ddlZddlZddlZddlZddlmZddlmZedZ edZ dZ ej Z ejZeeedddr|d d Znd d ZGd d d ejZGdddejZGdddejZGdddeZedZeZeeedddeeeeGdddejZ GdddeZ!dS)N) deprecated)PYOMO_ROOT_DIRz\s*z'(?:[-*] +)|(\[\s*[A-Za-z0-9\.]+\s*\] +)z-*[managerdisablecCs0|jjtkrdS|}t|ko*tkSS)aYA variant of Logger.isEnableFor that returns False if NOTSET The implementation of logging.Logger.isEnableFor() returns True if the effective level of the logger is NOTSET. This variant only returns True if the effective level of the logger is NOTSET < level <= DEBUG. This is used in Pyomo to detect if the user explicitly requested DEBUG output. This implementation mimics the core functionality of isEnabledFor() by directly querying the (undocumented) 'manager' attribute to get the current value for logging.disabled() F)rr_DEBUGgetEffectiveLevel_NOTSET)logger_levelr 4/tmp/pip-unpacked-wheel-bi3529v6/pyomo/common/log.py is_debug_set*s r cCs|tsdS|tkS)NF) isEnabledForrrr)r r r r r As cs<eZdZdZfddZfddZddZdd ZZS) WrappingFormatterz <>c sd|kr`|dddkr"d|d<n>|ddkr8d|d<n(|ddkrNd|d<ntd |dftj|d d d |_|d d|_|dd|_tt |j f|dS)Nfmtstyle%z%(levelname)s: %(message)s{z{levelname}: {message}$z$levelname: $messagezunrecognized style flag "%s"wrapN)widthhangz base) get ValueErrortextwrap TextWrapperpop_wrapperrbasepathsuperr__init__)selfkwds) __class__r r r"Is     zWrappingFormatter.__init__c sfdddD}j_d_jrVjjrVdjtjd_ztt  }Wdx | D]\}}t ||qvWXt dfdd|DS)Ncsi|]}t||qSr )getattr).0k)recordr r Zsz,WrappingFormatter.format..)msgargspathnamez[base] c3s(|] }j|kr|n|VqdS)N)_flag _wrap_msg)r'l)r+r#r r sz+WrappingFormatter.format..) getMessager/r+r,r r- startswithlenr!rformatitemssetattrrdedentstripjoin splitlines)r#r)Z_origZraw_msgr(v)r%)r+r)r#r r6Ys zWrappingFormatter.formatcCs(t|}|||j||S)N)_indentation_rematchgroup_wrapr:replacer/)r#r1r+indentr r r r0szWrappingFormatter._wrap_msgcCsg}d}x|D]}t|}|}|s@|dq|dkrR|dN}q|rf|d|fqt|}|r||dt||gfq|r|dd|kr|dd|q|||gfqW|j pd |}xt |D]\} \} } | dkr"| dkrd || <q|| || <q|| } | |j _ | sX|j rX| t|j d|j _ n| |j _ t| d} | r| dt|  |j _ |j d| || <qWd |S) NF)NNz```T rr.)rstripr<r>r?r@r:append _bullet_rer5r enumeratersubsequent_indentinitial_indentfillr;)r#r+Z base_indentZ paragraphsZverbatimlineleadingcontentZ matchBulletirCparZ par_indentZbulletr r r rAsF       zWrappingFormatter._wrap) __name__ __module__ __qualname__r/r"r6r0rA __classcell__r r )r%r rFs   +rcs(eZdZdZfddZddZZS)LegacyPyomoFormatterzThis mocks up the legacy Pyomo log formating. This formatter takes a callback function (`verbosity`) that will be called for each message. Based on the result, one of two formatting templates will be used. c sfd|krtdd|kr td|ddd|_tf||_tfdd d ||_tt|dS) Nrz3'fmt' is not a valid option for the LegacyFormatterrz5'style' is not a valid option for the LegacyFormatter verbositycSsdS)NTr r r r r z/LegacyPyomoFormatter.__init__..zG%(levelname)s: "%(pathname)s", %(lineno)d, %(funcName)s %(message)sF)rr) rrrYrstandard_formatterverbose_formatterr!rXr")r#r$)r%r r r"s  zLegacyPyomoFormatter.__init__cCs$|r|j|S|j|SdS)N)rYr]r6r\)r#r)r r r r6s zLegacyPyomoFormatter.format)rTrUrV__doc__r"r6rWr r )r%r rXs rXcs,eZdZdZfddZfddZZS) StdoutHandlerz?A logging handler that emits to the current value of sys.stdoutcstj|_tt|dS)N)sysstdoutstreamr!r_flush)r#)r%r r rcszStdoutHandler.flushcstj|_tt||dS)N)r`rarbr!r_emit)r#r))r%r r rdszStdoutHandler.emit)rTrUrVr^rcrdrWr r )r%r r_s r_c@seZdZddZddZdS)_GlobalLogFiltercCst|_dS)N)logging getLoggerr )r#r r r r"sz_GlobalLogFilter.__init__cCs |jj S)N)r handlers)r#r)r r r filtersz_GlobalLogFilter.filterN)rTrUrVr"rir r r r resreZpyomocCs ttjS)N) _pyomoLoggerrrfDEBUGr r r r rZr[rZ)rrYcs4eZdZedddddejdffdd ZZS) LogHandlerzThe pyomo.common.log.LogHandler class has been deprecated in favor of standard Handlers from the Python logging module combined with the pyomo.common.log.WrappingFormatter.z5.7.3)versionrGNcsBtt||||f|dkr,dd}|t||ddS)NcSsdS)NTr r r r r rZr[z%LogHandler.__init__..)rrY)r!rlr"setLevel setFormatterrX)r#rrblevelrY)r%r r r"s zLogHandler.__init__)rTrUrVrrfNOTSETr"rWr r )r%r rlsrlc@s0eZdZdZdejfddZddZddZdS) LoggingInterceptaContext manager for intercepting messages sent to a log stream This class is designed to enable easy testing of log messages. The LoggingIntercept context manager will intercept messages sent to a log stream matching a specified level and send the messages to the specified output stream. Other handlers registered to the target logger will be temporarily removed and the logger will be set not to propagate messages up to higher-level loggers. Args: output (FILE): the file stream to send log messages to module (str): the target logger name to intercept level (int): the logging level to intercept Examples: >>> import six, logging >>> from pyomo.common.log import LoggingIntercept >>> buf = six.StringIO() >>> with LoggingIntercept(buf, 'pyomo.core', logging.WARNING): ... logging.getLogger('pyomo.core').warning('a simple message') >>> buf.getvalue() NcCs:t||_|jtd|j|||_d|_dS)Nz %(message)s)rf StreamHandlerhandlerro Formatterrnmodule_save)r#outputrvrpr r r r"(s   zLoggingIntercept.__init__cCsHt|j}|j|j|jf|_g|_d|_||jj| |jdS)Nr) rfrgrvrp propagaterhrwrnrt addHandler)r#r r r r __enter__/s  zLoggingIntercept.__enter__cCsXt|j}||j||jd|jd|_x|jdD]}|j |q@WdS)NrrF) rfrgrv removeHandlerrtrnrwryrhrI)r#etZevtbr hr r r __exit__7s    zLoggingIntercept.__exit__) rTrUrVr^rfWARNINGr"r{rr r r r rrsrr)"rfrer`rZpyomo.common.deprecationrZpyomo.common.fileutilsrcompiler>rJZ _bullet_charrkrrqrhasattrr&rgr rurrXrsr_objectrerjZ_handlerro addFilterrzrlrrr r r r s4     u!