forked from arnaudsj/suds
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides the unmarshaller part of the 'enhanced soap encoded array su…
…pport'. Flattens soap encoded arrays returned by rpc/encoded servers into python lists. ** IMPORTANT: This changes (improves) the form of returned soap encoded arrays. They are now flattened. Old, person.pets=(Pets)pets[]=[pet,], New person.pets=[pet,]. git-svn-id: http://svn.fedorahosted.org/svn/suds/trunk@607 0b8c961e-115e-4cb0-8d11-a7d6dae58e8c
- Loading branch information
jortel
committed
Nov 24, 2009
1 parent
8481d87
commit ed87a5b
Showing
5 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the (LGPL) GNU Lesser General Public License as | ||
# published by the Free Software Foundation; either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Library Lesser General Public License for more details at | ||
# ( http://www.gnu.org/licenses/lgpl.html ). | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
# written by: Jeff Ortel ( jortel@redhat.com ) | ||
|
||
""" | ||
Provides soap encoded unmarshaller classes. | ||
""" | ||
|
||
from logging import getLogger | ||
from suds import * | ||
from suds.umx import * | ||
from suds.umx.typed import Typed | ||
from suds.sax import splitPrefix | ||
from suds.xsd.query import TypeQuery | ||
|
||
log = getLogger(__name__) | ||
|
||
|
||
Content.extensions.append('aty') | ||
|
||
|
||
class Encoded(Typed): | ||
""" | ||
A SOAP section (5) encoding unmarshaller. | ||
This marshaller supports rpc/encoded soap styles. | ||
""" | ||
|
||
def start(self, content): | ||
# | ||
# Grab the array type and continue | ||
# | ||
start = Typed.start(self, content) | ||
self.setaty(content) | ||
return start | ||
|
||
def end(self, content): | ||
# | ||
# Squash soap encoded arrays into python lists. This is | ||
# also where we insure that empty arrays are represented | ||
# as empty python lists. | ||
# | ||
aty = content.aty | ||
if aty is not None: | ||
pylist = [] | ||
if len(content.data): | ||
items = content.data[0] | ||
for x in items: | ||
pylist.append(aty.translate(x)) | ||
content.data = pylist | ||
return Typed.end(self, content) | ||
|
||
def postprocess(self, content): | ||
# | ||
# Ensure proper rendering of empty arrays. | ||
# | ||
if content.aty is None: | ||
return Typed.postprocess(self, content) | ||
else: | ||
return content.data | ||
|
||
def setaty(self, content): | ||
""" | ||
Grab the (aty) soap-enc:arrayType and attach it to the | ||
content for proper array processing later in end(). | ||
@param content: The current content being unmarshalled. | ||
@type content: L{Content} | ||
@return: self | ||
@rtype: L{Encoded} | ||
""" | ||
spns = (None, 'http://schemas.xmlsoap.org/soap/encoding/') | ||
aty = content.node.get('arrayType', spns) | ||
if aty is None: | ||
return | ||
aty = aty.split('[')[0] | ||
p,t = splitPrefix(aty) | ||
ns = content.node.resolvePrefix(p) | ||
qref = (t, ns[1]) | ||
query = TypeQuery(qref) | ||
content.aty = query.execute(self.resolver.schema) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters