Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Public Member Functions
MultiOrderedConfigParser Class Reference
Inheritance diagram for MultiOrderedConfigParser:
Inheritance graph
[legend]

Public Member Functions

def __init__ (self, parent=None)
 
def add_default (self, key, template_keys=None)
 
def add_include (self, filename, parser=None)
 
def add_section (self, key, template_keys=None, mdicts=None)
 
def default (self, key)
 
def defaults (self)
 
def find_value (self, sections, key)
 
def get (self, section, key)
 
def get_defaults (self, key)
 
def get_sections (self, key, attr='_sections', searched=None)
 
def includes (self)
 
def multi_get (self, section, key_list)
 
def read (self, filename, sect=None)
 
def section (self, key)
 
def sections (self)
 
def set (self, section, key, val)
 
def write (self, config_file)
 

Detailed Description

Definition at line 323 of file astconfigparser.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  parent = None 
)

Reimplemented in SqlConfigParser.

Definition at line 324 of file astconfigparser.py.

324 def __init__(self, parent=None):
325 self._parent = parent
326 self._defaults = MultiOrderedDict()
327 self._sections = MultiOrderedDict()
328 self._includes = OrderedDict()
329

References Section._defaults, MultiOrderedConfigParser._defaults, MultiOrderedConfigParser._includes, MultiOrderedConfigParser._parent, and MultiOrderedConfigParser._sections.

Member Function Documentation

◆ add_default()

def add_default (   self,
  key,
  template_keys = None 
)
Adds a default section to defaults, returning the
default Section object.

Definition at line 359 of file astconfigparser.py.

359 def add_default(self, key, template_keys=None):
360 """
361 Adds a default section to defaults, returning the
362 default Section object.
363 """
364 if template_keys is None:
365 template_keys = []
366 return self.add_section(key, template_keys, self._defaults)
367

References Section._defaults, MultiOrderedConfigParser._defaults, and MultiOrderedConfigParser.add_section().

Referenced by MultiOrderedConfigParser.read().

◆ add_include()

def add_include (   self,
  filename,
  parser = None 
)
Add a new #include file to the configuration.

Definition at line 422 of file astconfigparser.py.

422 def add_include(self, filename, parser=None):
423 """
424 Add a new #include file to the configuration.
425 """
426 if filename in self._includes:
427 return self._includes[filename]
428
429 self._includes[filename] = res = \
430 MultiOrderedConfigParser(self) if parser is None else parser
431 return res
432

References MultiOrderedConfigParser._includes.

Referenced by MultiOrderedConfigParser.read().

◆ add_section()

def add_section (   self,
  key,
  template_keys = None,
  mdicts = None 
)
Create a new section in the configuration. The name of the
new section is the 'key' parameter.

Definition at line 403 of file astconfigparser.py.

403 def add_section(self, key, template_keys=None, mdicts=None):
404 """
405 Create a new section in the configuration. The name of the
406 new section is the 'key' parameter.
407 """
408 if template_keys is None:
409 template_keys = []
410 if mdicts is None:
411 mdicts = self._sections
412 res = Section()
413 for t in template_keys:
414 res.add_templates(self.get_defaults(t))
415 res.add_defaults(self.get_defaults(DEFAULTSECT))
416 mdicts.insert(0, key, res)
417 return res
418

References MultiOrderedConfigParser._sections, and MultiOrderedConfigParser.get_defaults().

Referenced by MultiOrderedConfigParser.add_default(), MultiOrderedConfigParser.read(), and SqlConfigParser.read().

◆ default()

def default (   self,
  key 
)
Retrieves a list of dictionaries for a default section.

Definition at line 355 of file astconfigparser.py.

355 def default(self, key):
356 """Retrieves a list of dictionaries for a default section."""
357 return self.get_defaults(key)
358

References MultiOrderedConfigParser.get_defaults().

Referenced by MultiOrderedConfigParser.get().

◆ defaults()

def defaults (   self)

Definition at line 352 of file astconfigparser.py.

