Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
take nameless types as element arguments
- Loading branch information
Showing
7 changed files
with
53 additions
and
54 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 |
---|---|---|
@@ -1,32 +1,39 @@ | ||
from . import xs | ||
from .model import Namespace | ||
from .model import Namespace, get_root, etree | ||
|
||
namespace = Namespace('http://schemas.xmlsoap.org/soap/envelope/', 'soap') | ||
|
||
Header = xs.element('Header', minOccurs=0)( | ||
xs.complexType()( | ||
xs.sequence()( | ||
xs.any(minOccurs=0, maxOccurs=xs.unbounded)))) | ||
schema = xs.schema(namespace)( | ||
xs.element('Envelope', xs.cts( | ||
xs.element('Header', xs.optional(xs.cts( | ||
xs.any(minOccurs=0, maxOccurs=xs.unbounded)))), | ||
xs.element('Body', xs.optional(xs.cts( | ||
xs.any(minOccurs=0, maxOccurs=xs.unbounded)))), | ||
)), | ||
xs.element('Fault', xs.cts( | ||
xs.element('faultcode', xs.string), | ||
xs.element('faultstring', xs.string), | ||
xs.element('faultactor', xs.optional(xs.string)), | ||
xs.element('detail', xs.optional(xs.string)), | ||
)), | ||
) | ||
|
||
Body = xs.element('Body', minOccurs=0)( | ||
xs.complexType()( | ||
xs.sequence()( | ||
xs.any(minOccurs=0, maxOccurs=xs.unbounded)))) | ||
Envelope = schema['Envelope'] | ||
Fault = schema['Fault'] | ||
|
||
Envelope = xs.element('Envelope')( | ||
xs.complexType()( | ||
xs.sequence()( | ||
Header, | ||
Body))) | ||
|
||
Fault = xs.element('Fault')(xs.cts( | ||
xs.element('faultcode', xs.string), | ||
xs.element('faultstring', xs.string), | ||
xs.element('faultactor', xs.string, minOccurs=0), | ||
xs.element('detail', xs.string, minOccurs=0))) | ||
def make_envelope(response=None, header=None): | ||
envelope = {} | ||
if response: | ||
envelope['Body'] = {'_any': [response]} | ||
if header: | ||
envelope['Header'] = {'_any': [header]} | ||
|
||
return Envelope.normalize(envelope) | ||
|
||
schema = xs.schema(namespace)( | ||
Envelope | ||
) | ||
|
||
schema.update_schema([Fault]) | ||
def response_tostring(response=None, header=None): | ||
renvelope = make_envelope(response, header) | ||
tree = get_root(renvelope) | ||
tree.attrib['soap:encodingStyle'] = 'http://www.w3.org/2001/12/soap-encoding' | ||
return etree.tostring(tree, encoding='utf-8') |
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
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