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 11 of file XML2Python.py.

Constructor & Destructor Documentation

def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 15 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__().

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 
20 
def __init__(self, kwargs)
Definition: XML2Python.py:15
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:33
def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 33 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__contains__().

33  def __contains__ (self, name):
34  return name in self._attrs
35 
36 
def __contains__(self, name)
Definition: XML2Python.py:33
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:41
def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 41 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getattr__().

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

Definition at line 26 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getitem__().

26  def __getitem__ (self, key):
27  if isinstance (key, str):
28  return self._attrs.get(key,None)
29  else:
30  return [self][key]
31 
32 
def __getitem__(self, key)
Definition: XML2Python.py:26
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:21
def XML2Python.DataNode.__len__ (   self)

Definition at line 21 of file XML2Python.py.

Referenced by XML2Python.DataNode.__len__().

21  def __len__ (self):
22  # treat single element as a list of 1
23  return 1
24 
25 
def __len__(self)
Definition: XML2Python.py:21
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:67
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def XML2Python.DataNode.__repr__ (   self)

Definition at line 67 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__().

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

Definition at line 63 of file XML2Python.py.

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

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

Definition at line 48 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode._add_xml_attr().

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

Definition at line 84 of file XML2Python.py.

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 
115 
def _outputValues(obj, name, offset)
Definition: XML2Python.py:84
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:74
def XML2Python.DataNode.attributes (   self)

Definition at line 74 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

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

Definition at line 79 of file XML2Python.py.

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

Definition at line 116 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__().

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

Member Data Documentation

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