pubsubclient: diff 41906b05 1b6830d4

Branch: master

Commit: 41906b059c77f333e007c6f77fa29b6ed4e55c66

Author: Chris Warburton <chriswarbo@gmail.com>
Date: Tue Sep 22 01:00:33 PM UTC 2015
Parent: 1b6830d43833aa36ad18d4a0b317d8871110c9d5
Log message:

    Pushing old changes

    1: diff --git a/.gitignore b/.gitignore
    2: new file mode 100644
    3: index 0000000..f7b6735
    4: --- /dev/null
    5: +++ b/.gitignore
    6: @@ -0,0 +1,2 @@
    7: +*.pyc
    8: +report
    9: diff --git a/pubsubclient.py b/pubsubclient.py
   10: index 16545f5..627c06f 100644
   11: --- a/pubsubclient.py
   12: +++ b/pubsubclient.py
   13: @@ -688,10 +688,8 @@ class PubSubClient(object):
   14:  		print "Sending"
   15:  		self.send(stanza, handler, return_function)
   16:  
   17: -	def delete_an_item_from_a_node(self, server, node, item_id, jid=None, return_function=None, stanza_id=None):		#FIXME NO HANDLER
   18: -		"""Removes the item with ID item_id from node at server.
   19: -
   20: -		Replies are not handled yet."""
   21: +	def delete_an_item_from_a_node(self, server, node, item_id, jid=None, return_function=None, stanza_id=None):
   22: +		"""Removes the item with ID item_id from node at server."""
   23:  		#<iq type='set'
   24:  		#    from='us'
   25:  		#    to='them'>
   26: @@ -770,7 +768,7 @@ class PubSubClient(object):
   27:  
   28:  		self.send(stanza, handler, return_function)
   29:  
   30: -	def entity_request_instant_node(self, server, return_function=None, stanza_id=None):		#FIXME NO HANDLER
   31: +	def entity_request_instant_node(self, server, return_function=None, stanza_id=None):
   32:  		"""Asks the given server for an instant node (ie. one without
   33:  		a predetermined name/id)."""
   34:  		#<iq type='set' from='us' to='them'>
   35: @@ -781,7 +779,7 @@ class PubSubClient(object):
   36:  		#</iq>
   37:  		self.request_node(server, None, "leaf", None, None, return_function, stanza_id)
   38:  
   39: -	def get_new_leaf_node(self, server, node, parent, options, return_function=None, stanza_id=None):		#FIXME NO HANDLER
   40: +	def get_new_leaf_node(self, server, node, parent, options, return_function=None, stanza_id=None):
   41:  		"""Requests a new leaf node (which can store items) with name
   42:  		node, as a sub-node of the node parent on server.
   43:  
   44: @@ -796,7 +794,7 @@ class PubSubClient(object):
   45:  		#</iq>
   46:  		self.request_node(server, node, "leaf", parent, options, return_function, stanza_id)
   47:  
   48: -	def get_new_collection_node(self, server, node, parent, options, return_function=None, stanza_id=None):		#FIXME NO HANDLER
   49: +	def get_new_collection_node(self, server, node, parent, options, return_function=None, stanza_id=None):
   50:  		"""Requests a new collection node (which can store nodes) with
   51:  		name node, as a sub-node of the node parent on server.
   52:  
   53: @@ -1019,10 +1017,8 @@ class PubSubClient(object):
   54:  
   55:  		self.send(stanza, handler, return_function)
   56:  
   57: -	def purge_all_items_from_a_node(self, server, node, return_function=None, stanza_id=None):		#FIXME NO HANDLER
   58: -		"""Remove every item which has been published to node on server.
   59: -
   60: -		Replies are not yet handled."""
   61: +	def purge_all_items_from_a_node(self, server, node, return_function=None, stanza_id=None):
   62: +		"""Remove every item which has been published to node on server."""
   63:  		#<iq type='set'
   64:  		#    from='us'
   65:  		#    to='them'>
   66: @@ -1035,7 +1031,15 @@ class PubSubClient(object):
   67:  		purge = SubElement(pubsub, 'purge', attrib={'node':str(node)})
   68:  
   69:  		def handler(stanza, callback):
   70: -			print etree.tostring(stanza)
   71: +			#<iq type='result'
   72: +			#    from='pubsub.shakespeare.lit'
   73: +			#    id='purge1'/>
   74: +			if callback is not None:
   75: +				if stanza.get('type') == 'result':
   76: +					reply = True
   77: +				else:
   78: +					reply = False
   79: +				callback(reply)
   80:  
   81:  		self.send(stanza, handler, return_function)
   82:  
   83: @@ -1055,6 +1059,23 @@ class PubSubClient(object):
   84:  		command = SubElement(stanza, 'command', attrib={'xmlns':'http://jabber.org/protocol/commands', 'node':'http://jabber.org/protocol/pubsub#get-pending', 'action':'execute'})
   85:  
   86:  		def handler(stanza, callback):
   87: +			#<iq type='result'
   88: +			#    from='pubsub.shakespeare.lit'
   89: +			#    to='hamlet@denmark.lit/elsinore'
   90: +			#    id='pending1'>
   91: +			#  <command xmlns='http://jabber.org/protocol/commands'
   92: +			#           sessionid='pubsub-get-pending:20031021T150901Z-600'
   93: +			#           node='http://jabber.org/protocol/pubsub#get-pending'
   94: +			#           status='executing'
   95: +			#           action='execute'>
   96: +			#    <x xmlns='jabber:x:data' type='form'>
   97: +			#      <field type='list-single' var='pubsub#node'>
   98: +			#        <option><value>princely_musings</value></option>
   99: +			#        <option><value>news_from_elsinore</value></option>
  100: +			#      </field>
  101: +			#    </x>
  102: +			#  </command>
  103: +			#</iq>
  104:  			print etree.tostring(stanza)
  105:  
  106:  		self.send(stanza, handler, return_function)
  107: @@ -1193,13 +1214,12 @@ class PubSubClient(object):
  108:  
  109:  		self.send(stanza, handler, return_function)
  110:  
  111: -	def modify_affiliation(self, server, node, affiliations, return_function=None, stanza_id=None):		#FIXME NO HANDLER
  112: +	def modify_affiliation(self, server, node, affiliations, return_function=None, stanza_id=None):
  113:  		"""Tells server to change the affiliation of some entities to
  114:  		the node node. affiliations is a dictionary of the form:
  115:  
  116:  		{JID1:affiliation_type, JID2:affiliation_type, ...}
  117: -
  118: -		Replies are not yet handled."""
  119: +		"""
  120:  		#<iq type='set'
  121:  		#    from='us'
  122:  		#    to='them'>
  123: @@ -1216,12 +1236,12 @@ class PubSubClient(object):
  124:  			affiliations_element.append(Element('affiliation', attrib={'jid':str(current_affiliation), 'affiliation':affiliations[current_affiliation]}))
  125:  
  126:  		def handler(stanza, callback):
  127: -			print etree.tostring(stanza)
  128:  			if callback is not None:
  129:  				if stanza.get("type") == "result":
  130: -					callback(0)
  131: +					reply = True
  132:  				else:
  133: -					callback("error")
  134: +					reply = False
  135: +				callback(reply)
  136:  
  137:  		self.send(stanza, handler, return_function)
  138:  
  139: @@ -1773,3 +1793,7 @@ class Item(object):
  140:  		self.name = name
  141:  		self.jid = jid
  142:  		self.node = node
  143: +
  144: +class Form(object):
  145: +	"""A form stores a list of fields, which can contain a list of
  146: +	values. Each field and value is accessed with
  147: diff --git a/test.py b/test.py
  148: new file mode 100644
  149: index 0000000..8469faa
  150: --- /dev/null
  151: +++ b/test.py
  152: @@ -0,0 +1,40 @@
  153: +#!/usr/bin/env python
  154: +import pubsubclient
  155: +import time
  156: +
  157: +# This will run when we get a reply
  158: +def handle_nodes(node_list):
  159: +	# This function should take one argument, a list of pubsubclient.Node objects
  160: +	global client
  161: +	# We've received a reply, so reduce the amount we're waiting for by one
  162: +	global wait
  163: +	wait -= 1
  164: +
  165: +	for node in node_list:
  166: +		print "Found node " + str(node)		# str on a Node will give its name/ID
  167: +		# Now we can request this Node's children
  168: +		# We need to supply a PubSubClient to use and a return function
  169: +		node.get_sub_nodes(client, handle_nodes)
  170: +		# We're now waiting for another reply, so increment wait
  171: +		wait += 1
  172: +
  173: +
  174: +global wait
  175: +global client
  176: +# Make a client
  177: +client = pubsubclient.PubSubClient("test1@localhost", "test")
  178: +# Log on
  179: +client.connect()
  180: +
  181: +# The following line requests the top-level nodes on aserver.com and makes handle_nodes the return function
  182: +client.get_nodes('pubsub.localhost', node=None, return_function=handle_nodes)
  183: +
  184: +# This keeps track of how many replies we are waiting on
  185: +# Needs to be global since we're using it in the function too
  186: +wait = 1
  187: +while wait > 0:
  188: +	# Handle any replies
  189: +	client.process()
  190: +	# Wait for a second
  191: +	time.sleep(1)
  192: +# Now we can close

Generated by git2html.