Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
logging.config.BaseConfigurator Class Reference
Inheritance diagram for logging.config.BaseConfigurator:
Inheritance graph
[legend]
Collaboration diagram for logging.config.BaseConfigurator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def resolve
def ext_convert
def cfg_convert
def convert
def configure_custom
def as_tuple

Public Attributes

 config
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

tuple CONVERT_PATTERN = re.compile(r'^(?P<prefix>[a-z]+)://(?P<suffix>.*)$')
tuple WORD_PATTERN = re.compile(r'^\s*(\w+)\s*')
tuple DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*')
tuple INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*')
tuple DIGIT_PATTERN = re.compile(r'^\d+$')
dictionary value_converters
tuple importer = staticmethod(__import__)

Detailed Description

The configurator base class which defines some useful defaults.

Definition at line 358 of file config.py.


Constructor & Destructor Documentation

def logging.config.BaseConfigurator.__init__ (   self,
  config 
)

Definition at line 378 of file config.py.

00378 
00379     def __init__(self, config):
00380         self.config = ConvertingDict(config)
00381         self.config.configurator = self

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def logging.config.BaseConfigurator.as_tuple (   self,
  value 
)
Utility function which converts lists to tuples.

Definition at line 485 of file config.py.

00485 
00486     def as_tuple(self, value):
00487         """Utility function which converts lists to tuples."""
00488         if isinstance(value, list):
00489             value = tuple(value)
00490         return value

Here is the caller graph for this function:

def logging.config.BaseConfigurator.cfg_convert (   self,
  value 
)
Default converter for the cfg:// protocol.

Definition at line 409 of file config.py.

00409 
00410     def cfg_convert(self, value):
00411         """Default converter for the cfg:// protocol."""
00412         rest = value
00413         m = self.WORD_PATTERN.match(rest)
00414         if m is None:
00415             raise ValueError("Unable to convert %r" % value)
00416         else:
00417             rest = rest[m.end():]
00418             d = self.config[m.groups()[0]]
00419             #print d, rest
00420             while rest:
00421                 m = self.DOT_PATTERN.match(rest)
00422                 if m:
00423                     d = d[m.groups()[0]]
00424                 else:
00425                     m = self.INDEX_PATTERN.match(rest)
00426                     if m:
00427                         idx = m.groups()[0]
00428                         if not self.DIGIT_PATTERN.match(idx):
00429                             d = d[idx]
00430                         else:
00431                             try:
00432                                 n = int(idx) # try as number first (most likely)
00433                                 d = d[n]
00434                             except TypeError:
00435                                 d = d[idx]
00436                 if m:
00437                     rest = rest[m.end():]
00438                 else:
00439                     raise ValueError('Unable to convert '
00440                                      '%r at %r' % (value, rest))
00441         #rest should be empty
00442         return d

def logging.config.BaseConfigurator.configure_custom (   self,
  config 
)
Configure an object with a user-supplied factory.

Definition at line 471 of file config.py.

00471 
00472     def configure_custom(self, config):
00473         """Configure an object with a user-supplied factory."""
00474         c = config.pop('()')
00475         if not hasattr(c, '__call__'):
00476             c = self.resolve(c)
00477         props = config.pop('.', None)
00478         # Check for valid identifiers
00479         kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
00480         result = c(**kwargs)
00481         if props:
00482             for name, value in props.items():
00483                 setattr(result, name, value)
00484         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def logging.config.BaseConfigurator.convert (   self,
  value 
)
Convert values to an appropriate type. dicts, lists and tuples are
replaced by their converting alternatives. Strings are checked to
see if they have a conversion format and are converted if they do.

Definition at line 443 of file config.py.

00443 
00444     def convert(self, value):
00445         """
00446         Convert values to an appropriate type. dicts, lists and tuples are
00447         replaced by their converting alternatives. Strings are checked to
00448         see if they have a conversion format and are converted if they do.
00449         """
00450         if not isinstance(value, ConvertingDict) and isinstance(value, dict):
00451             value = ConvertingDict(value)
00452             value.configurator = self
00453         elif not isinstance(value, ConvertingList) and isinstance(value, list):
00454             value = ConvertingList(value)
00455             value.configurator = self
00456         elif not isinstance(value, ConvertingTuple) and\
00457                  isinstance(value, tuple):
00458             value = ConvertingTuple(value)
00459             value.configurator = self
00460         elif isinstance(value, str): # str for py3k
00461             m = self.CONVERT_PATTERN.match(value)
00462             if m:
00463                 d = m.groupdict()
00464                 prefix = d['prefix']
00465                 converter = self.value_converters.get(prefix, None)
00466                 if converter:
00467                     suffix = d['suffix']
00468                     converter = getattr(self, converter)
00469                     value = converter(suffix)
00470         return value

Here is the call graph for this function:

def logging.config.BaseConfigurator.ext_convert (   self,
  value 
)
Default converter for the ext:// protocol.

Definition at line 405 of file config.py.

00405 
00406     def ext_convert(self, value):
00407         """Default converter for the ext:// protocol."""
00408         return self.resolve(value)

Here is the call graph for this function:

def logging.config.BaseConfigurator.resolve (   self,
  s 
)
Resolve strings to objects using standard import and attribute
syntax.

Definition at line 382 of file config.py.

00382 
00383     def resolve(self, s):
00384         """
00385         Resolve strings to objects using standard import and attribute
00386         syntax.
00387         """
00388         name = s.split('.')
00389         used = name.pop(0)
00390         try:
00391             found = self.importer(used)
00392             for frag in name:
00393                 used += '.' + frag
00394                 try:
00395                     found = getattr(found, frag)
00396                 except AttributeError:
00397                     self.importer(used)
00398                     found = getattr(found, frag)
00399             return found
00400         except ImportError:
00401             e, tb = sys.exc_info()[1:]
00402             v = ValueError('Cannot resolve %r: %s' % (s, e))
00403             v.__cause__, v.__traceback__ = e, tb
00404             raise v

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 379 of file config.py.

tuple logging.config.BaseConfigurator.CONVERT_PATTERN = re.compile(r'^(?P<prefix>[a-z]+)://(?P<suffix>.*)$') [static]

Definition at line 363 of file config.py.

tuple logging.config.BaseConfigurator.DIGIT_PATTERN = re.compile(r'^\d+$') [static]

Definition at line 368 of file config.py.

tuple logging.config.BaseConfigurator.DOT_PATTERN = re.compile(r'^\.\s*(\w+)\s*') [static]

Definition at line 366 of file config.py.

tuple logging.config.BaseConfigurator.importer = staticmethod(__import__) [static]

Definition at line 376 of file config.py.

tuple logging.config.BaseConfigurator.INDEX_PATTERN = re.compile(r'^\[\s*(\w+)\s*\]\s*') [static]

Definition at line 367 of file config.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

dictionary logging.config.BaseConfigurator.value_converters [static]
Initial value:
{
        'ext' : 'ext_convert',
        'cfg' : 'cfg_convert',
    }

Definition at line 370 of file config.py.

tuple logging.config.BaseConfigurator.WORD_PATTERN = re.compile(r'^\s*(\w+)\s*') [static]

Definition at line 365 of file config.py.


The documentation for this class was generated from the following file: