Asterisk - The Open Source Telephony Project  21.4.1
Public Member Functions | Data Fields | Static Public Attributes
Section Class Reference
Inheritance diagram for Section:
MultiOrderedDict OrderedDict

Public Member Functions

def __cmp__ (self, other)
 
def __eq__ (self, other)
 
def __ge__ (self, other)
 
def __getitem__ (self, key)
 
def __gt__ (self, other)
 
def __init__
 
def __le__ (self, other)
 
def __lt__ (self, other)
 
def add_defaults (self, defaults)
 
def add_templates (self, templates)
 
def get
 
def get_merged (self, key)
 
def keys
 
- Public Member Functions inherited from MultiOrderedDict
def __init__ (self, args, kwds)
 
def __setitem__
 
def copy (self)
 
def insert (self, i, key, val)
 
- Public Member Functions inherited from OrderedDict
def __delitem__
 
def __eq__ (self, other)
 
def __init__ (self, args, kwds)
 
def __iter__ (self)
 
def __ne__ (self, other)
 
def __reduce__ (self)
 
def __repr__
 
def __reversed__ (self)
 
def __setitem__
 
def clear (self)
 
def copy (self)
 
def fromkeys
 
def items (self)
 
def iteritems (self)
 
def iterkeys (self)
 
def itervalues (self)
 
def keys (self)
 
def pop
 
def popitem
 
def setdefault
 
def update (args, kwds)
 
def values (self)
 
def viewitems (self)
 
def viewkeys (self)
 
def viewvalues (self)
 

Data Fields

 id
 

Static Public Attributes

int count = 0
 

Detailed Description

A Section is a MultiOrderedDict itself that maintains a list of
key/value options.  However, in the case of an Asterisk config
file a section may have other defaults sections that is can pull
data from (i.e. templates).  So when an option is looked up by key
it first checks the base section and if not found looks in the
added default sections. If not found at that point then a 'KeyError'
exception is raised.

Definition at line 29 of file astconfigparser.py.

Member Function Documentation

def __cmp__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 49 of file astconfigparser.py.

References Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

49  def __cmp__(self, other):
50  """
51  Use self.id as means of determining equality
52  """
53  return (self.id > other.id) - (self.id < other.id)
54 
def __cmp__(self, other)
def __eq__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 55 of file astconfigparser.py.

References Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

55  def __eq__(self, other):
56  """
57  Use self.id as means of determining equality
58  """
59  return self.id == other.id
60 
def __eq__(self, other)
def __ge__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 79 of file astconfigparser.py.

References Section.get(), Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

79  def __ge__(self, other):
80  """
81  Use self.id as means of determining equality
82  """
83  return self.id >= other.id
84 
def __ge__(self, other)
def __getitem__ (   self,
  key 
)
Get the value for the given key. If it is not found in the 'self'
then check inside templates and defaults before declaring raising
a KeyError exception.

Definition at line 121 of file astconfigparser.py.

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

121  def __getitem__(self, key):
122  """
123  Get the value for the given key. If it is not found in the 'self'
124  then check inside templates and defaults before declaring raising
125  a KeyError exception.
126  """
127  return self.get(key)
128 
def __getitem__(self, key)
def __gt__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 67 of file astconfigparser.py.

References Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

67  def __gt__(self, other):
68  """
69  Use self.id as means of determining equality
70  """
71  return self.id > other.id
72 
def __gt__(self, other)
def __le__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 73 of file astconfigparser.py.

References Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

73  def __le__(self, other):
74  """
75  Use self.id as means of determining equality
76  """
77  return self.id <= other.id
78 
def __le__(self, other)
def __lt__ (   self,
  other 
)
Use self.id as means of determining equality

Definition at line 61 of file astconfigparser.py.

References Section.id, audiosocket_instance.id, native_rtp_framehook_data.id, adsi_event.id, opus_coder_pvt.id, adapter_pvt.id, mbl_pvt.id, adsi_soft_key.id, adsi_subscript.id, adsi_state.id, adsi_flag.id, adsi_display.id, unistim_device.id, conf_menu_action.id, adsi_key_cmd.id, id, and local_optimization.id.

