CMS 3D CMS Logo

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__ (self, name)
 
def __contains__ (self, name)
 
def __getattr__ (self, name)
 
def __getattr__ (self, name)
 
def __getitem__ (self, key)
 
def __getitem__ (self, key)
 
def __init__ (self, **kwargs)
 
def __init__ (self, **kwargs)
 
def __len__ (self)
 
def __len__ (self)
 
def __nonzero__ (self)
 
def __nonzero__ (self)
 
def __repr__ (self)
 
def __repr__ (self)
 
def __str__ (self)
 
def __str__ (self)
 
def attributes (self)
 
def attributes (self)
 
def stringify (self, name='', offset=0)
 

Static Public Member Functions

def isiterable (obj)
 

Static Public Attributes

 spaces
 

Private Member Functions

def _add_xml_attr (self, name, value)
 
def _add_xml_attr (self, name, value)
 

Static Private Member Functions

def _outputValues (obj, name, offset)
 

Private Attributes

 _attrs
 
 _data
 
 _ncDict
 

Detailed Description

Definition at line 12 of file XML2Python.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def XML2Python.DataNode.__init__ (   self,
**  kwargs 
)

Definition at line 16 of file XML2Python.py.

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

Referenced by XML2Python.DataNode.__init__().

◆ __init__() [2/2]

def XML2Python.DataNode.__init__ (   self,
**  kwargs 
)

Definition at line 11 of file XML2Python.py.

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

References XML2Python.DataNode.__init__(), XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, and XML2Python.DataNode._ncDict.

Member Function Documentation

◆ __contains__() [1/2]

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 26 of file XML2Python.py.

26  def __contains__ (self, name):
27  return name in self._attrs
28 

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

◆ __contains__() [2/2]

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 34 of file XML2Python.py.

34  def __contains__ (self, name):
35  return name in self._attrs
36 
37 

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__contains__().

◆ __getattr__() [1/2]

def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

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

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

◆ __getattr__() [2/2]

def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 42 of file XML2Python.py.

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

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__getattr__().

◆ __getitem__() [1/2]

def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 20 of file XML2Python.py.

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

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

◆ __getitem__() [2/2]

def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 27 of file XML2Python.py.

27  def __getitem__ (self, key):
28  if isinstance (key, str):
29  return self._attrs.get(key,None)
30  else:
31  return [self][key]
32 
33 

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__getitem__().

◆ __len__() [1/2]

def XML2Python.DataNode.__len__ (   self)

Definition at line 16 of file XML2Python.py.

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

References XML2Python.DataNode.__len__().

◆ __len__() [2/2]

def XML2Python.DataNode.__len__ (   self)

Definition at line 22 of file XML2Python.py.

22  def __len__ (self):
23  # treat single element as a list of 1
24  return 1
25 
26 

Referenced by XML2Python.DataNode.__len__().

◆ __nonzero__() [1/2]

def XML2Python.DataNode.__nonzero__ (   self)

◆ __nonzero__() [2/2]

def XML2Python.DataNode.__nonzero__ (   self)

◆ __repr__() [1/2]

def XML2Python.DataNode.__repr__ (   self)

Definition at line 55 of file XML2Python.py.

55  def __repr__ (self):
56  items = sorted (self._attrs.items())
57  if self._data:
58  items.append(('data', self._data))
59  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
60 

References XML2Python.DataNode.__repr__(), XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, mps_monitormerge.items, and join().

◆ __repr__() [2/2]

def XML2Python.DataNode.__repr__ (   self)

Definition at line 68 of file XML2Python.py.

68  def __repr__ (self):
69  items = sorted (self._attrs.items())
70  if self._data:
71  items.append(('data', self._data))
72  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
73 
74 

References XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, mps_monitormerge.items, and join().

Referenced by XML2Python.DataNode.__repr__().

◆ __str__() [1/2]

def XML2Python.DataNode.__str__ (   self)

◆ __str__() [2/2]

def XML2Python.DataNode.__str__ (   self)

Definition at line 64 of file XML2Python.py.

64  def __str__ (self):
65  return self.stringify()
66 
67 

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

◆ _add_xml_attr() [1/2]

def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 38 of file XML2Python.py.

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

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

◆ _add_xml_attr() [2/2]

def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 49 of file XML2Python.py.

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

References XML2Python.DataNode._attrs, and XML2Python.DataNode._ncDict.

Referenced by XML2Python.DataNode._add_xml_attr().

◆ _outputValues()

def XML2Python.DataNode._outputValues (   obj,
  name,
  offset 
)
staticprivate

Definition at line 85 of file XML2Python.py.

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

References edm.print().

◆ attributes() [1/2]

def XML2Python.DataNode.attributes (   self)

Definition at line 61 of file XML2Python.py.

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

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

◆ attributes() [2/2]

def XML2Python.DataNode.attributes (   self)

Definition at line 75 of file XML2Python.py.

75  def attributes (self):
76  return self._attrs
77 
78 

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

◆ isiterable()

def XML2Python.DataNode.isiterable (   obj)
static

Definition at line 80 of file XML2Python.py.

80  def isiterable (obj):
81  return getattr (obj, '__iter__', False)
82 
83 

◆ stringify()

def XML2Python.DataNode.stringify (   self,
  name = '',
  offset = 0 
)

Definition at line 117 of file XML2Python.py.

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

References XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, data_sources.json_dict._data, data_sources.json_basic._data, and DTTFBitArray< N >._data.

Referenced by XML2Python.DataNode.__str__().

Member Data Documentation

◆ _attrs

XML2Python.DataNode._attrs
private

◆ _data

XML2Python.DataNode._data
private

◆ _ncDict

XML2Python.DataNode._ncDict
private

◆ spaces

XML2Python.DataNode.spaces
static

Definition at line 14 of file XML2Python.py.

join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
stringify
std::string stringify(const T &t)
Definition: SideBandSubtraction.cc:45
CommonMethods.__nonzero__
__nonzero__
Definition: CommonMethods.py:139
TriggerAnalyzer.__str__
def __str__(self)
Definition: TriggerAnalyzer.py:103
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66