# Path: wokkel/generic.py
# IQ_GET = '/iq[@type="get"]'
# IQ_SET = '/iq[@type="set"]'
# NS_VERSION = 'jabber:iq:version'
# VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
# def parseXml(string):
# def stripNamespace(rootElement):
#     def strip(element):
#     def connectionInitialized(self):
#     def iqFallback(self, iq):
#     def __init__(self, name, version):
#     def connectionInitialized(self):
#     def onVersion(self, iq):
#     def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
#     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
#     def __init__(self):
#     def __init__(self, recipient=None, sender=None):
#     def fromElement(Class, element):
#     def parseElement(self, element):
#     def toElement(self):
#     def parseElement(self, element):
#     def __init__(self, recipient=None, sender=None, stanzaType=None):
#     def parseRequest(self, element):
#     def toElement(self):
#     def __init__(self, authenticator):
#     def buildProtocol(self, addr):
#     def clientConnectionFailed(self, connector, reason):
# def prepareIDNName(name):
# class FallbackHandler(XMPPHandler):
# class VersionHandler(XMPPHandler):
# class XmlPipe(object):
# class Stanza(object):
# class ErrorStanza(Stanza):
# class Request(Stanza):
# class DeferredXmlStreamFactory(BootstrapMixin, protocol.ClientFactory):
# 
# Path: wokkel/iwokkel.py
# class IDisco(Interface):
#     """
#     Interface for XMPP service discovery.
#     """
# 
#     def getDiscoInfo(requestor, target, nodeIdentifier=''):
#         """
#         Get identity and features from this entity, node.
# 
#         @param requestor: The entity the request originated from.
#         @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param target: The target entity to which the request is made.
#         @type target: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param nodeIdentifier: The optional identifier of the node at this
#             entity to retrieve the identify and features of.  The default is
#             C{''}, meaning the root node.
#         @type nodeIdentifier: C{unicode}
#         """
# 
#     def getDiscoItems(requestor, target, nodeIdentifier=''):
#         """
#         Get contained items for this entity, node.
# 
#         @param requestor: The entity the request originated from.
#         @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param target: The target entity to which the request is made.
#         @type target: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param nodeIdentifier: The optional identifier of the node at this
#                                entity to retrieve the identify and features of.
#                                The default is C{''}, meaning the root node.
#         @type nodeIdentifier: C{unicode}
#         """
# 
# Path: wokkel/test/helpers.py
# class XmlStreamStub(object):
#     """
#     Stub for testing objects that communicate through XML Streams.
# 
#     Instances of this stub hold an object in L{xmlstream} that acts like an
#     L{XmlStream<twisted.words.xish.xmlstream.XmlStream} after connection stream
#     initialization. Stanzas can be sent through it by calling its C{send}
#     method with an object implementing
#     L{IElement<twisted.words.xish.domish.IElement>} as its first argument.
#     These appear in sequence in the L{output} instance variable of the stub.
# 
#     For the reverse direction, stanzas passed to L{send} of the stub, will be
#     dispatched in the stubbed XmlStream as if it was received over the wire, so
#     that registered observers will be called.
# 
#     Example::
# 
#         >>> stub = XmlStreamStub()
#         >>> stub.xmlstream.send(domish.Element((None, 'presence')))
#         >>> stub.output[-1].toXml()
#         u'<presence/>'
#         >>> def cb(stanza):
#         ...     print("Got: %r" stanza.toXml())
#         >>> stub.xmlstream.addObserver('/presence')
#         >>> stub.send(domish.Element((None, 'presence')))
#         Got: u'<presence/>'
# 
#     @ivar xmlstream: Stubbed XML Stream.
#     @type xmlstream: L{EventDispatcher}
#     @ivar output: List of stanzas sent to the XML Stream.
#     @type output: L{list}
#     """
# 
#     def __init__(self):
#         self.output = []
#         self.xmlstream = EventDispatcher()
#         self.xmlstream.send = self.output.append
# 
#     def send(self, obj):
#         """
#         Pass an element to the XML Stream as if received.
# 
#         @param obj: Element to be dispatched to C{self.xmlstream}.
#         @type obj: object implementing
#                    L{IElement<twisted.words.xish.domish.IElement>}.
#         """
#         self.xmlstream.dispatch(obj)


import re
from zope.interface.verify import verifyObject
from twisted.python import deprecate
from twisted.python.compat import unicode
from twisted.trial import unittest
from twisted.trial.util import suppress as SUPPRESS
from twisted.words.xish import domish
from twisted.words.protocols.jabber.jid import JID
from incremental import Version
from wokkel import generic
from wokkel.iwokkel import IDisco
from wokkel.test.helpers import XmlStreamStub
    def test_fromElementChildParserAll(self):
        """
        Child elements for which no parser is defined are ignored.
        """
        xml = """
        <message from='other@example.org' to='user@example.org'>
          <x xmlns='http://example.org/'/>
        </message>
        """

        class Message(generic.Stanza):
            childParsers = {None: '_childParser'}
            elements = []

            def _childParser(self, element):
                self.elements.append(element)

        message = Message.fromElement(generic.parseXml(xml))
        self.assertEqual(1, len(message.elements))


    def test_fromElementChildParserUnknown(self):
        """
        Child elements for which no parser is defined are ignored.
        """
        xml = """
        <message from='other@example.org' to='user@example.org'>
          <x xmlns='http://example.org/'/>
        </message>
        """

