Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_invitation_file.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 | b256e90612d0 |
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 to detect language (experimental) | 4 # SAT plugin to detect language (experimental) |
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 |
29 PLUGIN_INFO = { | 29 PLUGIN_INFO = { |
30 C.PI_NAME: "File Sharing Invitation", | 30 C.PI_NAME: "File Sharing Invitation", |
31 C.PI_IMPORT_NAME: "FILE_SHARING_INVITATION", | 31 C.PI_IMPORT_NAME: "FILE_SHARING_INVITATION", |
32 C.PI_TYPE: "EXP", | 32 C.PI_TYPE: "EXP", |
33 C.PI_PROTOCOLS: [], | 33 C.PI_PROTOCOLS: [], |
34 C.PI_DEPENDENCIES: ["XEP-0329", u"INVITATION"], | 34 C.PI_DEPENDENCIES: ["XEP-0329", "INVITATION"], |
35 C.PI_RECOMMENDATIONS: [], | 35 C.PI_RECOMMENDATIONS: [], |
36 C.PI_MAIN: "FileSharingInvitation", | 36 C.PI_MAIN: "FileSharingInvitation", |
37 C.PI_HANDLER: "no", | 37 C.PI_HANDLER: "no", |
38 C.PI_DESCRIPTION: _(u"Experimental handling of invitations for file sharing"), | 38 C.PI_DESCRIPTION: _("Experimental handling of invitations for file sharing"), |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 class FileSharingInvitation(object): | 42 class FileSharingInvitation(object): |
43 | 43 |
44 def __init__(self, host): | 44 def __init__(self, host): |
45 log.info(_(u"File Sharing Invitation plugin initialization")) | 45 log.info(_("File Sharing Invitation plugin initialization")) |
46 self.host = host | 46 self.host = host |
47 ns_fis = host.getNamespace(u"fis") | 47 ns_fis = host.getNamespace("fis") |
48 host.plugins[u"INVITATION"].registerNamespace(ns_fis, self.onInvitation) | 48 host.plugins["INVITATION"].registerNamespace(ns_fis, self.onInvitation) |
49 host.bridge.addMethod( | 49 host.bridge.addMethod( |
50 "FISInvite", | 50 "FISInvite", |
51 ".plugin", | 51 ".plugin", |
52 in_sign="ssssssss", | 52 in_sign="ssssssss", |
53 out_sign="", | 53 out_sign="", |
54 method=self._sendFileSharingInvitation, | 54 method=self._sendFileSharingInvitation, |
55 ) | 55 ) |
56 | 56 |
57 def _sendFileSharingInvitation( | 57 def _sendFileSharingInvitation( |
58 self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None, | 58 self, invitee_jid_s, service_s, repos_type=None, namespace=None, path=None, |
59 name=None, extra_s=u'', profile_key=C.PROF_KEY_NONE): | 59 name=None, extra_s='', profile_key=C.PROF_KEY_NONE): |
60 client = self.host.getClient(profile_key) | 60 client = self.host.getClient(profile_key) |
61 invitee_jid = jid.JID(invitee_jid_s) | 61 invitee_jid = jid.JID(invitee_jid_s) |
62 service = jid.JID(service_s) | 62 service = jid.JID(service_s) |
63 extra = data_format.deserialise(extra_s) | 63 extra = data_format.deserialise(extra_s) |
64 return self.host.plugins[u"INVITATION"].sendFileSharingInvitation( | 64 return self.host.plugins["INVITATION"].sendFileSharingInvitation( |
65 client, invitee_jid, service, repos_type=repos_type or None, | 65 client, invitee_jid, service, repos_type=repos_type or None, |
66 namespace=namespace or None, path=path or None, name=name or None, | 66 namespace=namespace or None, path=path or None, name=name or None, |
67 extra=extra) | 67 extra=extra) |
68 | 68 |
69 def onInvitation(self, client, name, extra, service, repos_type, namespace, path): | 69 def onInvitation(self, client, name, extra, service, repos_type, namespace, path): |
70 if repos_type == u"files": | 70 if repos_type == "files": |
71 type_human = _(u"file sharing") | 71 type_human = _("file sharing") |
72 elif repos_type == u"photos": | 72 elif repos_type == "photos": |
73 type_human = _(u"photos album") | 73 type_human = _("photos album") |
74 else: | 74 else: |
75 log.warning(u"Unknown repository type: {repos_type}".format( | 75 log.warning("Unknown repository type: {repos_type}".format( |
76 repos_type=repos_type)) | 76 repos_type=repos_type)) |
77 repos_type = u"file" | 77 repos_type = "file" |
78 type_human = _(u"file sharing") | 78 type_human = _("file sharing") |
79 log.info(_( | 79 log.info(_( |
80 u'{profile} has received an invitation for a files repository ({type_human}) ' | 80 '{profile} has received an invitation for a files repository ({type_human}) ' |
81 u'with namespace "{namespace}" at path [{path}]').format( | 81 'with namespace "{namespace}" at path [{path}]').format( |
82 profile=client.profile, type_human=type_human, namespace=namespace, path=path) | 82 profile=client.profile, type_human=type_human, namespace=namespace, path=path) |
83 ) | 83 ) |
84 return self.host.plugins[u'LIST_INTEREST'].registerFileSharing( | 84 return self.host.plugins['LIST_INTEREST'].registerFileSharing( |
85 client, service, repos_type, namespace, path, name, extra) | 85 client, service, repos_type, namespace, path, name, extra) |