CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
cmsHarvester.DBSXMLHandler Class Reference

Helper class: DBSXMLHandler. More...

Inheritance diagram for cmsHarvester.DBSXMLHandler:

Public Member Functions

def __init__ (self, tag_names)
 
def characters (self, content)
 
def check_results_validity (self)
 
def current_element (self)
 
def endElement (self, name)
 
def startElement (self, name, attrs)
 

Public Attributes

 current_value
 
 element_position
 
 results
 
 tag_names
 

Detailed Description

Helper class: DBSXMLHandler.

XML handler class to parse DBS results.

The tricky thing here is that older DBS versions (2.0.5 and
earlier) return results in a different XML format than newer
versions. Previously the result values were returned as attributes
to the `result' element. The new approach returns result values as
contents of named elements.

The old approach is handled directly in startElement(), the new
approach in characters().

NOTE: All results are returned in the form of string values of
      course!

Definition at line 185 of file cmsHarvester.py.

Constructor & Destructor Documentation

def cmsHarvester.DBSXMLHandler.__init__ (   self,
  tag_names 
)

Definition at line 218 of file cmsHarvester.py.

218  def __init__(self, tag_names):
219  # This is a list used as stack to keep track of where we are
220  # in the element tree.
222  self.tag_names = tag_names
223  self.results = {}
224 
def __init__(self, tag_names)

Member Function Documentation

def cmsHarvester.DBSXMLHandler.characters (   self,
  content 
)

Definition at line 257 of file cmsHarvester.py.

References cmsHarvester.DBSXMLHandler.current_element(), and cmsHarvester.DBSXMLHandler.tag_names.

257  def characters(self, content):
258  # NOTE: It is possible that the actual contents of the tag
259  # gets split into multiple pieces. This method will be called
260  # for each of the pieces. This means we have to concatenate
261  # everything ourselves.
262  if self.current_element() in self.tag_names:
263  self.current_value.append(content)
264 
def characters(self, content)
def cmsHarvester.DBSXMLHandler.check_results_validity (   self)
Make sure that all results arrays have equal length.

We should have received complete rows from DBS. I.e. all
results arrays in the handler should be of equal length.

Definition at line 268 of file cmsHarvester.py.

References cmsHarvester.DBSXMLHandler.results.

269  """Make sure that all results arrays have equal length.
270 
271  We should have received complete rows from DBS. I.e. all
272  results arrays in the handler should be of equal length.
273 
274  """
275 
276  results_valid = True
277 
278  res_names = self.results.keys()
279  if len(res_names) > 1:
280  for res_name in res_names[1:]:
281  res_tmp = self.results[res_name]
282  if len(res_tmp) != len(self.results[res_names[0]]):
283  results_valid = False
284 
285  return results_valid
286 
def cmsHarvester.DBSXMLHandler.current_element (   self)
def cmsHarvester.DBSXMLHandler.endElement (   self,
  name 
)

Definition at line 244 of file cmsHarvester.py.

References mps_alisetup.append, cmsHarvester.DBSXMLHandler.current_element(), cmsHarvester.DBSXMLHandler.current_value, join(), cmsHarvester.DBSXMLHandler.results, and cmsHarvester.DBSXMLHandler.tag_names.

244  def endElement(self, name):
245  assert self.current_element() == name, \
246  "closing unopenend element `%s'" % name
247 
248  if self.current_element() in self.tag_names:
249  contents = "".join(self.current_value)
250  if self.current_element() in self.results:
251  self.results[self.current_element()].append(contents)
252  else:
253  self.results[self.current_element()] = [contents]
254 
255  self.element_position.pop()
256 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def endElement(self, name)
def cmsHarvester.DBSXMLHandler.startElement (   self,
  name,
  attrs 
)

Definition at line 225 of file cmsHarvester.py.

225  def startElement(self, name, attrs):
226  self.element_position.append(name)
227 
228  self.current_value = []
229 
230  #----------
231 
232  # This is to catch results from DBS 2.0.5 and earlier.
233  if name == "result":
234  for name in self.tag_names:
235  key = DBSXMLHandler.mapping[name]
236  value = str(attrs[key])
237  try:
238  self.results[name].append(value)
239  except KeyError:
240  self.results[name] = [value]
241 
242  #----------
243 
def startElement(self, name, attrs)

Member Data Documentation

cmsHarvester.DBSXMLHandler.current_value

Definition at line 228 of file cmsHarvester.py.

Referenced by cmsHarvester.DBSXMLHandler.endElement().

cmsHarvester.DBSXMLHandler.element_position

Definition at line 221 of file cmsHarvester.py.

Referenced by cmsHarvester.DBSXMLHandler.current_element().

cmsHarvester.DBSXMLHandler.results
cmsHarvester.DBSXMLHandler.tag_names