From 17d4236df6bfe02e06eeee75fd0eb6dc1db63bb0 Mon Sep 17 00:00:00 2001 From: Tarek Galal Date: Mon, 22 Apr 2019 19:42:28 +0200 Subject: [PATCH] [chore] cleanup autherror and encryptionenabled Purge references to AuthError Remove all parameters allowing optional enabling of Axolotl Layer --- yowsup-cli | 9 ++++----- yowsup/demos/cli/stack.py | 10 ++++------ yowsup/demos/contacts/stack.py | 12 ++++-------- yowsup/demos/echoclient/stack.py | 11 ++++------- yowsup/demos/sendclient/stack.py | 11 +++-------- yowsup/layers/auth/__init__.py | 1 - yowsup/layers/auth/autherror.py | 2 -- yowsup/layers/auth/layer_authentication.py | 3 +-- yowsup/stacks/__init__.py | 2 +- yowsup/stacks/yowstack.py | 13 ++++++------- 10 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 yowsup/layers/auth/autherror.py diff --git a/yowsup-cli b/yowsup-cli index b8475be73..27a982431 100755 --- a/yowsup-cli +++ b/yowsup-cli @@ -450,7 +450,7 @@ class DemosArgParser(YowArgParser): sys.exit(1) try: self.printInfoText() - stack = echoclient.YowsupEchoStack(credentials, not self.args["unmoxie"]) + stack = echoclient.YowsupEchoStack(credentials) stack.start() except KeyboardInterrupt: print("\nYowsdown") @@ -465,8 +465,7 @@ class DemosArgParser(YowArgParser): try: self.printInfoText() - stack = sendclient.YowsupSendStack(credentials, [([self.args["send"][0], self.args["send"][1]])], - not self.args["unmoxie"]) + stack = sendclient.YowsupSendStack(credentials, [([self.args["send"][0], self.args["send"][1]])]) stack.start() except KeyboardInterrupt: print("\nYowsdown") @@ -474,13 +473,13 @@ class DemosArgParser(YowArgParser): def startSyncContacts(self): from yowsup.demos import contacts - credentials = self._config.phone, self._config.password + credentials = self._config.phone, self._config.client_static_keypair if not credentials: print("Error: You must specify a configuration method") sys.exit(1) try: self.printInfoText() - stack = contacts.YowsupSyncStack(credentials, self.args["sync"].split(','), not self.args["unmoxie"]) + stack = contacts.YowsupSyncStack(credentials, self.args["sync"].split(',')) stack.start() except KeyboardInterrupt: print("\nYowsdown") diff --git a/yowsup/demos/cli/stack.py b/yowsup/demos/cli/stack.py index 4b37dfea4..5f7b54f68 100644 --- a/yowsup/demos/cli/stack.py +++ b/yowsup/demos/cli/stack.py @@ -1,16 +1,16 @@ from yowsup.stacks import YowStackBuilder from .layer import YowsupCliLayer -from yowsup.layers.auth import AuthError from yowsup.layers import YowLayerEvent from yowsup.layers.axolotl.props import PROP_IDENTITY_AUTOTRUST import sys + class YowsupCliStack(object): - def __init__(self, credentials, encryptionEnabled = True): + def __init__(self, credentials): stackBuilder = YowStackBuilder() self.stack = stackBuilder\ - .pushDefaultLayers(encryptionEnabled)\ + .pushDefaultLayers()\ .push(YowsupCliLayer)\ .build() @@ -23,9 +23,7 @@ def start(self): self.stack.broadcastEvent(YowLayerEvent(YowsupCliLayer.EVENT_START)) try: - self.stack.loop(timeout = 0.5, discrete = 0.5) - except AuthError as e: - print("Auth Error, reason %s" % e) + self.stack.loop() except KeyboardInterrupt: print("\nYowsdown") sys.exit(0) diff --git a/yowsup/demos/contacts/stack.py b/yowsup/demos/contacts/stack.py index 26228ec35..e9c0d9745 100644 --- a/yowsup/demos/contacts/stack.py +++ b/yowsup/demos/contacts/stack.py @@ -1,23 +1,22 @@ from .layer import SyncLayer from yowsup.stacks import YowStackBuilder -from yowsup.layers.auth import AuthError from yowsup.layers import YowLayerEvent from yowsup.layers.auth import YowAuthenticationProtocolLayer from yowsup.layers.network import YowNetworkLayer + class YowsupSyncStack(object): - def __init__(self, credentials, contacts, encryptionEnabled = False): + def __init__(self, credentials, contacts): """ :param credentials: :param contacts: list of [jid ] - :param encryptionEnabled: :return: """ stackBuilder = YowStackBuilder() self.stack = stackBuilder \ - .pushDefaultLayers(encryptionEnabled) \ + .pushDefaultLayers() \ .push(SyncLayer) \ .build() @@ -27,7 +26,4 @@ def __init__(self, credentials, contacts, encryptionEnabled = False): def start(self): self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) - try: - self.stack.loop() - except AuthError as e: - print("Authentication Error: %s" % e.message) + self.stack.loop() diff --git a/yowsup/demos/echoclient/stack.py b/yowsup/demos/echoclient/stack.py index 3c9d82138..259ad3810 100644 --- a/yowsup/demos/echoclient/stack.py +++ b/yowsup/demos/echoclient/stack.py @@ -1,15 +1,15 @@ from yowsup.stacks import YowStackBuilder from .layer import EchoLayer -from yowsup.layers.auth import AuthError from yowsup.layers import YowLayerEvent from yowsup.layers.network import YowNetworkLayer + class YowsupEchoStack(object): - def __init__(self, credentials, encryptionEnabled = True): + def __init__(self, credentials): stackBuilder = YowStackBuilder() self.stack = stackBuilder\ - .pushDefaultLayers(encryptionEnabled)\ + .pushDefaultLayers()\ .push(EchoLayer)\ .build() @@ -17,7 +17,4 @@ def __init__(self, credentials, encryptionEnabled = True): def start(self): self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) - try: - self.stack.loop() - except AuthError as e: - print("Authentication Error: %s" % e.message) + self.stack.loop() diff --git a/yowsup/demos/sendclient/stack.py b/yowsup/demos/sendclient/stack.py index 5351e27c4..e44f362fa 100644 --- a/yowsup/demos/sendclient/stack.py +++ b/yowsup/demos/sendclient/stack.py @@ -1,23 +1,21 @@ from yowsup.stacks import YowStackBuilder from .layer import SendLayer -from yowsup.layers.auth import AuthError from yowsup.layers import YowLayerEvent from yowsup.layers.auth import YowAuthenticationProtocolLayer from yowsup.layers.network import YowNetworkLayer class YowsupSendStack(object): - def __init__(self, credentials, messages, encryptionEnabled = True): + def __init__(self, credentials, messages): """ :param credentials: :param messages: list of (jid, message) tuples - :param encryptionEnabled: :return: """ stackBuilder = YowStackBuilder() self.stack = stackBuilder\ - .pushDefaultLayers(encryptionEnabled)\ + .pushDefaultLayers()\ .push(SendLayer)\ .build() @@ -27,7 +25,4 @@ def __init__(self, credentials, messages, encryptionEnabled = True): def start(self): self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) - try: - self.stack.loop() - except AuthError as e: - print("Authentication Error: %s" % e.message) + self.stack.loop() diff --git a/yowsup/layers/auth/__init__.py b/yowsup/layers/auth/__init__.py index a053d2d83..68225e876 100644 --- a/yowsup/layers/auth/__init__.py +++ b/yowsup/layers/auth/__init__.py @@ -1,4 +1,3 @@ from .layer_crypt import YowCryptLayer from .layer_authentication import YowAuthenticationProtocolLayer -from .autherror import AuthError #import protocolentities diff --git a/yowsup/layers/auth/autherror.py b/yowsup/layers/auth/autherror.py deleted file mode 100644 index 324fb60b2..000000000 --- a/yowsup/layers/auth/autherror.py +++ /dev/null @@ -1,2 +0,0 @@ -class AuthError(Exception): - pass \ No newline at end of file diff --git a/yowsup/layers/auth/layer_authentication.py b/yowsup/layers/auth/layer_authentication.py index 039d1b482..f63036919 100644 --- a/yowsup/layers/auth/layer_authentication.py +++ b/yowsup/layers/auth/layer_authentication.py @@ -1,7 +1,6 @@ from yowsup.common import YowConstants from yowsup.layers import YowLayerEvent, YowProtocolLayer, EventCallback from yowsup.layers.network import YowNetworkLayer -from .autherror import AuthError from .protocolentities import * from .layer_interface_authentication import YowAuthenticationProtocolLayerInterface from .protocolentities import StreamErrorProtocolEntity @@ -75,6 +74,6 @@ def handleStreamError(self, node): errorType = nodeEntity.getErrorType() if not errorType: - raise AuthError("Unhandled stream:error node:\n%s" % node) + raise NotImplementedError("Unhandled stream:error node:\n%s" % node) self.toUpper(nodeEntity) diff --git a/yowsup/stacks/__init__.py b/yowsup/stacks/__init__.py index 78853af5c..683688804 100644 --- a/yowsup/stacks/__init__.py +++ b/yowsup/stacks/__init__.py @@ -1,6 +1,6 @@ from .yowstack import YowStack, YowStackBuilder -from yowsup.layers.auth import YowCryptLayer, YowAuthenticationProtocolLayer, AuthError +from yowsup.layers.auth import YowCryptLayer, YowAuthenticationProtocolLayer from yowsup.layers.coder import YowCoderLayer from yowsup.layers.logger import YowLoggerLayer from yowsup.layers.network import YowNetworkLayer diff --git a/yowsup/stacks/yowstack.py b/yowsup/stacks/yowstack.py index b0bb77b8b..bae4f7f71 100644 --- a/yowsup/stacks/yowstack.py +++ b/yowsup/stacks/yowstack.py @@ -24,6 +24,7 @@ from yowsup.layers.protocol_calls import YowCallsProtocolLayer from yowsup.env import YowsupEnv from yowsup.common.constants import YowConstants +from yowsup.layers.axolotl import AxolotlSendLayer, AxolotlControlLayer, AxolotlReceivelayer import inspect try: import Queue @@ -50,8 +51,8 @@ def setProp(self, key, value): self._props[key] = value return self - def pushDefaultLayers(self, axolotl = False): - defaultLayers = YowStackBuilder.getDefaultLayers(axolotl) + def pushDefaultLayers(self): + defaultLayers = YowStackBuilder.getDefaultLayers() self.layers += defaultLayers return self @@ -67,15 +68,13 @@ def build(self): return YowStack(self.layers, reversed = False, props = self._props) @staticmethod - def getDefaultLayers(axolotl = False, groups = True, media = True, privacy = True, profiles = True): + def getDefaultLayers(groups = True, media = True, privacy = True, profiles = True): coreLayers = YowStackBuilder.getCoreLayers() protocolLayers = YowStackBuilder.getProtocolLayers(groups = groups, media=media, privacy=privacy, profiles=profiles) allLayers = coreLayers - if axolotl: - from yowsup.layers.axolotl import AxolotlSendLayer, AxolotlControlLayer, AxolotlReceivelayer - allLayers += (AxolotlControlLayer,) - allLayers += (YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),) + allLayers += (AxolotlControlLayer,) + allLayers += (YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),) allLayers += (YowParallelLayer(protocolLayers),)