-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
84 additions
and
56 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class MqttListener: | ||
"""MqttListener is a wrapper for (hb)mqtt connection.""" | ||
|
||
def __init__(self, user: str, password: str, topic: str): | ||
"""Init (hb)mqtt client.""" | ||
self.mqtt_client = MQTTClient() | ||
self.user = user | ||
self.password = password | ||
self.topic = topic |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ast | ||
|
||
from pep8ext_naming import NamingChecker | ||
|
||
|
||
class _ClassVisitor(ast.NodeVisitor): | ||
def __init__(self, transformer: NamingChecker) -> None: | ||
super().__init__() | ||
self.transformer = transformer | ||
|
||
def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: N802 | ||
self.transformer.tag_class_functions(node) | ||
self.generic_visit(node) | ||
|
||
|
||
def _set_parent(tree: ast.AST) -> ast.AST: | ||
""" | ||
Sets parents for all nodes that do not have this prop. | ||
This step is required due to how `flake8` works. | ||
It does not set the same properties as `ast` module. | ||
This function was the cause of `issue-112`. | ||
.. versionchanged:: 0.0.11 | ||
""" | ||
for statement in ast.walk(tree): | ||
for child in ast.iter_child_nodes(statement): | ||
setattr(child, 'parent', statement) | ||
return tree | ||
|
||
|
||
def _set_function_type(tree: ast.AST) -> ast.AST: | ||
""" | ||
Sets the function type for methods. | ||
Can set: `method`, `classmethod`, `staticmethod`. | ||
.. versionchanged:: 0.3.0 | ||
""" | ||
transformer = _ClassVisitor(NamingChecker(tree, 'stdin')) | ||
transformer.visit(tree) | ||
return tree | ||
|
||
|
||
def transform(tree: ast.AST) -> ast.AST: | ||
""" | ||
Mutates the given ``ast`` tree. | ||
Applies all possible tranformations. | ||
""" | ||
pipeline = ( | ||
_set_parent, | ||
_set_function_type, | ||
) | ||
|
||
for tranformation in pipeline: | ||
tree = tranformation(tree) | ||
return tree |