[Docstring-checkins] CVS: dps/dps utils.py,1.16,1.17
Status: Pre-Alpha
Brought to you by:
goodger
From: David G. <go...@us...> - 2002-03-11 03:37:58
|
Update of /cvsroot/docstring/dps/dps In directory usw-pr-cvs1:/tmp/cvs-serv13433/dps/dps Modified Files: utils.py Log Message: Reworked Reporter; added ConditionSet class. Index: utils.py =================================================================== RCS file: /cvsroot/docstring/dps/dps/utils.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** utils.py 22 Feb 2002 02:02:57 -0000 1.16 --- utils.py 11 Mar 2002 03:37:55 -0000 1.17 *************** *** 55,96 **** """List of names for system message levels, indexed by level.""" ! def __init__(self, warninglevel, errorlevel, warningstream=None, debug=0): """ ! Initialize the `Reporter`'s default logging category. ! Parameters: ! - `warninglevel`: The level at or above which warning output will be ! sent to `warningstream`. ! - `errorlevel`: The level at or above which `SystemMessage` exceptions ! will be raised. ! - `debug`: Show debug (level=0) system messages? ! - `warningstream`: Where warning output is sent (`None` implies ! `sys.stderr`). """ ! if warningstream is None: ! warningstream = sys.stderr ! self.categories = {'': (debug, warninglevel, errorlevel, warningstream)} ! """Mapping of category names to levels. Default category is ''.""" ! def setcategory(self, category, warninglevel, errorlevel, ! warningstream=None, debug=0): ! if warningstream is None: ! warningstream = sys.stderr ! self.categories[category] = (debug, warninglevel, errorlevel, ! warningstream) ! def unsetcategory(self, category): if category and self.categories.has_key(category): del self.categories[category] ! def getcategory(self, category): while not self.categories.has_key(category): category = category[:category.rfind('.') + 1][:-1] return self.categories[category] ! def system_message(self, level, comment=None, children=[], category=''): """ Return a system_message object. --- 55,102 ---- """List of names for system message levels, indexed by level.""" ! def __init__(self, warninglevel, errorlevel, stream=None, debug=0): """ ! Initialize the `ConditionSet` forthe `Reporter`'s default category. ! :Parameters: ! - `warninglevel`: The level at or above which warning output will ! be sent to `stream`. ! - `errorlevel`: The level at or above which `SystemMessage` ! exceptions will be raised. ! - `debug`: Show debug (level=0) system messages? ! - `stream`: Where warning output is sent (`None` implies ! `sys.stderr`). """ ! if stream is None: ! stream = sys.stderr ! self.categories = {'': ConditionSet(debug, warninglevel, errorlevel, ! stream)} ! """Mapping of category names to conditions. Default category is ''.""" ! def setconditions(self, category, warninglevel, errorlevel, ! stream=None, debug=0): ! if stream is None: ! stream = sys.stderr ! self.categories[category] = ConditionSet(debug, warninglevel, ! errorlevel, stream) ! def unsetconditions(self, category): if category and self.categories.has_key(category): del self.categories[category] ! __delitem__ = unsetconditions ! ! def getconditions(self, category): while not self.categories.has_key(category): category = category[:category.rfind('.') + 1][:-1] return self.categories[category] ! __getitem__ = getconditions ! ! def system_message(self, level, comment=None, category='', ! *children, **attributes): """ Return a system_message object. *************** *** 99,104 **** """ msg = nodes.system_message(comment, level=level, ! type=self.levels[level], *children) ! debug, warninglevel, errorlevel, stream = self.getcategory(category) if level >= warninglevel or debug and level == 0: if category: --- 105,111 ---- """ msg = nodes.system_message(comment, level=level, ! type=self.levels[level], ! *children, **attributes) ! debug, warninglevel, errorlevel, stream = self[category].astuple() if level >= warninglevel or debug and level == 0: if category: *************** *** 110,114 **** return msg ! def debug(self, comment=None, children=[], category=''): """ Level-0, "DEBUG": an internal reporting issue. Typically, there is no --- 117,121 ---- return msg ! def debug(self, comment=None, category='', *children, **attributes): """ Level-0, "DEBUG": an internal reporting issue. Typically, there is no *************** *** 116,143 **** separately from the others. """ ! return self.system_message(0, comment, children, category) ! def info(self, comment=None, children=[], category=''): """ Level-1, "INFO": a minor issue that can be ignored. Typically there is no effect on processing, and level-1 system messages are not reported. """ ! return self.system_message(1, comment, children, category) ! def warning(self, comment=None, children=[], category=''): """ Level-2, "WARNING": an issue that should be addressed. If ignored, there may be unpredictable problems with the output. """ ! return self.system_message(2, comment, children, category) ! def error(self, comment=None, children=[], category=''): """ Level-3, "ERROR": an error that should be addressed. If ignored, the output will contain errors. """ ! return self.system_message(3, comment, children, category) ! def severe(self, comment=None, children=[], category=''): """ Level-4, "SEVERE": a severe error that must be addressed. If ignored, --- 123,154 ---- separately from the others. """ ! return self.system_message( ! 0, comment, category, *children, **attributes) ! def info(self, comment=None, category='', *children, **attributes): """ Level-1, "INFO": a minor issue that can be ignored. Typically there is no effect on processing, and level-1 system messages are not reported. """ ! return self.system_message( ! 1, comment, category, *children, **attributes) ! def warning(self, comment=None, category='', *children, **attributes): """ Level-2, "WARNING": an issue that should be addressed. If ignored, there may be unpredictable problems with the output. """ ! return self.system_message( ! 2, comment, category, *children, **attributes) ! def error(self, comment=None, category='', *children, **attributes): """ Level-3, "ERROR": an error that should be addressed. If ignored, the output will contain errors. """ ! return self.system_message( ! 3, comment, category, *children, **attributes) ! def severe(self, comment=None, category='', *children, **attributes): """ Level-4, "SEVERE": a severe error that must be addressed. If ignored, *************** *** 145,149 **** messages are turned into exceptions which halt processing. """ ! return self.system_message(4, comment, children, category) --- 156,179 ---- messages are turned into exceptions which halt processing. """ ! return self.system_message( ! 4, comment, category, *children, **attributes) ! ! ! class ConditionSet: ! ! """ ! A set of thresholds, switches, and streams corresponding to one `Reporter` ! category. ! """ ! ! def __init__(self, debug, warninglevel, errorlevel, stream): ! self.debug = debug ! self.warninglevel = warninglevel ! self.errorlevel = errorlevel ! self.stream = stream ! ! def astuple(self): ! return (self.debug, self.warninglevel, self.errorlevel, ! self.stream) *************** *** 166,170 **** conversion function such as `int` or `float`. ! :Raises: - `KeyError` for unknown attribute names. - `ValueError` for invalid attribute values (raised by conversion --- 196,200 ---- conversion function such as `int` or `float`. ! :Exceptions: - `KeyError` for unknown attribute names. - `ValueError` for invalid attribute values (raised by conversion *************** *** 188,192 **** ['[name1=value1 name2=value2]', '[name3="value 3"]'] ! :Raises: - `BadAttributeLineError` for input lines not enclosed in brackets. - `BadAttributeDataError` for invalid attribute data (missing name, --- 218,222 ---- ['[name1=value1 name2=value2]', '[name3="value 3"]'] ! :Exceptions: - `BadAttributeLineError` for input lines not enclosed in brackets. - `BadAttributeDataError` for invalid attribute data (missing name, *************** *** 207,212 **** Return a list of (name, value) from a line of the form "name=value ...". ! :Raises: `BadAttributeDataError` for invalid attribute data (missing name, ! missing data, bad quotes, etc.). """ attlist = [] --- 237,243 ---- Return a list of (name, value) from a line of the form "name=value ...". ! :Exception: ! `BadAttributeDataError` for invalid attribute data (missing name, ! missing data, bad quotes, etc.). """ attlist = [] *************** *** 256,260 **** conversion function such as `int` or `float`. ! :Raises: - `KeyError` for unknown attribute names. - `DuplicateAttributeError` for duplicate attributes. --- 287,291 ---- conversion function such as `int` or `float`. ! :Exceptions: - `KeyError` for unknown attribute names. - `DuplicateAttributeError` for duplicate attributes. *************** *** 275,280 **** def newdocument(languagecode='en', warninglevel=2, errorlevel=4, ! warningstream=None, debug=0): ! reporter = Reporter(warninglevel, errorlevel, warningstream, debug) document = nodes.document(languagecode=languagecode, reporter=reporter) return document --- 306,311 ---- def newdocument(languagecode='en', warninglevel=2, errorlevel=4, ! stream=None, debug=0): ! reporter = Reporter(warninglevel, errorlevel, stream, debug) document = nodes.document(languagecode=languagecode, reporter=reporter) return document |