From 7fd375da66405fd62266a23400d358cc22e5a4b1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 13 Jun 2018 22:09:28 +0200 Subject: [PATCH] Added plugin for handling general-purpose session variables across tasks. Supported methods: variable.get, variable.set, variable.unset --- platypush/plugins/variable.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 platypush/plugins/variable.py diff --git a/platypush/plugins/variable.py b/platypush/plugins/variable.py new file mode 100644 index 00000000..fd106df6 --- /dev/null +++ b/platypush/plugins/variable.py @@ -0,0 +1,31 @@ +from platypush.message.response import Response +from platypush.plugins import Plugin + + +class VariablePlugin(Plugin): + """ + This plugin allows you to manipulate context variables that can be + accessed across your tasks. + """ + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._variables = {} + + def get(self, name, default_value=None): + return Response(output={name: self._variables.get(name, default_value)}) + + def set(self, name, value): + self._variables[name] = value + return Response(output={'status':'ok'}) + + def unset(self, name): + if name in self._variables: + del self._variables[name] + return Response(output={'status':'ok'}) + else: + return Response(output={'status':'not_found'}) + + +# vim:sw=4:ts=4:et: +