astconfigparser Namespace Reference


Data Structures

class  MultiOrderedConfigParser
class  Section

Functions

def find_dict
def merge_values
def remove_comment
def try_include
def try_option
def try_section
def write_dicts

Variables

string COMMENT = ';'
string COMMENT_END = '--;'
string COMMENT_START = ';--'
string DEFAULTSECT = 'general'


Function Documentation

def astconfigparser::find_dict (   mdicts,
  key,
  val 
)

Given a list of mult-dicts, return the multi-dict that contains
the given key/value pair.

Definition at line 234 of file astconfigparser.py.

00234                                :
00235     """
00236     Given a list of mult-dicts, return the multi-dict that contains
00237     the given key/value pair.
00238     """
00239 
00240     def found(d):
00241         return key in d and val in d[key]
00242 
00243     try:
00244         return [d for d in mdicts if found(d)][0]
00245     except IndexError:
00246         raise LookupError("Dictionary not located for key = %s, value = %s"
00247                           % (key, val))
00248 
00249 
def write_dicts(config_file, mdicts):

def astconfigparser::merge_values (   left,
  right,
  key 
)

Merges values from right into left.

Definition at line 8 of file astconfigparser.py.

00008                                   :
00009     """Merges values from right into left."""
00010     if isinstance(left, list):
00011         vals0 = left
00012     else:  # assume dictionary
00013         vals0 = left[key] if key in left else []
00014     vals1 = right[key] if key in right else []
00015 
00016     return vals0 + [i for i in vals1 if i not in vals0]
00017 
###############################################################################

def astconfigparser::remove_comment (   line,
  is_comment 
)

Remove any commented elements from the line.

Definition at line 157 of file astconfigparser.py.

00157                                     :
00158     """Remove any commented elements from the line."""
00159     if not line:
00160         return line, is_comment
00161 
00162     if is_comment:
00163         part = line.partition(COMMENT_END)
00164         if part[1]:
00165             # found multi-line comment end check string after it
00166             return remove_comment(part[2], False)
00167         return "", True
00168 
00169     part = line.partition(COMMENT_START)
00170     if part[1]:
00171         # found multi-line comment start check string before
00172         # it to make sure there wasn't an eol comment in it
00173         has_comment = part[0].partition(COMMENT)
00174         if has_comment[1]:
00175             # eol comment found return anything before it
00176             return has_comment[0], False
00177 
00178         # check string after it to see if the comment ends
00179         line, is_comment = remove_comment(part[2], True)
00180         if is_comment:
00181             # return possible string data before comment
00182             return part[0].strip(), True
00183 
00184         # otherwise it was an embedded comment so combine
00185         return ''.join([part[0].strip(), ' ', line]).rstrip(), False
00186 
00187     # check for eol comment
00188     return line.partition(COMMENT)[0].strip(), False
00189 
00190 
def try_include(line):

def astconfigparser::try_include (   line  ) 

Checks to see if the given line is an include.  If so return the
included filename, otherwise None.

Definition at line 191 of file astconfigparser.py.

Referenced by process_text_line().

00191                      :
00192     """
00193     Checks to see if the given line is an include.  If so return the
00194     included filename, otherwise None.
00195     """
00196 
00197     match = re.match('^#include\s*[<"]?(.*)[>"]?$', line)
00198     return match.group(1) if match else None
00199 
00200 
def try_section(line):

def astconfigparser::try_option (   line  ) 

Parses the line as an option, returning the key/value pair.

Definition at line 225 of file astconfigparser.py.

00225                     :
00226     """Parses the line as an option, returning the key/value pair."""
00227     data = re.split('=>?', line)
00228     # should split in two (key/val), but either way use first two elements
00229     return data[0].rstrip(), data[1].lstrip()
00230 
###############################################################################

def astconfigparser::try_section (   line  ) 

Checks to see if the given line is a section. If so return the section
name, otherwise return 'None'.

Definition at line 201 of file astconfigparser.py.

00201                      :
00202     """
00203     Checks to see if the given line is a section. If so return the section
00204     name, otherwise return 'None'.
00205     """
00206     # leading spaces were stripped when checking for comments
00207     if not line.startswith('['):
00208         return None, False, []
00209 
00210     section, delim, templates = line.partition(']')
00211     if not templates:
00212         return section[1:], False, []
00213 
00214     # strip out the parens and parse into an array
00215     templates = templates.replace('(', "").replace(')', "").split(',')
00216     # go ahead and remove extra whitespace
00217     templates = [i.strip() for i in templates]
00218     try:
00219         templates.remove('!')
00220         return section[1:], True, templates
00221     except:
00222         return section[1:], False, templates
00223 
00224 
def try_option(line):

def astconfigparser::write_dicts (   config_file,
  mdicts 
)

Write the contents of the mdicts to the specified config file

Definition at line 250 of file astconfigparser.py.

00250                                     :
00251     """Write the contents of the mdicts to the specified config file"""
00252     for section, sect_list in mdicts.iteritems():
00253         # every section contains a list of dictionaries
00254         for sect in sect_list:
00255             config_file.write("[%s]\n" % section)
00256             for key, val_list in sect.iteritems():
00257                 # every value is also a list
00258                 for v in val_list:
00259                     key_val = key
00260                     if v is not None:
00261                         key_val += " = " + str(v)
00262                         config_file.write("%s\n" % (key_val))
00263             config_file.write("\n")
00264 
###############################################################################


Variable Documentation

string COMMENT = ';'

Definition at line 150 of file astconfigparser.py.

Definition at line 152 of file astconfigparser.py.

Definition at line 151 of file astconfigparser.py.

string DEFAULTSECT = 'general'

Definition at line 154 of file astconfigparser.py.


Generated on Thu Apr 16 06:41:37 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6