From 30fa675efb3283e8c61ceb4d0ad585eace169262 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Tue, 23 Jul 2019 14:57:07 +0200 Subject: [PATCH 1/5] Fix presence trie handling --- emitter/emitter.py | 8 +++++++- emitter/sample-python3.py | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/emitter/emitter.py b/emitter/emitter.py index 9db8424..b8fb752 100644 --- a/emitter/emitter.py +++ b/emitter/emitter.py @@ -158,7 +158,13 @@ def _on_message(self, client, userdata, msg): elif message.channel.startswith("emitter/presence"): # This is a presence message. - self._invoke_trie_handlers(self._handler_trie_presence, self._handler_presence, message) + #self._invoke_trie_handlers(self._handler_trie_presence, self._handler_presence, message) + messageContent = message.as_object() + handlers = self._handler_trie_presence.lookup(messageContent["channel"]) + if len(handlers) == 0 and self._handler_presence: + self._handler_presence(messageContent) + for h in handlers: + h(messageContent) elif self._handler_error and message.channel.startswith("emitter/error"): # This is an error message. diff --git a/emitter/sample-python3.py b/emitter/sample-python3.py index bd841dd..52269fc 100644 --- a/emitter/sample-python3.py +++ b/emitter/sample-python3.py @@ -19,12 +19,12 @@ #share_group_key = tkinter.StringVar(root, value="Q_dM5ODuhWjaR_LNo886hVjoecvt5pMJ") #local def connect(): - #emitter.connect(host="127.0.0.1", port=8080, secure=False) - emitter.connect() + emitter.connect(host="127.0.0.1", port=8080, secure=False) + #emitter.connect() emitter.on_connect = lambda: result_text.insert("0.0", "Connected\n\n") emitter.on_disconnect = lambda: result_text.insert("0.0", "Disconnected\n\n") - emitter.on_presence = lambda p: result_text.insert("0.0", "Presence message: '" + p.as_string() + "'\n\n") + emitter.on_presence = lambda p: result_text.insert("0.0", "Presence message on channel: '" + str(p) + "'\n\n") emitter.on_message = lambda m: result_text.insert("0.0", "Message received on default handler, destined to " + m.channel + ": " + m.as_string() + "\n\n") emitter.on_error = lambda e: result_text.insert("0.0", "Error received: " + str(e) + "\n\n") emitter.on_me = lambda me: result_text.insert("0.0", "Information about Me received: " + str(me) +"\n\n") @@ -61,7 +61,7 @@ def unsubscribe(): def presence(): str_key = channel_key.get() str_channel = channel.get() - emitter.presence(str_key, str_channel, status=True, changes=True) + emitter.presence(str_key, str_channel, status=True, changes=True) #optional_handler=lambda p: result_text.insert("0.0", "Optional handler: '" + str(p) + "'\n\n")) result_text.insert("0.0", "Presence on '" + str_channel + "' requested.\n\n") def message(retain=False): From c1e9cd19568f82bf4233ff144844679074c64877 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Tue, 23 Jul 2019 15:00:45 +0200 Subject: [PATCH 2/5] as_object comment fix --- README.md | 3 ++- emitter/emitter.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a3653b..10f2cf9 100644 --- a/README.md +++ b/README.md @@ -362,7 +362,7 @@ Returns the payload as a utf-8 `String`. ``` message.asObject() ``` -Returns the payload as a JSON-deserialized Python `Object`. +Returns the payload as a JSON-deserialized dictionary. ------------------------------------------------------- @@ -381,6 +381,7 @@ There are some points where the Python libary can be improved: - Complete the [keygen](#client-keygen) entry in the README (see the **ToDo** markings) - Describe how to use the trie of handlers for regular messages and presence. - Add `with_from` and `with_until`. +- asObject should return an actual object instead of a dictionary. ## License diff --git a/emitter/emitter.py b/emitter/emitter.py index b8fb752..becfcd0 100644 --- a/emitter/emitter.py +++ b/emitter/emitter.py @@ -383,9 +383,10 @@ def as_string(self): """ return str(self.binary) + # TODO: rename this one and produce a real object. def as_object(self): """ - * Returns the payload as an JSON-deserialized Python object. + * Returns the payload as an JSON-deserialized dictionary. """ msg = None try: From 22dbbfb139fd5047b7679c926ce75d2c3458e279 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Tue, 23 Jul 2019 15:01:19 +0200 Subject: [PATCH 3/5] Update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b7722ad..38f5d85 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="emitter-io", - version="2.0.2", + version="2.0.3", author="Florimond Husquinet", author_email="florimond@emitter.io", description="A Python library to interact with the Emitter API.", From 5c965e004c834dcfd1ff1590a5e41a375d83bceb Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Sat, 3 Aug 2019 11:03:55 +0200 Subject: [PATCH 4/5] subtrie add test replace handler --- emitter/subtrie_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/emitter/subtrie_test.py b/emitter/subtrie_test.py index 97ca774..d699abf 100644 --- a/emitter/subtrie_test.py +++ b/emitter/subtrie_test.py @@ -33,6 +33,14 @@ def test_lookup_with_wildcard(): results = t.lookup(k) assert len(results) == v +def test_replace_handler(): + t = SubTrie() + t.insert("a", lambda: "a1") + t.insert("a", lambda: "a2") + + results = t.lookup("a") + assert len(results) == 1 + assert results[0]() == "a2" def test_delete_parent(): t = SubTrie() From 1db912d7a3b0ed9d4509882dd241d1e6b37450f6 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Sun, 24 May 2020 13:03:50 +0200 Subject: [PATCH 5/5] Create pythonpublish.yml --- .github/workflows/pythonpublish.yml | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/pythonpublish.yml diff --git a/.github/workflows/pythonpublish.yml b/.github/workflows/pythonpublish.yml new file mode 100644 index 0000000..4e1ef42 --- /dev/null +++ b/.github/workflows/pythonpublish.yml @@ -0,0 +1,31 @@ +# This workflows will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/*