<s> """<STR_LIT>""" <EOL> import mimetools <EOL> from time import gmtime , strftime <EOL> from StringIO import StringIO <EOL> import urllib <EOL> import urlparse <EOL> import simplejson <EOL> from twisted . application import service <EOL> from twisted . internet import defer , reactor <EOL> from twisted . python import log <EOL> from twisted . web import client , http , resource , server <EOL> from twisted . web . error import Error <EOL> from twisted . words . protocols . jabber . jid import JID <EOL> from twisted . words . protocols . jabber . error import StanzaError <EOL> from twisted . words . xish import domish <EOL> from wokkel . generic import parseXml <EOL> from wokkel . pubsub import Item <EOL> from wokkel . pubsub import PubSubClient <EOL> from idavoll import error <EOL> NS_ATOM = '<STR_LIT>' <EOL> MIME_ATOM_ENTRY = b'<STR_LIT>' <EOL> MIME_ATOM_FEED = b'<STR_LIT>' <EOL> MIME_JSON = b'<STR_LIT:application/json>' <EOL> class XMPPURIParseError ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> def getServiceAndNode ( uri ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> scheme , rest = uri . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> raise XMPPURIParseError ( "<STR_LIT>" ) <EOL> if scheme != '<STR_LIT>' : <EOL> raise XMPPURIParseError ( "<STR_LIT>" ) <EOL> if rest . startswith ( "<STR_LIT>" ) : <EOL> raise XMPPURIParseError ( "<STR_LIT>" ) <EOL> try : <EOL> entity , query = rest . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> entity , query = rest , '<STR_LIT>' <EOL> if not entity : <EOL> raise XMPPURIParseError ( "<STR_LIT>" ) <EOL> try : <EOL> service = JID ( entity ) <EOL> except Exception , e : <EOL> raise XMPPURIParseError ( "<STR_LIT>" % e ) <EOL> params = urlparse . parse_qs ( query ) <EOL> try : <EOL> nodeIdentifier = params [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> except ( KeyError , ValueError ) : <EOL> nodeIdentifier = '<STR_LIT>' <EOL> return service , nodeIdentifier <EOL> def getXMPPURI ( service , nodeIdentifier ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % ( service . full ( ) , nodeIdentifier or '<STR_LIT>' ) <EOL> def _parseContentType ( header ) : <EOL> """<STR_LIT>""" <EOL> return mimetools . Message ( StringIO ( b'<STR_LIT>' + header ) ) <EOL> def _asyncResponse ( render ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def wrapped ( self , request ) : <EOL> def eb ( failure ) : <EOL> if failure . check ( Error ) : <EOL> err = failure . value <EOL> else : <EOL> log . err ( failure ) <EOL> err = Error ( <NUM_LIT> ) <EOL> request . setResponseCode ( err . status , err . message ) <EOL> return err . response <EOL> def finish ( result ) : <EOL> if result is server . NOT_DONE_YET : <EOL> return <EOL> if result : <EOL> request . write ( result ) <EOL> request . finish ( ) <EOL> d = defer . maybeDeferred ( render , self , request ) <EOL> d . addErrback ( eb ) <EOL> d . addCallback ( finish ) <EOL> return server . NOT_DONE_YET <EOL> return wrapped <EOL> class CreateResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , backend , serviceJID , owner ) : <EOL> self . backend = backend <EOL> self . serviceJID = serviceJID <EOL> self . owner = owner <EOL> http_GET = None <EOL> @ _asyncResponse <EOL> def render_POST ( self , request ) : <EOL> """<STR_LIT>""" <EOL> def toResponse ( nodeIdentifier ) : <EOL> uri = getXMPPURI ( self . serviceJID , nodeIdentifier ) <EOL> body = simplejson . dumps ( { '<STR_LIT>' : uri } ) <EOL> request . setHeader ( b'<STR_LIT:Content-Type>' , MIME_JSON ) <EOL> return body <EOL> d = self . backend . createNode ( None , self . owner ) <EOL> d . addCallback ( toResponse ) <EOL> return d <EOL> class DeleteResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , backend , serviceJID , owner ) : <EOL> self . backend = backend <EOL> self . serviceJID = serviceJID <EOL> self . owner = owner <EOL> render_GET = None <EOL> @ _asyncResponse <EOL> def render_POST ( self , request ) : <EOL> """<STR_LIT>""" <EOL> def toResponse ( result ) : <EOL> request . setResponseCode ( http . NO_CONTENT ) <EOL> def trapNotFound ( failure ) : <EOL> failure . trap ( error . NodeNotFound ) <EOL> raise Error ( http . NOT_FOUND , "<STR_LIT>" ) <EOL> if not request . args . get ( '<STR_LIT>' ) : <EOL> raise Error ( http . BAD_REQUEST , "<STR_LIT>" ) <EOL> try : <EOL> jid , nodeIdentifier = getServiceAndNode ( request . args [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> except XMPPURIParseError , e : <EOL> raise Error ( http . BAD_REQUEST , "<STR_LIT>" % e ) <EOL> data = request . content . read ( ) <EOL> if data : <EOL> params = simplejson . loads ( data ) <EOL> redirectURI = params . get ( '<STR_LIT>' , None ) <EOL> else : <EOL> redirectURI = None <EOL> d = self . backend . deleteNode ( nodeIdentifier , self . owner , <EOL> redirectURI ) <EOL> d . addCallback ( toResponse ) <EOL> d . addErrback ( trapNotFound ) <EOL> return d <EOL> class PublishResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , backend , serviceJID , owner ) : <EOL> self . backend = backend <EOL> self . serviceJID = serviceJID <EOL> self . owner = owner <EOL> render_GET = None <EOL> def checkMediaType ( self , request ) : <EOL> ctype = request . getHeader ( b'<STR_LIT>' ) <EOL> if not ctype : <EOL> request . setResponseCode ( http . BAD_REQUEST ) <EOL> raise Error ( http . BAD_REQUEST , b"<STR_LIT>" ) <EOL> message = _parseContentType ( ctype ) <EOL> if ( message . maintype != b'<STR_LIT>' or <EOL> message . subtype != b'<STR_LIT>' or <EOL> message . getparam ( b'<STR_LIT:type>' ) != b'<STR_LIT>' or <EOL> ( message . getparam ( b'<STR_LIT>' ) or b'<STR_LIT:utf-8>' ) != b'<STR_LIT:utf-8>' ) : <EOL> raise Error ( http . UNSUPPORTED_MEDIA_TYPE , <EOL> b"<STR_LIT>" % ctype ) <EOL> @ _asyncResponse <EOL> def render_POST ( self , request ) : <EOL> """<STR_LIT>""" <EOL> def toResponse ( nodeIdentifier ) : <EOL> uri = getXMPPURI ( self . serviceJID , nodeIdentifier ) <EOL> body = simplejson . dumps ( { '<STR_LIT>' : uri } ) <EOL> request . setHeader ( b'<STR_LIT:Content-Type>' , MIME_JSON ) <EOL> return body <EOL> def gotNode ( nodeIdentifier , payload ) : <EOL> item = Item ( id = '<STR_LIT>' , payload = payload ) <EOL> d = self . backend . publish ( nodeIdentifier , [ item ] , self . owner ) <EOL> d . addCallback ( lambda _ : nodeIdentifier ) <EOL> return d <EOL> def getNode ( ) : <EOL> if request . args . get ( '<STR_LIT>' ) : <EOL> jid , nodeIdentifier = getServiceAndNode ( request . args [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> return defer . succeed ( nodeIdentifier ) <EOL> else : <EOL> return self . backend . createNode ( None , self . owner ) <EOL> def trapNotFound ( failure ) : <EOL> failure . trap ( error . NodeNotFound ) <EOL> raise Error ( http . NOT_FOUND , "<STR_LIT>" ) <EOL> def trapXMPPURIParseError ( failure ) : <EOL> failure . trap ( XMPPURIParseError ) <EOL> raise Error ( http . BAD_REQUEST , <EOL> "<STR_LIT>" % failure . value ) <EOL> self . checkMediaType ( request ) <EOL> payload = parseXml ( request . content . read ( ) ) <EOL> d = getNode ( ) <EOL> d . addCallback ( gotNode , payload ) <EOL> d . addCallback ( toResponse ) <EOL> d . addErrback ( trapNotFound ) <EOL> d . addErrback ( trapXMPPURIParseError ) <EOL> return d <EOL> class ListResource ( resource . Resource ) : <EOL> def __init__ ( self , service ) : <EOL> self . service = service <EOL> @ _asyncResponse <EOL> def render_GET ( self , request ) : <EOL> def responseFromNodes ( nodeIdentifiers ) : <EOL> body = simplejson . dumps ( nodeIdentifiers ) <EOL> request . setHeader ( b'<STR_LIT:Content-Type>' , MIME_JSON ) <EOL> return body <EOL> d = self . service . getNodes ( ) <EOL> d . addCallback ( responseFromNodes ) <EOL> return d <EOL> def extractAtomEntries ( items ) : <EOL> """<STR_LIT>""" <EOL> atomEntries = [ ] <EOL> for item in items : <EOL> if item . name != '<STR_LIT>' : <EOL> continue <EOL> atomEntry = None <EOL> for element in item . elements ( ) : <EOL> if element . uri == NS_ATOM and element . name == '<STR_LIT>' : <EOL> atomEntry = element <EOL> break <EOL> if atomEntry : <EOL> atomEntries . append ( atomEntry ) <EOL> return atomEntries <EOL> def constructFeed ( service , nodeIdentifier , entries , title ) : <EOL> nodeURI = getXMPPURI ( service , nodeIdentifier ) <EOL> now = strftime ( "<STR_LIT>" , gmtime ( ) ) <EOL> feed = domish . Element ( ( NS_ATOM , '<STR_LIT>' ) ) <EOL> feed . addElement ( '<STR_LIT:title>' , content = title ) <EOL> feed . addElement ( '<STR_LIT:id>' , content = nodeURI ) <EOL> feed . addElement ( '<STR_LIT>' , content = now ) <EOL> for entry in entries : <EOL> feed . addChild ( entry ) <EOL> return feed <EOL> class RemoteSubscriptionService ( service . Service , PubSubClient ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , jid , storage ) : <EOL> self . jid = jid <EOL> self . storage = storage <EOL> def trapNotFound ( self , failure ) : <EOL> failure . trap ( StanzaError ) <EOL> if failure . value . condition == '<STR_LIT>' : <EOL> raise error . NodeNotFound ( ) <EOL> else : <EOL> return failure <EOL> def subscribeCallback ( self , jid , nodeIdentifier , callback ) : <EOL> """<STR_LIT>""" <EOL> def callbackForLastItem ( items ) : <EOL> atomEntries = extractAtomEntries ( items ) <EOL> if not atomEntries : <EOL> return <EOL> self . _postTo ( [ callback ] , jid , nodeIdentifier , atomEntries [ <NUM_LIT:0> ] , <EOL> MIME_ATOM_ENTRY ) <EOL> def subscribeOrItems ( hasCallbacks ) : <EOL> if hasCallbacks : <EOL> if not nodeIdentifier : <EOL> return None <EOL> d = self . items ( jid , nodeIdentifier , <NUM_LIT:1> ) <EOL> d . addCallback ( callbackForLastItem ) <EOL> else : <EOL> d = self . subscribe ( jid , nodeIdentifier , self . jid ) <EOL> d . addErrback ( self . trapNotFound ) <EOL> return d <EOL> d = self . storage . hasCallbacks ( jid , nodeIdentifier ) <EOL> d . addCallback ( subscribeOrItems ) <EOL> d . addCallback ( lambda _ : self . storage . addCallback ( jid , nodeIdentifier , <EOL> callback ) ) <EOL> return d <EOL> def unsubscribeCallback ( self , jid , nodeIdentifier , callback ) : <EOL> """<STR_LIT>""" <EOL> def cb ( last ) : <EOL> if last : <EOL> return self . unsubscribe ( jid , nodeIdentifier , self . jid ) <EOL> d = self . storage . removeCallback ( jid , nodeIdentifier , callback ) <EOL> d . addCallback ( cb ) <EOL> return d <EOL> def itemsReceived ( self , event ) : <EOL> """<STR_LIT>""" <EOL> atomEntries = extractAtomEntries ( event . items ) <EOL> service = event . sender <EOL> nodeIdentifier = event . nodeIdentifier <EOL> headers = event . headers <EOL> if not atomEntries : <EOL> return <EOL> if len ( atomEntries ) == <NUM_LIT:1> : <EOL> contentType = MIME_ATOM_ENTRY <EOL> payload = atomEntries [ <NUM_LIT:0> ] <EOL> else : <EOL> contentType = MIME_ATOM_FEED <EOL> payload = constructFeed ( service , nodeIdentifier , atomEntries , <EOL> title = '<STR_LIT>' ) <EOL> self . callCallbacks ( service , nodeIdentifier , payload , contentType ) <EOL> if '<STR_LIT>' in headers : <EOL> for collection in headers [ '<STR_LIT>' ] : <EOL> nodeIdentifier = collection or '<STR_LIT>' <EOL> self . callCallbacks ( service , nodeIdentifier , payload , <EOL> contentType ) <EOL> def deleteReceived ( self , event ) : <EOL> """<STR_LIT>""" <EOL> service = event . sender <EOL> nodeIdentifier = event . nodeIdentifier <EOL> redirectURI = event . redirectURI <EOL> self . callCallbacks ( service , nodeIdentifier , eventType = '<STR_LIT>' , <EOL> redirectURI = redirectURI ) <EOL> def _postTo ( self , callbacks , service , nodeIdentifier , <EOL> payload = None , contentType = None , eventType = None , <EOL> redirectURI = None ) : <EOL> if not callbacks : <EOL> return <EOL> postdata = None <EOL> nodeURI = getXMPPURI ( service , nodeIdentifier ) <EOL> headers = { '<STR_LIT>' : nodeURI . encode ( '<STR_LIT:utf-8>' ) , <EOL> '<STR_LIT>' : service . full ( ) . encode ( '<STR_LIT:utf-8>' ) } <EOL> if payload : <EOL> postdata = payload . toXml ( ) . encode ( '<STR_LIT:utf-8>' ) <EOL> if contentType : <EOL> headers [ '<STR_LIT:Content-Type>' ] = "<STR_LIT>" % contentType <EOL> if eventType : <EOL> headers [ '<STR_LIT>' ] = eventType <EOL> if redirectURI : <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' % ( <EOL> redirectURI . encode ( '<STR_LIT:utf-8>' ) , <EOL> ) <EOL> def postNotification ( callbackURI ) : <EOL> f = getPageWithFactory ( str ( callbackURI ) , <EOL> method = '<STR_LIT:POST>' , <EOL> postdata = postdata , <EOL> headers = headers ) <EOL> d = f . deferred <EOL> d . addErrback ( log . err ) <EOL> for callbackURI in callbacks : <EOL> reactor . callLater ( <NUM_LIT:0> , postNotification , callbackURI ) <EOL> def callCallbacks ( self , service , nodeIdentifier , <EOL> payload = None , contentType = None , eventType = None , <EOL> redirectURI = None ) : <EOL> def eb ( failure ) : <EOL> failure . trap ( error . NoCallbacks ) <EOL> d = self . storage . getCallbacks ( service , nodeIdentifier ) <EOL> d . addCallback ( self . _postTo , service , nodeIdentifier , payload , <EOL> contentType , eventType , redirectURI ) <EOL> d . addErrback ( eb ) <EOL> d . addErrback ( log . err ) <EOL> class RemoteSubscribeBaseResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> serviceMethod = None <EOL> errorMap = { <EOL> error . NodeNotFound : <EOL> ( http . FORBIDDEN , "<STR_LIT>" ) , <EOL> error . NotSubscribed : <EOL> ( http . FORBIDDEN , "<STR_LIT>" ) , <EOL> error . SubscriptionExists : <EOL> ( http . FORBIDDEN , "<STR_LIT>" ) , <EOL> } <EOL> def __init__ ( self , service ) : <EOL> self . service = service <EOL> self . params = None <EOL> render_GET = None <EOL> @ _asyncResponse <EOL> def render_POST ( self , request ) : <EOL> def trapNotFound ( failure ) : <EOL> err = failure . trap ( * self . errorMap . keys ( ) ) <EOL> status , message = self . errorMap [ err ] <EOL> raise Error ( status , message ) <EOL> def toResponse ( result ) : <EOL> request . setResponseCode ( http . NO_CONTENT ) <EOL> return b'<STR_LIT>' <EOL> def trapXMPPURIParseError ( failure ) : <EOL> failure . trap ( XMPPURIParseError ) <EOL> raise Error ( http . BAD_REQUEST , <EOL> "<STR_LIT>" % failure . value ) <EOL> data = request . content . read ( ) <EOL> self . params = simplejson . loads ( data ) <EOL> uri = self . params [ '<STR_LIT>' ] <EOL> callback = self . params [ '<STR_LIT>' ] <EOL> jid , nodeIdentifier = getServiceAndNode ( uri ) <EOL> method = getattr ( self . service , self . serviceMethod ) <EOL> d = method ( jid , nodeIdentifier , callback ) <EOL> d . addCallback ( toResponse ) <EOL> d . addErrback ( trapNotFound ) <EOL> d . addErrback ( trapXMPPURIParseError ) <EOL> return d <EOL> class RemoteSubscribeResource ( RemoteSubscribeBaseResource ) : <EOL> """<STR_LIT>""" <EOL> serviceMethod = '<STR_LIT>' <EOL> class RemoteUnsubscribeResource ( RemoteSubscribeBaseResource ) : <EOL> """<STR_LIT>""" <EOL> serviceMethod = '<STR_LIT>' <EOL> class RemoteItemsResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , service ) : <EOL> self . service = service <EOL> @ _asyncResponse <EOL> def render_GET ( self , request ) : <EOL> try : <EOL> maxItems = int ( request . args . get ( '<STR_LIT>' , [ <NUM_LIT:0> ] ) [ <NUM_LIT:0> ] ) or None <EOL> except ValueError : <EOL> raise Error ( http . BAD_REQUEST , <EOL> "<STR_LIT>" ) <EOL> try : <EOL> uri = request . args [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> raise Error ( http . BAD_REQUEST , <EOL> "<STR_LIT>" ) <EOL> try : <EOL> jid , nodeIdentifier = getServiceAndNode ( uri ) <EOL> except XMPPURIParseError : <EOL> raise Error ( http . BAD_REQUEST , <EOL> "<STR_LIT>" % uri ) <EOL> def toResponse ( items ) : <EOL> """<STR_LIT>""" <EOL> atomEntries = extractAtomEntries ( items ) <EOL> feed = constructFeed ( jid , nodeIdentifier , atomEntries , <EOL> "<STR_LIT>" ) <EOL> body = feed . toXml ( ) . encode ( '<STR_LIT:utf-8>' ) <EOL> request . setHeader ( b'<STR_LIT:Content-Type>' , MIME_ATOM_FEED ) <EOL> return body <EOL> def trapNotFound ( failure ) : <EOL> failure . trap ( StanzaError ) <EOL> if not failure . value . condition == '<STR_LIT>' : <EOL> raise failure <EOL> raise Error ( http . NOT_FOUND , "<STR_LIT>" ) <EOL> d = self . service . items ( jid , nodeIdentifier , maxItems ) <EOL> d . addCallback ( toResponse ) <EOL> d . addErrback ( trapNotFound ) <EOL> return d <EOL> def getPageWithFactory ( url , contextFactory = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> factory = client . HTTPClientFactory ( url , * args , ** kwargs ) <EOL> factory . protocol . handleStatus_204 = lambda self : self . handleStatus_200 ( ) <EOL> if factory . scheme == '<STR_LIT>' : <EOL> from twisted . internet import ssl <EOL> if contextFactory is None : <EOL> contextFactory = ssl . ClientContextFactory ( ) <EOL> reactor . connectSSL ( factory . host , factory . port , factory , contextFactory ) <EOL> else : <EOL> reactor . connectTCP ( factory . host , factory . port , factory ) <EOL> return factory <EOL> class CallbackResource ( resource . Resource ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , callback ) : <EOL> self . callback = callback <EOL> http_GET = None <EOL> def render_POST ( self , request ) : <EOL> if request . requestHeaders . hasHeader ( b'<STR_LIT>' ) : <EOL> payload = None <EOL> else : <EOL> payload = parseXml ( request . content . read ( ) ) <EOL> self . callback ( payload , request . requestHeaders ) <EOL> request . setResponseCode ( http . NO_CONTENT ) <EOL> return b'<STR_LIT>' <EOL> class GatewayClient ( service . Service ) : <EOL> """<STR_LIT>""" <EOL> agent = "<STR_LIT>" <EOL> def __init__ ( self , baseURI , callbackHost = None , callbackPort = None ) : <EOL> self . baseURI = baseURI <EOL> self . callbackHost = callbackHost or '<STR_LIT:localhost>' <EOL> self . callbackPort = callbackPort or <NUM_LIT> <EOL> root = resource . Resource ( ) <EOL> root . putChild ( '<STR_LIT>' , CallbackResource ( <EOL> lambda * args , ** kwargs : self . callback ( * args , ** kwargs ) ) ) <EOL> self . site = server . Site ( root ) <EOL> def startService ( self ) : <EOL> self . port = reactor . listenTCP ( self . callbackPort , <EOL> self . site ) <EOL> def stopService ( self ) : <EOL> return self . port . stopListening ( ) <EOL> def _makeURI ( self , verb , query = None ) : <EOL> uriComponents = urlparse . urlparse ( self . baseURI ) <EOL> uri = urlparse . urlunparse ( ( uriComponents [ <NUM_LIT:0> ] , <EOL> uriComponents [ <NUM_LIT:1> ] , <EOL> uriComponents [ <NUM_LIT:2> ] + verb , <EOL> '<STR_LIT>' , <EOL> query and urllib . urlencode ( query ) or '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> return uri <EOL> def callback ( self , data , headers ) : <EOL> pass <EOL> def ping ( self ) : <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT>' , <EOL> agent = self . agent ) <EOL> return f . deferred <EOL> def create ( self ) : <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> agent = self . agent ) <EOL> return f . deferred . addCallback ( simplejson . loads ) <EOL> def delete ( self , xmppURI , redirectURI = None ) : <EOL> query = { '<STR_LIT>' : xmppURI } <EOL> if redirectURI : <EOL> params = { '<STR_LIT>' : redirectURI } <EOL> postdata = simplejson . dumps ( params ) <EOL> headers = { '<STR_LIT:Content-Type>' : MIME_JSON } <EOL> else : <EOL> postdata = None <EOL> headers = None <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' , query ) , <EOL> method = '<STR_LIT:POST>' , <EOL> postdata = postdata , <EOL> headers = headers , <EOL> agent = self . agent ) <EOL> return f . deferred <EOL> def publish ( self , entry , xmppURI = None ) : <EOL> query = xmppURI and { '<STR_LIT>' : xmppURI } <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' , query ) , <EOL> method = '<STR_LIT:POST>' , <EOL> postdata = entry . toXml ( ) . encode ( '<STR_LIT:utf-8>' ) , <EOL> headers = { '<STR_LIT:Content-Type>' : MIME_ATOM_ENTRY } , <EOL> agent = self . agent ) <EOL> return f . deferred . addCallback ( simplejson . loads ) <EOL> def listNodes ( self ) : <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT:list>' ) , <EOL> method = '<STR_LIT:GET>' , <EOL> agent = self . agent ) <EOL> return f . deferred . addCallback ( simplejson . loads ) <EOL> def subscribe ( self , xmppURI ) : <EOL> params = { '<STR_LIT>' : xmppURI , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( self . callbackHost , <EOL> self . callbackPort ) } <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> postdata = simplejson . dumps ( params ) , <EOL> headers = { '<STR_LIT:Content-Type>' : MIME_JSON } , <EOL> agent = self . agent ) <EOL> return f . deferred <EOL> def unsubscribe ( self , xmppURI ) : <EOL> params = { '<STR_LIT>' : xmppURI , <EOL> '<STR_LIT>' : '<STR_LIT>' % ( self . callbackHost , <EOL> self . callbackPort ) } <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' ) , <EOL> method = '<STR_LIT:POST>' , <EOL> postdata = simplejson . dumps ( params ) , <EOL> headers = { '<STR_LIT:Content-Type>' : MIME_JSON } , <EOL> agent = self . agent ) <EOL> return f . deferred <EOL> def items ( self , xmppURI , maxItems = None ) : <EOL> query = { '<STR_LIT>' : xmppURI } <EOL> if maxItems : <EOL> query [ '<STR_LIT>' ] = int ( maxItems ) <EOL> f = getPageWithFactory ( self . _makeURI ( '<STR_LIT>' , query ) , <EOL> method = '<STR_LIT:GET>' , <EOL> agent = self . agent ) <EOL> return f . deferred </s>
