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 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  def __init__ (self, **kwargs):
15  self._attrs = {} # XML attributes and child elements
16  self._data = None # child text data
17  self._ncDict = kwargs.get ('nameChangeDict', {})
18 
19 
def __init__(self, kwargs)
Definition: XML2Python.py:14
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:32
def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__contains__().

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

Definition at line 40 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getattr__().

40  def __getattr__ (self, name):
41  if name.startswith('__'):
42  # need to do this for Python special methods???
43  raise AttributeError (name)
44  return self._attrs.get (name, None)
45 
46 
def __getattr__(self, name)
Definition: XML2Python.py:40
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, basestring):
22  return self._attrs.get(key,None)
23  else:
24  return [self][key]
25 
def __getitem__(self, key)
Definition: XML2Python.py:25
def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 25 of file XML2Python.py.

Referenced by XML2Python.DataNode.__getitem__().

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

Definition at line 20 of file XML2Python.py.

Referenced by XML2Python.DataNode.__len__().

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

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

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

Definition at line 62 of file XML2Python.py.

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

62  def __str__ (self):
63  return self.stringify()
64 
65 
def __str__(self)
Definition: XML2Python.py:62
def stringify(self, name='', offset=0)
Definition: XML2Python.py:115
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:47
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  def _add_xml_attr (self, name, value):
48  change = self._ncDict.get (name)
49  if change:
50  name = change
51  if name in self._attrs:
52  # multiple attribute of the same name are represented by a list
53  children = self._attrs[name]
54  if not isinstance(children, list):
55  children = [children]
56  self._attrs[name] = children
57  children.append(value)
58  else:
59  self._attrs[name] = value
60 
61 
def _add_xml_attr(self, name, value)
Definition: XML2Python.py:47
def XML2Python.DataNode._outputValues (   obj,
  name,
  offset 
)
staticprivate

Definition at line 83 of file XML2Python.py.

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

Definition at line 73 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

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

Definition at line 78 of file XML2Python.py.

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

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

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

Member Data Documentation

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