CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
XML2Python.DataNode Class Reference
Inheritance diagram for XML2Python.DataNode:

Public Member Functions

def __contains__
 
def __contains__
 
def __getattr__
 
def __getattr__
 
def __getitem__
 
def __getitem__
 
def __init__
 
def __init__
 
def __len__
 
def __len__
 
def __nonzero__
 
def __nonzero__
 
def __repr__
 
def __repr__
 
def __str__
 
def __str__
 
def attributes
 
def attributes
 
def stringify
 

Static Public Member Functions

def isiterable
 

Static Public Attributes

int spaces = 4
 

Private Member Functions

def _add_xml_attr
 
def _add_xml_attr
 

Static Private Member Functions

def _outputValues
 

Private Attributes

 _attrs
 
 _data
 
 _ncDict
 

Detailed Description

Definition at line 10 of file XML2Python.py.

Constructor & Destructor Documentation

def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 14 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__().

14 
15  def __init__ (self, **kwargs):
16  self._attrs = {} # XML attributes and child elements
17  self._data = None # child text data
18  self._ncDict = kwargs.get ('nameChangeDict', {})
19 
def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 11 of file XML2Python.py.

References XML2Python.DataNode.__init__(), XML2Python.DataNode._attrs, XML2Python.DataNode._data, HcalTriggerKey._data, DTTFBitArray< N >._data, and XML2Python.DataNode._ncDict.

11 
12  def __init__ (self, **kwargs):
13  self._attrs = {} # XML attributes and child elements
14  self._data = None # child text data
15  self._ncDict = kwargs.get ('nameChangeDict', {})

Member Function Documentation

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 26 of file XML2Python.py.

References XML2Python.DataNode.__contains__().

26 
27  def __contains__ (self, name):
28  return self._attrs.has_key(name)
def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

Referenced by XML2Python.DataNode.__contains__().

32 
33  def __contains__ (self, name):
34  return self._attrs.has_key(name)
35 
def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

References XML2Python.DataNode.__getattr__().

32 
33  def __getattr__ (self, name):
34  if name.startswith('__'):
35  # need to do this for Python special methods???
36  raise AttributeError (name)
37  return self._attrs.get (name, None)
def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 40 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getattr__().

40 
41  def __getattr__ (self, name):
42  if name.startswith('__'):
43  # need to do this for Python special methods???
44  raise AttributeError (name)
45  return self._attrs.get (name, None)
46 
def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 20 of file XML2Python.py.

References XML2Python.DataNode.__getitem__().

20 
21  def __getitem__ (self, key):
22  if isinstance (key, basestring):
23  return self._attrs.get(key,None)
24  else:
25  return [self][key]
def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 25 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getitem__().

25 
26  def __getitem__ (self, key):
27  if isinstance (key, basestring):
28  return self._attrs.get(key,None)
29  else:
30  return [self][key]
31 
def XML2Python.DataNode.__len__ (   self)

Definition at line 16 of file XML2Python.py.

References XML2Python.DataNode.__len__().

16 
17  def __len__ (self):
18  # treat single element as a list of 1
19  return 1
def XML2Python.DataNode.__len__ (   self)

Definition at line 20 of file XML2Python.py.

Referenced by XML2Python.DataNode.__len__().

20 
21  def __len__ (self):
22  # treat single element as a list of 1
23  return 1
24 
def XML2Python.DataNode.__nonzero__ (   self)

Definition at line 29 of file XML2Python.py.

References XML2Python.DataNode.__nonzero__(), XML2Python.DataNode._attrs, XML2Python.DataNode._data, HcalTriggerKey._data, and DTTFBitArray< N >._data.

29 
30  def __nonzero__ (self):
31  return bool (self._attrs or self._data)
def XML2Python.DataNode.__nonzero__ (   self)

Definition at line 36 of file XML2Python.py.

References XML2Python.DataNode._attrs, XML2Python.DataNode._data, HcalTriggerKey._data, and DTTFBitArray< N >._data.

Referenced by XML2Python.DataNode.__nonzero__().

36 
37  def __nonzero__ (self):
38  return bool (self._attrs or self._data)
39 
def XML2Python.DataNode.__repr__ (   self)

Definition at line 55 of file XML2Python.py.

References XML2Python.DataNode.__repr__(), XML2Python.DataNode._data, HcalTriggerKey._data, DTTFBitArray< N >._data, and join().

55 
56  def __repr__ (self):
57  items = sorted (self._attrs.items())
58  if self._data:
59  items.append(('data', self._data))
60  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def XML2Python.DataNode.__repr__ (   self)

Definition at line 66 of file XML2Python.py.

References XML2Python.DataNode._data, HcalTriggerKey._data, DTTFBitArray< N >._data, and join().

Referenced by XML2Python.DataNode.__repr__().

66 
67  def __repr__ (self):
68  items = sorted (self._attrs.items())
69  if self._data:
70  items.append(('data', self._data))
71  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
72 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def XML2Python.DataNode.__str__ (   self)

Definition at line 52 of file XML2Python.py.

References XML2Python.DataNode.__str__(), XML2Python.DataNode._data, HcalTriggerKey._data, and DTTFBitArray< N >._data.

52 
53  def __str__ (self):
54  return self._data or ''
def XML2Python.DataNode.__str__ (   self)

Definition at line 62 of file XML2Python.py.

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

62 
63  def __str__ (self):
64  return self.stringify()
65 
def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 38 of file XML2Python.py.

