comparison sat/plugins/plugin_misc_xmllog.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 559a625a236b
comparison
equal deleted inserted replaced
3039:a1bc34f90fa5 3040:fee60f17ebac
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 sat.core.log import getLogger 22 from sat.core.log import getLogger
23 from twisted.words.xish import domish
24 from functools import partial
23 25
24 log = getLogger(__name__) 26 log = getLogger(__name__)
25 from twisted.words.xish import domish
26 from functools import partial
27 27
28 PLUGIN_INFO = { 28 PLUGIN_INFO = {
29 C.PI_NAME: "Raw XML log Plugin", 29 C.PI_NAME: "Raw XML log Plugin",
30 C.PI_IMPORT_NAME: "XmlLog", 30 C.PI_IMPORT_NAME: "XmlLog",
31 C.PI_TYPE: "Misc", 31 C.PI_TYPE: "Misc",
72 def onReceive(self, element, client): 72 def onReceive(self, element, client):
73 self.host.bridge.xmlLog("IN", element.toXml(), client.profile) 73 self.host.bridge.xmlLog("IN", element.toXml(), client.profile)
74 74
75 def onSend(self, obj, client): 75 def onSend(self, obj, client):
76 if isinstance(obj, str): 76 if isinstance(obj, str):
77 log = str(obj) 77 xml_log = obj
78 elif isinstance(obj, domish.Element): 78 elif isinstance(obj, domish.Element):
79 log = obj.toXml() 79 xml_log = obj.toXml()
80 else: 80 else:
81 log.error(_("INTERNAL ERROR: Unmanaged XML type")) 81 log.error(_("INTERNAL ERROR: Unmanaged XML type"))
82 self.host.bridge.xmlLog("OUT", log, client.profile) 82 self.host.bridge.xmlLog("OUT", xml_log, client.profile)