# Path: wokkel/generic.py
# IQ_GET = '/iq[@type="get"]'
# IQ_SET = '/iq[@type="set"]'
# NS_VERSION = 'jabber:iq:version'
# VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
# def parseXml(string):
# def stripNamespace(rootElement):
#     def strip(element):
#     def connectionInitialized(self):
#     def iqFallback(self, iq):
#     def __init__(self, name, version):
#     def connectionInitialized(self):
#     def onVersion(self, iq):
#     def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
#     def getDiscoItems(self, requestor, target, nodeIdentifier=''):
#     def __init__(self):
#     def __init__(self, recipient=None, sender=None):
#     def fromElement(Class, element):
#     def parseElement(self, element):
#     def toElement(self):
#     def parseElement(self, element):
#     def __init__(self, recipient=None, sender=None, stanzaType=None):
#     def parseRequest(self, element):
#     def toElement(self):
#     def __init__(self, authenticator):
#     def buildProtocol(self, addr):
#     def clientConnectionFailed(self, connector, reason):
# def prepareIDNName(name):
# class FallbackHandler(XMPPHandler):
# class VersionHandler(XMPPHandler):
# class XmlPipe(object):
# class Stanza(object):
# class ErrorStanza(Stanza):
# class Request(Stanza):
# class DeferredXmlStreamFactory(BootstrapMixin, protocol.ClientFactory):
# 
# Path: wokkel/iwokkel.py
# class IDisco(Interface):
#     """
#     Interface for XMPP service discovery.
#     """
# 
#     def getDiscoInfo(requestor, target, nodeIdentifier=''):
#         """
#         Get identity and features from this entity, node.
# 
#         @param requestor: The entity the request originated from.
#         @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param target: The target entity to which the request is made.
#         @type target: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param nodeIdentifier: The optional identifier of the node at this
#             entity to retrieve the identify and features of.  The default is
#             C{''}, meaning the root node.
#         @type nodeIdentifier: C{unicode}
#         """
# 
#     def getDiscoItems(requestor, target, nodeIdentifier=''):
#         """
#         Get contained items for this entity, node.
# 
#         @param requestor: The entity the request originated from.
#         @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param target: The target entity to which the request is made.
#         @type target: L{JID<twisted.words.protocols.jabber.jid.JID>}
#         @param nodeIdentifier: The optional identifier of the node at this
#                                entity to retrieve the identify and features of.
#                                The default is C{''}, meaning the root node.
#         @type nodeIdentifier: C{unicode}
#         """
# 
# Path: wokkel/test/helpers.py
# class XmlStreamStub(object):
#     """
#     Stub for testing objects that communicate through XML Streams.
# 
#     Instances of this stub hold an object in L{xmlstream} that acts like an
#     L{XmlStream<twisted.words.xish.xmlstream.XmlStream} after connection stream
#     initialization. Stanzas can be sent through it by calling its C{send}
#     method with an object implementing
#     L{IElement<twisted.words.xish.domish.IElement>} as its first argument.
#     These appear in sequence in the L{output} instance variable of the stub.
# 
#     For the reverse direction, stanzas passed to L{send} of the stub, will be
#     dispatched in the stubbed XmlStream as if it was received over the wire, so
#     that registered observers will be called.
# 
#     Example::
# 
#         >>> stub = XmlStreamStub()
#         >>> stub.xmlstream.send(domish.Element((None, 'presence')))
#         >>> stub.output[-1].toXml()
#         u'<presence/>'
#         >>> def cb(stanza):
#         ...     print("Got: %r" stanza.toXml())
#         >>> stub.xmlstream.addObserver('/presence')
#         >>> stub.send(domish.Element((None, 'presence')))
#         Got: u'<presence/>'
# 
#     @ivar xmlstream: Stubbed XML Stream.
#     @type xmlstream: L{EventDispatcher}
#     @ivar output: List of stanzas sent to the XML Stream.
#     @type output: L{list}
#     """
# 
#     def __init__(self):
#         self.output = []
#         self.xmlstream = EventDispatcher()
#         self.xmlstream.send = self.output.append
# 
#     def send(self, obj):
#         """
#         Pass an element to the XML Stream as if received.
# 
#         @param obj: Element to be dispatched to C{self.xmlstream}.
#         @type obj: object implementing
#                    L{IElement<twisted.words.xish.domish.IElement>}.
#         """
#         self.xmlstream.dispatch(obj)


# Path: wokkel/test/test_generic.py
import re
from zope.interface.verify import verifyObject
from twisted.python import deprecate
from twisted.python.compat import unicode
from twisted.trial import unittest
from twisted.trial.util import suppress as SUPPRESS
from twisted.words.xish import domish
from twisted.words.protocols.jabber.jid import JID
from incremental import Version
from wokkel import generic
from wokkel.iwokkel import IDisco
from wokkel.test.helpers import XmlStreamStub

    def test_fromElementChildParserAll(self):
        """
        Child elements for which no parser is defined are ignored.
        """
        xml = """
        <message from='other@example.org' to='user@example.org'>
          <x xmlns='http://example.org/'/>
        </message>
        """

        class Message(generic.Stanza):
            childParsers = {None: '_childParser'}
            elements = []

            def _childParser(self, element):
                self.elements.append(element)

        message = Message.fromElement(generic.parseXml(xml))
        self.assertEqual(1, len(message.elements))


    def test_fromElementChildParserUnknown(self):
        """
        Child elements for which no parser is defined are ignored.
        """
        xml = """
        <message from='other@example.org' to='user@example.org'>
          <x xmlns='http://example.org/'/>
        </message>
        """

        generic.Stanza.fromElement(generic.parseXml(xml))