References XML2Python.DataNode._add_xml_attr(), and XML2Python.DataNode._attrs.

38 
39  def _add_xml_attr (self, name, value):
40  change = self._ncDict.get (name)
41  if change:
42  name = change
43  if name in self._attrs:
44  # multiple attribute of the same name are represented by a list
45  children = self._attrs[name]
46  if not isinstance(children, list):
47  children = [children]
48  self._attrs[name] = children
49  children.append(value)
50  else:
51  self._attrs[name] = value
def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 47 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode._add_xml_attr().

47 
48  def _add_xml_attr (self, name, value):
49  change = self._ncDict.get (name)
50  if change:
51  name = change
52  if name in self._attrs:
53  # multiple attribute of the same name are represented by a list
54  children = self._attrs[name]
55  if not isinstance(children, list):
56  children = [children]
57  self._attrs[name] = children
58  children.append(value)
59  else:
60  self._attrs[name] = value
61 
def XML2Python.DataNode._outputValues (   obj,
  name,
  offset 
)
staticprivate

Definition at line 83 of file XML2Python.py.

83 
84  def _outputValues (obj, name, offset):
85  retval = ' ' * offset
86  if name:
87  retval += '%s: ' % name
88  offset += len (name) + DataNode.spaces
89  # if this is a list
90  if isinstance (obj, list):
91  first = True
92  for value in obj:
93  print "value", value, value.__class__.__name__
94  if first:
95  tempoffset = offset
96  first = False
97  retval += '[\n ' + ' ' * offset
98  else:
99  retval += ',\n ' + ' ' * offset
100  tempoffset = offset
101  if isinstance (value, DataNode):
102  retval += value.stringify (offset=tempoffset)
103  print " calling stringify for %s" % value
104  elif DataNode.isiterable (value):
105  retval += DataNode._outputValues (value, '', offset)
106  else:
107  retval += "%s" % value
108  retval += '\n' + ' ' * (offset - 2) +']\n'
109  return retval
110  retval += pprint.pformat(obj,
111  indent= offset,
112  width=1)
113  return retval
114 
def XML2Python.DataNode.attributes (   self)

Definition at line 61 of file XML2Python.py.

References XML2Python.DataNode._attrs, and XML2Python.DataNode.attributes().

61 
62  def attributes (self):
63  return self._attrs
64 
def XML2Python.DataNode.attributes (   self)

Definition at line 73 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

73 
74  def attributes (self):
75  return self._attrs
76 
def XML2Python.DataNode.isiterable (   obj)
static

Definition at line 78 of file XML2Python.py.

78 
79  def isiterable (obj):
80  return getattr (obj, '__iter__', False)
81 
def XML2Python.DataNode.stringify (   self,
  name = '',
  offset = 0 
)

Definition at line 115 of file XML2Python.py.

References XML2Python.DataNode._attrs, XML2Python.DataNode._data, HcalTriggerKey._data, and DTTFBitArray< N >._data.

Referenced by XML2Python.DataNode.__str__().

116  def stringify (self, name = '', offset = 0):
117  # is this just data and nothing below
118  if self._data and not len (self._attrs):
119  return _outputValues (self._data, name, offset)
120  retval = ' ' * offset
121  if name:
122  retval += '%s : %s\n' % \
123  (name,
124  pprint.pformat (self._data,
125  indent= offset+DataNode.spaces,
126  width=1) )
127  else:
128  retval += pprint.pformat (self._data,
129  indent=offset+DataNode.spaces,
130  width=1)
131  return retval
132  # this has attributes
133  retval = ''
134  if name:
135  retval += '\n' + ' ' * offset
136  retval += '%s: ' % name
137  first = True
138  for key, value in sorted (self._attrs.iteritems()):
139  if first:
140  retval += '{ \n'
141  tempspace = offset + 3
142  first = False
143  else:
144  retval += ',\n'
145  tempspace = offset + 3
146  if isinstance (value, DataNode):
147  retval += value.stringify (key, tempspace)
148  else:
149  retval += DataNode._outputValues (value, key, tempspace)
150  # this has data too
151  if self._data:
152  retval += ',\n'
153  tempspace = offset + 3
154  retval += DataNode._ouptputValues (self._data, name, tempspace)
155  retval += '\n ' + ' ' * offset + '}'
156  return retval
157 
158 

Member Data Documentation

XML2Python.DataNode._attrs
private

Definition at line 15 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__(), python.XML2Python.DataNode.__nonzero__(), XML2Python.DataNode.__nonzero__(), python.XML2Python.DataNode._add_xml_attr(), XML2Python.DataNode._add_xml_attr(), python.XML2Python.DataNode.attributes(), XML2Python.DataNode.attributes(), and XML2Python.DataNode.stringify().

XML2Python.DataNode._data
private

Definition at line 16 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__(), python.XML2Python.DataNode.__nonzero__(), XML2Python.DataNode.__nonzero__(), python.XML2Python.DataNode.__repr__(), XML2Python.DataNode.__repr__(), XML2Python.DataNode.__str__(), python.XML2Python.DataNode.__str__(), cfg-viewer.unscheduled._proceed(), cfg-viewer.unscheduled._saveData(), and XML2Python.DataNode.stringify().

XML2Python.DataNode._ncDict
private

Definition at line 17 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__(), XML2Python.TreeBuilder.__init__(), python.XML2Python.TreeBuilder.startElement(), and XML2Python.TreeBuilder.startElement().

int XML2Python.DataNode.spaces = 4
static

Definition at line 12 of file XML2Python.py.