Skip to content

Commit

Permalink
[chore] cleanup autherror and encryptionenabled
Browse files Browse the repository at this point in the history
Purge references to AuthError
Remove all parameters allowing optional enabling of Axolotl Layer
  • Loading branch information
tgalal committed Apr 23, 2019
1 parent 3126f1e commit 17d4236
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 47 deletions.
9 changes: 4 additions & 5 deletions yowsup-cli
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -465,22 +465,21 @@ 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")
sys.exit(0)

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")
Expand Down
10 changes: 4 additions & 6 deletions yowsup/demos/cli/stack.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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)
12 changes: 4 additions & 8 deletions yowsup/demos/contacts/stack.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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()
11 changes: 4 additions & 7 deletions yowsup/demos/echoclient/stack.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
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()

self.stack.setCredentials(credentials)

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()
11 changes: 3 additions & 8 deletions yowsup/demos/sendclient/stack.py
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -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()
1 change: 0 additions & 1 deletion yowsup/layers/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .layer_crypt import YowCryptLayer
from .layer_authentication import YowAuthenticationProtocolLayer
from .autherror import AuthError
#import protocolentities
2 changes: 0 additions & 2 deletions yowsup/layers/auth/autherror.py

This file was deleted.

3 changes: 1 addition & 2 deletions yowsup/layers/auth/layer_authentication.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion yowsup/stacks/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 6 additions & 7 deletions yowsup/stacks/yowstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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),)

Expand Down

0 comments on commit 17d4236

Please sign in to comment.