61  def __lt__(self, other):
62  """
63  Use self.id as means of determining equality
64  """
65  return self.id < other.id
66 
def __lt__(self, other)
def add_defaults (   self,
  defaults 
)
Add a list of defaults to the section. Defaults are
sections such as 'general'

Definition at line 150 of file astconfigparser.py.

150  def add_defaults(self, defaults):
151  """
152  Add a list of defaults to the section. Defaults are
153  sections such as 'general'
154  """
155  defaults.sort()
156  for i in defaults:
157  self._defaults.insert(0, i)
158 
def add_defaults(self, defaults)
def add_templates (   self,
  templates 
)
Add a list of templates to the section.

Definition at line 159 of file astconfigparser.py.

159  def add_templates(self, templates):
160  """
161  Add a list of templates to the section.
162  """
163  templates.sort()
164  for i in templates:
165  self._templates.insert(0, i)
166 
def add_templates(self, templates)
def get (   self,
  key,
  from_self = True,
  from_templates = True,
  from_defaults = True 
)
Get the values corresponding to a given key. The parameters to this
function form a hierarchy that determines priority of the search.
from_self takes priority over from_templates, and from_templates takes
priority over from_defaults.

Parameters:
from_self - If True, search within the given section.
from_templates - If True, search in this section's templates.
from_defaults - If True, search within this section's defaults.

Definition at line 86 of file astconfigparser.py.

References Section._defaults, and Section._templates.

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

86  from_defaults=True):
87  """
88  Get the values corresponding to a given key. The parameters to this
89  function form a hierarchy that determines priority of the search.
90  from_self takes priority over from_templates, and from_templates takes
91  priority over from_defaults.
92 
93  Parameters:
94  from_self - If True, search within the given section.
95  from_templates - If True, search in this section's templates.
96  from_defaults - If True, search within this section's defaults.
97  """
98  if from_self and key in self:
99  return MultiOrderedDict.__getitem__(self, key)
100 
101  if from_templates:
102  if self in self._templates:
103  return []
104  for t in self._templates:
105  try:
106  # fail if not found on the search - doing it this way
107  # allows template's templates to be searched.
108  return t.get(key, True, from_templates, from_defaults)
109  except KeyError:
110  pass
111 
112  if from_defaults:
113  for d in self._defaults:
114  try:
115  return d.get(key, True, from_templates, from_defaults)
116  except KeyError:
117  pass
118 
119  raise KeyError(key)
120 
def get_merged (   self,
  key 
)
Return a list of values for a given key merged from default(s)

Definition at line 167 of file astconfigparser.py.

References Section._defaults, Section._templates, and astconfigparser.merge_values().

167  def get_merged(self, key):
168  """Return a list of values for a given key merged from default(s)"""
169  # first merge key/values from defaults together
170  merged = []
171  for i in reversed(self._defaults):
172  if not merged:
173  merged = i
174  continue
175  merged = merge_values(merged, i, key)
176 
177  for i in reversed(self._templates):
178  if not merged:
179  merged = i
180  continue
181  merged = merge_values(merged, i, key)
182 
183  # then merge self in
184  return merge_values(merged, self, key)
185 
def merge_values(left, right, key)
def keys (   self,
  self_only = False 
)
Get the keys from this section. If self_only is True, then
keys from this section's defaults and templates are not
included in the returned value

Definition at line 129 of file astconfigparser.py.

References Section._defaults, and Section._templates.

129  def keys(self, self_only=False):
130  """
131  Get the keys from this section. If self_only is True, then
132  keys from this section's defaults and templates are not
133  included in the returned value
134  """
135  res = MultiOrderedDict.keys(self)
136  if self_only:
137  return res
138 
139  for d in self._templates:
140  for key in d.keys():
141  if key not in res:
142  res.append(key)
143 
144  for d in self._defaults:
145  for key in d.keys():
146  if key not in res:
147  res.append(key)
148  return res
149 

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