352 def defaults(self):
353 return self._defaults
354

References Section._defaults, and MultiOrderedConfigParser._defaults.

Referenced by MultiOrderedConfigParser.set().

◆ find_value()

def find_value (   self,
  sections,
  key 
)
Given a list of sections, try to find value(s) for the given key.

Definition at line 330 of file astconfigparser.py.

330 def find_value(self, sections, key):
331 """Given a list of sections, try to find value(s) for the given key."""
332 # always start looking in the last one added
333 sections.sort(reverse=True)
334 for s in sections:
335 try:
336 # try to find in section and section's templates
337 return s.get(key, from_defaults=False)
338 except KeyError:
339 pass
340
341 # wasn't found in sections or a section's templates so check in
342 # defaults
343 for s in sections:
344 try:
345 # try to find in section's defaultsects
346 return s.get(key, from_self=False, from_templates=False)
347 except KeyError:
348 pass
349
350 raise KeyError(key)
351

Referenced by MultiOrderedConfigParser.get().

◆ get()

def get (   self,
  section,
  key 
)
Retrieves the list of values from a section for a key.

Definition at line 433 of file astconfigparser.py.

433 def get(self, section, key):
434 """Retrieves the list of values from a section for a key."""
435 try:
436 # search for the value in the list of sections
437 return self.find_value(self.section(section), key)
438 except KeyError:
439 pass
440
441 try:
442 # section may be a default section so, search
443 # for the value in the list of defaults
444 return self.find_value(self.default(section), key)
445 except KeyError:
446 raise LookupError("key %r not found for section %r"
447 % (key, section))
448

References MultiOrderedConfigParser.default(), MultiOrderedConfigParser.find_value(), and MultiOrderedConfigParser.section().

Referenced by Section.__getitem__(), and MultiOrderedConfigParser.multi_get().

◆ get_defaults()

def get_defaults (   self,
  key 
)
Retrieve a list of defaults that have values for the given key.

Definition at line 397 of file astconfigparser.py.

397 def get_defaults(self, key):
398 """
399 Retrieve a list of defaults that have values for the given key.
400 """
401 return self.get_sections(key, '_defaults')
402
static struct varshead * get_defaults(void)

References MultiOrderedConfigParser.get_sections().

Referenced by MultiOrderedConfigParser.add_section(), and MultiOrderedConfigParser.default().

◆ get_sections()

def get_sections (   self,
  key,
  attr = '_sections',
  searched = None 
)
Retrieve a list of sections that have values for the given key.
The attr parameter can be used to control what part of the parser
to retrieve values from.

Definition at line 375 of file astconfigparser.py.

375 def get_sections(self, key, attr='_sections', searched=None):
376 """
377 Retrieve a list of sections that have values for the given key.
378 The attr parameter can be used to control what part of the parser
379 to retrieve values from.
380 """
381 if searched is None:
382 searched = []
383 if self in searched:
384 return []
385
386 sections = getattr(self, attr)
387 res = sections[key] if key in sections else []
388 searched.append(self)
389 if self._includes:
390 res.extend(list(itertools.chain(*[
391 incl.get_sections(key, attr, searched)
392 for incl in self._includes.itervalues()])))
393 if self._parent:
394 res += self._parent.get_sections(key, attr, searched)
395 return res
396

References MultiOrderedConfigParser._includes, MultiOrderedConfigParser._parent, and MultiOrderedConfigParser.get_sections().

Referenced by MultiOrderedConfigParser.get_defaults(), MultiOrderedConfigParser.get_sections(), and MultiOrderedConfigParser.section().

◆ includes()

def includes (   self)

Definition at line 419 of file astconfigparser.py.

419 def includes(self):
420 return self._includes
421

References MultiOrderedConfigParser._includes.

◆ multi_get()

def multi_get (   self,
  section,
  key_list 
)
Retrieves the list of values from a section for a list of keys.
This method is intended to be used for equivalent keys. Thus, as soon
as any match is found for any key in the key_list, the match is
returned. This does not concatenate the lookups of all of the keys
together.

