CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | 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)
 

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

def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 16 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__().

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 
def __init__(self, kwargs)
Definition: XML2Python.py:16
def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Member Function Documentation

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 26 of file XML2Python.py.

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

26  def __contains__ (self, name):
27  return name in self._attrs
28 
def __contains__(self, name)
Definition: XML2Python.py:34
def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 34 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__contains__().

34  def __contains__ (self, name):
35  return name in self._attrs
36 
37 
def __contains__(self, name)
Definition: XML2Python.py:34
def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

References XML2Python.DataNode.__getattr__().

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 
def __getattr__(self, name)
Definition: XML2Python.py:42
def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 42 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getattr__().

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 
def __getattr__(self, name)
Definition: XML2Python.py:42
def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 20 of file XML2Python.py.

References XML2Python.DataNode.__getitem__().

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

Definition at line 27 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getitem__().

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 
def __getitem__(self, key)
Definition: XML2Python.py:27
def XML2Python.DataNode.__len__ (   self)

Definition at line 16 of file XML2Python.py.

References XML2Python.DataNode.__len__().

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

Definition at line 22 of file XML2Python.py.

Referenced by XML2Python.DataNode.__len__().

22  def __len__ (self):
23  # treat single element as a list of 1
24  return 1
25 
26 
def __len__(self)
Definition: XML2Python.py:22
def XML2Python.DataNode.__nonzero__ (   self)
def XML2Python.DataNode.__nonzero__ (   self)
def XML2Python.DataNode.__repr__ (   self)

Definition at line 55 of file XML2Python.py.

References XML2Python.DataNode.__repr__(), 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 join().

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 
def __repr__(self)
Definition: XML2Python.py:68
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def XML2Python.DataNode.__repr__ (   self)

Definition at line 68 of file XML2Python.py.

References 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 join().

Referenced by XML2Python.DataNode.__repr__().

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 
def __repr__(self)
Definition: XML2Python.py:68
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def XML2Python.DataNode.__str__ (   self)
def XML2Python.DataNode.__str__ (   self)

Definition at line 64 of file XML2Python.py.

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

64  def __str__ (self):
65  return self.stringify()
66 
67 
def __str__(self)
Definition: XML2Python.py:64
def stringify(self, name='', offset=0)
Definition: XML2Python.py:117
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  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 
def _add_xml_attr(self, name, value)
Definition: XML2Python.py:49
def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 49 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode._add_xml_attr().

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 
def _add_xml_attr(self, name, value)
Definition: XML2Python.py:49
def XML2Python.DataNode._outputValues (   obj,
  name,
  offset 
)
staticprivate

Definition at line 85 of file XML2Python.py.

References edm.print().

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 
def _outputValues(obj, name, offset)
Definition: XML2Python.py:85
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def XML2Python.DataNode.attributes (   self)

Definition at line 61 of file XML2Python.py.

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

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

Definition at line 75 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

75  def attributes (self):
76  return self._attrs
77 
78 
def attributes(self)
Definition: XML2Python.py:75
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 
def isiterable(obj)
Definition: XML2Python.py:80
def XML2Python.DataNode.stringify (   self,
  name = '',
  offset = 0 
)

Definition at line 117 of file XML2Python.py.

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__().

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 
def stringify(self, name='', offset=0)
Definition: XML2Python.py:117

Member Data Documentation

XML2Python.DataNode._attrs
private
XML2Python.DataNode._data
private
XML2Python.DataNode._ncDict
private