Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../logging
File: config.py
# Copyright 2001-2019 by Vinay Sajip. All Rights Reserved.
[0] Fix | Delete
#
[1] Fix | Delete
# Permission to use, copy, modify, and distribute this software and its
[2] Fix | Delete
# documentation for any purpose and without fee is hereby granted,
[3] Fix | Delete
# provided that the above copyright notice appear in all copies and that
[4] Fix | Delete
# both that copyright notice and this permission notice appear in
[5] Fix | Delete
# supporting documentation, and that the name of Vinay Sajip
[6] Fix | Delete
# not be used in advertising or publicity pertaining to distribution
[7] Fix | Delete
# of the software without specific, written prior permission.
[8] Fix | Delete
# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
[9] Fix | Delete
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
[10] Fix | Delete
# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
[11] Fix | Delete
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
[12] Fix | Delete
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
[13] Fix | Delete
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
[14] Fix | Delete
[15] Fix | Delete
"""
[16] Fix | Delete
Configuration functions for the logging package for Python. The core package
[17] Fix | Delete
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
[18] Fix | Delete
by Apache's log4j system.
[19] Fix | Delete
[20] Fix | Delete
Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved.
[21] Fix | Delete
[22] Fix | Delete
To use, simply 'import logging' and log away!
[23] Fix | Delete
"""
[24] Fix | Delete
[25] Fix | Delete
import errno
[26] Fix | Delete
import io
[27] Fix | Delete
import logging
[28] Fix | Delete
import logging.handlers
[29] Fix | Delete
import re
[30] Fix | Delete
import struct
[31] Fix | Delete
import sys
[32] Fix | Delete
import threading
[33] Fix | Delete
import traceback
[34] Fix | Delete
[35] Fix | Delete
from socketserver import ThreadingTCPServer, StreamRequestHandler
[36] Fix | Delete
[37] Fix | Delete
[38] Fix | Delete
DEFAULT_LOGGING_CONFIG_PORT = 9030
[39] Fix | Delete
[40] Fix | Delete
RESET_ERROR = errno.ECONNRESET
[41] Fix | Delete
[42] Fix | Delete
#
[43] Fix | Delete
# The following code implements a socket listener for on-the-fly
[44] Fix | Delete
# reconfiguration of logging.
[45] Fix | Delete
#
[46] Fix | Delete
# _listener holds the server object doing the listening
[47] Fix | Delete
_listener = None
[48] Fix | Delete
[49] Fix | Delete
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
[50] Fix | Delete
"""
[51] Fix | Delete
Read the logging configuration from a ConfigParser-format file.
[52] Fix | Delete
[53] Fix | Delete
This can be called several times from an application, allowing an end user
[54] Fix | Delete
the ability to select from various pre-canned configurations (if the
[55] Fix | Delete
developer provides a mechanism to present the choices and load the chosen
[56] Fix | Delete
configuration).
[57] Fix | Delete
"""
[58] Fix | Delete
import configparser
[59] Fix | Delete
[60] Fix | Delete
if isinstance(fname, configparser.RawConfigParser):
[61] Fix | Delete
cp = fname
[62] Fix | Delete
else:
[63] Fix | Delete
cp = configparser.ConfigParser(defaults)
[64] Fix | Delete
if hasattr(fname, 'readline'):
[65] Fix | Delete
cp.read_file(fname)
[66] Fix | Delete
else:
[67] Fix | Delete
cp.read(fname)
[68] Fix | Delete
[69] Fix | Delete
formatters = _create_formatters(cp)
[70] Fix | Delete
[71] Fix | Delete
# critical section
[72] Fix | Delete
logging._acquireLock()
[73] Fix | Delete
try:
[74] Fix | Delete
_clearExistingHandlers()
[75] Fix | Delete
[76] Fix | Delete
# Handlers add themselves to logging._handlers
[77] Fix | Delete
handlers = _install_handlers(cp, formatters)
[78] Fix | Delete
_install_loggers(cp, handlers, disable_existing_loggers)
[79] Fix | Delete
finally:
[80] Fix | Delete
logging._releaseLock()
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
def _resolve(name):
[84] Fix | Delete
"""Resolve a dotted name to a global object."""
[85] Fix | Delete
name = name.split('.')
[86] Fix | Delete
used = name.pop(0)
[87] Fix | Delete
found = __import__(used)
[88] Fix | Delete
for n in name:
[89] Fix | Delete
used = used + '.' + n
[90] Fix | Delete
try:
[91] Fix | Delete
found = getattr(found, n)
[92] Fix | Delete
except AttributeError:
[93] Fix | Delete
__import__(used)
[94] Fix | Delete
found = getattr(found, n)
[95] Fix | Delete
return found
[96] Fix | Delete
[97] Fix | Delete
def _strip_spaces(alist):
[98] Fix | Delete
return map(str.strip, alist)
[99] Fix | Delete
[100] Fix | Delete
def _create_formatters(cp):
[101] Fix | Delete
"""Create and return formatters"""
[102] Fix | Delete
flist = cp["formatters"]["keys"]
[103] Fix | Delete
if not len(flist):
[104] Fix | Delete
return {}
[105] Fix | Delete
flist = flist.split(",")
[106] Fix | Delete
flist = _strip_spaces(flist)
[107] Fix | Delete
formatters = {}
[108] Fix | Delete
for form in flist:
[109] Fix | Delete
sectname = "formatter_%s" % form
[110] Fix | Delete
fs = cp.get(sectname, "format", raw=True, fallback=None)
[111] Fix | Delete
dfs = cp.get(sectname, "datefmt", raw=True, fallback=None)
[112] Fix | Delete
stl = cp.get(sectname, "style", raw=True, fallback='%')
[113] Fix | Delete
c = logging.Formatter
[114] Fix | Delete
class_name = cp[sectname].get("class")
[115] Fix | Delete
if class_name:
[116] Fix | Delete
c = _resolve(class_name)
[117] Fix | Delete
f = c(fs, dfs, stl)
[118] Fix | Delete
formatters[form] = f
[119] Fix | Delete
return formatters
[120] Fix | Delete
[121] Fix | Delete
[122] Fix | Delete
def _install_handlers(cp, formatters):
[123] Fix | Delete
"""Install and return handlers"""
[124] Fix | Delete
hlist = cp["handlers"]["keys"]
[125] Fix | Delete
if not len(hlist):
[126] Fix | Delete
return {}
[127] Fix | Delete
hlist = hlist.split(",")
[128] Fix | Delete
hlist = _strip_spaces(hlist)
[129] Fix | Delete
handlers = {}
[130] Fix | Delete
fixups = [] #for inter-handler references
[131] Fix | Delete
for hand in hlist:
[132] Fix | Delete
section = cp["handler_%s" % hand]
[133] Fix | Delete
klass = section["class"]
[134] Fix | Delete
fmt = section.get("formatter", "")
[135] Fix | Delete
try:
[136] Fix | Delete
klass = eval(klass, vars(logging))
[137] Fix | Delete
except (AttributeError, NameError):
[138] Fix | Delete
klass = _resolve(klass)
[139] Fix | Delete
args = section.get("args", '()')
[140] Fix | Delete
args = eval(args, vars(logging))
[141] Fix | Delete
kwargs = section.get("kwargs", '{}')
[142] Fix | Delete
kwargs = eval(kwargs, vars(logging))
[143] Fix | Delete
h = klass(*args, **kwargs)
[144] Fix | Delete
if "level" in section:
[145] Fix | Delete
level = section["level"]
[146] Fix | Delete
h.setLevel(level)
[147] Fix | Delete
if len(fmt):
[148] Fix | Delete
h.setFormatter(formatters[fmt])
[149] Fix | Delete
if issubclass(klass, logging.handlers.MemoryHandler):
[150] Fix | Delete
target = section.get("target", "")
[151] Fix | Delete
if len(target): #the target handler may not be loaded yet, so keep for later...
[152] Fix | Delete
fixups.append((h, target))
[153] Fix | Delete
handlers[hand] = h
[154] Fix | Delete
#now all handlers are loaded, fixup inter-handler references...
[155] Fix | Delete
for h, t in fixups:
[156] Fix | Delete
h.setTarget(handlers[t])
[157] Fix | Delete
return handlers
[158] Fix | Delete
[159] Fix | Delete
def _handle_existing_loggers(existing, child_loggers, disable_existing):
[160] Fix | Delete
"""
[161] Fix | Delete
When (re)configuring logging, handle loggers which were in the previous
[162] Fix | Delete
configuration but are not in the new configuration. There's no point
[163] Fix | Delete
deleting them as other threads may continue to hold references to them;
[164] Fix | Delete
and by disabling them, you stop them doing any logging.
[165] Fix | Delete
[166] Fix | Delete
However, don't disable children of named loggers, as that's probably not
[167] Fix | Delete
what was intended by the user. Also, allow existing loggers to NOT be
[168] Fix | Delete
disabled if disable_existing is false.
[169] Fix | Delete
"""
[170] Fix | Delete
root = logging.root
[171] Fix | Delete
for log in existing:
[172] Fix | Delete
logger = root.manager.loggerDict[log]
[173] Fix | Delete
if log in child_loggers:
[174] Fix | Delete
if not isinstance(logger, logging.PlaceHolder):
[175] Fix | Delete
logger.setLevel(logging.NOTSET)
[176] Fix | Delete
logger.handlers = []
[177] Fix | Delete
logger.propagate = True
[178] Fix | Delete
else:
[179] Fix | Delete
logger.disabled = disable_existing
[180] Fix | Delete
[181] Fix | Delete
def _install_loggers(cp, handlers, disable_existing):
[182] Fix | Delete
"""Create and install loggers"""
[183] Fix | Delete
[184] Fix | Delete
# configure the root first
[185] Fix | Delete
llist = cp["loggers"]["keys"]
[186] Fix | Delete
llist = llist.split(",")
[187] Fix | Delete
llist = list(_strip_spaces(llist))
[188] Fix | Delete
llist.remove("root")
[189] Fix | Delete
section = cp["logger_root"]
[190] Fix | Delete
root = logging.root
[191] Fix | Delete
log = root
[192] Fix | Delete
if "level" in section:
[193] Fix | Delete
level = section["level"]
[194] Fix | Delete
log.setLevel(level)
[195] Fix | Delete
for h in root.handlers[:]:
[196] Fix | Delete
root.removeHandler(h)
[197] Fix | Delete
hlist = section["handlers"]
[198] Fix | Delete
if len(hlist):
[199] Fix | Delete
hlist = hlist.split(",")
[200] Fix | Delete
hlist = _strip_spaces(hlist)
[201] Fix | Delete
for hand in hlist:
[202] Fix | Delete
log.addHandler(handlers[hand])
[203] Fix | Delete
[204] Fix | Delete
#and now the others...
[205] Fix | Delete
#we don't want to lose the existing loggers,
[206] Fix | Delete
#since other threads may have pointers to them.
[207] Fix | Delete
#existing is set to contain all existing loggers,
[208] Fix | Delete
#and as we go through the new configuration we
[209] Fix | Delete
#remove any which are configured. At the end,
[210] Fix | Delete
#what's left in existing is the set of loggers
[211] Fix | Delete
#which were in the previous configuration but
[212] Fix | Delete
#which are not in the new configuration.
[213] Fix | Delete
existing = list(root.manager.loggerDict.keys())
[214] Fix | Delete
#The list needs to be sorted so that we can
[215] Fix | Delete
#avoid disabling child loggers of explicitly
[216] Fix | Delete
#named loggers. With a sorted list it is easier
[217] Fix | Delete
#to find the child loggers.
[218] Fix | Delete
existing.sort()
[219] Fix | Delete
#We'll keep the list of existing loggers
[220] Fix | Delete
#which are children of named loggers here...
[221] Fix | Delete
child_loggers = []
[222] Fix | Delete
#now set up the new ones...
[223] Fix | Delete
for log in llist:
[224] Fix | Delete
section = cp["logger_%s" % log]
[225] Fix | Delete
qn = section["qualname"]
[226] Fix | Delete
propagate = section.getint("propagate", fallback=1)
[227] Fix | Delete
logger = logging.getLogger(qn)
[228] Fix | Delete
if qn in existing:
[229] Fix | Delete
i = existing.index(qn) + 1 # start with the entry after qn
[230] Fix | Delete
prefixed = qn + "."
[231] Fix | Delete
pflen = len(prefixed)
[232] Fix | Delete
num_existing = len(existing)
[233] Fix | Delete
while i < num_existing:
[234] Fix | Delete
if existing[i][:pflen] == prefixed:
[235] Fix | Delete
child_loggers.append(existing[i])
[236] Fix | Delete
i += 1
[237] Fix | Delete
existing.remove(qn)
[238] Fix | Delete
if "level" in section:
[239] Fix | Delete
level = section["level"]
[240] Fix | Delete
logger.setLevel(level)
[241] Fix | Delete
for h in logger.handlers[:]:
[242] Fix | Delete
logger.removeHandler(h)
[243] Fix | Delete
logger.propagate = propagate
[244] Fix | Delete
logger.disabled = 0
[245] Fix | Delete
hlist = section["handlers"]
[246] Fix | Delete
if len(hlist):
[247] Fix | Delete
hlist = hlist.split(",")
[248] Fix | Delete
hlist = _strip_spaces(hlist)
[249] Fix | Delete
for hand in hlist:
[250] Fix | Delete
logger.addHandler(handlers[hand])
[251] Fix | Delete
[252] Fix | Delete
#Disable any old loggers. There's no point deleting
[253] Fix | Delete
#them as other threads may continue to hold references
[254] Fix | Delete
#and by disabling them, you stop them doing any logging.
[255] Fix | Delete
#However, don't disable children of named loggers, as that's
[256] Fix | Delete
#probably not what was intended by the user.
[257] Fix | Delete
#for log in existing:
[258] Fix | Delete
# logger = root.manager.loggerDict[log]
[259] Fix | Delete
# if log in child_loggers:
[260] Fix | Delete
# logger.level = logging.NOTSET
[261] Fix | Delete
# logger.handlers = []
[262] Fix | Delete
# logger.propagate = 1
[263] Fix | Delete
# elif disable_existing_loggers:
[264] Fix | Delete
# logger.disabled = 1
[265] Fix | Delete
_handle_existing_loggers(existing, child_loggers, disable_existing)
[266] Fix | Delete
[267] Fix | Delete
[268] Fix | Delete
def _clearExistingHandlers():
[269] Fix | Delete
"""Clear and close existing handlers"""
[270] Fix | Delete
logging._handlers.clear()
[271] Fix | Delete
logging.shutdown(logging._handlerList[:])
[272] Fix | Delete
del logging._handlerList[:]
[273] Fix | Delete
[274] Fix | Delete
[275] Fix | Delete
IDENTIFIER = re.compile('^[a-z_][a-z0-9_]*$', re.I)
[276] Fix | Delete
[277] Fix | Delete
[278] Fix | Delete
def valid_ident(s):
[279] Fix | Delete
m = IDENTIFIER.match(s)
[280] Fix | Delete
if not m:
[281] Fix | Delete
raise ValueError('Not a valid Python identifier: %r' % s)
[282] Fix | Delete
return True
[283] Fix | Delete
[284] Fix | Delete
[285] Fix | Delete
class ConvertingMixin(object):
[286] Fix | Delete
"""For ConvertingXXX's, this mixin class provides common functions"""
[287] Fix | Delete
[288] Fix | Delete
def convert_with_key(self, key, value, replace=True):
[289] Fix | Delete
result = self.configurator.convert(value)
[290] Fix | Delete
#If the converted value is different, save for next time
[291] Fix | Delete
if value is not result:
[292] Fix | Delete
if replace:
[293] Fix | Delete
self[key] = result
[294] Fix | Delete
if type(result) in (ConvertingDict, ConvertingList,
[295] Fix | Delete
ConvertingTuple):
[296] Fix | Delete
result.parent = self
[297] Fix | Delete
result.key = key
[298] Fix | Delete
return result
[299] Fix | Delete
[300] Fix | Delete
def convert(self, value):
[301] Fix | Delete
result = self.configurator.convert(value)
[302] Fix | Delete
if value is not result:
[303] Fix | Delete
if type(result) in (ConvertingDict, ConvertingList,
[304] Fix | Delete
ConvertingTuple):
[305] Fix | Delete
result.parent = self
[306] Fix | Delete
return result
[307] Fix | Delete
[308] Fix | Delete
[309] Fix | Delete
# The ConvertingXXX classes are wrappers around standard Python containers,
[310] Fix | Delete
# and they serve to convert any suitable values in the container. The
[311] Fix | Delete
# conversion converts base dicts, lists and tuples to their wrapped
[312] Fix | Delete
# equivalents, whereas strings which match a conversion format are converted
[313] Fix | Delete
# appropriately.
[314] Fix | Delete
#
[315] Fix | Delete
# Each wrapper should have a configurator attribute holding the actual
[316] Fix | Delete
# configurator to use for conversion.
[317] Fix | Delete
[318] Fix | Delete
class ConvertingDict(dict, ConvertingMixin):
[319] Fix | Delete
"""A converting dictionary wrapper."""
[320] Fix | Delete
[321] Fix | Delete
def __getitem__(self, key):
[322] Fix | Delete
value = dict.__getitem__(self, key)
[323] Fix | Delete
return self.convert_with_key(key, value)
[324] Fix | Delete
[325] Fix | Delete
def get(self, key, default=None):
[326] Fix | Delete
value = dict.get(self, key, default)
[327] Fix | Delete
return self.convert_with_key(key, value)
[328] Fix | Delete
[329] Fix | Delete
def pop(self, key, default=None):
[330] Fix | Delete
value = dict.pop(self, key, default)
[331] Fix | Delete
return self.convert_with_key(key, value, replace=False)
[332] Fix | Delete
[333] Fix | Delete
class ConvertingList(list, ConvertingMixin):
[334] Fix | Delete
"""A converting list wrapper."""
[335] Fix | Delete
def __getitem__(self, key):
[336] Fix | Delete
value = list.__getitem__(self, key)
[337] Fix | Delete
return self.convert_with_key(key, value)
[338] Fix | Delete
[339] Fix | Delete
def pop(self, idx=-1):
[340] Fix | Delete
value = list.pop(self, idx)
[341] Fix | Delete
return self.convert(value)
[342] Fix | Delete
[343] Fix | Delete
class ConvertingTuple(tuple, ConvertingMixin):
[344] Fix | Delete
"""A converting tuple wrapper."""
[345] Fix | Delete
def __getitem__(self, key):
[346] Fix | Delete
value = tuple.__getitem__(self, key)
[347] Fix | Delete
# Can't replace a tuple entry.
[348] Fix | Delete
return self.convert_with_key(key, value, replace=False)
[349] Fix | Delete
[350] Fix | Delete
class BaseConfigurator(object):
[351] Fix | Delete
"""
[352] Fix | Delete
The configurator base class which defines some useful defaults.
[353] Fix | Delete
"""
[354] Fix | Delete
[355] Fix | Delete
CONVERT_PATTERN = re.compile(r'^(?P<prefix>[a-z]+)://(?P<suffix>.*)$')
[356] Fix | Delete
[357] Fix | Delete
WORD_PATTERN = re.compile(r'^\s*(\w+)\s*')
[358] Fix | Delete
DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*')
[359] Fix | Delete
INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*')
[360] Fix | Delete
DIGIT_PATTERN = re.compile(r'^\d+$')
[361] Fix | Delete
[362] Fix | Delete
value_converters = {
[363] Fix | Delete
'ext' : 'ext_convert',
[364] Fix | Delete
'cfg' : 'cfg_convert',
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
# We might want to use a different one, e.g. importlib
[368] Fix | Delete
importer = staticmethod(__import__)
[369] Fix | Delete
[370] Fix | Delete
def __init__(self, config):
[371] Fix | Delete
self.config = ConvertingDict(config)
[372] Fix | Delete
self.config.configurator = self
[373] Fix | Delete
[374] Fix | Delete
def resolve(self, s):
[375] Fix | Delete
"""
[376] Fix | Delete
Resolve strings to objects using standard import and attribute
[377] Fix | Delete
syntax.
[378] Fix | Delete
"""
[379] Fix | Delete
name = s.split('.')
[380] Fix | Delete
used = name.pop(0)
[381] Fix | Delete
try:
[382] Fix | Delete
found = self.importer(used)
[383] Fix | Delete
for frag in name:
[384] Fix | Delete
used += '.' + frag
[385] Fix | Delete
try:
[386] Fix | Delete
found = getattr(found, frag)
[387] Fix | Delete
except AttributeError:
[388] Fix | Delete
self.importer(used)
[389] Fix | Delete
found = getattr(found, frag)
[390] Fix | Delete
return found
[391] Fix | Delete
except ImportError:
[392] Fix | Delete
e, tb = sys.exc_info()[1:]
[393] Fix | Delete
v = ValueError('Cannot resolve %r: %s' % (s, e))
[394] Fix | Delete
v.__cause__, v.__traceback__ = e, tb
[395] Fix | Delete
raise v
[396] Fix | Delete
[397] Fix | Delete
def ext_convert(self, value):
[398] Fix | Delete
"""Default converter for the ext:// protocol."""
[399] Fix | Delete
return self.resolve(value)
[400] Fix | Delete
[401] Fix | Delete
def cfg_convert(self, value):
[402] Fix | Delete
"""Default converter for the cfg:// protocol."""
[403] Fix | Delete
rest = value
[404] Fix | Delete
m = self.WORD_PATTERN.match(rest)
[405] Fix | Delete
if m is None:
[406] Fix | Delete
raise ValueError("Unable to convert %r" % value)
[407] Fix | Delete
else:
[408] Fix | Delete
rest = rest[m.end():]
[409] Fix | Delete
d = self.config[m.groups()[0]]
[410] Fix | Delete
#print d, rest
[411] Fix | Delete
while rest:
[412] Fix | Delete
m = self.DOT_PATTERN.match(rest)
[413] Fix | Delete
if m:
[414] Fix | Delete
d = d[m.groups()[0]]
[415] Fix | Delete
else:
[416] Fix | Delete
m = self.INDEX_PATTERN.match(rest)
[417] Fix | Delete
if m:
[418] Fix | Delete
idx = m.groups()[0]
[419] Fix | Delete
if not self.DIGIT_PATTERN.match(idx):
[420] Fix | Delete
d = d[idx]
[421] Fix | Delete
else:
[422] Fix | Delete
try:
[423] Fix | Delete
n = int(idx) # try as number first (most likely)
[424] Fix | Delete
d = d[n]
[425] Fix | Delete
except TypeError:
[426] Fix | Delete
d = d[idx]
[427] Fix | Delete
if m:
[428] Fix | Delete
rest = rest[m.end():]
[429] Fix | Delete
else:
[430] Fix | Delete
raise ValueError('Unable to convert '
[431] Fix | Delete
'%r at %r' % (value, rest))
[432] Fix | Delete
#rest should be empty
[433] Fix | Delete
return d
[434] Fix | Delete
[435] Fix | Delete
def convert(self, value):
[436] Fix | Delete
"""
[437] Fix | Delete
Convert values to an appropriate type. dicts, lists and tuples are
[438] Fix | Delete
replaced by their converting alternatives. Strings are checked to
[439] Fix | Delete
see if they have a conversion format and are converted if they do.
[440] Fix | Delete
"""
[441] Fix | Delete
if not isinstance(value, ConvertingDict) and isinstance(value, dict):
[442] Fix | Delete
value = ConvertingDict(value)
[443] Fix | Delete
value.configurator = self
[444] Fix | Delete
elif not isinstance(value, ConvertingList) and isinstance(value, list):
[445] Fix | Delete
value = ConvertingList(value)
[446] Fix | Delete
value.configurator = self
[447] Fix | Delete
elif not isinstance(value, ConvertingTuple) and\
[448] Fix | Delete
isinstance(value, tuple) and not hasattr(value, '_fields'):
[449] Fix | Delete
value = ConvertingTuple(value)
[450] Fix | Delete
value.configurator = self
[451] Fix | Delete
elif isinstance(value, str): # str for py3k
[452] Fix | Delete
m = self.CONVERT_PATTERN.match(value)
[453] Fix | Delete
if m:
[454] Fix | Delete
d = m.groupdict()
[455] Fix | Delete
prefix = d['prefix']
[456] Fix | Delete
converter = self.value_converters.get(prefix, None)
[457] Fix | Delete
if converter:
[458] Fix | Delete
suffix = d['suffix']
[459] Fix | Delete
converter = getattr(self, converter)
[460] Fix | Delete
value = converter(suffix)
[461] Fix | Delete
return value
[462] Fix | Delete
[463] Fix | Delete
def configure_custom(self, config):
[464] Fix | Delete
"""Configure an object with a user-supplied factory."""
[465] Fix | Delete
c = config.pop('()')
[466] Fix | Delete
if not callable(c):
[467] Fix | Delete
c = self.resolve(c)
[468] Fix | Delete
props = config.pop('.', None)
[469] Fix | Delete
# Check for valid identifiers
[470] Fix | Delete
kwargs = {k: config[k] for k in config if valid_ident(k)}
[471] Fix | Delete
result = c(**kwargs)
[472] Fix | Delete
if props:
[473] Fix | Delete
for name, value in props.items():
[474] Fix | Delete
setattr(result, name, value)
[475] Fix | Delete
return result
[476] Fix | Delete
[477] Fix | Delete
def as_tuple(self, value):
[478] Fix | Delete
"""Utility function which converts lists to tuples."""
[479] Fix | Delete
if isinstance(value, list):
[480] Fix | Delete
value = tuple(value)
[481] Fix | Delete
return value
[482] Fix | Delete
[483] Fix | Delete
class DictConfigurator(BaseConfigurator):
[484] Fix | Delete
"""
[485] Fix | Delete
Configure logging using a dictionary-like object to describe the
[486] Fix | Delete
configuration.
[487] Fix | Delete
"""
[488] Fix | Delete
[489] Fix | Delete
def configure(self):
[490] Fix | Delete
"""Do the configuration."""
[491] Fix | Delete
[492] Fix | Delete
config = self.config
[493] Fix | Delete
if 'version' not in config:
[494] Fix | Delete
raise ValueError("dictionary doesn't specify a version")
[495] Fix | Delete
if config['version'] != 1:
[496] Fix | Delete
raise ValueError("Unsupported version: %s" % config['version'])
[497] Fix | Delete
incremental = config.pop('incremental', False)
[498] Fix | Delete
EMPTY_DICT = {}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function