forked from Robert904/pymumble
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup #51
Open
tikki
wants to merge
17
commits into
azlux:pymumble_py3
Choose a base branch
from
tikki:cleanup
base: pymumble_py3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cleanup #51
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
95940a3
reformat using Black, isort, autoflake
tikki 0c0881e
fix property name
tikki d6656bc
add strict type annotations
tikki c023234
fix creating wrong type when working with bytes
tikki fff0fe1
fix invalid method access
tikki df01373
fix calling non-existing method on Channel
tikki 2817dd4
fix wrong argument type
tikki 75e1e73
add constant PYMUMBLE_CHANNELS
tikki 0f9ce9e
fix cyclic imports for type checking
tikki 10d77be
fix forward refs for type checking
tikki 5c83f28
add type annotations for examples
tikki 5b7f28a
fix type annotations for soundoutput
tikki efa0606
explicitly export Mumble from package
tikki cc55e96
fix type errors
tikki fa1b2d6
fix type annotation
tikki 58594aa
revert generated file to original state
tikki 2c3e5c2
fix set_whisper by reverting to upstream
tikki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
import struct | ||
import typing | ||
|
||
from .constants import * | ||
from .mumble import Mumble | ||
from .mumble_pb2 import RequestBlob | ||
|
||
|
||
class Blobs(dict): | ||
class Blobs(typing.Dict[bytes, typing.Any]): | ||
""" | ||
Manage the Blob library | ||
""" | ||
def __init__(self, mumble_object): | ||
|
||
def __init__(self, mumble_object: Mumble): | ||
self.mumble_object = mumble_object | ||
def get_user_comment(self, hash): | ||
|
||
def get_user_comment(self, hash: bytes) -> None: | ||
"""Request the comment of a user""" | ||
if hash in self: | ||
return | ||
request = RequestBlob() | ||
request.session_comment.extend(struct.unpack("!5I", hash)) | ||
|
||
self.mumble_object.send_message(PYMUMBLE_MSG_TYPES_REQUESTBLOB, request) | ||
def get_user_texture(self, hash): | ||
|
||
def get_user_texture(self, hash: bytes) -> None: | ||
"""Request the image of a user""" | ||
if hash in self: | ||
return | ||
|
||
request = RequestBlob() | ||
request.session_texture.extend(struct.unpack("!5I", hash)) | ||
|
||
self.mumble_object.send_message(PYMUMBLE_MSG_TYPES_REQUESTBLOB, request) | ||
def get_channel_description(self, hash): | ||
|
||
def get_channel_description(self, hash: bytes) -> None: | ||
"""Request the description/comment of a channel""" | ||
if hash in self: | ||
return | ||
|
||
request = RequestBlob() | ||
request.channel_description.extend(struct.unpack("!5I", hash)) | ||
|
||
self.mumble_object.send_message(PYMUMBLE_MSG_TYPES_REQUESTBLOB, request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,102 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from .errors import UnknownCallbackError | ||
from .constants import * | ||
import threading | ||
import typing | ||
|
||
from .constants import * | ||
from .errors import UnknownCallbackError | ||
|
||
_Callback = typing.Callable[..., typing.Any] | ||
_Callbacks = typing.List[_Callback] | ||
|
||
|
||
class CallBacks(dict): | ||
class CallBacks(typing.Dict[str, typing.Optional[_Callbacks]]): | ||
""" | ||
Define the callbacks that can be registered by the application. | ||
Multiple functions can be assigned to a callback using "add_callback" | ||
|
||
The call is done from within the pymumble loop thread, it's important to | ||
keep processing short to avoid delays on audio transmission | ||
""" | ||
def __init__(self): | ||
self.update({ | ||
PYMUMBLE_CLBK_CONNECTED: None, # Connection succeeded | ||
PYMUMBLE_CLBK_CHANNELCREATED: None, # send the created channel object as parameter | ||
PYMUMBLE_CLBK_CHANNELUPDATED: None, # send the updated channel object and a dict with all the modified fields as parameter | ||
PYMUMBLE_CLBK_CHANNELREMOVED: None, # send the removed channel object as parameter | ||
PYMUMBLE_CLBK_USERCREATED: None, # send the added user object as parameter | ||
PYMUMBLE_CLBK_USERUPDATED: None, # send the updated user object and a dict with all the modified fields as parameter | ||
PYMUMBLE_CLBK_USERREMOVED: None, # send the removed user object and the mumble message as parameter | ||
PYMUMBLE_CLBK_SOUNDRECEIVED: None, # send the user object that received the sound and the SoundChunk object itself | ||
PYMUMBLE_CLBK_TEXTMESSAGERECEIVED: None, # Send the received message | ||
PYMUMBLE_CLBK_CONTEXTACTIONRECEIVED: None, # Send the contextaction message | ||
}) | ||
|
||
def set_callback(self, callback, dest): | ||
|
||
def __init__(self) -> None: | ||
self.update( | ||
{ | ||
PYMUMBLE_CLBK_CONNECTED: None, # Connection succeeded | ||
PYMUMBLE_CLBK_CHANNELCREATED: None, # send the created channel object as parameter | ||
PYMUMBLE_CLBK_CHANNELUPDATED: None, # send the updated channel object and a dict with all the modified fields as parameter | ||
PYMUMBLE_CLBK_CHANNELREMOVED: None, # send the removed channel object as parameter | ||
PYMUMBLE_CLBK_USERCREATED: None, # send the added user object as parameter | ||
PYMUMBLE_CLBK_USERUPDATED: None, # send the updated user object and a dict with all the modified fields as parameter | ||
PYMUMBLE_CLBK_USERREMOVED: None, # send the removed user object and the mumble message as parameter | ||
PYMUMBLE_CLBK_SOUNDRECEIVED: None, # send the user object that received the sound and the SoundChunk object itself | ||
PYMUMBLE_CLBK_TEXTMESSAGERECEIVED: None, # Send the received message | ||
PYMUMBLE_CLBK_CONTEXTACTIONRECEIVED: None, # Send the contextaction message | ||
} | ||
) | ||
|
||
def set_callback(self, callback: str, dest: _Callback) -> None: | ||
"""Define the function to call for a specific callback. Suppress any existing callback function""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
self[callback] = [dest] | ||
def add_callback(self, callback, dest): | ||
|
||
def add_callback(self, callback: str, dest: _Callback) -> None: | ||
"""Add the function to call for a specific callback.""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
if self[callback] is None: | ||
self[callback] = list() | ||
self[callback].append(dest) | ||
def get_callback(self, callback): | ||
typing.cast(_Callbacks, self[callback]).append(dest) | ||
|
||
def get_callback(self, callback: str) -> typing.Optional[_Callbacks]: | ||
"""Get the functions assigned to a callback as a list. Return None if no callback defined""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
return self[callback] | ||
def remove_callback(self, callback, dest): | ||
|
||
def remove_callback(self, callback: str, dest: _Callback) -> None: | ||
"""Remove a specific function from a specific callback. Function object must be the one added before.""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
|
||
if self[callback] is None or dest not in self[callback]: | ||
raise UnknownCallbackError("Function not registered for callback \"%s\"." % callback) | ||
|
||
self[callback].remove(dest) | ||
if len(self[callback]) == 0: | ||
self[callback] = None | ||
|
||
def reset_callback(self, callback): | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
callbacks = self[callback] | ||
if callbacks is None or dest not in callbacks: | ||
raise UnknownCallbackError( | ||
'Function not registered for callback "%s".' % callback | ||
) | ||
|
||
callbacks.remove(dest) | ||
if len(callbacks) == 0: | ||
callbacks = None | ||
|
||
def reset_callback(self, callback: str) -> None: | ||
"""remove functions for a defined callback""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
self[callback] = None | ||
def call_callback(self, callback, *pos_parameters): | ||
|
||
def call_callback(self, callback: str, *pos_parameters: typing.Any) -> None: | ||
"""Call all the registered function for a specific callback.""" | ||
if callback not in self: | ||
raise UnknownCallbackError("Callback \"%s\" does not exists." % callback) | ||
raise UnknownCallbackError('Callback "%s" does not exists.' % callback) | ||
|
||
if self[callback]: | ||
for func in self[callback]: | ||
for func in typing.cast(_Callbacks, self[callback]): | ||
if callback is PYMUMBLE_CLBK_TEXTMESSAGERECEIVED: | ||
thr = threading.Thread(target=func, args=pos_parameters) | ||
thr.start() | ||
else: | ||
func(*pos_parameters) | ||
def __call__(self, callback, *pos_parameters): | ||
|
||
def __call__(self, callback: str, *pos_parameters: typing.Any) -> None: | ||
"""shortcut to be able to call the dict element as a function""" | ||
self.call_callback(callback, *pos_parameters) | ||
def get_callbacks_list(self): | ||
|
||
def get_callbacks_list(self) -> typing.List[str]: | ||
"""Get a list of all callbacks""" | ||
return list(self.keys()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this change is a rather subjective one. It just makes the lines longer because the tool decided you need to have this hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, I completely agree with you. I would never format it like this manually.