from sleekxmpp.xmlstream import ElementBase, ET, JID, register_stanza_plugin
from sleekxmpp import Iq
from sleekxmpp.plugins.base import base_plugin
from sleekxmpp.xmlstream.handler.callback import Callback
from sleekxmpp.xmlstream.matcher.xpath import MatchXPath

class upload(base_plugin):

    def plugin_init(self):
        self.description = "upload files via http"
        self.xep = "0999"
        self.xmpp['xep_0030'].add_feature("eu:siacs:conversations:http:upload")
        self.xmpp['xep_0030'].add_identity(category='store', itype='file', name='HTTP File Upload')
        self.xmpp.register_handler(
            Callback('Upload request',
                MatchXPath('{%s}iq/{eu:siacs:conversations:http:upload}request' % self.xmpp.default_ns),
                self._handleUpload))
        register_stanza_plugin(Iq, UploadRequest)
        register_stanza_plugin(Iq, UploadSlot)


    def _handleUpload(self, iq):
        if iq['type'] == 'get':
            self.xmpp.event('request_upload_slot',iq)


class UploadRequest(ElementBase):
    namespace = "eu:siacs:conversations:http:upload"
    name = "request"
    plugin_attrib = "request"
    interfaces = set(('size','filename'))
    sub_interfaces = interfaces

class UploadSlot(ElementBase):
    namespace = "eu:siacs:conversations:http:upload"
    name = "slot"
    plugin_attrib = "slot"
    interfaces = set(('put','get'))
    sub_interfaces = interfaces

@@ -433,38 +433,24 @@
 eature(%22
-eu:siacs:conversations
+urn:xmpp
 :http:up
@@ -667,38 +667,24 @@
 %7B%25s%7Diq/%7B
-eu:siacs:conversations
+urn:xmpp
 :http:up
@@ -1030,38 +1030,24 @@
 pace = %22
-eu:siacs:conversations
+urn:xmpp
 :http:up
@@ -1230,30 +1230,16 @@
  = %22
-eu:siacs:conversations
+urn:xmpp
 :htt

use namespace from XEP