From 63f4cc0daf8f2629e5d0296de2ae8a74f14b0dc1 Mon Sep 17 00:00:00 2001 From: Zaran Date: Thu, 20 Jan 2011 01:54:49 +0100 Subject: Simplification of the object module : now use only one class (maybe add some function back later) Requesting the child items now works Add a zip example of objects for testing --- server/plugin.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'server/plugin.py') diff --git a/server/plugin.py b/server/plugin.py index 62ae958..c3bd81d 100644 --- a/server/plugin.py +++ b/server/plugin.py @@ -1,5 +1,6 @@ import logging import base64 +import hashlib from xml.etree import cElementTree as ET from sleekxmpp.xmlstream.stanzabase import ElementBase, register_stanza_plugin @@ -8,7 +9,8 @@ from sleekxmpp.xmlstream.handler.callback import Callback from sleekxmpp.xmlstream.matcher.xpath import MatchXPath from sleekxmpp.stanza.iq import Iq -import object +from object import Object +from permission import PermissionError class AliasQuery(ElementBase): namespace = 'alias:query' @@ -21,7 +23,7 @@ class AliasQuery(ElementBase): item = AliasItem(None, self) item['node'] = node if permission is not None: - item['permission'] = permission + item['permission'] = str(permission) class AliasItem(ElementBase): namespace = 'alias:query' @@ -38,7 +40,7 @@ class AliasPlugin(base.base_plugin): AliasQuery.namespace)) self.xmpp.register_handler(Callback('Alias queries', query_parser, self.handle_alias_query)) - + def post_init(self): base.base_plugin.post_init(self) self.xmpp.plugin['xep_0030'].add_feature("alias:query") @@ -48,17 +50,19 @@ class AliasPlugin(base.base_plugin): callee = base64.b64decode(iq['to'].user) except TypeError: logging.error("callee field not base64 encoded") - caller = iq['alias']['from'] - handler = object.ObjectHandler(self.config['root'],callee) + caller = iq['from'].bare node = iq['alias']['node'] if not node: - node = handler.get_home_node() + node = hashlib.sha1(callee).hexdigest() + + node = Object(callee, node) + if iq['alias']['type'] == 'items': logging.debug('childs of {} requested'.format(node)) - childs = handler.get_child_list(node, caller) + childs = Object.get_child_list(node, caller) reply = AliasQuery() - reply['node'] = node + reply['node'] = node.hash reply['type'] = 'items' - for child in childs: - reply.addItem(child, "test") + for name, perm in childs: + reply.addItem(name, perm) iq.reply().set_payload(reply).send() \ No newline at end of file -- cgit v1.2.3-70-g09d2