Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/emitter-io/python
Browse files Browse the repository at this point in the history
  • Loading branch information
Florimond committed May 24, 2020
2 parents accd65e + 1db912d commit b4239b6
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 7 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
@@ -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/*
3 changes: 3 additions & 0 deletions .vs/PythonSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"TestFramework": "Pytest"
}
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\emitter"
],
"SelectedNode": "\\emitter\\sample-python3.py",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/emitter-python/v16/.suo
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,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.

-------------------------------------------------------
<a id="asBinary"></a>
Expand All @@ -379,6 +379,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.

<a id="license"></a>
## License
Expand Down
Binary file added emitter/.vs/emitter-python-sdk/v15/.suo
Binary file not shown.
11 changes: 9 additions & 2 deletions emitter/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -377,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:
Expand Down
6 changes: 3 additions & 3 deletions emitter/sample-python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#share_group_key = tkinter.StringVar(root, value="Q_dM5ODuhWjaR_LNo886hVjoecvt5pMJ") #local

def connect():
emitter.connect(host="192.168.0.10", port=8080, secure=False)
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")
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions emitter/subtrie_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="emitter-io",
version="2.0.2",
version="2.0.3",
author="Florimond Husquinet",
author_email="[email protected]",
description="A Python library to interact with the Emitter API.",
Expand Down

0 comments on commit b4239b6

Please sign in to comment.