Package suds :: Package umx :: Module encoded
[hide private]
[frames] | no frames]

Source Code for Module suds.umx.encoded

  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 soap encoded unmarshaller classes. 
 19  """ 
 20   
 21  from logging import getLogger 
 22  from suds import * 
 23  from suds.umx import * 
 24  from suds.umx.typed import Typed 
 25  from suds.sax import splitPrefix, Namespace 
 26   
 27  log = getLogger(__name__) 
 28   
 29  # 
 30  # Add encoded extensions 
 31  # aty = The soap (section 5) encoded array type. 
 32  # 
 33  Content.extensions.append('aty') 
 34   
 35   
36 -class Encoded(Typed):
37 """ 38 A SOAP section (5) encoding unmarshaller. 39 This marshaller supports rpc/encoded soap styles. 40 """ 41
42 - def start(self, content):
43 # 44 # Grab the array type and continue 45 # 46 self.setaty(content) 47 Typed.start(self, content)
48
49 - def end(self, content):
50 # 51 # Squash soap encoded arrays into python lists. This is 52 # also where we insure that empty arrays are represented 53 # as empty python lists. 54 # 55 aty = content.aty 56 if aty is not None: 57 self.promote(content) 58 return Typed.end(self, content)
59
60 - def postprocess(self, content):
61 # 62 # Ensure proper rendering of empty arrays. 63 # 64 if content.aty is None: 65 return Typed.postprocess(self, content) 66 else: 67 return content.data
68
69 - def setaty(self, content):
70 """ 71 Grab the (aty) soap-enc:arrayType and attach it to the 72 content for proper array processing later in end(). 73 @param content: The current content being unmarshalled. 74 @type content: L{Content} 75 @return: self 76 @rtype: L{Encoded} 77 """ 78 name = 'arrayType' 79 ns = (None, 'http://schemas.xmlsoap.org/soap/encoding/') 80 aty = content.node.get(name, ns) 81 if aty is not None: 82 content.aty = aty 83 parts = aty.split('[') 84 ref = parts[0] 85 if len(parts) == 2: 86 self.applyaty(content, ref) 87 else: 88 pass # (2) dimensional array 89 return self
90
91 - def applyaty(self, content, xty):
92 """ 93 Apply the type referenced in the I{arrayType} to the content 94 (child nodes) of the array. Each element (node) in the array 95 that does not have an explicit xsi:type attribute is given one 96 based on the I{arrayType}. 97 @param content: An array content. 98 @type content: L{Content} 99 @param xty: The XSI type reference. 100 @type xty: str 101 @return: self 102 @rtype: L{Encoded} 103 """ 104 name = 'type' 105 ns = Namespace.xsins 106 parent = content.node 107 for child in parent.getChildren(): 108 ref = child.get(name, ns) 109 if ref is None: 110 parent.addPrefix(ns[0], ns[1]) 111 attr = ':'.join((ns[0], name)) 112 child.set(attr, xty) 113 return self
114
115 - def promote(self, content):
116 """ 117 Promote (replace) the content.data with the first attribute 118 of the current content.data that is a I{list}. Note: the 119 content.data may be empty or contain only _x attributes. 120 In either case, the content.data is assigned an empty list. 121 @param content: An array content. 122 @type content: L{Content} 123 """ 124 for n,v in content.data: 125 if isinstance(v, list): 126 content.data = v 127 return 128 content.data = []
129