summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/logging
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Lib/logging
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/logging')
-rw-r--r--contrib/tools/python3/src/Lib/logging/__init__.py358
-rw-r--r--contrib/tools/python3/src/Lib/logging/config.py34
-rw-r--r--contrib/tools/python3/src/Lib/logging/handlers.py226
3 files changed, 309 insertions, 309 deletions
diff --git a/contrib/tools/python3/src/Lib/logging/__init__.py b/contrib/tools/python3/src/Lib/logging/__init__.py
index 1ab35a8c21a..92cb8f08f9c 100644
--- a/contrib/tools/python3/src/Lib/logging/__init__.py
+++ b/contrib/tools/python3/src/Lib/logging/__init__.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -18,17 +18,17 @@
Logging package for Python. Based on PEP 282 and comments thereto in
comp.lang.python.
-Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
-import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
+import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
from string import Template
-from string import Formatter as StrFormatter
-
+from string import Formatter as StrFormatter
+
__all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR',
'FATAL', 'FileHandler', 'Filter', 'Formatter', 'Handler', 'INFO',
'LogRecord', 'Logger', 'LoggerAdapter', 'NOTSET', 'NullHandler',
@@ -118,7 +118,7 @@ _nameToLevel = {
def getLevelName(level):
"""
- Return the textual or numeric representation of logging level 'level'.
+ Return the textual or numeric representation of logging level 'level'.
If the level is one of the predefined levels (CRITICAL, ERROR, WARNING,
INFO, DEBUG) then you get the corresponding string. If you have
@@ -128,11 +128,11 @@ def getLevelName(level):
If a numeric value corresponding to one of the defined levels is passed
in, the corresponding string representation is returned.
- If a string representation of the level is passed in, the corresponding
- numeric value is returned.
-
- If no matching numeric or string value is passed in, the string
- 'Level %s' % level is returned.
+ If a string representation of the level is passed in, the corresponding
+ numeric value is returned.
+
+ If no matching numeric or string value is passed in, the string
+ 'Level %s' % level is returned.
"""
# See Issues #22386, #27937 and #29220 for why it's this way
result = _levelToName.get(level)
@@ -235,32 +235,32 @@ def _releaseLock():
# Prevent a held logging lock from blocking a child from logging.
if not hasattr(os, 'register_at_fork'): # Windows and friends.
- def _register_at_fork_reinit_lock(instance):
+ def _register_at_fork_reinit_lock(instance):
pass # no-op when os.register_at_fork does not exist.
-else:
- # A collection of instances with a _at_fork_reinit method (logging.Handler)
- # to be called in the child after forking. The weakref avoids us keeping
- # discarded Handler instances alive.
- _at_fork_reinit_lock_weakset = weakref.WeakSet()
+else:
+ # A collection of instances with a _at_fork_reinit method (logging.Handler)
+ # to be called in the child after forking. The weakref avoids us keeping
+ # discarded Handler instances alive.
+ _at_fork_reinit_lock_weakset = weakref.WeakSet()
- def _register_at_fork_reinit_lock(instance):
- _acquireLock()
- try:
- _at_fork_reinit_lock_weakset.add(instance)
- finally:
- _releaseLock()
+ def _register_at_fork_reinit_lock(instance):
+ _acquireLock()
+ try:
+ _at_fork_reinit_lock_weakset.add(instance)
+ finally:
+ _releaseLock()
- def _after_at_fork_child_reinit_locks():
- for handler in _at_fork_reinit_lock_weakset:
- handler._at_fork_reinit()
+ def _after_at_fork_child_reinit_locks():
+ for handler in _at_fork_reinit_lock_weakset:
+ handler._at_fork_reinit()
- # _acquireLock() was called in the parent before forking.
- # The lock is reinitialized to unlocked state.
- _lock._at_fork_reinit()
+ # _acquireLock() was called in the parent before forking.
+ # The lock is reinitialized to unlocked state.
+ _lock._at_fork_reinit()
- os.register_at_fork(before=_acquireLock,
- after_in_child=_after_at_fork_child_reinit_locks,
- after_in_parent=_releaseLock)
+ os.register_at_fork(before=_acquireLock,
+ after_in_child=_after_at_fork_child_reinit_locks,
+ after_in_parent=_releaseLock)
#---------------------------------------------------------------------------
@@ -351,7 +351,7 @@ class LogRecord(object):
else:
self.process = None
- def __repr__(self):
+ def __repr__(self):
return '<LogRecord: %s, %s, %s, %s, "%s">'%(self.name, self.levelno,
self.pathname, self.lineno, self.msg)
@@ -400,20 +400,20 @@ def makeLogRecord(dict):
rv.__dict__.update(dict)
return rv
-
+
#---------------------------------------------------------------------------
# Formatter classes and functions
#---------------------------------------------------------------------------
-_str_formatter = StrFormatter()
-del StrFormatter
-
+_str_formatter = StrFormatter()
+del StrFormatter
+
class PercentStyle(object):
default_format = '%(message)s'
asctime_format = '%(asctime)s'
asctime_search = '%(asctime)'
- validation_pattern = re.compile(r'%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa%]', re.I)
+ validation_pattern = re.compile(r'%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa%]', re.I)
def __init__(self, fmt):
self._fmt = fmt or self.default_format
@@ -421,51 +421,51 @@ class PercentStyle(object):
def usesTime(self):
return self._fmt.find(self.asctime_search) >= 0
- def validate(self):
- """Validate the input format, ensure it matches the correct style"""
- if not self.validation_pattern.search(self._fmt):
- raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
-
- def _format(self, record):
+ def validate(self):
+ """Validate the input format, ensure it matches the correct style"""
+ if not self.validation_pattern.search(self._fmt):
+ raise ValueError("Invalid format '%s' for '%s' style" % (self._fmt, self.default_format[0]))
+
+ def _format(self, record):
return self._fmt % record.__dict__
- def format(self, record):
- try:
- return self._format(record)
- except KeyError as e:
- raise ValueError('Formatting field not found in record: %s' % e)
-
-
+ def format(self, record):
+ try:
+ return self._format(record)
+ except KeyError as e:
+ raise ValueError('Formatting field not found in record: %s' % e)
+
+
class StrFormatStyle(PercentStyle):
default_format = '{message}'
asctime_format = '{asctime}'
asctime_search = '{asctime'
- fmt_spec = re.compile(r'^(.?[<>=^])?[+ -]?#?0?(\d+|{\w+})?[,_]?(\.(\d+|{\w+}))?[bcdefgnosx%]?$', re.I)
- field_spec = re.compile(r'^(\d+|\w+)(\.\w+|\[[^]]+\])*$')
-
- def _format(self, record):
+ fmt_spec = re.compile(r'^(.?[<>=^])?[+ -]?#?0?(\d+|{\w+})?[,_]?(\.(\d+|{\w+}))?[bcdefgnosx%]?$', re.I)
+ field_spec = re.compile(r'^(\d+|\w+)(\.\w+|\[[^]]+\])*$')
+
+ def _format(self, record):
return self._fmt.format(**record.__dict__)
- def validate(self):
- """Validate the input format, ensure it is the correct string formatting style"""
- fields = set()
- try:
- for _, fieldname, spec, conversion in _str_formatter.parse(self._fmt):
- if fieldname:
- if not self.field_spec.match(fieldname):
- raise ValueError('invalid field name/expression: %r' % fieldname)
- fields.add(fieldname)
- if conversion and conversion not in 'rsa':
- raise ValueError('invalid conversion: %r' % conversion)
- if spec and not self.fmt_spec.match(spec):
- raise ValueError('bad specifier: %r' % spec)
- except ValueError as e:
- raise ValueError('invalid format: %s' % e)
- if not fields:
- raise ValueError('invalid format: no fields')
-
+ def validate(self):
+ """Validate the input format, ensure it is the correct string formatting style"""
+ fields = set()
+ try:
+ for _, fieldname, spec, conversion in _str_formatter.parse(self._fmt):
+ if fieldname:
+ if not self.field_spec.match(fieldname):
+ raise ValueError('invalid field name/expression: %r' % fieldname)
+ fields.add(fieldname)
+ if conversion and conversion not in 'rsa':
+ raise ValueError('invalid conversion: %r' % conversion)
+ if spec and not self.fmt_spec.match(spec):
+ raise ValueError('bad specifier: %r' % spec)
+ except ValueError as e:
+ raise ValueError('invalid format: %s' % e)
+ if not fields:
+ raise ValueError('invalid format: no fields')
+
class StringTemplateStyle(PercentStyle):
default_format = '${message}'
asctime_format = '${asctime}'
@@ -479,24 +479,24 @@ class StringTemplateStyle(PercentStyle):
fmt = self._fmt
return fmt.find('$asctime') >= 0 or fmt.find(self.asctime_format) >= 0
- def validate(self):
- pattern = Template.pattern
- fields = set()
- for m in pattern.finditer(self._fmt):
- d = m.groupdict()
- if d['named']:
- fields.add(d['named'])
- elif d['braced']:
- fields.add(d['braced'])
- elif m.group(0) == '$':
- raise ValueError('invalid format: bare \'$\' not allowed')
- if not fields:
- raise ValueError('invalid format: no fields')
-
- def _format(self, record):
+ def validate(self):
+ pattern = Template.pattern
+ fields = set()
+ for m in pattern.finditer(self._fmt):
+ d = m.groupdict()
+ if d['named']:
+ fields.add(d['named'])
+ elif d['braced']:
+ fields.add(d['braced'])
+ elif m.group(0) == '$':
+ raise ValueError('invalid format: bare \'$\' not allowed')
+ if not fields:
+ raise ValueError('invalid format: no fields')
+
+ def _format(self, record):
return self._tpl.substitute(**record.__dict__)
-
+
BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
_STYLES = {
@@ -513,7 +513,7 @@ class Formatter(object):
responsible for converting a LogRecord to (usually) a string which can
be interpreted by either a human or an external system. The base Formatter
allows a formatting string to be specified. If none is supplied, the
- style-dependent default value, "%(message)s", "{message}", or
+ style-dependent default value, "%(message)s", "{message}", or
"${message}", is used.
The Formatter can be initialized with a format string which makes use of
@@ -550,7 +550,7 @@ class Formatter(object):
converter = time.localtime
- def __init__(self, fmt=None, datefmt=None, style='%', validate=True):
+ def __init__(self, fmt=None, datefmt=None, style='%', validate=True):
"""
Initialize the formatter with specified format strings.
@@ -570,9 +570,9 @@ class Formatter(object):
raise ValueError('Style must be one of: %s' % ','.join(
_STYLES.keys()))
self._style = _STYLES[style][0](fmt)
- if validate:
- self._style.validate()
-
+ if validate:
+ self._style.validate()
+
self._fmt = self._style._fmt
self.datefmt = datefmt
@@ -601,9 +601,9 @@ class Formatter(object):
if datefmt:
s = time.strftime(datefmt, ct)
else:
- s = time.strftime(self.default_time_format, ct)
- if self.default_msec_format:
- s = self.default_msec_format % (s, record.msecs)
+ s = time.strftime(self.default_time_format, ct)
+ if self.default_msec_format:
+ s = self.default_msec_format % (s, record.msecs)
return s
def formatException(self, ei):
@@ -752,8 +752,8 @@ class Filter(object):
"""
Determine if the specified record is to be logged.
- Returns True if the record should be logged, or False otherwise.
- If deemed appropriate, the record may be modified in-place.
+ Returns True if the record should be logged, or False otherwise.
+ If deemed appropriate, the record may be modified in-place.
"""
if self.nlen == 0:
return True
@@ -888,11 +888,11 @@ class Handler(Filterer):
Acquire a thread lock for serializing access to the underlying I/O.
"""
self.lock = threading.RLock()
- _register_at_fork_reinit_lock(self)
-
- def _at_fork_reinit(self):
- self.lock._at_fork_reinit()
+ _register_at_fork_reinit_lock(self)
+ def _at_fork_reinit(self):
+ self.lock._at_fork_reinit()
+
def acquire(self):
"""
Acquire the I/O thread lock.
@@ -1021,8 +1021,8 @@ class Handler(Filterer):
sys.stderr.write('Message: %r\n'
'Arguments: %s\n' % (record.msg,
record.args))
- except RecursionError: # See issue 36272
- raise
+ except RecursionError: # See issue 36272
+ raise
except Exception:
sys.stderr.write('Unable to print the message and arguments'
' - possible formatting error.\nUse the'
@@ -1085,8 +1085,8 @@ class StreamHandler(Handler):
# issue 35046: merged two stream.writes into one.
stream.write(msg + self.terminator)
self.flush()
- except RecursionError: # See issue 36272
- raise
+ except RecursionError: # See issue 36272
+ raise
except Exception:
self.handleError(record)
@@ -1113,8 +1113,8 @@ class StreamHandler(Handler):
def __repr__(self):
level = getLevelName(self.level)
name = getattr(self.stream, 'name', '')
- # bpo-36015: name can be an int
- name = str(name)
+ # bpo-36015: name can be an int
+ name = str(name)
if name:
name += ' '
return '<%s %s(%s)>' % (self.__class__.__name__, name, level)
@@ -1124,7 +1124,7 @@ class FileHandler(StreamHandler):
"""
A handler class which writes formatted logging records to disk files.
"""
- def __init__(self, filename, mode='a', encoding=None, delay=False, errors=None):
+ def __init__(self, filename, mode='a', encoding=None, delay=False, errors=None):
"""
Open the specified file and use it as the stream for logging.
"""
@@ -1135,7 +1135,7 @@ class FileHandler(StreamHandler):
self.baseFilename = os.path.abspath(filename)
self.mode = mode
self.encoding = encoding
- self.errors = errors
+ self.errors = errors
self.delay = delay
if delay:
#We don't open the stream, but we still need to call the
@@ -1172,8 +1172,8 @@ class FileHandler(StreamHandler):
Open the current base file with the (original) mode and encoding.
Return the resulting stream.
"""
- return open(self.baseFilename, self.mode, encoding=self.encoding,
- errors=self.errors)
+ return open(self.baseFilename, self.mode, encoding=self.encoding,
+ errors=self.errors)
def emit(self, record):
"""
@@ -1273,14 +1273,14 @@ class Manager(object):
self.loggerClass = None
self.logRecordFactory = None
- @property
- def disable(self):
- return self._disable
-
- @disable.setter
- def disable(self, value):
- self._disable = _checkLevel(value)
-
+ @property
+ def disable(self):
+ return self._disable
+
+ @disable.setter
+ def disable(self, value):
+ self._disable = _checkLevel(value)
+
def getLogger(self, name):
"""
Get a logger with the specified name (channel name), creating it
@@ -1511,7 +1511,7 @@ class Logger(Filterer):
if self.isEnabledFor(level):
self._log(level, msg, args, **kwargs)
- def findCaller(self, stack_info=False, stacklevel=1):
+ def findCaller(self, stack_info=False, stacklevel=1):
"""
Find the stack frame of the caller so that we can note the source
file name, line number and function name.
@@ -1521,12 +1521,12 @@ class Logger(Filterer):
#IronPython isn't run with -X:Frames.
if f is not None:
f = f.f_back
- orig_f = f
- while f and stacklevel > 1:
- f = f.f_back
- stacklevel -= 1
- if not f:
- f = orig_f
+ orig_f = f
+ while f and stacklevel > 1:
+ f = f.f_back
+ stacklevel -= 1
+ if not f:
+ f = orig_f
rv = "(unknown file)", 0, "(unknown function)", None
while hasattr(f, "f_code"):
co = f.f_code
@@ -1562,8 +1562,8 @@ class Logger(Filterer):
rv.__dict__[key] = extra[key]
return rv
- def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False,
- stacklevel=1):
+ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False,
+ stacklevel=1):
"""
Low-level logging routine which creates a LogRecord and then calls
all the handlers of this logger to handle the record.
@@ -1574,7 +1574,7 @@ class Logger(Filterer):
#exception on some versions of IronPython. We trap it here so that
#IronPython can use logging.
try:
- fn, lno, func, sinfo = self.findCaller(stack_info, stacklevel)
+ fn, lno, func, sinfo = self.findCaller(stack_info, stacklevel)
except ValueError: # pragma: no cover
fn, lno, func = "(unknown file)", 0, "(unknown function)"
else: # pragma: no cover
@@ -1690,22 +1690,22 @@ class Logger(Filterer):
"""
Is this logger enabled for level 'level'?
"""
- if self.disabled:
- return False
-
+ if self.disabled:
+ return False
+
try:
return self._cache[level]
except KeyError:
_acquireLock()
- try:
- if self.manager.disable >= level:
- is_enabled = self._cache[level] = False
- else:
- is_enabled = self._cache[level] = (
- level >= self.getEffectiveLevel()
- )
- finally:
- _releaseLock()
+ try:
+ if self.manager.disable >= level:
+ is_enabled = self._cache[level] = False
+ else:
+ is_enabled = self._cache[level] = (
+ level >= self.getEffectiveLevel()
+ )
+ finally:
+ _releaseLock()
return is_enabled
def getChild(self, suffix):
@@ -1910,8 +1910,8 @@ def basicConfig(**kwargs):
Do basic configuration for the logging system.
This function does nothing if the root logger already has handlers
- configured, unless the keyword argument *force* is set to ``True``.
- It is a convenience method intended for use by simple scripts
+ configured, unless the keyword argument *force* is set to ``True``.
+ It is a convenience method intended for use by simple scripts
to do one-shot configuration of the logging package.
The default behaviour is to create a StreamHandler which writes to
@@ -1939,18 +1939,18 @@ def basicConfig(**kwargs):
handlers, which will be added to the root handler. Any handler
in the list which does not have a formatter assigned will be
assigned the formatter created in this function.
- force If this keyword is specified as true, any existing handlers
- attached to the root logger are removed and closed, before
- carrying out the configuration as specified by the other
- arguments.
- encoding If specified together with a filename, this encoding is passed to
- the created FileHandler, causing it to be used when the file is
- opened.
- errors If specified together with a filename, this value is passed to the
- created FileHandler, causing it to be used when the file is
- opened in text mode. If not specified, the default value is
- `backslashreplace`.
-
+ force If this keyword is specified as true, any existing handlers
+ attached to the root logger are removed and closed, before
+ carrying out the configuration as specified by the other
+ arguments.
+ encoding If specified together with a filename, this encoding is passed to
+ the created FileHandler, causing it to be used when the file is
+ opened.
+ errors If specified together with a filename, this value is passed to the
+ created FileHandler, causing it to be used when the file is
+ opened in text mode. If not specified, the default value is
+ `backslashreplace`.
+
Note that you could specify a stream created using open(filename, mode)
rather than passing the filename and mode in. However, it should be
remembered that StreamHandler does not close its stream (since it may be
@@ -1966,24 +1966,24 @@ def basicConfig(**kwargs):
``filename``/``filemode``, or ``filename``/``filemode`` specified
together with ``stream``, or ``handlers`` specified together with
``stream``.
-
- .. versionchanged:: 3.8
- Added the ``force`` parameter.
-
- .. versionchanged:: 3.9
- Added the ``encoding`` and ``errors`` parameters.
+
+ .. versionchanged:: 3.8
+ Added the ``force`` parameter.
+
+ .. versionchanged:: 3.9
+ Added the ``encoding`` and ``errors`` parameters.
"""
# Add thread safety in case someone mistakenly calls
# basicConfig() from multiple threads
_acquireLock()
try:
- force = kwargs.pop('force', False)
- encoding = kwargs.pop('encoding', None)
- errors = kwargs.pop('errors', 'backslashreplace')
- if force:
- for h in root.handlers[:]:
- root.removeHandler(h)
- h.close()
+ force = kwargs.pop('force', False)
+ encoding = kwargs.pop('encoding', None)
+ errors = kwargs.pop('errors', 'backslashreplace')
+ if force:
+ for h in root.handlers[:]:
+ root.removeHandler(h)
+ h.close()
if len(root.handlers) == 0:
handlers = kwargs.pop("handlers", None)
if handlers is None:
@@ -1998,10 +1998,10 @@ def basicConfig(**kwargs):
filename = kwargs.pop("filename", None)
mode = kwargs.pop("filemode", 'a')
if filename:
- if 'b'in mode:
- errors = None
- h = FileHandler(filename, mode,
- encoding=encoding, errors=errors)
+ if 'b'in mode:
+ errors = None
+ h = FileHandler(filename, mode,
+ encoding=encoding, errors=errors)
else:
stream = kwargs.pop("stream", None)
h = StreamHandler(stream)
@@ -2037,9 +2037,9 @@ def getLogger(name=None):
If no name is specified, return the root logger.
"""
- if not name or isinstance(name, str) and name == root.name:
+ if not name or isinstance(name, str) and name == root.name:
return root
- return Logger.manager.getLogger(name)
+ return Logger.manager.getLogger(name)
def critical(msg, *args, **kwargs):
"""
@@ -2178,9 +2178,9 @@ class NullHandler(Handler):
def createLock(self):
self.lock = None
- def _at_fork_reinit(self):
- pass
-
+ def _at_fork_reinit(self):
+ pass
+
# Warnings integration
_warnings_showwarning = None
diff --git a/contrib/tools/python3/src/Lib/logging/config.py b/contrib/tools/python3/src/Lib/logging/config.py
index fd3aded7608..6cdcc022ad9 100644
--- a/contrib/tools/python3/src/Lib/logging/config.py
+++ b/contrib/tools/python3/src/Lib/logging/config.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -19,7 +19,7 @@ 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-2019 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging' and log away!
"""
@@ -143,7 +143,7 @@ def _install_handlers(cp, formatters):
kwargs = section.get("kwargs", '{}')
kwargs = eval(kwargs, vars(logging))
h = klass(*args, **kwargs)
- h.name = hand
+ h.name = hand
if "level" in section:
level = section["level"]
h.setLevel(level)
@@ -174,10 +174,10 @@ def _handle_existing_loggers(existing, child_loggers, disable_existing):
for log in existing:
logger = root.manager.loggerDict[log]
if log in child_loggers:
- if not isinstance(logger, logging.PlaceHolder):
- logger.setLevel(logging.NOTSET)
- logger.handlers = []
- logger.propagate = True
+ if not isinstance(logger, logging.PlaceHolder):
+ logger.setLevel(logging.NOTSET)
+ logger.handlers = []
+ logger.propagate = True
else:
logger.disabled = disable_existing
@@ -448,7 +448,7 @@ class BaseConfigurator(object):
value = ConvertingList(value)
value.configurator = self
elif not isinstance(value, ConvertingTuple) and\
- isinstance(value, tuple) and not hasattr(value, '_fields'):
+ isinstance(value, tuple) and not hasattr(value, '_fields'):
value = ConvertingTuple(value)
value.configurator = self
elif isinstance(value, str): # str for py3k
@@ -668,19 +668,19 @@ class DictConfigurator(BaseConfigurator):
dfmt = config.get('datefmt', None)
style = config.get('style', '%')
cname = config.get('class', None)
-
+
if not cname:
c = logging.Formatter
else:
c = _resolve(cname)
-
- # A TypeError would be raised if "validate" key is passed in with a formatter callable
- # that does not accept "validate" as a parameter
- if 'validate' in config: # if user hasn't mentioned it, the default will be fine
- result = c(fmt, dfmt, style, config['validate'])
- else:
- result = c(fmt, dfmt, style)
-
+
+ # A TypeError would be raised if "validate" key is passed in with a formatter callable
+ # that does not accept "validate" as a parameter
+ if 'validate' in config: # if user hasn't mentioned it, the default will be fine
+ result = c(fmt, dfmt, style, config['validate'])
+ else:
+ result = c(fmt, dfmt, style)
+
return result
def configure_filter(self, config):
diff --git a/contrib/tools/python3/src/Lib/logging/handlers.py b/contrib/tools/python3/src/Lib/logging/handlers.py
index 572e370110a..af0b49ee705 100644
--- a/contrib/tools/python3/src/Lib/logging/handlers.py
+++ b/contrib/tools/python3/src/Lib/logging/handlers.py
@@ -1,4 +1,4 @@
-# Copyright 2001-2021 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2021 by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
@@ -18,7 +18,7 @@
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python.
-Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
"""
@@ -27,7 +27,7 @@ import logging, socket, os, pickle, struct, time, re
from stat import ST_DEV, ST_INO, ST_MTIME
import queue
import threading
-import copy
+import copy
#
# Some constants...
@@ -48,19 +48,19 @@ class BaseRotatingHandler(logging.FileHandler):
Not meant to be instantiated directly. Instead, use RotatingFileHandler
or TimedRotatingFileHandler.
"""
- namer = None
- rotator = None
-
- def __init__(self, filename, mode, encoding=None, delay=False, errors=None):
+ namer = None
+ rotator = None
+
+ def __init__(self, filename, mode, encoding=None, delay=False, errors=None):
"""
Use the specified filename for streamed logging
"""
- logging.FileHandler.__init__(self, filename, mode=mode,
- encoding=encoding, delay=delay,
- errors=errors)
+ logging.FileHandler.__init__(self, filename, mode=mode,
+ encoding=encoding, delay=delay,
+ errors=errors)
self.mode = mode
self.encoding = encoding
- self.errors = errors
+ self.errors = errors
def emit(self, record):
"""
@@ -121,8 +121,8 @@ class RotatingFileHandler(BaseRotatingHandler):
Handler for logging to a set of files, which switches from one file
to the next when the current file reaches a certain size.
"""
- def __init__(self, filename, mode='a', maxBytes=0, backupCount=0,
- encoding=None, delay=False, errors=None):
+ def __init__(self, filename, mode='a', maxBytes=0, backupCount=0,
+ encoding=None, delay=False, errors=None):
"""
Open the specified file and use it as the stream for logging.
@@ -150,8 +150,8 @@ class RotatingFileHandler(BaseRotatingHandler):
# on each run.
if maxBytes > 0:
mode = 'a'
- BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
- delay=delay, errors=errors)
+ BaseRotatingHandler.__init__(self, filename, mode, encoding=encoding,
+ delay=delay, errors=errors)
self.maxBytes = maxBytes
self.backupCount = backupCount
@@ -185,17 +185,17 @@ class RotatingFileHandler(BaseRotatingHandler):
Basically, see if the supplied record would cause the file to exceed
the size limit we have.
"""
- # See bpo-45401: Never rollover anything other than regular files
- if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
- return False
+ # See bpo-45401: Never rollover anything other than regular files
+ if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
+ return False
if self.stream is None: # delay was set...
self.stream = self._open()
if self.maxBytes > 0: # are we rolling over?
msg = "%s\n" % self.format(record)
self.stream.seek(0, 2) #due to non-posix-compliant Windows feature
if self.stream.tell() + len(msg) >= self.maxBytes:
- return True
- return False
+ return True
+ return False
class TimedRotatingFileHandler(BaseRotatingHandler):
"""
@@ -205,11 +205,11 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
If backupCount is > 0, when rollover is done, no more than backupCount
files are kept - the oldest ones are deleted.
"""
- def __init__(self, filename, when='h', interval=1, backupCount=0,
- encoding=None, delay=False, utc=False, atTime=None,
- errors=None):
- BaseRotatingHandler.__init__(self, filename, 'a', encoding=encoding,
- delay=delay, errors=errors)
+ def __init__(self, filename, when='h', interval=1, backupCount=0,
+ encoding=None, delay=False, utc=False, atTime=None,
+ errors=None):
+ BaseRotatingHandler.__init__(self, filename, 'a', encoding=encoding,
+ delay=delay, errors=errors)
self.when = when.upper()
self.backupCount = backupCount
self.utc = utc
@@ -345,13 +345,13 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
record is not used, as we are just comparing times, but it is needed so
the method signatures are the same
"""
- # See bpo-45401: Never rollover anything other than regular files
- if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
- return False
+ # See bpo-45401: Never rollover anything other than regular files
+ if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename):
+ return False
t = int(time.time())
if t >= self.rolloverAt:
- return True
- return False
+ return True
+ return False
def getFilesToDelete(self):
"""
@@ -362,32 +362,32 @@ class TimedRotatingFileHandler(BaseRotatingHandler):
dirName, baseName = os.path.split(self.baseFilename)
fileNames = os.listdir(dirName)
result = []
- # See bpo-44753: Don't use the extension when computing the prefix.
- n, e = os.path.splitext(baseName)
- prefix = n + '.'
+ # See bpo-44753: Don't use the extension when computing the prefix.
+ n, e = os.path.splitext(baseName)
+ prefix = n + '.'
plen = len(prefix)
for fileName in fileNames:
- if self.namer is None:
- # Our files will always start with baseName
- if not fileName.startswith(baseName):
- continue
- else:
- # Our files could be just about anything after custom naming, but
- # likely candidates are of the form
- # foo.log.DATETIME_SUFFIX or foo.DATETIME_SUFFIX.log
- if (not fileName.startswith(baseName) and fileName.endswith(e) and
- len(fileName) > (plen + 1) and not fileName[plen+1].isdigit()):
- continue
-
+ if self.namer is None:
+ # Our files will always start with baseName
+ if not fileName.startswith(baseName):
+ continue
+ else:
+ # Our files could be just about anything after custom naming, but
+ # likely candidates are of the form
+ # foo.log.DATETIME_SUFFIX or foo.DATETIME_SUFFIX.log
+ if (not fileName.startswith(baseName) and fileName.endswith(e) and
+ len(fileName) > (plen + 1) and not fileName[plen+1].isdigit()):
+ continue
+
if fileName[:plen] == prefix:
suffix = fileName[plen:]
- # See bpo-45628: The date/time suffix could be anywhere in the
- # filename
- parts = suffix.split('.')
- for part in parts:
- if self.extMatch.match(part):
- result.append(os.path.join(dirName, fileName))
- break
+ # See bpo-45628: The date/time suffix could be anywhere in the
+ # filename
+ parts = suffix.split('.')
+ for part in parts:
+ if self.extMatch.match(part):
+ result.append(os.path.join(dirName, fileName))
+ break
if len(result) < self.backupCount:
result = []
else:
@@ -465,11 +465,11 @@ class WatchedFileHandler(logging.FileHandler):
This handler is based on a suggestion and patch by Chad J.
Schroeder.
"""
- def __init__(self, filename, mode='a', encoding=None, delay=False,
- errors=None):
- logging.FileHandler.__init__(self, filename, mode=mode,
- encoding=encoding, delay=delay,
- errors=errors)
+ def __init__(self, filename, mode='a', encoding=None, delay=False,
+ errors=None):
+ logging.FileHandler.__init__(self, filename, mode=mode,
+ encoding=encoding, delay=delay,
+ errors=errors)
self.dev, self.ino = -1, -1
self._statstream()
@@ -767,10 +767,10 @@ class SysLogHandler(logging.Handler):
LOG_CRON = 9 # clock daemon
LOG_AUTHPRIV = 10 # security/authorization messages (private)
LOG_FTP = 11 # FTP daemon
- LOG_NTP = 12 # NTP subsystem
- LOG_SECURITY = 13 # Log audit
- LOG_CONSOLE = 14 # Log alert
- LOG_SOLCRON = 15 # Scheduling daemon (Solaris)
+ LOG_NTP = 12 # NTP subsystem
+ LOG_SECURITY = 13 # Log audit
+ LOG_CONSOLE = 14 # Log alert
+ LOG_SOLCRON = 15 # Scheduling daemon (Solaris)
# other codes through 15 reserved for system use
LOG_LOCAL0 = 16 # reserved for local use
@@ -798,30 +798,30 @@ class SysLogHandler(logging.Handler):
}
facility_names = {
- "auth": LOG_AUTH,
- "authpriv": LOG_AUTHPRIV,
- "console": LOG_CONSOLE,
- "cron": LOG_CRON,
- "daemon": LOG_DAEMON,
- "ftp": LOG_FTP,
- "kern": LOG_KERN,
- "lpr": LOG_LPR,
- "mail": LOG_MAIL,
- "news": LOG_NEWS,
- "ntp": LOG_NTP,
- "security": LOG_SECURITY,
- "solaris-cron": LOG_SOLCRON,
- "syslog": LOG_SYSLOG,
- "user": LOG_USER,
- "uucp": LOG_UUCP,
- "local0": LOG_LOCAL0,
- "local1": LOG_LOCAL1,
- "local2": LOG_LOCAL2,
- "local3": LOG_LOCAL3,
- "local4": LOG_LOCAL4,
- "local5": LOG_LOCAL5,
- "local6": LOG_LOCAL6,
- "local7": LOG_LOCAL7,
+ "auth": LOG_AUTH,
+ "authpriv": LOG_AUTHPRIV,
+ "console": LOG_CONSOLE,
+ "cron": LOG_CRON,
+ "daemon": LOG_DAEMON,
+ "ftp": LOG_FTP,
+ "kern": LOG_KERN,
+ "lpr": LOG_LPR,
+ "mail": LOG_MAIL,
+ "news": LOG_NEWS,
+ "ntp": LOG_NTP,
+ "security": LOG_SECURITY,
+ "solaris-cron": LOG_SOLCRON,
+ "syslog": LOG_SYSLOG,
+ "user": LOG_USER,
+ "uucp": LOG_UUCP,
+ "local0": LOG_LOCAL0,
+ "local1": LOG_LOCAL1,
+ "local2": LOG_LOCAL2,
+ "local3": LOG_LOCAL3,
+ "local4": LOG_LOCAL4,
+ "local5": LOG_LOCAL5,
+ "local6": LOG_LOCAL6,
+ "local7": LOG_LOCAL7,
}
#The map below appears to be trivially lowercasing the key. However,
@@ -1198,20 +1198,20 @@ class HTTPHandler(logging.Handler):
"""
return record.__dict__
- def getConnection(self, host, secure):
- """
- get a HTTP[S]Connection.
-
- Override when a custom connection is required, for example if
- there is a proxy.
- """
- import http.client
- if secure:
- connection = http.client.HTTPSConnection(host, context=self.context)
- else:
- connection = http.client.HTTPConnection(host)
- return connection
-
+ def getConnection(self, host, secure):
+ """
+ get a HTTP[S]Connection.
+
+ Override when a custom connection is required, for example if
+ there is a proxy.
+ """
+ import http.client
+ if secure:
+ connection = http.client.HTTPSConnection(host, context=self.context)
+ else:
+ connection = http.client.HTTPConnection(host)
+ return connection
+
def emit(self, record):
"""
Emit a record.
@@ -1219,9 +1219,9 @@ class HTTPHandler(logging.Handler):
Send the record to the Web server as a percent-encoded dictionary
"""
try:
- import urllib.parse
+ import urllib.parse
host = self.host
- h = self.getConnection(host, self.secure)
+ h = self.getConnection(host, self.secure)
url = self.url
data = urllib.parse.urlencode(self.mapLogRecord(record))
if self.method == "GET":
@@ -1297,7 +1297,7 @@ class BufferingHandler(logging.Handler):
"""
self.acquire()
try:
- self.buffer.clear()
+ self.buffer.clear()
finally:
self.release()
@@ -1349,11 +1349,11 @@ class MemoryHandler(BufferingHandler):
"""
Set the target handler for this handler.
"""
- self.acquire()
- try:
- self.target = target
- finally:
- self.release()
+ self.acquire()
+ try:
+ self.target = target
+ finally:
+ self.release()
def flush(self):
"""
@@ -1368,7 +1368,7 @@ class MemoryHandler(BufferingHandler):
if self.target:
for record in self.buffer:
self.target.handle(record)
- self.buffer.clear()
+ self.buffer.clear()
finally:
self.release()
@@ -1437,8 +1437,8 @@ class QueueHandler(logging.Handler):
# exc_info and exc_text attributes, as they are no longer
# needed and, if not None, will typically not be pickleable.
msg = self.format(record)
- # bpo-35726: make copy of record to avoid affecting other handlers in the chain.
- record = copy.copy(record)
+ # bpo-35726: make copy of record to avoid affecting other handlers in the chain.
+ record = copy.copy(record)
record.message = msg
record.msg = msg
record.args = None
@@ -1496,7 +1496,7 @@ class QueueListener(object):
t.daemon = True
t.start()
- def prepare(self, record):
+ def prepare(self, record):
"""
Prepare a record for handling.
@@ -1536,8 +1536,8 @@ class QueueListener(object):
try:
record = self.dequeue(True)
if record is self._sentinel:
- if has_task_done:
- q.task_done()
+ if has_task_done:
+ q.task_done()
break
self.handle(record)
if has_task_done: