Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factory():
- document = {'root': None,
- 'stack': []}
- class Tag(object):
- def __init__(self, name, namespace='', **attrs):
- _base = namespace + name if namespace else name
- self._el = etree.Element(_base, **attrs)
- def __enter__(self):
- if document['root'] is None:
- document['root'] = self._el
- document['stack'].append(self._el)
- return self._el
- def __exit__(self, *args):
- document['stack'].pop()
- if document['stack']:
- document['stack'][-1].append(self._el)
- return Tag, document
- tag, doc = factory()
- with tag('GetRequestRequest', NS_1):
- with tag('MessageTypeSelector', NS_2):
- with tag('NamespaceURI') as ns_uri:
- ns_uri.text = 'some bullshit about ns'
- with tag('RootElementLocalName'):
- pass
- with tag('Timestamp'):
- pass
- with tag('CallerInformationSystemSignature', NS_1):
- with tag('Signature'):
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement