Package suds :: Package mx :: Module core
[hide private]
[frames] | no frames]

Source Code for Module suds.mx.core

  1  # This program is free software; you can redistribute it and/or modify 
  2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
  3  # published by the Free Software Foundation; either version 3 of the  
  4  # License, or (at your option) any later version. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library Lesser General Public License for more details at 
 10  # ( http://www.gnu.org/licenses/lgpl.html ). 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15  # written by: Jeff Ortel ( jortel@redhat.com ) 
 16   
 17  """ 
 18  Provides I{marshaller} core classes. 
 19  """ 
 20   
 21  from logging import getLogger 
 22  from suds import * 
 23  from suds.mx import * 
 24  from suds.mx.appender import ContentAppender 
 25  from suds.sax.element import Element 
 26  from suds.sax.document import Document 
 27  from suds.sudsobject import Property 
 28   
 29   
 30  log = getLogger(__name__) 
 31   
 32   
33 -class Core:
34 """ 35 An I{abstract} marshaller. This class implement the core 36 functionality of the marshaller. 37 @ivar appender: A content appender. 38 @type appender: L{ContentAppender} 39 """ 40
41 - def __init__(self):
42 """ 43 """ 44 self.appender = ContentAppender(self)
45
46 - def process(self, content):
47 """ 48 Process (marshal) the tag with the specified value using the 49 optional type information. 50 @param content: The content to process. 51 @type content: L{Object} 52 """ 53 log.debug('processing:\n%s', content) 54 self.reset() 55 if content.tag is None: 56 content.tag = content.value.__class__.__name__ 57 document = Document() 58 if isinstance(content.value, Property): 59 root = self.node(content) 60 self.append(document, content) 61 else: 62 self.append(document, content) 63 return document.root()
64
65 - def append(self, parent, content):
66 """ 67 Append the specified L{content} to the I{parent}. 68 @param parent: The parent node to append to. 69 @type parent: L{Element} 70 @param content: The content to append. 71 @type content: L{Object} 72 """ 73 log.debug('appending parent:\n%s\ncontent:\n%s', parent, content) 74 if self.start(content): 75 self.appender.append(parent, content) 76 self.end(parent, content)
77
78 - def reset(self):
79 """ 80 Reset the marshaller. 81 """ 82 pass
83
84 - def node(self, content):
85 """ 86 Create and return an XML node. 87 @param content: The content for which proccessing has been suspended. 88 @type content: L{Object} 89 @return: An element. 90 @rtype: L{Element} 91 """ 92 return Element(content.tag)
93
94 - def start(self, content):
95 """ 96 Appending this content has started. 97 @param content: The content for which proccessing has started. 98 @type content: L{Content} 99 @return: True to continue appending 100 @rtype: boolean 101 """ 102 return True
103
104 - def suspend(self, content):
105 """ 106 Appending this content has suspended. 107 @param content: The content for which proccessing has been suspended. 108 @type content: L{Content} 109 """ 110 pass
111
112 - def resume(self, content):
113 """ 114 Appending this content has resumed. 115 @param content: The content for which proccessing has been resumed. 116 @type content: L{Content} 117 """ 118 pass
119
120 - def end(self, parent, content):
121 """ 122 Appending this content has ended. 123 @param parent: The parent node ending. 124 @type parent: L{Element} 125 @param content: The content for which proccessing has ended. 126 @type content: L{Content} 127 """ 128 pass
129
130 - def setnil(self, node, content):
131 """ 132 Set the value of the I{node} to nill. 133 @param node: A I{nil} node. 134 @type node: L{Element} 135 @param content: The content to set nil. 136 @type content: L{Content} 137 """ 138 pass
139
140 - def setdefault(self, node, content):
141 """ 142 Set the value of the I{node} to a default value. 143 @param node: A I{nil} node. 144 @type node: L{Element} 145 @param content: The content to set the default value. 146 @type content: L{Content} 147 @return: The default. 148 """ 149 pass
150
151 - def optional(self, content):
152 """ 153 Get whether the specified content is optional. 154 @param content: The content which to check. 155 @type content: L{Content} 156 """ 157 return False
158