HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python2.7/site-packages/wsdiscovery/actions/bye.py
from ..namespaces import NS_WSA, NS_WSD
from ..envelope import SoapEnvelope
from ..util import createSkelSoapMessage, getBodyEl, getHeaderEl, addElementWithText, \
                   addTypes, addScopes, getDocAsString, getScopes, addEPR, \
                   _parseAppSequence


ACTION_BYE = "http://schemas.xmlsoap.org/ws/2005/04/discovery/Bye"


def createByeMessage(env):
    doc = createSkelSoapMessage(ACTION_BYE)

    bodyEl = getBodyEl(doc)
    headerEl = getHeaderEl(doc)

    addElementWithText(doc, headerEl, "wsa:MessageID", NS_WSA, env.getMessageId())
    addElementWithText(doc, headerEl, "wsa:To", NS_WSA, env.getTo())

    appSeqEl = doc.createElementNS(NS_WSD, "wsd:AppSequence")
    appSeqEl.setAttribute("InstanceId", env.getInstanceId())
    appSeqEl.setAttribute("MessageNumber", env.getMessageNumber())
    headerEl.appendChild(appSeqEl)

    byeEl = doc.createElementNS(NS_WSD, "wsd:Bye")
    addEPR(doc, byeEl, env.getEPR())
    bodyEl.appendChild(byeEl)

    return getDocAsString(doc)


def parseByeMessage(dom):
    env = SoapEnvelope()
    env.setAction(ACTION_BYE)

    try:
        env.setMessageId(dom.getElementsByTagNameNS(NS_WSA, "MessageID")[0].firstChild.data.strip())
        env.setTo(dom.getElementsByTagNameNS(NS_WSA, "To")[0].firstChild.data.strip())

        _parseAppSequence(dom, env)

        env.setEPR(dom.getElementsByTagNameNS(NS_WSA, "Address")[0].firstChild.data.strip())

        return env
    except Exception:
        env = None
        return None