Definition at line 449 of file astconfigparser.py.

449 def multi_get(self, section, key_list):
450 """
451 Retrieves the list of values from a section for a list of keys.
452 This method is intended to be used for equivalent keys. Thus, as soon
453 as any match is found for any key in the key_list, the match is
454 returned. This does not concatenate the lookups of all of the keys
455 together.
456 """
457 for i in key_list:
458 try:
459 return self.get(section, i)
460 except LookupError:
461 pass
462
463 # Making it here means all lookups failed.
464 raise LookupError("keys %r not found for section %r" %
465 (key_list, section))
466

References Section.get(), MultiOrderedConfigParser.get(), ast_jb_impl.get, and ast_speech_engine.get.

◆ read()

def read (   self,
  filename,
  sect = None 
)
Parse configuration information from a file

Reimplemented in SqlConfigParser.

Definition at line 476 of file astconfigparser.py.

476 def read(self, filename, sect=None):
477 """Parse configuration information from a file"""
478 try:
479 with open(filename, 'rt') as config_file:
480 self._read(config_file, sect)
481 except IOError:
482 print("Could not open file " + filename + " for reading")
483

References MultiOrderedConfigParser._read(), MultiOrderedConfigParser.add_default(), MultiOrderedConfigParser.add_include(), MultiOrderedConfigParser.add_section(), astconfigparser.remove_comment(), astconfigparser.try_include(), astconfigparser.try_option(), and astconfigparser.try_section().

◆ section()

def section (   self,
  key 
)
Retrieves a list of dictionaries for a section.

Definition at line 371 of file astconfigparser.py.

371 def section(self, key):
372 """Retrieves a list of dictionaries for a section."""
373 return self.get_sections(key)
374

References MultiOrderedConfigParser.get_sections().

Referenced by MultiOrderedConfigParser.get(), and MultiOrderedConfigParser.set().

◆ sections()

def sections (   self)

Definition at line 368 of file astconfigparser.py.

368 def sections(self):
369 return self._sections
370

References MultiOrderedConfigParser._sections.

◆ set()

def set (   self,
  section,
  key,
  val 
)
Sets an option in the given section.

Definition at line 467 of file astconfigparser.py.

467 def set(self, section, key, val):
468 """Sets an option in the given section."""
469 # TODO - set in multiple sections? (for now set in first)
470 # TODO - set in both sections and defaults?
471 if section in self._sections:
472 self.section(section)[0][key] = val
473 else:
474 self.defaults(section)[0][key] = val
475
static int set(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:238

References MultiOrderedConfigParser._sections, MultiOrderedConfigParser.defaults(), and MultiOrderedConfigParser.section().

◆ write()

def write (   self,
  config_file 
)
Write configuration information out to a file

Reimplemented in SqlConfigParser.

Definition at line 513 of file astconfigparser.py.

513 def write(self, config_file):
514 """Write configuration information out to a file"""
515 try:
516 for key, val in self._includes.iteritems():
517 val.write(key)
518 config_file.write('#include "%s"\n' % key)
519
520 config_file.write('\n')
521 write_dicts(config_file, self._defaults)
522 write_dicts(config_file, self._sections)
523 except:
524 try:
525 with open(config_file, 'wt') as fp:
526 self.write(fp)
527 except IOError:
528 print("Could not open file " + config_file + " for writing")
def write_dicts(config_file, mdicts)

References Section._defaults, MultiOrderedConfigParser._defaults, MultiOrderedConfigParser._includes, MultiOrderedConfigParser._sections, MultiOrderedConfigParser.write(), SqlConfigParser.write(), Registration.write(), ast_bridge_technology.write, ast_channel_tech.write, ast_format_def.write, ast_custom_function.write, aeap_transport_vtable.write, ast_fax_tech.write, ast_rtp_engine.write, ast_speech_engine.write, and astconfigparser.write_dicts().

Referenced by MultiOrderedConfigParser.write().


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