diff sat/plugins/plugin_misc_tickets.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 989b622faff6
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_tickets.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/plugins/plugin_misc_tickets.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SAT plugin for Pubsub Schemas
@@ -21,7 +21,6 @@
 from sat.core.constants import Const as C
 from twisted.internet import defer
 from sat.tools.common import uri
-from sat.tools import utils
 import shortuuid
 from sat.core.log import getLogger
 
@@ -30,41 +29,47 @@
 NS_TICKETS = "org.salut-a-toi.tickets:0"
 
 PLUGIN_INFO = {
-    C.PI_NAME: _(u"Tickets management"),
-    C.PI_IMPORT_NAME: u"TICKETS",
-    C.PI_TYPE: u"EXP",
+    C.PI_NAME: _("Tickets management"),
+    C.PI_IMPORT_NAME: "TICKETS",
+    C.PI_TYPE: "EXP",
     C.PI_PROTOCOLS: [],
-    C.PI_DEPENDENCIES: [u"XEP-0060", u"PUBSUB_SCHEMA", u"XEP-0277", u"IDENTITY"],
-    C.PI_MAIN: u"Tickets",
-    C.PI_HANDLER: u"no",
-    C.PI_DESCRIPTION: _(u"""Tickets management plugin"""),
+    C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
+    C.PI_MAIN: "Tickets",
+    C.PI_HANDLER: "no",
+    C.PI_DESCRIPTION: _("""Tickets management plugin"""),
 }
 
 
 class Tickets(object):
     def __init__(self, host):
-        log.info(_(u"Tickets plugin initialization"))
+        log.info(_("Tickets plugin initialization"))
         self.host = host
-        host.registerNamespace(u"tickets", NS_TICKETS)
-        self._p = self.host.plugins[u"XEP-0060"]
-        self._s = self.host.plugins[u"PUBSUB_SCHEMA"]
-        self._m = self.host.plugins[u"XEP-0277"]
+        host.registerNamespace("tickets", NS_TICKETS)
+        self._p = self.host.plugins["XEP-0060"]
+        self._s = self.host.plugins["PUBSUB_SCHEMA"]
+        self._m = self.host.plugins["XEP-0277"]
         host.bridge.addMethod(
-            u"ticketsGet",
-            u".plugin",
-            in_sign=u"ssiassa{ss}s",
-            out_sign=u"(asa{ss})",
-            method=utils.partial(
-                self._s._get,
+            "ticketsGet",
+            ".plugin",
+            in_sign="ssiassa{ss}s",
+            out_sign="(asa{ss})",
+            method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key:
+                self._s._get(
+                service,
+                node,
+                max_items,
+                items_ids,
+                sub_id,
+                extra,
                 default_node=NS_TICKETS,
                 form_ns=NS_TICKETS,
                 filters={
-                    u"author": self._s.valueOrPublisherFilter,
-                    u"created": self._s.dateFilter,
-                    u"updated": self._s.dateFilter,
+                    "author": self._s.valueOrPublisherFilter,
+                    "created": self._s.dateFilter,
+                    "updated": self._s.dateFilter,
                 },
-            ),
-            async=True,
+                profile_key=profile_key),
+            async_=True,
         )
         host.bridge.addMethod(
             "ticketSet",
@@ -72,18 +77,20 @@
             in_sign="ssa{sas}ssss",
             out_sign="s",
             method=self._set,
-            async=True,
+            async_=True,
         )
         host.bridge.addMethod(
             "ticketsSchemaGet",
             ".plugin",
             in_sign="sss",
             out_sign="s",
-            method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS),
-            async=True,
+            method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema(
+                service, nodeIdentifier, default_node=NS_TICKETS,
+                profile_key=profile_key),
+            async_=True,
         )
 
-    def _set(self, service, node, values, schema=None, item_id=None, extra=u'',
+    def _set(self, service, node, values, schema=None, item_id=None, extra='',
              profile_key=C.PROF_KEY_NONE):
         client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
             service, node, schema, item_id, extra, profile_key
@@ -91,7 +98,7 @@
         d = self.set(
             client, service, node, values, schema, item_id, extra, deserialise=True
         )
-        d.addCallback(lambda ret: ret or u"")
+        d.addCallback(lambda ret: ret or "")
         return d
 
     @defer.inlineCallbacks
@@ -123,7 +130,7 @@
             # advance (we don't want to set it ourselves to let the server choose, so we
             # can have a nicer id if serial ids is activated)
             comments_node = self._m.getCommentsNode(
-                node + u"_" + unicode(shortuuid.uuid())
+                node + "_" + str(shortuuid.uuid())
             )
             options = {
                 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
@@ -134,8 +141,8 @@
                 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
             }
             yield self._p.createNode(client, comments_service, comments_node, options)
-            values[u"comments_uri"] = uri.buildXMPPUri(
-                u"pubsub",
+            values["comments_uri"] = uri.buildXMPPUri(
+                "pubsub",
                 subtype="microblog",
                 path=comments_service.full(),
                 node=comments_node,