Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT plugin for Pubsub Schemas | 4 # SAT plugin for Pubsub Schemas |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from twisted.internet import defer | 22 from twisted.internet import defer |
23 from sat.tools.common import uri | 23 from sat.tools.common import uri |
24 from sat.tools import utils | |
25 import shortuuid | 24 import shortuuid |
26 from sat.core.log import getLogger | 25 from sat.core.log import getLogger |
27 | 26 |
28 log = getLogger(__name__) | 27 log = getLogger(__name__) |
29 | 28 |
30 NS_TICKETS = "org.salut-a-toi.tickets:0" | 29 NS_TICKETS = "org.salut-a-toi.tickets:0" |
31 | 30 |
32 PLUGIN_INFO = { | 31 PLUGIN_INFO = { |
33 C.PI_NAME: _(u"Tickets management"), | 32 C.PI_NAME: _("Tickets management"), |
34 C.PI_IMPORT_NAME: u"TICKETS", | 33 C.PI_IMPORT_NAME: "TICKETS", |
35 C.PI_TYPE: u"EXP", | 34 C.PI_TYPE: "EXP", |
36 C.PI_PROTOCOLS: [], | 35 C.PI_PROTOCOLS: [], |
37 C.PI_DEPENDENCIES: [u"XEP-0060", u"PUBSUB_SCHEMA", u"XEP-0277", u"IDENTITY"], | 36 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"], |
38 C.PI_MAIN: u"Tickets", | 37 C.PI_MAIN: "Tickets", |
39 C.PI_HANDLER: u"no", | 38 C.PI_HANDLER: "no", |
40 C.PI_DESCRIPTION: _(u"""Tickets management plugin"""), | 39 C.PI_DESCRIPTION: _("""Tickets management plugin"""), |
41 } | 40 } |
42 | 41 |
43 | 42 |
44 class Tickets(object): | 43 class Tickets(object): |
45 def __init__(self, host): | 44 def __init__(self, host): |
46 log.info(_(u"Tickets plugin initialization")) | 45 log.info(_("Tickets plugin initialization")) |
47 self.host = host | 46 self.host = host |
48 host.registerNamespace(u"tickets", NS_TICKETS) | 47 host.registerNamespace("tickets", NS_TICKETS) |
49 self._p = self.host.plugins[u"XEP-0060"] | 48 self._p = self.host.plugins["XEP-0060"] |
50 self._s = self.host.plugins[u"PUBSUB_SCHEMA"] | 49 self._s = self.host.plugins["PUBSUB_SCHEMA"] |
51 self._m = self.host.plugins[u"XEP-0277"] | 50 self._m = self.host.plugins["XEP-0277"] |
52 host.bridge.addMethod( | 51 host.bridge.addMethod( |
53 u"ticketsGet", | 52 "ticketsGet", |
54 u".plugin", | 53 ".plugin", |
55 in_sign=u"ssiassa{ss}s", | 54 in_sign="ssiassa{ss}s", |
56 out_sign=u"(asa{ss})", | 55 out_sign="(asa{ss})", |
57 method=utils.partial( | 56 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key: |
58 self._s._get, | 57 self._s._get( |
58 service, | |
59 node, | |
60 max_items, | |
61 items_ids, | |
62 sub_id, | |
63 extra, | |
59 default_node=NS_TICKETS, | 64 default_node=NS_TICKETS, |
60 form_ns=NS_TICKETS, | 65 form_ns=NS_TICKETS, |
61 filters={ | 66 filters={ |
62 u"author": self._s.valueOrPublisherFilter, | 67 "author": self._s.valueOrPublisherFilter, |
63 u"created": self._s.dateFilter, | 68 "created": self._s.dateFilter, |
64 u"updated": self._s.dateFilter, | 69 "updated": self._s.dateFilter, |
65 }, | 70 }, |
66 ), | 71 profile_key=profile_key), |
67 async=True, | 72 async_=True, |
68 ) | 73 ) |
69 host.bridge.addMethod( | 74 host.bridge.addMethod( |
70 "ticketSet", | 75 "ticketSet", |
71 ".plugin", | 76 ".plugin", |
72 in_sign="ssa{sas}ssss", | 77 in_sign="ssa{sas}ssss", |
73 out_sign="s", | 78 out_sign="s", |
74 method=self._set, | 79 method=self._set, |
75 async=True, | 80 async_=True, |
76 ) | 81 ) |
77 host.bridge.addMethod( | 82 host.bridge.addMethod( |
78 "ticketsSchemaGet", | 83 "ticketsSchemaGet", |
79 ".plugin", | 84 ".plugin", |
80 in_sign="sss", | 85 in_sign="sss", |
81 out_sign="s", | 86 out_sign="s", |
82 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS), | 87 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema( |
83 async=True, | 88 service, nodeIdentifier, default_node=NS_TICKETS, |
89 profile_key=profile_key), | |
90 async_=True, | |
84 ) | 91 ) |
85 | 92 |
86 def _set(self, service, node, values, schema=None, item_id=None, extra=u'', | 93 def _set(self, service, node, values, schema=None, item_id=None, extra='', |
87 profile_key=C.PROF_KEY_NONE): | 94 profile_key=C.PROF_KEY_NONE): |
88 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( | 95 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( |
89 service, node, schema, item_id, extra, profile_key | 96 service, node, schema, item_id, extra, profile_key |
90 ) | 97 ) |
91 d = self.set( | 98 d = self.set( |
92 client, service, node, values, schema, item_id, extra, deserialise=True | 99 client, service, node, values, schema, item_id, extra, deserialise=True |
93 ) | 100 ) |
94 d.addCallback(lambda ret: ret or u"") | 101 d.addCallback(lambda ret: ret or "") |
95 return d | 102 return d |
96 | 103 |
97 @defer.inlineCallbacks | 104 @defer.inlineCallbacks |
98 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, | 105 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, |
99 deserialise=False, form_ns=NS_TICKETS): | 106 deserialise=False, form_ns=NS_TICKETS): |
121 | 128 |
122 # we need to use uuid for comments node, because we don't know item id in | 129 # we need to use uuid for comments node, because we don't know item id in |
123 # advance (we don't want to set it ourselves to let the server choose, so we | 130 # advance (we don't want to set it ourselves to let the server choose, so we |
124 # can have a nicer id if serial ids is activated) | 131 # can have a nicer id if serial ids is activated) |
125 comments_node = self._m.getCommentsNode( | 132 comments_node = self._m.getCommentsNode( |
126 node + u"_" + unicode(shortuuid.uuid()) | 133 node + "_" + str(shortuuid.uuid()) |
127 ) | 134 ) |
128 options = { | 135 options = { |
129 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, | 136 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, |
130 self._p.OPT_PERSIST_ITEMS: 1, | 137 self._p.OPT_PERSIST_ITEMS: 1, |
131 self._p.OPT_MAX_ITEMS: -1, | 138 self._p.OPT_MAX_ITEMS: -1, |
132 self._p.OPT_DELIVER_PAYLOADS: 1, | 139 self._p.OPT_DELIVER_PAYLOADS: 1, |
133 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, | 140 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
134 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, | 141 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
135 } | 142 } |
136 yield self._p.createNode(client, comments_service, comments_node, options) | 143 yield self._p.createNode(client, comments_service, comments_node, options) |
137 values[u"comments_uri"] = uri.buildXMPPUri( | 144 values["comments_uri"] = uri.buildXMPPUri( |
138 u"pubsub", | 145 "pubsub", |
139 subtype="microblog", | 146 subtype="microblog", |
140 path=comments_service.full(), | 147 path=comments_service.full(), |
141 node=comments_node, | 148 node=comments_node, |
142 ) | 149 ) |
143 | 150 |