├── yowsup
├── config
│ ├── __init__.py
│ ├── v1
│ │ └── __init__.py
│ ├── base
│ │ ├── __init__.py
│ │ ├── transform.py
│ │ ├── config.py
│ │ └── serialize.py
│ └── transforms
│ │ ├── __init__.py
│ │ ├── dict_json.py
│ │ ├── serialize.py
│ │ ├── config_dict.py
│ │ ├── dict_keyval.py
│ │ ├── meta.py
│ │ ├── map.py
│ │ ├── filter.py
│ │ └── props.py
├── demos
│ ├── __init__.py
│ ├── common
│ │ └── __init__.py
│ ├── cli
│ │ ├── __init__.py
│ │ └── stack.py
│ ├── mediasink
│ │ ├── __init__.py
│ │ └── stack.py
│ ├── contacts
│ │ ├── __init__.py
│ │ ├── stack.py
│ │ └── layer.py
│ ├── echoclient
│ │ ├── __init__.py
│ │ ├── stack.py
│ │ └── layer.py
│ └── sendclient
│ │ ├── __init__.py
│ │ └── stack.py
├── profile
│ └── __init__.py
├── axolotl
│ ├── store
│ │ ├── __init__.py
│ │ └── sqlite
│ │ │ └── __init__.py
│ ├── __init__.py
│ ├── exceptions.py
│ └── factory.py
├── layers
│ ├── noise
│ │ ├── __init__.py
│ │ ├── workers
│ │ │ ├── __init__.py
│ │ │ └── handshake.py
│ │ └── layer_noise_segments.py
│ ├── network
│ │ ├── dispatcher
│ │ │ ├── __init__.py
│ │ │ ├── dispatcher.py
│ │ │ └── dispatcher_asyncore.py
│ │ ├── __init__.py
│ │ └── layer_interface.py
│ ├── protocol_messages
│ │ ├── proto
│ │ │ └── __init__.py
│ │ ├── protocolentities
│ │ │ ├── attributes
│ │ │ │ ├── __init__.py
│ │ │ │ ├── attributes_media.py
│ │ │ │ ├── attributes_protocol.py
│ │ │ │ ├── attributes_message_meta.py
│ │ │ │ ├── attributes_sender_key_distribution_message.py
│ │ │ │ ├── attributes_contact.py
│ │ │ │ ├── attributes_message_key.py
│ │ │ │ └── attributes_sticker.py
│ │ │ ├── __init__.py
│ │ │ ├── test_message_text.py
│ │ │ ├── test_message_text_broadcast.py
│ │ │ ├── test_message.py
│ │ │ ├── proto.py
│ │ │ ├── message_text.py
│ │ │ ├── message_text_broadcast.py
│ │ │ └── message_extendedtext.py
│ │ └── __init__.py
│ ├── coder
│ │ ├── __init__.py
│ │ ├── test_tokendictionary.py
│ │ ├── test_decoder.py
│ │ ├── layer.py
│ │ └── test_encoder.py
│ ├── logger
│ │ ├── __init__.py
│ │ └── layer.py
│ ├── protocol_groups
│ │ ├── structs
│ │ │ ├── __init__.py
│ │ │ └── group.py
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ │ ├── test_iq_groups.py
│ │ │ ├── test_iq_result_groups.py
│ │ │ ├── test_iq_groups_list.py
│ │ │ ├── iq_groups.py
│ │ │ ├── test_iq_groups_create.py
│ │ │ ├── test_iq_groups_create_success.py
│ │ │ ├── test_iq_result_groups_list.py
│ │ │ ├── iq_groups_participants_add_failure.py
│ │ │ ├── iq_groups_subject.py
│ │ │ ├── iq_groups_participants_add.py
│ │ │ ├── iq_groups_participants_demote.py
│ │ │ ├── iq_groups_participants_remove.py
│ │ │ ├── iq_groups_participants_promote.py
│ │ │ ├── iq_groups_create_success.py
│ │ │ ├── iq_groups_info.py
│ │ │ ├── iq_groups_leave_success.py
│ │ │ ├── __init__.py
│ │ │ ├── iq_groups_participants.py
│ │ │ ├── iq_result_participants_list.py
│ │ │ └── iq_groups_leave.py
│ ├── protocol_iq
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ │ ├── test_iq_result.py
│ │ │ ├── __init__.py
│ │ │ ├── iq_props.py
│ │ │ ├── iq_result_pong.py
│ │ │ ├── iq_push.py
│ │ │ ├── test_iq.py
│ │ │ ├── iq_result.py
│ │ │ ├── test_iq_error.py
│ │ │ ├── iq_ping.py
│ │ │ ├── iq_crypto.py
│ │ │ └── iq_error.py
│ ├── protocol_acks
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_ack_outgoing.py
│ │ │ ├── test_ack_incoming.py
│ │ │ ├── ack.py
│ │ │ ├── ack_incoming.py
│ │ │ └── ack_outgoing.py
│ │ ├── layer.py
│ │ └── test_layer.py
│ ├── protocol_calls
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ └── test_call.py
│ │ └── layer.py
│ ├── protocol_contacts
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── test_iq_sync_get.py
│ │ │ ├── __init__.py
│ │ │ ├── test_notification_contact_remove.py
│ │ │ ├── test_notification_contact_update.py
│ │ │ ├── test_notification_contact_add.py
│ │ │ ├── test_iq_sync_result.py
│ │ │ ├── notification_contact.py
│ │ │ ├── notificiation_contacts_sync.py
│ │ │ ├── notification_contact_add.py
│ │ │ ├── notification_contact_remove.py
│ │ │ └── notification_contact_update.py
│ │ ├── test_layer.py
│ │ └── layer.py
│ ├── protocol_ib
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_ib.py
│ │ │ ├── test_offline_iq.py
│ │ │ ├── ib.py
│ │ │ ├── test_clean_iq.py
│ │ │ ├── test_dirty_ib.py
│ │ │ ├── offline_ib.py
│ │ │ ├── dirty_ib.py
│ │ │ └── clean_iq.py
│ │ └── layer.py
│ ├── protocol_media
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ │ ├── test_iq_requestupload_result.py
│ │ │ ├── test_iq_requestupload.py
│ │ │ ├── test_message_media.py
│ │ │ ├── test_message_media_contact.py
│ │ │ ├── __init__.py
│ │ │ ├── test_message_media_location.py
│ │ │ ├── test_message_media_downloadable_audio.py
│ │ │ ├── test_message_media_downloadable_image.py
│ │ │ ├── message_media_contact.py
│ │ │ ├── test_message_media_downloadable_video.py
│ │ │ ├── test_message_media_extendedtext.py
│ │ │ └── message_media_downloadable_sticker.py
│ ├── protocol_privacy
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ └── privacylist_iq.py
│ │ └── layer.py
│ ├── protocol_profiles
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ │ ├── test_iq_unregister.py
│ │ │ ├── test_iq_privacy_get.py
│ │ │ ├── test_iq_privacy_set.py
│ │ │ ├── test_iq_status_set.py
│ │ │ ├── iq_picture.py
│ │ │ ├── test_iq_privacy_result.py
│ │ │ ├── __init__.py
│ │ │ ├── iq_privacy_get.py
│ │ │ ├── iq_unregister.py
│ │ │ ├── iq_picture_get.py
│ │ │ ├── iq_pictures_list.py
│ │ │ ├── iq_status_set.py
│ │ │ └── iq_statuses_get.py
│ ├── protocol_chatstate
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_chatstate_incoming.py
│ │ │ ├── test_chatstate_outgoing.py
│ │ │ ├── chatstate_outgoing.py
│ │ │ ├── chatstate_incoming.py
│ │ │ └── chatstate.py
│ │ ├── layer.py
│ │ └── test_layer.py
│ ├── protocol_presence
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── presence_available.py
│ │ │ ├── presence_unavailable.py
│ │ │ ├── __init__.py
│ │ │ ├── test_presence.py
│ │ │ ├── test_presence_available.py
│ │ │ ├── test_presence_unavailable.py
│ │ │ ├── test_presence_subscribe.py
│ │ │ ├── test_presence_unsubscribe.py
│ │ │ ├── iq_lastseen.py
│ │ │ ├── iq_lastseen_result.py
│ │ │ ├── presence_subscribe.py
│ │ │ └── presence_unsubscribe.py
│ │ └── layer.py
│ ├── protocol_notifications
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_notification_picture.py
│ │ │ ├── test_notification_status.py
│ │ │ ├── test_notification_picture_set.py
│ │ │ ├── test_notification.py
│ │ │ ├── test_notification_picture_delete.py
│ │ │ ├── notification_picture.py
│ │ │ ├── notification_status.py
│ │ │ ├── notification_picture_set.py
│ │ │ └── notification_picture_delete.py
│ ├── protocol_receipts
│ │ ├── __init__.py
│ │ ├── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_receipt_outgoing.py
│ │ │ ├── test_receipt_incoming.py
│ │ │ └── receipt.py
│ │ └── layer.py
│ ├── auth
│ │ ├── __init__.py
│ │ ├── layer_interface_authentication.py
│ │ └── protocolentities
│ │ │ ├── __init__.py
│ │ │ ├── test_failure.py
│ │ │ ├── response.py
│ │ │ ├── test_success.py
│ │ │ ├── failure.py
│ │ │ ├── stream_features.py
│ │ │ ├── challenge.py
│ │ │ ├── auth.py
│ │ │ └── success.py
│ ├── interface
│ │ └── __init__.py
│ └── axolotl
│ │ ├── props.py
│ │ ├── __init__.py
│ │ └── protocolentities
│ │ ├── __init__.py
│ │ ├── test_notification_encrypt_requestkeys.py
│ │ ├── test_iq_keys_set.py
│ │ ├── notification_encrypt_identitychange.py
│ │ ├── notification_encrypt_requestkeys.py
│ │ ├── iq_key_get.py
│ │ └── enc.py
├── common
│ ├── __init__.py
│ ├── http
│ │ ├── test_warequest.py
│ │ └── __init__.py
│ ├── mime.types
│ ├── constants.py
│ └── optionalmodules.py
├── env
│ └── __init__.py
├── structs
│ ├── __init__.py
│ └── protocolentity.py
├── registration
│ ├── __init__.py
│ └── existsrequest.py
└── __init__.py
├── .github
└── FUNDING.yml
├── MANIFEST.in
├── .gitignore
├── requirements.txt
├── tox.ini
├── .travis.yml
└── setup.py
/yowsup/config/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/config/v1/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/demos/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/profile/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/axolotl/store/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/config/base/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/demos/common/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/layers/noise/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [tgalal]
2 |
--------------------------------------------------------------------------------
/yowsup/axolotl/store/sqlite/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/layers/noise/workers/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include yowsup/common/mime.types
2 |
--------------------------------------------------------------------------------
/yowsup/layers/network/dispatcher/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/proto/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/common/__init__.py:
--------------------------------------------------------------------------------
1 | from .constants import YowConstants
--------------------------------------------------------------------------------
/yowsup/layers/coder/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowCoderLayer
--------------------------------------------------------------------------------
/yowsup/demos/cli/__init__.py:
--------------------------------------------------------------------------------
1 | from .stack import YowsupCliStack
2 |
--------------------------------------------------------------------------------
/yowsup/demos/mediasink/__init__.py:
--------------------------------------------------------------------------------
1 | from .stack import MediaSinkStack
--------------------------------------------------------------------------------
/yowsup/demos/contacts/__init__.py:
--------------------------------------------------------------------------------
1 | from .stack import YowsupSyncStack
2 |
--------------------------------------------------------------------------------
/yowsup/demos/echoclient/__init__.py:
--------------------------------------------------------------------------------
1 | from .stack import YowsupEchoStack
--------------------------------------------------------------------------------
/yowsup/demos/sendclient/__init__.py:
--------------------------------------------------------------------------------
1 | from .stack import YowsupSendStack
--------------------------------------------------------------------------------
/yowsup/layers/logger/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowLoggerLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/network/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowNetworkLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/structs/__init__.py:
--------------------------------------------------------------------------------
1 | from .group import Group
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowIqProtocolLayer
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowAckProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/common/http/test_warequest.py:
--------------------------------------------------------------------------------
1 | from yowsup.common.http.warequest import WARequest
--------------------------------------------------------------------------------
/yowsup/layers/protocol_calls/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowCallsProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowContactsIqProtocolLayer
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowGroupsProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowIbProtocolLayer
2 |
3 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowMediaProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_privacy/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowPrivacyProtocolLayer
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowProfilesProtocolLayer
--------------------------------------------------------------------------------
/yowsup/axolotl/__init__.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | logger = logging.getLogger(__name__)
4 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowChatstateProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowMessagesProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowPresenceProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowNotificationsProtocolLayer
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer import YowReceiptProtocolLayer
2 |
3 |
--------------------------------------------------------------------------------
/yowsup/env/__init__.py:
--------------------------------------------------------------------------------
1 | from .env import YowsupEnv
2 | from .env_android import AndroidYowsupEnv
3 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer_authentication import YowAuthenticationProtocolLayer
2 |
--------------------------------------------------------------------------------
/yowsup/layers/interface/__init__.py:
--------------------------------------------------------------------------------
1 | from .interface import YowInterfaceLayer, ProtocolEntityCallback
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/props.py:
--------------------------------------------------------------------------------
1 | PROP_IDENTITY_AUTOTRUST = "org.openwhatsapp.yowsup.prop.axolotl.INDENTITY_AUTOTRUST"
--------------------------------------------------------------------------------
/yowsup/layers/protocol_calls/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .call import CallProtocolEntity
2 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_privacy/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .privacylist_iq import PrivacyListIqProtocolEntity
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | *.class
3 | todo
4 | *.egg-info
5 | tp
6 | tests
7 | dist
8 | build
9 | .idea
10 | .tox
11 |
--------------------------------------------------------------------------------
/yowsup/structs/__init__.py:
--------------------------------------------------------------------------------
1 | from .protocolentity import ProtocolEntity
2 | from .protocoltreenode import ProtocolTreeNode
--------------------------------------------------------------------------------
/yowsup/common/http/__init__.py:
--------------------------------------------------------------------------------
1 | from .httpproxy import HttpProxy
2 | from .warequest import WARequest
3 | from .waresponseparser import JSONResponseParser
--------------------------------------------------------------------------------
/yowsup/registration/__init__.py:
--------------------------------------------------------------------------------
1 | from .coderequest import WACodeRequest
2 | from .existsrequest import WAExistsRequest
3 | from .regrequest import WARegRequest
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/__init__.py:
--------------------------------------------------------------------------------
1 | from .layer_send import AxolotlSendLayer
2 | from .layer_control import AxolotlControlLayer
3 | from .layer_receive import AxolotlReceivelayer
4 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .ack import AckProtocolEntity
2 | from .ack_incoming import IncomingAckProtocolEntity
3 | from .ack_outgoing import OutgoingAckProtocolEntity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_groups.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 |
3 | class GroupsIqProtocolEntityTest(IqProtocolEntityTest):
4 | pass
5 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .receipt import ReceiptProtocolEntity
2 | from .receipt_incoming import IncomingReceiptProtocolEntity
3 | from .receipt_outgoing import OutgoingReceiptProtocolEntity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .chatstate import ChatstateProtocolEntity
2 | from .chatstate_incoming import IncomingChatstateProtocolEntity
3 | from .chatstate_outgoing import OutgoingChatstateProtocolEntity
4 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .clean_iq import CleanIqProtocolEntity
2 | from .dirty_ib import DirtyIbProtocolEntity
3 | from .offline_ib import OfflineIbProtocolEntity
4 | from .account_ib import AccountIbProtocolEntity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_result_groups.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq_result import ResultIqProtocolEntityTest
2 |
3 | class GroupsResultIqProtocolEntityTest(ResultIqProtocolEntityTest):
4 | pass
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | appdirs==1.4.4
2 | cffi==1.15.0
3 | consonance==0.1.5
4 | cryptography==36.0.0
5 | dissononce==0.34.3
6 | protobuf==4.0.0rc2
7 | pycparser==2.21
8 | python-axolotl==0.2.2
9 | python-axolotl-curve25519==0.4.1.post2
10 | six==1.10.0
11 | transitions==0.8.10
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .message_text import TextMessageProtocolEntity
2 | from .message import MessageProtocolEntity
3 | from .message_text_broadcast import BroadcastTextMessage
4 | from .message_extendedtext import ExtendedTextMessageProtocolEntity
5 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/test_iq_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | class ResultIqProtocolEntityTest(IqProtocolEntityTest):
3 | def setUp(self):
4 | super(ResultIqProtocolEntityTest, self).setUp()
5 | self.node.setAttribute("type", "result")
--------------------------------------------------------------------------------
/yowsup/layers/network/layer_interface.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayerInterface
2 | class YowNetworkLayerInterface(YowLayerInterface):
3 | def connect(self):
4 | self._layer.createConnection()
5 |
6 | def disconnect(self):
7 | self._layer.destroyConnection()
8 |
9 | def getStatus(self):
10 | return self._layer.getStatus()
--------------------------------------------------------------------------------
/yowsup/config/transforms/dict_json.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 | import json
3 |
4 |
5 | class DictJsonTransform(ConfigTransform):
6 | def transform(self, data):
7 | return json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
8 |
9 | def reverse(self, data):
10 | return json.loads(data)
11 |
12 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/layer_interface_authentication.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayerInterface
2 |
3 | class YowAuthenticationProtocolLayerInterface(YowLayerInterface):
4 | def setCredentials(self, phone, keypair):
5 | self._layer.setCredentials((phone, keypair))
6 |
7 | def getUsername(self, full = False):
8 | return self._layer.getUsername(full)
9 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .auth import AuthProtocolEntity
2 | from .challenge import ChallengeProtocolEntity
3 | from .response import ResponseProtocolEntity
4 | from .stream_features import StreamFeaturesProtocolEntity
5 | from .success import SuccessProtocolEntity
6 | from .failure import FailureProtocolEntity
7 | from .stream_error import StreamErrorProtocolEntity
8 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .iq import IqProtocolEntity
2 | from .iq_result import ResultIqProtocolEntity
3 | from .iq_ping import PingIqProtocolEntity
4 | from .iq_result_pong import PongResultIqProtocolEntity
5 | from .iq_error import ErrorIqProtocolEntity
6 | from .iq_push import PushIqProtocolEntity
7 | from .iq_props import PropsIqProtocolEntity
8 | from .iq_crypto import CryptoIqProtocolEntity
9 |
--------------------------------------------------------------------------------
/yowsup/config/base/transform.py:
--------------------------------------------------------------------------------
1 | class ConfigTransform(object):
2 | def transform(self, config):
3 | """
4 | :param config:
5 | :type config: yowsup.config.base.config.Config
6 | :return: dict
7 | :rtype:
8 | """
9 |
10 | def reverse(self, data):
11 | """
12 | :param data:
13 | :type data:
14 | :return:
15 | :rtype: yowsup.config.base.config.Config
16 | """
17 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/test_ib.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_ib.protocolentities.ib import IbProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class IbProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = IbProtocolEntity
9 | self.node = ProtocolTreeNode("ib")
10 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .notification import NotificationProtocolEntity
2 | from .notification_picture import PictureNotificationProtocolEntity
3 | from .notification_picture_set import SetPictureNotificationProtocolEntity
4 | from .notification_picture_delete import DeletePictureNotificationProtocolEntity
5 | from .notification_status import StatusNotificationProtocolEntity
6 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_props.py:
--------------------------------------------------------------------------------
1 | from .iq import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | class PropsIqProtocolEntity(IqProtocolEntity):
4 | def __init__(self):
5 | super(PropsIqProtocolEntity, self).__init__("w", _type="get")
6 |
7 | def toProtocolTreeNode(self):
8 | node = super(PropsIqProtocolEntity, self).toProtocolTreeNode()
9 | node.addChild(ProtocolTreeNode("props"))
10 | return node
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_result_pong.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_result import ResultIqProtocolEntity
3 | class PongResultIqProtocolEntity(ResultIqProtocolEntity):
4 |
5 | '''
6 |
7 |
8 | '''
9 | def __init__(self, to, _id = None):
10 | super(PongResultIqProtocolEntity, self).__init__("w:p", _id = _id, to = to)
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_push.py:
--------------------------------------------------------------------------------
1 | from .iq import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | class PushIqProtocolEntity(IqProtocolEntity):
4 | def __init__(self):
5 | super(PushIqProtocolEntity, self).__init__("urn:xmpp:whatsapp:push", _type="get")
6 |
7 | def toProtocolTreeNode(self):
8 | node = super(PushIqProtocolEntity, self).toProtocolTreeNode()
9 | node.addChild(ProtocolTreeNode("config"))
10 | return node
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/presence_available.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .presence import PresenceProtocolEntity
3 | class AvailablePresenceProtocolEntity(PresenceProtocolEntity):
4 | '''
5 |
6 | response:
7 |
8 |
9 |
10 | '''
11 | def __init__(self):
12 | super(AvailablePresenceProtocolEntity, self).__init__("available")
--------------------------------------------------------------------------------
/yowsup/__init__.py:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | __version__ = "3.3.0"
4 | __author__ = "Tarek Galal"
5 |
6 | logger = logging.getLogger(__name__)
7 |
8 | # create console handler and set level to debug
9 | ch = logging.StreamHandler()
10 | ch.setLevel(logging.DEBUG)
11 |
12 | # create formatter
13 | formatter = logging.Formatter('%(levelname).1s %(asctime)s %(name)s - %(message)s')
14 |
15 | # add formatter to ch
16 | ch.setFormatter(formatter)
17 |
18 | # add ch to logger
19 | logger.addHandler(ch)
20 |
21 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/test_failure.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.auth.protocolentities.failure import FailureProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 |
7 | class FailureProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = FailureProtocolEntity
10 | self.node = ProtocolTreeNode("failure", {"reason": "not-authorized"})
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/test_iq.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.iq import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class IqProtocolEntityTest(unittest.TestCase, ProtocolEntityTest):
7 | def setUp(self):
8 | self.ProtocolEntity = IqProtocolEntity
9 | self.node = ProtocolTreeNode("iq", {"id": "test_id", "type": "get", "xmlns": "iq_xmlns"}, None, None)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/protocolentities/test_receipt_outgoing.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | class OutgoingReceiptProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
6 | def setUp(self):
7 | self.ProtocolEntity = OutgoingReceiptProtocolEntity
8 | self.node = OutgoingReceiptProtocolEntity("123", "target", "read").toProtocolTreeNode()
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq import IqProtocolEntity
3 | class ResultIqProtocolEntity(IqProtocolEntity):
4 |
5 | '''
6 |
7 |
8 | '''
9 |
10 | def __init__(self, xmlns = None, _id = None, to = None, _from = None):
11 | super(ResultIqProtocolEntity, self).__init__(xmlns = xmlns, _id = _id, _type = "result", to = to, _from = _from)
12 |
13 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/presence_unavailable.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .presence import PresenceProtocolEntity
3 | class UnavailablePresenceProtocolEntity(PresenceProtocolEntity):
4 | '''
5 |
6 | response:
7 |
8 |
9 | '''
10 | def __init__(self):
11 | super(UnavailablePresenceProtocolEntity, self).__init__("unavailable")
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_groups_list.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_groups.protocolentities.iq_groups_list import ListGroupsIqProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = ListGroupsIqProtocolEntity()
6 |
7 | class ListGroupsIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = ListGroupsIqProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/test_iq_sync_get.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_contacts.protocolentities.iq_sync_get import GetSyncIqProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = GetSyncIqProtocolEntity(["12345678", "8764543121"])
6 |
7 | class GetSyncIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = GetSyncIqProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .presence import PresenceProtocolEntity
2 | from .presence_available import AvailablePresenceProtocolEntity
3 | from .presence_unavailable import UnavailablePresenceProtocolEntity
4 | from .presence_subscribe import SubscribePresenceProtocolEntity
5 | from .presence_unsubscribe import UnsubscribePresenceProtocolEntity
6 | from .iq_lastseen import LastseenIqProtocolEntity
7 | from .iq_lastseen_result import ResultLastseenIqProtocolEntity
8 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .iq_sync import SyncIqProtocolEntity
2 | from .iq_sync_get import GetSyncIqProtocolEntity
3 | from .iq_sync_result import ResultSyncIqProtocolEntity
4 | from .notification_contact_add import AddContactNotificationProtocolEntity
5 | from .notification_contact_remove import RemoveContactNotificationProtocolEntity
6 | from .notification_contact_update import UpdateContactNotificationProtocolEntity
7 | from .notificiation_contacts_sync import ContactsSyncNotificationProtocolEntity
8 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | class GroupsIqProtocolEntity(IqProtocolEntity):
4 | '''
5 |
6 |
7 | '''
8 | def __init__(self, to = None, _from = None, _id = None, _type = None):
9 | super(GroupsIqProtocolEntity, self).__init__("w:g2", _id, _type, to = to, _from = _from)
10 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_groups_create.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_groups.protocolentities.iq_groups_create import CreateGroupsIqProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = CreateGroupsIqProtocolEntity("group subject")
6 |
7 | class CreateGroupsIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = CreateGroupsIqProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/test_offline_iq.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_ib.protocolentities.test_ib import IbProtocolEntityTest
2 | from yowsup.layers.protocol_ib.protocolentities.offline_ib import OfflineIbProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | class OfflineIbProtocolEntityTest(IbProtocolEntityTest):
5 | def setUp(self):
6 | super(OfflineIbProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = OfflineIbProtocolEntity
8 | self.node.addChild(ProtocolTreeNode("offline", {"count": "5"}))
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/protocolentities/test_receipt_incoming.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_receipts.protocolentities import IncomingReceiptProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 | import time
5 |
6 | class IncomingReceiptProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = IncomingReceiptProtocolEntity
9 | self.node = IncomingReceiptProtocolEntity("123", "sender", int(time.time())).toProtocolTreeNode()
10 |
--------------------------------------------------------------------------------
/yowsup/config/base/config.py:
--------------------------------------------------------------------------------
1 | class Config(object):
2 | def __init__(self, version):
3 | self._version = version
4 |
5 | def __contains__(self, item):
6 | return self[item] is not None
7 |
8 | def __getitem__(self, item):
9 | return getattr(self, "_%s" % item)
10 |
11 | def __setitem__(self, key, value):
12 | setattr(self, key, value)
13 |
14 | def keys(self):
15 | return [var[1:] for var in vars(self)]
16 |
17 | @property
18 | def version(self):
19 | return self._version
20 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/test_ack_outgoing.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_acks.protocolentities.ack_outgoing import OutgoingAckProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = OutgoingAckProtocolEntity("12345", "receipt", "delivery", "to_jid")
6 |
7 | class OutgoingAckProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = OutgoingAckProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/common/mime.types:
--------------------------------------------------------------------------------
1 | audio/3gpp 3gpp
2 | audio/aac aac
3 | audio/aiff aif
4 | audio/amr amr
5 | audio/mp4 m4a
6 | audio/mpeg mp3 mp2 mpga mpega
7 | audio/ogg oga ogg opus spx
8 | audio/qcelp qcp
9 | audio/wav wav
10 | audio/webm webm
11 | audio/x-caf caf
12 | audio/x-ms-wma wma
13 | audio/ogg ogg
14 | image/gif gif
15 | image/jpeg jpe jpg jpeg
16 | image/png png
17 | video/3gpp 3gp
18 | video/avi avi
19 | video/mp4 mp4
20 | video/mpeg m1v mpeg mpa mpg mpe
21 | video/quicktime mov qt
22 | video/x-flv flv
23 | video/x-ms-asf asf asx
24 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/test_notification_picture.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.notification_picture import PictureNotificationProtocolEntity
2 | from yowsup.layers.protocol_notifications.protocolentities.test_notification import NotificationProtocolEntityTest
3 |
4 | class PictureNotificationProtocolEntityTest(NotificationProtocolEntityTest):
5 | def setUp(self):
6 | super(PictureNotificationProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = PictureNotificationProtocolEntity
8 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/test_presence.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_presence.protocolentities.presence import PresenceProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class PresenceProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = PresenceProtocolEntity
9 | self.node = ProtocolTreeNode("presence", {"type": "presence_type", "name": "presence_name"}, None, None)
10 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_groups_create_success.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs.protocolentity import ProtocolEntityTest
2 | from yowsup.layers.protocol_groups.protocolentities import SuccessCreateGroupsIqProtocolEntity
3 | import unittest
4 |
5 | entity = SuccessCreateGroupsIqProtocolEntity("123-456", "431-123")
6 |
7 | class SuccessCreateGroupsIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = SuccessCreateGroupsIqProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/test_presence_available.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_presence.protocolentities.presence_available import AvailablePresenceProtocolEntity
2 | from yowsup.layers.protocol_presence.protocolentities.test_presence import PresenceProtocolEntityTest
3 |
4 | class AvailablePresenceProtocolEntityTest(PresenceProtocolEntityTest):
5 | def setUp(self):
6 | super(AvailablePresenceProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = AvailablePresenceProtocolEntity
8 | self.node.setAttribute("type", "available")
9 |
--------------------------------------------------------------------------------
/yowsup/layers/logger/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer
2 | import logging
3 | logger = logging.getLogger(__name__)
4 | class YowLoggerLayer(YowLayer):
5 |
6 | def send(self, data):
7 | ldata = list(data) if type(data) is bytearray else data
8 | logger.debug("tx:\n%s" % ldata)
9 | self.toLower(data)
10 |
11 | def receive(self, data):
12 | ldata = list(data) if type(data) is bytearray else data
13 | logger.debug("rx:\n%s" % ldata)
14 | self.toUpper(data)
15 |
16 | def __str__(self):
17 | return "Logger Layer"
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/ib.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class IbProtocolEntity(ProtocolEntity):
3 | '''
4 |
5 | '''
6 | def __init__(self):
7 | super(IbProtocolEntity, self).__init__("ib")
8 |
9 | def toProtocolTreeNode(self):
10 | return self._createProtocolTreeNode({}, None, None)
11 |
12 | def __str__(self):
13 | out = "Ib:\n"
14 | return out
15 |
16 | @staticmethod
17 | def fromProtocolTreeNode(node):
18 | return IbProtocolEntity()
19 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/test_ack_incoming.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_acks.protocolentities.ack_incoming import IncomingAckProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 | import time
5 |
6 | entity = IncomingAckProtocolEntity("12345", "message", "sender@s.whatsapp.com", int(time.time()))
7 |
8 | class IncomingAckProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
9 | def setUp(self):
10 | self.ProtocolEntity = IncomingAckProtocolEntity
11 | self.node = entity.toProtocolTreeNode()
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/test_clean_iq.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from yowsup.layers.protocol_ib.protocolentities.clean_iq import CleanIqProtocolEntity
3 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
4 |
5 | class CleanIqProtocolEntityTest(IqProtocolEntityTest):
6 | def setUp(self):
7 | super(CleanIqProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = CleanIqProtocolEntity
9 | cleanNode = ProtocolTreeNode("clean", {"type": "groups"})
10 | self.node.addChild(cleanNode)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/test_presence_unavailable.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_presence.protocolentities.presence_unavailable import UnavailablePresenceProtocolEntity
2 | from yowsup.layers.protocol_presence.protocolentities.test_presence import PresenceProtocolEntityTest
3 |
4 | class UnavailablePresenceProtocolEntityTest(PresenceProtocolEntityTest):
5 | def setUp(self):
6 | super(UnavailablePresenceProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = UnavailablePresenceProtocolEntity
8 | self.node.setAttribute("type", "unavailable")
9 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/test_iq_unregister.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_profiles.protocolentities import UnregisterIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | class UnregisterIqProtocolEntityTest(IqProtocolEntityTest):
6 | def setUp(self):
7 | super(UnregisterIqProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = UnregisterIqProtocolEntity
9 | self.node.addChild(ProtocolTreeNode("remove", {"xmlns": "urn:xmpp:whatsapp:account"}))
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/test_iq_error.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_iq.protocolentities import ErrorIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | class ErrorIqProtocolEntityTest(IqProtocolEntityTest):
6 | def setUp(self):
7 | super(ErrorIqProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = ErrorIqProtocolEntity
9 | errorNode = ProtocolTreeNode("error", {"code": "123", "text": "abc"})
10 | self.node.addChild(errorNode)
11 |
--------------------------------------------------------------------------------
/tox.ini:
--------------------------------------------------------------------------------
1 | # Tox (http://tox.testrun.org/) is a tool for running tests
2 | # in multiple virtualenvs. This configuration file will run the
3 | # test suite on all supported python versions. To use it, "pip install tox"
4 | # and then run "tox" from this directory.
5 |
6 | [tox]
7 | skip_missing_interpreters = true
8 | envlist = py27, py32, py33, py34, py35, py36, py37
9 |
10 | [testenv]
11 | commands = nosetests --exclude demos yowsup
12 | deps =
13 | py26: importlib
14 | nose
15 | python-dateutil
16 | appdirs
17 | python-axolotl==0.2.2
18 | protobuf>=3.6.0
19 | consonance==0.1.5
20 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/test_iq_privacy_get.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_profiles.protocolentities import GetPrivacyIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | entity = GetPrivacyIqProtocolEntity()
6 |
7 | class GetPrivacyIqProtocolEntityTest(IqProtocolEntityTest):
8 | def setUp(self):
9 | super(GetPrivacyIqProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = GetPrivacyIqProtocolEntity
11 | self.node = entity.toProtocolTreeNode()
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/test_chatstate_incoming.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_chatstate.protocolentities.chatstate_incoming import IncomingChatstateProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = IncomingChatstateProtocolEntity(IncomingChatstateProtocolEntity.STATE_TYPING, "jid@s.whatsapp.net")
6 |
7 | class IncomingChatstateProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = IncomingChatstateProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/test_chatstate_outgoing.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_chatstate.protocolentities.chatstate_outgoing import OutgoingChatstateProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, "jid@s.whatsapp.net")
6 |
7 | class OutgoingChatstateProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = OutgoingChatstateProtocolEntity
10 | self.node = entity.toProtocolTreeNode()
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/test_presence_subscribe.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_presence.protocolentities.presence_subscribe import SubscribePresenceProtocolEntity
2 | from yowsup.layers.protocol_presence.protocolentities.test_presence import PresenceProtocolEntityTest
3 |
4 | class SubscribePresenceProtocolEntityTest(PresenceProtocolEntityTest):
5 | def setUp(self):
6 | super(SubscribePresenceProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = SubscribePresenceProtocolEntity
8 | self.node.setAttribute("type", "subscribe")
9 | self.node.setAttribute("to", "subscribe_jid")
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayer
2 | from .protocolentities import *
3 | class YowAckProtocolLayer(YowProtocolLayer):
4 | def __init__(self):
5 | handleMap = {
6 | "ack": (self.recvAckNode, self.sendAckEntity)
7 | }
8 | super(YowAckProtocolLayer, self).__init__(handleMap)
9 |
10 | def __str__(self):
11 | return "Ack Layer"
12 |
13 | def sendAckEntity(self, entity):
14 | self.entityToLower(entity)
15 |
16 | def recvAckNode(self, node):
17 | self.toUpper(IncomingAckProtocolEntity.fromProtocolTreeNode(node))
18 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .iq_key_get import GetKeysIqProtocolEntity
2 | from .iq_keys_set import SetKeysIqProtocolEntity
3 | from .iq_keys_get_result import ResultGetKeysIqProtocolEntity
4 | from .message_encrypted import EncryptedMessageProtocolEntity
5 | from .enc import EncProtocolEntity
6 | from .receipt_outgoing_retry import RetryOutgoingReceiptProtocolEntity
7 | from .receipt_incoming_retry import RetryIncomingReceiptProtocolEntity
8 | from .notification_encrypt_identitychange import IdentityChangeEncryptNotification
9 | from .notification_encrypt_requestkeys import RequestKeysEncryptNotification
10 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/test_notification_encrypt_requestkeys.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.test_notification import NotificationProtocolEntityTest
2 | from yowsup.layers.axolotl.protocolentities import RequestKeysEncryptNotification
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 |
6 | class TestRequestKeysEncryptNotification(NotificationProtocolEntityTest):
7 | def setUp(self):
8 | super(TestRequestKeysEncryptNotification, self).setUp()
9 | self.ProtocolEntity = RequestKeysEncryptNotification
10 | self.node.addChild(ProtocolTreeNode("count", {"value": "9"}))
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/test_presence_unsubscribe.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_presence.protocolentities.presence_unsubscribe import UnsubscribePresenceProtocolEntity
2 | from yowsup.layers.protocol_presence.protocolentities.test_presence import PresenceProtocolEntityTest
3 |
4 | class UnsubscribePresenceProtocolEntityTest(PresenceProtocolEntityTest):
5 | def setUp(self):
6 | super(UnsubscribePresenceProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = UnsubscribePresenceProtocolEntity
8 | self.node.setAttribute("type", "unsubscribe")
9 | self.node.setAttribute("to", "some_jid")
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/test_iq_privacy_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_profiles.protocolentities import SetPrivacyIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | entity = SetPrivacyIqProtocolEntity("all", ["profile","last","status"])
6 |
7 | class SetPrivacyIqProtocolEntityTest(IqProtocolEntityTest):
8 | def setUp(self):
9 | super(SetPrivacyIqProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = SetPrivacyIqProtocolEntity
11 | self.node = entity.toProtocolTreeNode()
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/test_iq_status_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_profiles.protocolentities import SetStatusIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | class SetStatusIqProtocolEntityTest(IqProtocolEntityTest):
6 | def setUp(self):
7 | super(SetStatusIqProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = SetStatusIqProtocolEntity
9 | statusNode = ProtocolTreeNode("status", {}, [], b"Hey there, I'm using WhatsApp")
10 | self.node.addChild(statusNode)
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_privacy/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
2 | from .protocolentities import *
3 | class YowPrivacyProtocolLayer(YowProtocolLayer):
4 | def __init__(self):
5 | handleMap = {
6 | "iq": (self.recvIq, self.sendIq)
7 | }
8 | super(YowPrivacyProtocolLayer, self).__init__(handleMap)
9 |
10 | def __str__(self):
11 | return "Privacy Layer"
12 |
13 | def sendIq(self, entity):
14 | if entity.getXmlns() == "jabber:iq:privacy":
15 | self.entityToLower(entity)
16 |
17 | def recvIq(self, node):
18 | pass
19 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/test_dirty_ib.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_ib.protocolentities.test_ib import IbProtocolEntityTest
2 | from yowsup.layers.protocol_ib.protocolentities.dirty_ib import DirtyIbProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | class DirtyIbProtocolEntityTest(IbProtocolEntityTest):
5 | def setUp(self):
6 | super(DirtyIbProtocolEntityTest, self).setUp()
7 | self.ProtocolEntity = DirtyIbProtocolEntity
8 | dirtyNode = ProtocolTreeNode("dirty")
9 | dirtyNode["timestamp"] = "123456"
10 | dirtyNode["type"] = "groups"
11 | self.node.addChild(dirtyNode)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_picture.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
2 | class PictureIqProtocolEntity(IqProtocolEntity):
3 | '''
4 | When receiving a profile picture:
5 |
6 |
7 | {{Binary bytes of the picture.}}
8 |
9 |
10 | '''
11 | XMLNS = "w:profile:picture"
12 |
13 | def __init__(self, jid, _id = None, type = "get"):
14 | super(PictureIqProtocolEntity, self).__init__(self.__class__.XMLNS, _id = _id, _type=type, to = jid)
--------------------------------------------------------------------------------
/yowsup/axolotl/exceptions.py:
--------------------------------------------------------------------------------
1 | class NoSessionException(Exception):
2 | pass
3 |
4 |
5 | class UntrustedIdentityException(Exception):
6 | def __init__(self, name, identity_key):
7 | self._name = name
8 | self._identity_key = identity_key
9 |
10 | @property
11 | def name(self):
12 | return self._name
13 |
14 | @property
15 | def identity_key(self):
16 | return self._identity_key
17 |
18 |
19 | class InvalidMessageException(Exception):
20 | pass
21 |
22 |
23 | class InvalidKeyIdException(Exception):
24 | pass
25 |
26 |
27 | class DuplicateMessageException(Exception):
28 | pass
29 |
30 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/response.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class ResponseProtocolEntity(ProtocolEntity):
3 | def __init__(self, data, xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"):
4 | super(ResponseProtocolEntity, self).__init__("response")
5 | self.xmlns = xmlns
6 | self.data = data
7 |
8 | def toProtocolTreeNode(self):
9 | return self._createProtocolTreeNode({"xmlns": self.xmlns}, children = None, data = self.data)
10 |
11 | @staticmethod
12 | def fromProtocolTreeNode(node):
13 | return ResponseProtocolEntity(node.getData(), node.getAttributeValue("xmlns"))
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/test_success.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.auth.protocolentities.success import SuccessProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 |
7 | class SuccessProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
8 | def setUp(self):
9 | self.ProtocolEntity = SuccessProtocolEntity
10 | attribs = {
11 | "creation": "1234",
12 | "location": "atn",
13 | "props": "2",
14 | "t": "1415470561"
15 | }
16 | self.node = ProtocolTreeNode("success", attribs)
17 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_ping.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq import IqProtocolEntity
3 | class PingIqProtocolEntity(IqProtocolEntity):
4 |
5 | '''
6 | Receive
7 |
8 |
9 | Send
10 |
11 |
12 | '''
13 |
14 | def __init__(self, _from = None, to = None, _id = None):
15 | super(PingIqProtocolEntity, self).__init__("urn:xmpp:ping" if _from else "w:p", _id = _id, _type = "get", _from = _from, to = to)
16 |
--------------------------------------------------------------------------------
/yowsup/axolotl/factory.py:
--------------------------------------------------------------------------------
1 | from yowsup.axolotl.manager import AxolotlManager
2 | from yowsup.common.tools import StorageTools
3 | from yowsup.axolotl.store.sqlite.liteaxolotlstore import LiteAxolotlStore
4 | import logging
5 |
6 | logger = logging.getLogger(__name__)
7 |
8 |
9 | class AxolotlManagerFactory(object):
10 | DB = "axolotl.db"
11 |
12 | def get_manager(self, profile_name, username):
13 | logger.debug("get_manager(profile_name=%s, username=%s)" % (profile_name, username))
14 | dbpath = StorageTools.constructPath(profile_name, self.DB)
15 | store = LiteAxolotlStore(dbpath)
16 | return AxolotlManager(store, username)
17 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_iq_requestupload_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq_result import ResultIqProtocolEntityTest
2 | from yowsup.layers.protocol_media.protocolentities import ResultRequestUploadIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | class ResultRequestUploadIqProtocolEntityTest(ResultIqProtocolEntityTest):
5 | def setUp(self):
6 | super(ResultRequestUploadIqProtocolEntityTest, self).setUp()
7 | mediaNode = ProtocolTreeNode("encr_media", {"url": "url", "ip": "1.2.3.4"})
8 | self.ProtocolEntity = ResultRequestUploadIqProtocolEntity
9 | self.node.addChild(mediaNode)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/test_iq_privacy_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_profiles.protocolentities import ResultPrivacyIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | entity = ResultPrivacyIqProtocolEntity({"profile":"all","last":"none","status":"contacts"})
6 |
7 | class ResultPrivacyIqProtocolEntityTest(IqProtocolEntityTest):
8 | def setUp(self):
9 | super(ResultPrivacyIqProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = ResultPrivacyIqProtocolEntity
11 | self.node = entity.toProtocolTreeNode()
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/test_layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayerTest
2 | from yowsup.layers.protocol_acks import YowAckProtocolLayer
3 | from yowsup.layers.protocol_acks.protocolentities.test_ack_incoming import entity as incomingAckEntity
4 | from yowsup.layers.protocol_acks.protocolentities.test_ack_outgoing import entity as outgoingAckEntity
5 | class YowAckProtocolLayerTest(YowProtocolLayerTest, YowAckProtocolLayer):
6 | def setUp(self):
7 | YowAckProtocolLayer.__init__(self)
8 |
9 | def test_receive(self):
10 | self.assertReceived(incomingAckEntity)
11 |
12 | def test_send(self):
13 | self.assertSent(outgoingAckEntity)
14 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
2 | from .protocolentities import *
3 | class YowReceiptProtocolLayer(YowProtocolLayer):
4 | def __init__(self):
5 | handleMap = {
6 | "receipt": (self.recvReceiptNode, self.sendReceiptEntity)
7 | }
8 | super(YowReceiptProtocolLayer, self).__init__(handleMap)
9 |
10 | def __str__(self):
11 | return "Receipt Layer"
12 |
13 | def sendReceiptEntity(self, entity):
14 | self.entityToLower(entity)
15 |
16 | def recvReceiptNode(self, node):
17 | self.toUpper(IncomingReceiptProtocolEntity.fromProtocolTreeNode(node))
18 |
19 |
20 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
2 | from .protocolentities import *
3 | class YowChatstateProtocolLayer(YowProtocolLayer):
4 | def __init__(self):
5 | handleMap = {
6 | "chatstate": (self.recvChatstateNode, self.sendChatstateEntity)
7 | }
8 | super(YowChatstateProtocolLayer, self).__init__(handleMap)
9 |
10 | def __str__(self):
11 | return "Chatstate Layer"
12 |
13 | def sendChatstateEntity(self, entity):
14 | self.entityToLower(entity)
15 |
16 | def recvChatstateNode(self, node):
17 | self.toUpper(IncomingChatstateProtocolEntity.fromProtocolTreeNode(node))
18 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/test_notification_status.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.notification_status import StatusNotificationProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_notifications.protocolentities.test_notification import NotificationProtocolEntityTest
4 |
5 | class StatusNotificationProtocolEntityTest(NotificationProtocolEntityTest):
6 | def setUp(self):
7 | super(StatusNotificationProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = StatusNotificationProtocolEntity
9 | setNode = ProtocolTreeNode("set", {}, [], b"status_data")
10 | self.node.addChild(setNode)
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_iq_requestupload.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.protocol_media.protocolentities import RequestUploadIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | class RequestUploadIqProtocolEntityTest(IqProtocolEntityTest):
5 | def setUp(self):
6 | super(RequestUploadIqProtocolEntityTest, self).setUp()
7 | mediaNode = ProtocolTreeNode("encr_media", {"hash": "hash", "size": "1234", "orighash": "orighash", "type": "image"})
8 | self.ProtocolEntity = RequestUploadIqProtocolEntity
9 | self.node.setAttribute("type", "set")
10 | self.node.addChild(mediaNode)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .iq_unregister import UnregisterIqProtocolEntity
2 | from .iq_status_set import SetStatusIqProtocolEntity
3 | from .iq_statuses_get import GetStatusesIqProtocolEntity
4 | from .iq_statuses_result import ResultStatusesIqProtocolEntity
5 | from .iq_picture_get import GetPictureIqProtocolEntity
6 | from .iq_picture_get_result import ResultGetPictureIqProtocolEntity
7 | from .iq_pictures_list import ListPicturesIqProtocolEntity
8 | from .iq_picture_set import SetPictureIqProtocolEntity
9 | from .iq_privacy_set import SetPrivacyIqProtocolEntity
10 | from .iq_privacy_get import GetPrivacyIqProtocolEntity
11 | from .iq_privacy_result import ResultPrivacyIqProtocolEntity
12 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/test_notification_contact_remove.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_contacts.protocolentities import RemoveContactNotificationProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import time
4 | import unittest
5 |
6 | entity = RemoveContactNotificationProtocolEntity("1234", "jid@s.whatsapp.net",
7 | int(time.time()), "notify", False, "contactjid@s.whatsapp.net")
8 |
9 | class RemoveContactNotificationProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
10 | def setUp(self):
11 | self.ProtocolEntity = RemoveContactNotificationProtocolEntity
12 | self.node = entity.toProtocolTreeNode()
13 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/test_notification_contact_update.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_contacts.protocolentities import UpdateContactNotificationProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import time
4 | import unittest
5 |
6 | entity = UpdateContactNotificationProtocolEntity("1234", "jid@s.whatsapp.net",
7 | int(time.time()), "notify", False,"contactjid@s.whatsapp.net")
8 |
9 | class UpdateContactNotificationProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
10 | def setUp(self):
11 | self.ProtocolEntity = UpdateContactNotificationProtocolEntity
12 | self.node = entity.toProtocolTreeNode()
13 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/failure.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class FailureProtocolEntity(ProtocolEntity):
3 |
4 | def __init__(self, reason):
5 | super(FailureProtocolEntity, self).__init__("failure")
6 | self.reason = reason
7 |
8 | def __str__(self):
9 | out = "Failure:\n"
10 | out += "Reason: %s\n" % self.reason
11 | return out
12 |
13 | def getReason(self):
14 | return self.reason
15 |
16 | def toProtocolTreeNode(self):
17 | return self._createProtocolTreeNode({"reason": self.reason})
18 |
19 | @staticmethod
20 | def fromProtocolTreeNode(node):
21 | return FailureProtocolEntity( node["reason"] )
22 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_crypto.py:
--------------------------------------------------------------------------------
1 | from .iq import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | class CryptoIqProtocolEntity(IqProtocolEntity):
4 | def __init__(self):
5 | super(CryptoIqProtocolEntity, self).__init__("urn:xmpp:whatsapp:account", _type="get")
6 |
7 | def toProtocolTreeNode(self):
8 | node = super(CryptoIqProtocolEntity, self).toProtocolTreeNode()
9 | cryptoNode = ProtocolTreeNode("crypto", {"action": "create"})
10 | googleNode = ProtocolTreeNode("google", data = "fe5cf90c511fb899781bbed754577098e460d048312c8b36c11c91ca4b49ca34".decode('hex'))
11 | cryptoNode.addChild(googleNode)
12 | node.addChild(cryptoNode)
13 | return node
--------------------------------------------------------------------------------
/yowsup/layers/network/dispatcher/dispatcher.py:
--------------------------------------------------------------------------------
1 | class ConnectionCallbacks(object):
2 | def onConnected(self):
3 | pass
4 |
5 | def onDisconnected(self):
6 | pass
7 |
8 | def onRecvData(self, data):
9 | pass
10 |
11 | def onConnecting(self):
12 | pass
13 |
14 | def onConnectionError(self, error):
15 | pass
16 |
17 |
18 | class YowConnectionDispatcher(object):
19 | def __init__(self, connectionCallbacks):
20 | assert isinstance(connectionCallbacks, ConnectionCallbacks)
21 | self.connectionCallbacks = connectionCallbacks
22 |
23 | def connect(self, host):
24 | pass
25 |
26 | def disconnect(self):
27 | pass
28 |
29 | def sendData(self, data):
30 | pass
--------------------------------------------------------------------------------
/yowsup/demos/echoclient/stack.py:
--------------------------------------------------------------------------------
1 | from yowsup.stacks import YowStackBuilder
2 | from .layer import EchoLayer
3 | from yowsup.layers import YowLayerEvent
4 | from yowsup.layers.network import YowNetworkLayer
5 |
6 |
7 | class YowsupEchoStack(object):
8 | def __init__(self, profile):
9 | stackBuilder = YowStackBuilder()
10 |
11 | self._stack = stackBuilder\
12 | .pushDefaultLayers()\
13 | .push(EchoLayer)\
14 | .build()
15 |
16 | self._stack.setProfile(profile)
17 |
18 | def set_prop(self, key, val):
19 | self._stack.setProp(key, val)
20 |
21 | def start(self):
22 | self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
23 | self._stack.loop()
24 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.message_media import MediaMessageProtocolEntity
2 | from yowsup.layers.protocol_messages.protocolentities.test_message import MessageProtocolEntityTest
3 | from yowsup.structs import ProtocolTreeNode
4 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
5 |
6 |
7 | class MediaMessageProtocolEntityTest(MessageProtocolEntityTest):
8 | def setUp(self):
9 | super(MediaMessageProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = MediaMessageProtocolEntity
11 | proto_node = ProtocolTreeNode("proto", {"mediatype": "image"}, None, Message().SerializeToString())
12 | self.node.addChild(proto_node)
13 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/serialize.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.transforms.props import PropsTransform
2 |
3 |
4 | class SerializeTransform(PropsTransform):
5 |
6 | def __init__(self, serialize_map):
7 | """
8 | {
9 | "keystore": serializer
10 | }
11 | :param serialize_map:
12 | :type serialize_map:
13 | """
14 | transform_map = {}
15 | reverse_map = {}
16 | for key, val in serialize_map:
17 | transform_map[key] = lambda key, val: key, serialize_map[key].serialize(val)
18 | reverse_map[key] = lambda key, val: key, serialize_map[key].deserialize(val)
19 |
20 | super(SerializeTransform, self).__init__(transform_map=transform_map, reverse_map=reverse_map)
21 |
22 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_calls/protocolentities/test_call.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_calls.protocolentities.call import CallProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class CallProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = CallProtocolEntity
9 | children = [ProtocolTreeNode("offer", {"call-id": "call_id"})]
10 | attribs = {
11 | "t": "12345",
12 | "from": "from_jid",
13 | "offline": "0",
14 | "id": "message_id",
15 | "notify": "notify_name"
16 | }
17 | self.node = ProtocolTreeNode("call", attribs, children)
18 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/test_notification_picture_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.notification_picture_set import SetPictureNotificationProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_notifications.protocolentities.test_notification_picture import PictureNotificationProtocolEntityTest
4 |
5 | class SetPictureNotificationProtocolEntityTest(PictureNotificationProtocolEntityTest):
6 | def setUp(self):
7 | super(SetPictureNotificationProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = SetPictureNotificationProtocolEntity
9 | setNode = ProtocolTreeNode("set", {"jid": "SET_JID", "id": "123"}, None, None)
10 | self.node.addChild(setNode)
11 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/config_dict.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 |
3 |
4 | class ConfigDictTransform(ConfigTransform):
5 | def __init__(self, cls):
6 | self._cls = cls
7 |
8 | def transform(self, config):
9 | """
10 | :param config:
11 | :type config: dict
12 | :return:
13 | :rtype: yowsup.config.config.Config
14 | """
15 | out = {}
16 | for prop in vars(config):
17 | out[prop] = getattr(config, prop)
18 | return out
19 |
20 | def reverse(self, data):
21 | """
22 | :param data:
23 | :type data: yowsup,config.config.Config
24 | :return:
25 | :rtype: dict
26 | """
27 | return self._cls(**data)
28 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/test_notification.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.notification import NotificationProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class NotificationProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = NotificationProtocolEntity
9 | attribs = {
10 | "t": "12345",
11 | "from": "from_jid",
12 | "offline": "0",
13 | "type": "notif_type",
14 | "id": "message-id",
15 | "notify": "notify_name"
16 | }
17 | self.node = ProtocolTreeNode("notification", attribs)
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/test_notification_contact_add.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_contacts.protocolentities import AddContactNotificationProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import time
4 | import unittest
5 |
6 | entity = AddContactNotificationProtocolEntity("1234", "jid@s.whatsapp.net", int(time.time()), "notify", False,
7 | "sender@s.whatsapp.net")
8 |
9 | class AddContactNotificationProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
10 | def setUp(self):
11 | super(AddContactNotificationProtocolEntityTest, self).setUp()
12 | self.ProtocolEntity = AddContactNotificationProtocolEntity
13 | self.node = entity.toProtocolTreeNode()
14 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/test_notification_picture_delete.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_notifications.protocolentities.notification_picture_delete import DeletePictureNotificationProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_notifications.protocolentities.test_notification_picture import PictureNotificationProtocolEntityTest
4 |
5 | class DeletePictureNotificationProtocolEntityTest(PictureNotificationProtocolEntityTest):
6 | def setUp(self):
7 | super(DeletePictureNotificationProtocolEntityTest, self).setUp()
8 | self.ProtocolEntity = DeletePictureNotificationProtocolEntity
9 | deleteNode = ProtocolTreeNode("delete", {"jid": "DELETE_JID"}, None, None)
10 | self.node.addChild(deleteNode)
11 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/test_message_text.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.message_text import TextMessageProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_messages.protocolentities.test_message import MessageProtocolEntityTest
4 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
5 |
6 |
7 | class TextMessageProtocolEntityTest(MessageProtocolEntityTest):
8 | def setUp(self):
9 | super(TextMessageProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = TextMessageProtocolEntity
11 | m = Message()
12 | m.conversation = "body_data"
13 | proto_node = ProtocolTreeNode("proto", {}, None, m.SerializeToString())
14 | self.node.addChild(proto_node)
15 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/stream_features.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class StreamFeaturesProtocolEntity(ProtocolEntity):
3 | def __init__(self, features = None):
4 | super(StreamFeaturesProtocolEntity, self).__init__("stream:features")
5 | self.setFeatures(features)
6 |
7 | def setFeatures(self, features = None):
8 | self.features = features or []
9 |
10 | def toProtocolTreeNode(self):
11 | featureNodes = [ProtocolTreeNode(feature) for feature in self.features]
12 | return self._createProtocolTreeNode({}, children = featureNodes, data = None)
13 |
14 |
15 | @staticmethod
16 | def fromProtocolTreeNode(node):
17 | return StreamFeaturesProtocolEntity([fnode.tag for fnode in node.getAllChildren()])
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/test_message_text_broadcast.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.test_message_text import TextMessageProtocolEntityTest
2 | from yowsup.layers.protocol_messages.protocolentities.message_text_broadcast import BroadcastTextMessage
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 |
6 | class BroadcastTextMessageTest(TextMessageProtocolEntityTest):
7 | def setUp(self):
8 | super(BroadcastTextMessageTest, self).setUp()
9 | self.ProtocolEntity = BroadcastTextMessage
10 | broadcastNode = ProtocolTreeNode("broadcast")
11 | jids = ["jid1", "jid2"]
12 | toNodes = [ProtocolTreeNode("to", {"jid" : jid}) for jid in jids]
13 | broadcastNode.addChildren(toNodes)
14 | self.node.addChild(broadcastNode)
15 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/iq_lastseen.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.iq import IqProtocolEntity
2 | from yowsup.structs.protocoltreenode import ProtocolTreeNode
3 | class LastseenIqProtocolEntity(IqProtocolEntity):
4 | XMLNS = "jabber:iq:last"
5 | def __init__(self, jid, _id = None):
6 | super(LastseenIqProtocolEntity, self).__init__(self.__class__.XMLNS, _type = "get", to = jid, _id = _id)
7 |
8 | @staticmethod
9 | def fromProtocolTreeNode(node):
10 | return LastseenIqProtocolEntity(node["to"])
11 |
12 | def toProtocolTreeNode(self):
13 | node = super(LastseenIqProtocolEntity, self).toProtocolTreeNode()
14 | node.setAttribute("xmlns", self.__class__.XMLNS)
15 | node.addChild(ProtocolTreeNode("query"))
16 | return node
17 |
--------------------------------------------------------------------------------
/yowsup/config/base/serialize.py:
--------------------------------------------------------------------------------
1 | class ConfigSerialize(object):
2 |
3 | def __init__(self, transforms):
4 | self._transforms = transforms
5 |
6 | def serialize(self, config):
7 | """
8 | :param config:
9 | :type config: yowsup.config.base.config.Config
10 | :return:
11 | :rtype: bytes
12 | """
13 | for transform in self._transforms:
14 | config = transform.transform(config)
15 | return config
16 |
17 | def deserialize(self, data):
18 | """
19 | :type cls: type
20 | :param data:
21 | :type data: bytes
22 | :return:
23 | :rtype: yowsup.config.base.config.Config
24 | """
25 | for transform in self._transforms[::-1]:
26 | data = transform.reverse(data)
27 | return data
28 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/test_layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayerTest
2 | from yowsup.layers.protocol_chatstate import YowChatstateProtocolLayer
3 | from yowsup.layers.protocol_chatstate.protocolentities import IncomingChatstateProtocolEntity, OutgoingChatstateProtocolEntity
4 |
5 | class YowChatStateProtocolLayerTest(YowProtocolLayerTest, YowChatstateProtocolLayer):
6 | def setUp(self):
7 | YowChatstateProtocolLayer.__init__(self)
8 |
9 | def test_send(self):
10 | entity = OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, "jid@s.whatsapp.net")
11 | self.assertSent(entity)
12 |
13 | def test_receive(self):
14 | entity = IncomingChatstateProtocolEntity(IncomingChatstateProtocolEntity.STATE_TYPING, "jid@s.whatsapp.net")
15 | self.assertReceived(entity)
--------------------------------------------------------------------------------
/yowsup/layers/coder/test_tokendictionary.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.coder.tokendictionary import TokenDictionary
2 | import unittest
3 | class TokenDictionaryTest(unittest.TestCase):
4 | def setUp(self):
5 | self.tokenDictionary = TokenDictionary()
6 |
7 | def test_getToken(self):
8 | self.assertEqual(self.tokenDictionary.getToken(10), "iq")
9 |
10 | def test_getIndex(self):
11 | self.assertEqual(self.tokenDictionary.getIndex("iq"), (10, False))
12 |
13 | def test_getSecondaryToken(self):
14 | self.assertEqual(self.tokenDictionary.getToken(238), "lc")
15 |
16 | def test_getSecondaryTokenExplicit(self):
17 | self.assertEqual(self.tokenDictionary.getToken(11, True), "reject")
18 |
19 | def test_getSecondaryIndex(self):
20 | self.assertEqual(self.tokenDictionary.getIndex("reject"), (11, True))
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/test_message.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.message import MessageProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.structs.protocolentity import ProtocolEntityTest
4 | import unittest
5 |
6 | class MessageProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
7 | def setUp(self):
8 | self.ProtocolEntity = MessageProtocolEntity
9 | # ORDER_MATTERS for node.toString() to output return attribs in same order
10 | attribs = {
11 | "type": "message_type",
12 | "id": "message-id",
13 | "t": "12345",
14 | "offline": "0",
15 | "from": "from_jid",
16 | "notify": "notify_name"
17 | }
18 | self.node = ProtocolTreeNode("message", attribs)
19 |
20 |
--------------------------------------------------------------------------------
/yowsup/demos/mediasink/stack.py:
--------------------------------------------------------------------------------
1 | from yowsup.stacks import YowStackBuilder
2 | from .layer import MediaSinkLayer
3 | from yowsup.layers import YowLayerEvent
4 | from yowsup.layers.network import YowNetworkLayer
5 |
6 |
7 | class MediaSinkStack(object):
8 | def __init__(self, profile, storage_dir=None):
9 | stackBuilder = YowStackBuilder()
10 |
11 | self._stack = stackBuilder\
12 | .pushDefaultLayers()\
13 | .push(MediaSinkLayer)\
14 | .build()
15 | self._stack.setProp(MediaSinkLayer.PROP_STORAGE_DIR, storage_dir)
16 | self._stack.setProfile(profile)
17 |
18 | def set_prop(self, key, val):
19 | self._stack.setProp(key, val)
20 |
21 | def start(self):
22 | self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
23 | self._stack.loop()
24 |
--------------------------------------------------------------------------------
/yowsup/layers/coder/test_decoder.py:
--------------------------------------------------------------------------------
1 | import unittest
2 | from yowsup.layers.coder.decoder import ReadDecoder
3 | from yowsup.layers.coder.tokendictionary import TokenDictionary
4 | from yowsup.structs import ProtocolTreeNode
5 | class DecoderTest(unittest.TestCase):
6 | def setUp(self):
7 | self.decoder = ReadDecoder(TokenDictionary())
8 | self.decoder.streamStarted = True
9 |
10 | def test_decode(self):
11 | data = bytearray([0, 248, 6, 9, 11, 252, 3, 120, 121, 122, 5, 252, 3, 97, 98, 99, 248, 1, 248, 4, 50, 238, 86, 255, 130, 18, 63,
12 | 252, 6, 49, 50, 51, 52, 53, 54])
13 | node = self.decoder.getProtocolTreeNode(data)
14 | targetNode = ProtocolTreeNode("message", {"from": "abc", "to":"xyz"}, [ProtocolTreeNode("media", {"width" : "123"}, data=b"123456")])
15 | self.assertEqual(node, targetNode)
16 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/proto.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class ProtoProtocolEntity(ProtocolEntity):
3 |
4 | def __init__(self, protoData, mediaType = None):
5 | super(ProtoProtocolEntity, self).__init__("proto")
6 | self.mediaType = mediaType
7 | self.protoData = protoData
8 |
9 | def getProtoData(self):
10 | return self.protoData
11 |
12 | def getMediaType(self):
13 | return self.mediaType
14 |
15 | def toProtocolTreeNode(self):
16 | attribs = {}
17 | if self.mediaType:
18 | attribs["mediatype"] = self.mediaType
19 | return ProtocolTreeNode("proto", attribs, data=self.protoData)
20 |
21 | @staticmethod
22 | def fromProtocolTreeNode(node):
23 | return ProtoProtocolEntity(node.data, node["mediatype"])
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | python: '3.7'
3 | # command to install dependencies
4 |
5 | env:
6 | global:
7 | - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
8 | - SEGFAULT_SIGNALS=all
9 | matrix:
10 | - TOXENV=py27
11 | - TOXENV=py33
12 | - TOXENV=py34
13 | - TOXENV=py35
14 | - TOXENV=py36
15 | - TOXENV=py37
16 | before_install:
17 | - python --version
18 | - uname -a
19 | - lsb_release -a
20 | install:
21 | - pip install tox
22 | - virtualenv --version
23 | - easy_install --version
24 | - pip --version
25 | - tox --version
26 | # command to run tests
27 | script:
28 | - tox -v
29 | after_failure:
30 | - more .tox/log/* | cat
31 | - more .tox/*/log/* | cat
32 | before_cache:
33 | - rm -rf $HOME/.cache/pip/log
34 | cache:
35 | directories:
36 | - $HOME/.cache/pip
37 | branches:
38 | only:
39 | - master
40 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/test_iq_sync_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_contacts.protocolentities.iq_sync_result import ResultSyncIqProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | import unittest
4 |
5 | entity = ResultSyncIqProtocolEntity("123", "1.30615237617e+17", 0,
6 | True, "123456", {"12345678": "12345678@s.whatsapp.net"},
7 | {"12345678": "12345678@s.whatsapp.net"}, ["1234"])
8 |
9 | class ResultSyncIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
10 | def setUp(self):
11 | self.ProtocolEntity = ResultSyncIqProtocolEntity
12 | self.node = entity.toProtocolTreeNode()
13 |
14 | def test_delta_result(self):
15 | del self.node.getChild("sync")["wait"]
16 | self.test_generation()
17 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_media.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_context_info import ContextInfoAttributes
2 |
3 |
4 | class MediaAttributes(object):
5 | def __init__(self, context_info=None):
6 | """
7 | :type context_info: ContextInfo | None
8 | """
9 | if context_info:
10 | assert type(context_info) is ContextInfoAttributes, type(context_info)
11 | self._context_info = context_info # type: ContextInfoAttributes | None
12 | else:
13 | self._context_info = None
14 |
15 | @property
16 | def context_info(self):
17 | return self._context_info
18 |
19 | @context_info.setter
20 | def context_info(self, value):
21 | assert type(value) is ContextInfoAttributes, type(value)
22 | self._context_info = value
23 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/test_iq_result_groups_list.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_groups.protocolentities.iq_result_groups_list import ListGroupsResultIqProtocolEntity
2 | from yowsup.structs.protocolentity import ProtocolEntityTest
3 | from yowsup.layers.protocol_groups.structs import Group
4 | import unittest
5 | import time
6 |
7 | entity = ListGroupsResultIqProtocolEntity(
8 | [
9 | Group("1234-456", "owner@s.whatsapp.net", "subject", "sOwnerJid@s.whatsapp.net", int(time.time()), int(time.time())),
10 | Group("4321-456", "owner@s.whatsapp.net", "subject", "sOwnerJid@s.whatsapp.net", int(time.time()), int(time.time()))
11 | ]
12 | )
13 |
14 | class ListGroupsResultIqProtocolEntityTest(ProtocolEntityTest, unittest.TestCase):
15 | def setUp(self):
16 | self.ProtocolEntity = ListGroupsResultIqProtocolEntity
17 | self.node = entity.toProtocolTreeNode()
18 |
--------------------------------------------------------------------------------
/yowsup/common/constants.py:
--------------------------------------------------------------------------------
1 | class YowConstants:
2 | DOMAIN = "s.whatsapp.net"
3 | ENDPOINTS = (
4 | ("e1.whatsapp.net", 443),
5 | ("e2.whatsapp.net", 443),
6 | ("e3.whatsapp.net", 443),
7 | ("e4.whatsapp.net", 443),
8 | ("e5.whatsapp.net", 443),
9 | ("e6.whatsapp.net", 443),
10 | ("e7.whatsapp.net", 443),
11 | ("e8.whatsapp.net", 443),
12 | ("e9.whatsapp.net", 443),
13 | ("e10.whatsapp.net", 443),
14 | ("e11.whatsapp.net", 443),
15 | ("e12.whatsapp.net", 443),
16 | ("e13.whatsapp.net", 443),
17 | ("e14.whatsapp.net", 443),
18 | ("e15.whatsapp.net", 443),
19 | ("e16.whatsapp.net", 443),
20 | )
21 |
22 | WHATSAPP_SERVER = "s.whatsapp.net"
23 | WHATSAPP_GROUP_SERVER = "g.us"
24 |
25 | YOWSUP = "yowsup"
26 |
27 | PREVIEW_WIDTH = 64
28 | PREVIEW_HEIGHT = 64
29 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/dict_keyval.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 |
3 |
4 | class DictKeyValTransform(ConfigTransform):
5 | def transform(self, data):
6 | """
7 | :param data:
8 | :type data: dict
9 | :return:
10 | :rtype:
11 | """
12 | out=[]
13 | keys = sorted(data.keys())
14 | for k in keys:
15 | out.append("%s=%s" % (k, data[k]))
16 | return "\n".join(out)
17 |
18 | def reverse(self, data):
19 | out = {}
20 | for l in data.split('\n'):
21 | line = l.strip()
22 | if len(line) and line[0] not in ('#',';'):
23 | prep = line.split('#', 1)[0].split(';', 1)[0].split('=', 1)
24 | varname = prep[0].strip()
25 | val = prep[1].strip()
26 | out[varname.replace('-', '_')] = val
27 | return out
28 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/challenge.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class ChallengeProtocolEntity(ProtocolEntity):
3 | def __init__(self, nonce):
4 | super(ChallengeProtocolEntity, self).__init__("challenge")
5 | self.nonce = nonce
6 |
7 | def getNonce(self):
8 | return self.nonce
9 |
10 | def toProtocolTreeNode(self):
11 | #return self._createProtocolTreeNode({}, children = None, data = self.nonce)
12 | return self._createProtocolTreeNode({}, children = [], data = "".join(map(chr, self.nonce)))
13 |
14 | def __str__(self):
15 | out = "Challenge\n"
16 | out += "Nonce: %s\n" % self.nonce
17 | return out
18 |
19 | @staticmethod
20 | def fromProtocolTreeNode(node):
21 | nonce = list(map(ord,node.getData()))
22 | entity = ChallengeProtocolEntity(bytearray(nonce))
23 | return entity
24 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/notification_contact.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from yowsup.layers.protocol_notifications.protocolentities import NotificationProtocolEntity
3 | class ContactNotificationProtocolEntity(NotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, _from, timestamp, notify, offline = False):
12 | super(ContactNotificationProtocolEntity, self).__init__("contacts", _id, _from, timestamp, notify, offline)
13 |
14 |
15 | @staticmethod
16 | def fromProtocolTreeNode(node):
17 | entity = NotificationProtocolEntity.fromProtocolTreeNode(node)
18 | entity.__class__ = ContactNotificationProtocolEntity
19 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/notification_picture.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .notification import NotificationProtocolEntity
3 | class PictureNotificationProtocolEntity(NotificationProtocolEntity):
4 | '''
5 |
7 |
8 | '''
9 |
10 | def __init__(self, _id, _from, status, timestamp, notify, offline, setJid, setId):
11 | super(PictureNotificationProtocolEntity, self).__init__("picture", _id, _from, timestamp, notify, offline)
12 | self.setData(setJid, setId)
13 |
14 | @staticmethod
15 | def fromProtocolTreeNode(node):
16 | entity = NotificationProtocolEntity.fromProtocolTreeNode(node)
17 | entity.__class__ = PictureNotificationProtocolEntity
18 | return entity
--------------------------------------------------------------------------------
/yowsup/registration/existsrequest.py:
--------------------------------------------------------------------------------
1 | from yowsup.common.http.warequest import WARequest
2 | from yowsup.common.http.waresponseparser import JSONResponseParser
3 | from yowsup.env import YowsupEnv
4 |
5 |
6 | class WAExistsRequest(WARequest):
7 |
8 | def __init__(self, config):
9 | """
10 | :param config:
11 | :type config: yowsup.config.v1.config.Config
12 | """
13 | super(WAExistsRequest,self).__init__(config)
14 | if config.id is None:
15 | raise ValueError("Config does not contain id")
16 |
17 | self.url = "v.whatsapp.net/v2/exist"
18 |
19 | self.pvars = ["status", "reason", "sms_length", "voice_length", "result","param", "login", "type",
20 | "chat_dns_domain", "edge_routing_info"
21 | ]
22 |
23 | self.setParser(JSONResponseParser())
24 | self.addParam("token", YowsupEnv.getCurrent().getToken(self._p_in))
25 |
--------------------------------------------------------------------------------
/yowsup/layers/coder/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer
2 | from .encoder import WriteEncoder
3 | from .decoder import ReadDecoder
4 | from .tokendictionary import TokenDictionary
5 |
6 |
7 | class YowCoderLayer(YowLayer):
8 |
9 | def __init__(self):
10 | YowLayer.__init__(self)
11 | tokenDictionary = TokenDictionary()
12 | self.writer = WriteEncoder(tokenDictionary)
13 | self.reader = ReadDecoder(tokenDictionary)
14 |
15 | def send(self, data):
16 | self.write(self.writer.protocolTreeNodeToBytes(data))
17 |
18 | def receive(self, data):
19 | node = self.reader.getProtocolTreeNode(bytearray(data))
20 | if node:
21 | self.toUpper(node)
22 |
23 | def write(self, i):
24 | if(type(i) in(list, tuple)):
25 | self.toLower(bytearray(i))
26 | else:
27 | self.toLower(bytearray([i]))
28 |
29 | def __str__(self):
30 | return "Coder Layer"
31 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants_add_failure.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities import ErrorIqProtocolEntity
2 | class FailureAddParticipantsIqProtocolEntity(ErrorIqProtocolEntity):
3 | '''
4 |
5 |
6 |
7 |
8 | '''
9 |
10 | def __init__(self, _id, _from, _code, _text, _backoff= 0 ):
11 | super(FailureAddParticipantsIqProtocolEntity, self).__init__(_from = _from,
12 | _id = _id, code = _code,
13 | text = _text, backoff = _backoff)
14 | @staticmethod
15 | def fromProtocolTreeNode(node):
16 | entity = ErrorIqProtocolEntity.fromProtocolTreeNode(node)
17 | entity.__class__ = FailureAddParticipantsIqProtocolEntity
18 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_contact.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.test_message_media import MediaMessageProtocolEntityTest
2 | from yowsup.layers.protocol_media.protocolentities import ContactMediaMessageProtocolEntity
3 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
4 |
5 |
6 | class ContactMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
7 | def setUp(self):
8 | super(ContactMediaMessageProtocolEntityTest, self).setUp()
9 | self.ProtocolEntity = ContactMediaMessageProtocolEntity
10 | m = Message()
11 | contact_message = Message.ContactMessage()
12 | contact_message.display_name = "abc"
13 | contact_message.vcard = b"VCARD_DATA"
14 | m.contact_message.MergeFrom(contact_message)
15 | proto_node = self.node.getChild("proto")
16 | proto_node["mediatype"] = "contact"
17 | proto_node.setData(m.SerializeToString())
18 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/meta.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 | from yowsup.config.transforms.props import PropsTransform
3 |
4 |
5 | class MetaPropsTransform(ConfigTransform):
6 | META_FORMAT = "__%s__"
7 |
8 | def __init__(self, meta_props=None, meta_format=META_FORMAT):
9 | meta_props = meta_props or ()
10 | meta_format = meta_format
11 | transform_map = {}
12 | reverse_map = {}
13 | for prop in meta_props:
14 | formatted = meta_format % prop
15 | transform_map[prop] = lambda key, val, formatted=formatted: (formatted, val)
16 | reverse_map[formatted] = lambda key, val, prop=prop: (prop, val)
17 |
18 | self._props_transform = PropsTransform(transform_map=transform_map, reverse_map=reverse_map)
19 |
20 | def transform(self, data):
21 | return self._props_transform.transform(data)
22 |
23 | def reverse(self, data):
24 | return self._props_transform.reverse(data)
25 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_protocol.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message_key import MessageKeyAttributes
2 |
3 |
4 | class ProtocolAttributes(object):
5 | TYPE_REVOKE = 0
6 | TYPES = {
7 | TYPE_REVOKE: "REVOKE"
8 | }
9 |
10 | def __init__(self, key, type):
11 | self.key = key
12 | self.type = type
13 |
14 | def __str__(self):
15 | return "[type=%s, key=%s]" % (self.TYPES[self.type], self.key)
16 |
17 | @property
18 | def key(self):
19 | return self._key
20 |
21 | @key.setter
22 | def key(self, value):
23 | assert isinstance(value, MessageKeyAttributes), type(value)
24 | self._key = value
25 |
26 | @property
27 | def type(self):
28 | return self._type
29 |
30 | @type.setter
31 | def type(self, value):
32 | assert value in self.TYPES, "Unknown type: %s" % value
33 | self._type = value
34 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .message_media import MediaMessageProtocolEntity
2 | from .message_media_downloadable import DownloadableMediaMessageProtocolEntity
3 | from .message_media_downloadable_image import ImageDownloadableMediaMessageProtocolEntity
4 | from .message_media_downloadable_audio import AudioDownloadableMediaMessageProtocolEntity
5 | from .message_media_downloadable_video import VideoDownloadableMediaMessageProtocolEntity
6 | from .message_media_downloadable_document import DocumentDownloadableMediaMessageProtocolEntity
7 | from .message_media_downloadable_sticker import StickerDownloadableMediaMessageProtocolEntity
8 | from .message_media_location import LocationMediaMessageProtocolEntity
9 | from .message_media_contact import ContactMediaMessageProtocolEntity
10 | from .message_media_extendedtext import ExtendedTextMediaMessageProtocolEntity
11 | from .iq_requestupload import RequestUploadIqProtocolEntity
12 | from .iq_requestupload_result import ResultRequestUploadIqProtocolEntity
13 |
--------------------------------------------------------------------------------
/yowsup/layers/coder/test_encoder.py:
--------------------------------------------------------------------------------
1 | import unittest
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.coder.encoder import WriteEncoder
4 | from yowsup.layers.coder.tokendictionary import TokenDictionary
5 |
6 | class EncoderTest(unittest.TestCase):
7 | def setUp(self):
8 | self.res = []
9 | self.encoder = WriteEncoder(TokenDictionary())
10 |
11 | def test_encode(self):
12 | node = ProtocolTreeNode("message", {"from": "abc", "to":"xyz"}, [ProtocolTreeNode("media", {"width" : "123"}, data=b"123456")])
13 | result = self.encoder.protocolTreeNodeToBytes(node)
14 |
15 | self.assertTrue(result in (
16 | [0, 248, 6, 9, 11, 252, 3, 120, 121, 122, 5, 252, 3, 97, 98, 99, 248, 1, 248, 4, 50, 238, 86, 255, 130, 18, 63,
17 | 252, 6, 49, 50, 51, 52, 53, 54],
18 | [0, 248, 6, 9, 5, 252, 3, 97, 98, 99, 11, 252, 3, 120, 121, 122, 248, 1, 248, 4, 50, 238, 86, 255, 130, 18, 63,
19 | 252, 6, 49, 50, 51, 52, 53, 54]
20 | )
21 | )
22 |
23 |
--------------------------------------------------------------------------------
/yowsup/demos/cli/stack.py:
--------------------------------------------------------------------------------
1 | from yowsup.stacks import YowStackBuilder
2 | from .layer import YowsupCliLayer
3 | from yowsup.layers import YowLayerEvent
4 | from yowsup.layers.axolotl.props import PROP_IDENTITY_AUTOTRUST
5 | import sys
6 |
7 |
8 | class YowsupCliStack(object):
9 | def __init__(self, profile):
10 | stackBuilder = YowStackBuilder()
11 |
12 | self._stack = stackBuilder\
13 | .pushDefaultLayers()\
14 | .push(YowsupCliLayer)\
15 | .build()
16 |
17 | self._stack.setProfile(profile)
18 | self._stack.setProp(PROP_IDENTITY_AUTOTRUST, True)
19 |
20 | def set_prop(self, prop, val):
21 | self._stack.setProp(prop, val)
22 |
23 | def start(self):
24 | print("Yowsup Cli client\n==================\nType /help for available commands\n")
25 | self._stack.broadcastEvent(YowLayerEvent(YowsupCliLayer.EVENT_START))
26 |
27 | try:
28 | self._stack.loop()
29 | except KeyboardInterrupt:
30 | print("\nYowsdown")
31 | sys.exit(0)
32 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/auth.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class AuthProtocolEntity(ProtocolEntity):
3 | def __init__(self, user, mechanism = "WAUTH-2", passive = False, nonce = None):
4 | super(AuthProtocolEntity, self).__init__("auth")
5 | self.user = user
6 | self.mechanism = mechanism
7 | self.passive = passive
8 | self.nonce = nonce
9 |
10 | def toProtocolTreeNode(self):
11 | attributes = {
12 | "user" : self.user,
13 | "mechanism" : self.mechanism,
14 | "passive" : "true" if self.passive else "false"
15 | }
16 | return self._createProtocolTreeNode(attributes, children = None, data = self.nonce)
17 |
18 | @staticmethod
19 | def fromProtocolTreeNode(node):
20 | return AuthProtocolEntity(
21 | node.getAttributeValue("user"),
22 | node.getAttributeValue("mechanism"),
23 | node.getAttributeValue("passive") != "false",
24 | node.getData()
25 | )
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_privacy_get.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 |
4 | '''
5 |
6 |
7 |
8 |
9 | '''
10 |
11 | class GetPrivacyIqProtocolEntity(IqProtocolEntity):
12 | XMLNS = "privacy"
13 | def __init__(self):
14 | super(GetPrivacyIqProtocolEntity, self).__init__(self.__class__.XMLNS, _type="get")
15 |
16 | def toProtocolTreeNode(self):
17 | node = super(GetPrivacyIqProtocolEntity, self).toProtocolTreeNode()
18 | queryNode = ProtocolTreeNode(self.__class__.XMLNS)
19 | node.addChild(queryNode)
20 | return node
21 |
22 | @staticmethod
23 | def fromProtocolTreeNode(node):
24 | assert node.getChild(GetPrivacyIqProtocolEntity.XMLNS) is not None, "Not a get privacy iq node %s" % node
25 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
26 | entity.__class__ = GetPrivacyIqProtocolEntity
27 | return entity
28 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_location.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.test_message_media import MediaMessageProtocolEntityTest
2 | from yowsup.layers.protocol_media.protocolentities import LocationMediaMessageProtocolEntity
3 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
4 |
5 |
6 | class LocationMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
7 | def setUp(self):
8 | super(LocationMediaMessageProtocolEntityTest, self).setUp()
9 | self.ProtocolEntity = LocationMediaMessageProtocolEntity
10 |
11 | m = Message()
12 | location_message = Message.LocationMessage()
13 | location_message.degrees_latitude = 30.089037
14 | location_message.degrees_longitude = 31.319488
15 | location_message.name = "kaos"
16 | location_message.url = "kaos_url"
17 |
18 | m.location_message.MergeFrom(location_message)
19 |
20 | proto_node = self.node.getChild("proto")
21 | proto_node["mediatype"] = "location"
22 | proto_node.setData(m.SerializeToString())
--------------------------------------------------------------------------------
/yowsup/demos/contacts/stack.py:
--------------------------------------------------------------------------------
1 | from .layer import SyncLayer
2 |
3 | from yowsup.stacks import YowStackBuilder
4 | from yowsup.layers import YowLayerEvent
5 | from yowsup.layers.auth import YowAuthenticationProtocolLayer
6 | from yowsup.layers.network import YowNetworkLayer
7 |
8 |
9 | class YowsupSyncStack(object):
10 | def __init__(self, profile, contacts):
11 | """
12 | :param profile:
13 | :param contacts: list of [jid ]
14 | :return:
15 | """
16 | stackBuilder = YowStackBuilder()
17 |
18 | self._stack = stackBuilder \
19 | .pushDefaultLayers() \
20 | .push(SyncLayer) \
21 | .build()
22 |
23 | self._stack.setProp(SyncLayer.PROP_CONTACTS, contacts)
24 | self._stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
25 | self._stack.setProfile(profile)
26 |
27 | def set_prop(self, key, val):
28 | self._stack.setProp(key, val)
29 |
30 | def start(self):
31 | self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
32 | self._stack.loop()
33 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/test_iq_keys_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.test_iq import IqProtocolEntityTest
2 | from yowsup.layers.axolotl.protocolentities import SetKeysIqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | class SetKeysIqProtocolEntityTest(IqProtocolEntityTest):
5 | def setUp(self):
6 | super(SetKeysIqProtocolEntityTest, self).setUp()
7 | # self.ProtocolEntity = SetKeysIqProtocolEntity
8 | #
9 | # regNode = ProtocolTreeNode("registration", data = "abcd")
10 | # idNode = ProtocolTreeNode("identity", data = "efgh")
11 | # typeNode = ProtocolTreeNode("type", data = "ijkl")
12 | # listNode = ProtocolTreeNode("list")
13 | # for i in range(0, 2):
14 | # keyNode = ProtocolTreeNode("key", children=[
15 | # ProtocolTreeNode("id", data = "id_%s" % i),
16 | # ProtocolTreeNode("value", data = "val_%s" % i)
17 | # ])
18 | # listNode.addChild(keyNode)
19 | #
20 | # self.node.addChildren([regNode, idNode, typeNode, listNode])
21 |
--------------------------------------------------------------------------------
/yowsup/demos/sendclient/stack.py:
--------------------------------------------------------------------------------
1 | from yowsup.stacks import YowStackBuilder
2 | from .layer import SendLayer
3 | from yowsup.layers import YowLayerEvent
4 | from yowsup.layers.auth import YowAuthenticationProtocolLayer
5 | from yowsup.layers.network import YowNetworkLayer
6 |
7 |
8 | class YowsupSendStack(object):
9 | def __init__(self, profile, messages):
10 | """
11 | :param profile:
12 | :param messages: list of (jid, message) tuples
13 | :return:
14 | """
15 | stackBuilder = YowStackBuilder()
16 |
17 | self._stack = stackBuilder\
18 | .pushDefaultLayers()\
19 | .push(SendLayer)\
20 | .build()
21 |
22 | self._stack.setProp(SendLayer.PROP_MESSAGES, messages)
23 | self._stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
24 | self._stack.setProfile(profile)
25 |
26 | def set_prop(self, key, val):
27 | self._stack.setProp(key, val)
28 |
29 | def start(self):
30 | self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
31 | self._stack.loop()
32 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_privacy/protocolentities/privacylist_iq.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | class PrivacyListIqProtocolEntity(IqProtocolEntity):
4 | def __init__(self, name = "default"):
5 | super(PrivacyListIqProtocolEntity, self).__init__("jabber:iq:privacy", _type="get")
6 | self.setListName(name)
7 |
8 | def setListName(self, name):
9 | self.listName = name
10 |
11 | def toProtocolTreeNode(self):
12 | node = super(PrivacyListIqProtocolEntity, self).toProtocolTreeNode()
13 | queryNode = ProtocolTreeNode("query")
14 | listNode = ProtocolTreeNode("list", {"name": self.listName})
15 | queryNode.addChild(listNode)
16 | node.addChild(queryNode)
17 | return node
18 |
19 | @staticmethod
20 | def fromProtocolTreeNode(node):
21 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
22 | entity.__class__ = PrivacyListIqProtocolEntity
23 | entity.setListName(node.getChild("query").getChild("list")["name"])
24 | return entity
25 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_unregister.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | class UnregisterIqProtocolEntity(IqProtocolEntity):
6 |
7 | XMLNS = "urn:xmpp:whatsapp:account"
8 |
9 | def __init__(self):
10 | super(UnregisterIqProtocolEntity, self).__init__(_type = "get", to = YowConstants.WHATSAPP_SERVER)
11 |
12 | def toProtocolTreeNode(self):
13 | node = super(UnregisterIqProtocolEntity, self).toProtocolTreeNode()
14 | rmNode = ProtocolTreeNode("remove", {"xmlns": self.__class__.XMLNS})
15 | node.addChild(rmNode)
16 | return node
17 |
18 | @staticmethod
19 | def fromProtocolTreeNode(node):
20 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
21 | entity.__class__ = UnregisterIqProtocolEntity
22 | removeNode = node.getChild("remove")
23 | assert removeNode["xmlns"] == UnregisterIqProtocolEntity.XMLNS, "Not an account delete xmlns, got %s" % removeNode["xmlns"]
24 |
25 | return entity
--------------------------------------------------------------------------------
/yowsup/config/transforms/map.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 |
3 |
4 | class MapTransform(ConfigTransform):
5 |
6 | def __init__(self, transform_map=None, reverse_map=None):
7 | """
8 | :param transform_map:
9 | :type transform_map: function | None
10 | :param reverse_map:
11 | :type reverse_map: function | None
12 | """
13 | self._transform_map = transform_map # type: function | None
14 | self._reverse_map = reverse_map # type: function | None
15 |
16 | def transform(self, data):
17 | if self._transform_map is not None:
18 | out = {}
19 | for key, val in data.items():
20 | key, val = self._transform_map(key, val)
21 | out[key] = val
22 | return out
23 | return data
24 |
25 | def reverse(self, data):
26 | if self._reverse_map is not None:
27 | out = {}
28 | for key, val in data.items():
29 | key, val = self._reverse_map(key, val)
30 | out[key] = val
31 | return out
32 | return data
33 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_downloadable_audio.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.message_media_downloadable_audio import AudioDownloadableMediaMessageProtocolEntity
2 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
3 | from .test_message_media import MediaMessageProtocolEntityTest
4 |
5 |
6 | class AudioDownloadableMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
7 | def setUp(self):
8 | super(AudioDownloadableMediaMessageProtocolEntityTest, self).setUp()
9 | self.ProtocolEntity = AudioDownloadableMediaMessageProtocolEntity
10 | proto_node = self.node.getChild("proto")
11 | m = Message()
12 | media_message = Message.AudioMessage()
13 | media_message.url = "url"
14 | media_message.mimetype = "audio/ogg"
15 | media_message.file_sha256 = b"SHA256"
16 | media_message.file_length = 123
17 | media_message.media_key = b"MEDIA_KEY"
18 | media_message.seconds = 24
19 | media_message.ptt = True
20 | m.audio_message.MergeFrom(media_message)
21 | proto_node.setData(m.SerializeToString())
22 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/iq_lastseen_result.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_iq.protocolentities.iq_result import ResultIqProtocolEntity
2 | from yowsup.structs.protocoltreenode import ProtocolTreeNode
3 | class ResultLastseenIqProtocolEntity(ResultIqProtocolEntity):
4 | def __init__(self, jid, seconds, _id = None):
5 | super(ResultLastseenIqProtocolEntity, self).__init__(_from=jid, _id=_id)
6 | self.setSeconds(seconds)
7 |
8 | def setSeconds(self, seconds):
9 | self.seconds = int(seconds)
10 |
11 | def getSeconds(self):
12 | return self.seconds
13 |
14 | def __str__(self):
15 | out = super(ResultIqProtocolEntity, self).__str__()
16 | out += "Seconds: %s\n" % self.seconds
17 | return out
18 |
19 | def toProtocolTreeNode(self):
20 | node = super(ResultLastseenIqProtocolEntity, self).toProtocolTreeNode()
21 | node.addChild(ProtocolTreeNode("query", {"seconds": str(self.seconds)}))
22 | return node
23 |
24 | @staticmethod
25 | def fromProtocolTreeNode(node):
26 | return ResultLastseenIqProtocolEntity(node["from"], node.getChild("query")["seconds"], node["id"])
--------------------------------------------------------------------------------
/yowsup/config/transforms/filter.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 |
3 |
4 | class FilterTransform(ConfigTransform):
5 |
6 | def __init__(self, transform_filter=None, reverse_filter=None):
7 | """
8 | :param transform_filter:
9 | :type transform_filter: function | None
10 | :param reverse_filter:
11 | :type reverse_filter: function | None
12 | """
13 | self._transform_filter = transform_filter # type: function | None
14 | self._reverse_filter = reverse_filter # type: function | None
15 |
16 | def transform(self, data):
17 | if self._transform_filter is not None:
18 | out = {}
19 | for key, val in data.items():
20 | if self._transform_filter(key, val):
21 | out[key] = val
22 | return out
23 | return data
24 |
25 | def reverse(self, data):
26 | if self._reverse_filter is not None:
27 | out = {}
28 | for key, val in data.items():
29 | if self._reverse_filter(key, val):
30 | out[key] = val
31 | return out
32 | return data
33 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/notification_encrypt_identitychange.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_notifications.protocolentities import NotificationProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 |
6 | class IdentityChangeEncryptNotification(NotificationProtocolEntity):
7 | """
8 |
9 |
10 |
11 | """
12 | def __init__(self, timestamp, _id = None, notify = None, offline = None):
13 | super(IdentityChangeEncryptNotification, self).__init__(
14 | "encrypt", _id, YowConstants.WHATSAPP_SERVER, timestamp, notify, offline
15 | )
16 |
17 | def toProtocolTreeNode(self):
18 | node = super(IdentityChangeEncryptNotification, self).toProtocolTreeNode()
19 | node.addChild(ProtocolTreeNode("identity"))
20 | return node
21 |
22 | @staticmethod
23 | def fromProtocolTreeNode(node):
24 | entity = NotificationProtocolEntity.fromProtocolTreeNode(node)
25 | entity.__class__ = IdentityChangeEncryptNotification
26 | return entity
27 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/ack.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class AckProtocolEntity(ProtocolEntity):
3 |
4 | '''
5 |
6 |
7 | '''
8 |
9 | def __init__(self, _id, _class):
10 | super(AckProtocolEntity, self).__init__("ack")
11 | self._id = _id
12 | self._class = _class
13 |
14 | def getId(self):
15 | return self._id
16 |
17 | def getClass(self):
18 | return self._class
19 |
20 | def toProtocolTreeNode(self):
21 | attribs = {
22 | "id" : self._id,
23 | "class" : self._class,
24 | }
25 |
26 | return self._createProtocolTreeNode(attribs, None, data = None)
27 |
28 | def __str__(self):
29 | out = "ACK:\n"
30 | out += "ID: %s\n" % self._id
31 | out += "Class: %s\n" % self._class
32 | return out
33 |
34 | @staticmethod
35 | def fromProtocolTreeNode(node):
36 | return AckProtocolEntity(
37 | node.getAttributeValue("id"),
38 | node.getAttributeValue("class")
39 | )
40 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/message_text.py:
--------------------------------------------------------------------------------
1 | from .protomessage import ProtomessageProtocolEntity
2 | from .message import MessageMetaAttributes
3 | from .attributes.attributes_message import MessageAttributes
4 |
5 |
6 | class TextMessageProtocolEntity(ProtomessageProtocolEntity):
7 | def __init__(self, body, message_meta_attributes=None, to=None):
8 | # flexible attributes for temp backwards compat
9 | assert(bool(message_meta_attributes) ^ bool(to)), "Either set message_meta_attributes, or to, and not both"
10 | if to:
11 | message_meta_attributes = MessageMetaAttributes(recipient=to)
12 | super(TextMessageProtocolEntity, self).__init__("text", MessageAttributes(body), message_meta_attributes)
13 | self.setBody(body)
14 |
15 | @property
16 | def conversation(self):
17 | return self.message_attributes.conversation
18 |
19 | @conversation.setter
20 | def conversation(self, value):
21 | self.message_attributes.conversation = value
22 |
23 | def getBody(self):
24 | #obsolete
25 | return self.conversation
26 |
27 | def setBody(self, body):
28 | #obsolete
29 | self.conversation = body
30 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/presence_subscribe.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .presence import PresenceProtocolEntity
3 | class SubscribePresenceProtocolEntity(PresenceProtocolEntity):
4 |
5 | '''
6 |
7 | '''
8 |
9 | def __init__(self, jid):
10 | super(SubscribePresenceProtocolEntity, self).__init__("subscribe")
11 | self.setProps(jid)
12 |
13 | def setProps(self, jid):
14 | self.jid = jid
15 |
16 | def toProtocolTreeNode(self):
17 | node = super(SubscribePresenceProtocolEntity, self).toProtocolTreeNode()
18 | node.setAttribute("to", self.jid)
19 | return node
20 |
21 | def __str__(self):
22 | out = super(SubscribePresenceProtocolEntity, self).__str__()
23 | out += "To: %s\n" % self.jid
24 | return out
25 |
26 | @staticmethod
27 | def fromProtocolTreeNode(node):
28 | entity = PresenceProtocolEntity.fromProtocolTreeNode(node)
29 | entity.__class__ = SubscribePresenceProtocolEntity
30 | entity.setProps(
31 | node.getAttributeValue("to")
32 | )
33 | return entity
34 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_subject.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups import GroupsIqProtocolEntity
3 | class SubjectGroupsIqProtocolEntity(GroupsIqProtocolEntity):
4 | '''
5 |
6 |
7 | {{NEW_VAL}}
8 |
9 |
10 | '''
11 | def __init__(self, jid, subject, _id = None):
12 | super(SubjectGroupsIqProtocolEntity, self).__init__(to = jid, _id = _id, _type = "set")
13 | self.setProps(subject)
14 |
15 | def setProps(self, subject):
16 | self.subject = subject
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(SubjectGroupsIqProtocolEntity, self).toProtocolTreeNode()
20 | node.addChild(ProtocolTreeNode("subject",{}, None, self.subject))
21 | return node
22 |
23 | @staticmethod
24 | def fromProtocolTreeNode(node):
25 | entity = super(SubjectGroupsIqProtocolEntity, SubjectGroupsIqProtocolEntity).fromProtocolTreeNode(node)
26 | entity.__class__ = SubjectGroupsIqProtocolEntity
27 | entity.setProps(node.getChild("subject").getData())
28 | return entity
29 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/offline_ib.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .ib import IbProtocolEntity
3 | class OfflineIbProtocolEntity(IbProtocolEntity):
4 | '''
5 |
6 |
7 |
8 | '''
9 | def __init__(self, count):
10 | super(IbProtocolEntity, self).__init__()
11 | self.setProps(count)
12 |
13 |
14 | def setProps(self, count):
15 | self.count = int(count)
16 |
17 | def toProtocolTreeNode(self):
18 | node = super(OfflineIbProtocolEntity, self).toProtocolTreeNode()
19 | offlineChild = ProtocolTreeNode("offline", {"count": str(self.count)})
20 | node.addChild(offlineChild)
21 | return node
22 |
23 | def __str__(self):
24 | out = super(OfflineIbProtocolEntity, self).__str__()
25 | out += "Offline count: %s\n" % self.count
26 | return out
27 |
28 | @staticmethod
29 | def fromProtocolTreeNode(node):
30 | entity = IbProtocolEntity.fromProtocolTreeNode(node)
31 | entity.__class__ = OfflineIbProtocolEntity
32 | entity.setProps(node.getChild("offline")["count"])
33 | return entity
34 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/protocolentities/presence_unsubscribe.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .presence import PresenceProtocolEntity
3 | class UnsubscribePresenceProtocolEntity(PresenceProtocolEntity):
4 |
5 | '''
6 |
7 | '''
8 |
9 | def __init__(self, jid):
10 | super(UnsubscribePresenceProtocolEntity, self).__init__("unsubscribe")
11 | self.setProps(jid)
12 |
13 | def setProps(self, jid):
14 | self.jid = jid
15 |
16 | def toProtocolTreeNode(self):
17 | node = super(UnsubscribePresenceProtocolEntity, self).toProtocolTreeNode()
18 | node.setAttribute("to", self.jid)
19 | return node
20 |
21 | def __str__(self):
22 | out = super(UnsubscribePresenceProtocolEntity, self).__str__()
23 | out += "To: %s\n" % self.jid
24 | return out
25 |
26 | @staticmethod
27 | def fromProtocolTreeNode(node):
28 | entity = PresenceProtocolEntity.fromProtocolTreeNode(node)
29 | entity.__class__ = UnsubscribePresenceProtocolEntity
30 | entity.setProps(
31 | node.getAttributeValue("to")
32 | )
33 | return entity
34 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants_add.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups_participants import ParticipantsGroupsIqProtocolEntity
3 |
4 | class AddParticipantsIqProtocolEntity(ParticipantsGroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, group_jid, participantList, _id = None):
15 | super(AddParticipantsIqProtocolEntity, self).__init__(group_jid, participantList, "add", _id = _id)
16 |
17 | @staticmethod
18 | def fromProtocolTreeNode(node):
19 | entity = super(AddParticipantsIqProtocolEntity, AddParticipantsIqProtocolEntity).fromProtocolTreeNode(node)
20 | entity.__class__ = AddParticipantsIqProtocolEntity
21 | participantList = []
22 | for participantNode in node.getChild("add").getAllChildren():
23 | participantList.append(participantNode["jid"])
24 | entity.setProps(node.getAttributeValue("to"), participantList)
25 | return entity
26 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_message_meta.py:
--------------------------------------------------------------------------------
1 | class MessageMetaAttributes(object):
2 | def __init__(
3 | self, id=None, sender=None, recipient=None, notify=None, timestamp=None, participant=None, offline=None,
4 | retry=None
5 | ):
6 | assert (sender or recipient), "Must specify either sender or recipient " \
7 | "jid to create the message "
8 | assert not (sender and recipient), "Can't set both attributes to message at same " \
9 | "time (sender, recipient) "
10 | self.id = id
11 | self.sender = sender
12 | self.recipient = recipient
13 | self.notify = notify
14 | self.timestamp = int(timestamp) if timestamp else None
15 | self.participant = participant
16 | self.offline = offline in ("1", True)
17 | self.retry = int(retry) if retry else None
18 |
19 | @staticmethod
20 | def from_message_protocoltreenode(node):
21 | return MessageMetaAttributes(
22 | node["id"], node["from"], node["to"], node["notify"], node["t"], node["participant"], node["offline"],
23 | node["retry"]
24 | )
25 |
--------------------------------------------------------------------------------
/yowsup/config/transforms/props.py:
--------------------------------------------------------------------------------
1 | from yowsup.config.base.transform import ConfigTransform
2 | import types
3 |
4 |
5 | class PropsTransform(ConfigTransform):
6 | def __init__(self, transform_map=None, reverse_map=None):
7 | self._transform_map = transform_map or {}
8 | self._reverse_map = reverse_map or {}
9 |
10 | def transform(self, data):
11 | """
12 | :param data:
13 | :type data: dict
14 | :return:
15 | :rtype: dict
16 | """
17 | out = {}
18 | for key, val in data.items():
19 | if key in self._transform_map:
20 | target = self._transform_map[key]
21 | key, val = target(key, val) if type(target) == types.FunctionType else (key, target)
22 |
23 | out[key] = val
24 |
25 |
26 | return out
27 |
28 | def reverse(self, data):
29 | transformed_dict = {}
30 |
31 | for key, val in data.items():
32 | if key in self._reverse_map:
33 | target = self._reverse_map[key]
34 | key, val = target(key, val) if type(target) == types.FunctionType else (key, target)
35 |
36 | transformed_dict[key] = val
37 |
38 | return transformed_dict
39 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_calls/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayer
2 | from .protocolentities import *
3 | from yowsup.layers.protocol_acks.protocolentities import OutgoingAckProtocolEntity
4 | from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity
5 | class YowCallsProtocolLayer(YowProtocolLayer):
6 |
7 | def __init__(self):
8 | handleMap = {
9 | "call": (self.recvCall, self.sendCall)
10 | }
11 | super(YowCallsProtocolLayer, self).__init__(handleMap)
12 |
13 | def __str__(self):
14 | return "call Layer"
15 |
16 | def sendCall(self, entity):
17 | if entity.getTag() == "call":
18 | self.toLower(entity.toProtocolTreeNode())
19 |
20 | def recvCall(self, node):
21 | entity = CallProtocolEntity.fromProtocolTreeNode(node)
22 | if entity.getType() == "offer":
23 | receipt = OutgoingReceiptProtocolEntity(node["id"], node["from"], callId = entity.getCallId())
24 | self.toLower(receipt.toProtocolTreeNode())
25 | else:
26 | ack = OutgoingAckProtocolEntity(node["id"], "call", None, node["from"])
27 | self.toLower(ack.toProtocolTreeNode())
28 | self.toUpper(entity)
29 |
30 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_receipts/protocolentities/receipt.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class ReceiptProtocolEntity(ProtocolEntity):
3 |
4 | '''
5 | delivered:
6 |
7 |
8 | read
9 |
10 |
11 | INCOMING
12 |
13 | '''
14 |
15 | def __init__(self, _id):
16 | super(ReceiptProtocolEntity, self).__init__("receipt")
17 | self._id = _id
18 |
19 | def getId(self):
20 | return self._id
21 |
22 | def toProtocolTreeNode(self):
23 | attribs = {
24 | "id" : self._id
25 | }
26 | return self._createProtocolTreeNode(attribs, None, data = None)
27 |
28 |
29 | def __str__(self):
30 | out = "Receipt:\n"
31 | out += "ID: %s\n" % self._id
32 | return out
33 |
34 | @staticmethod
35 | def fromProtocolTreeNode(node):
36 | return ReceiptProtocolEntity(
37 | node.getAttributeValue("id")
38 | )
39 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants_demote.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups_participants import ParticipantsGroupsIqProtocolEntity
3 |
4 | class DemoteParticipantsIqProtocolEntity(ParticipantsGroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, group_jid, participantList, _id = None):
15 | super(DemoteParticipantsIqProtocolEntity, self).__init__(group_jid, participantList, "demote", _id = _id)
16 |
17 | @staticmethod
18 | def fromProtocolTreeNode(node):
19 | entity = super(DemoteParticipantsIqProtocolEntity, DemoteParticipantsIqProtocolEntity).fromProtocolTreeNode(node)
20 | entity.__class__ = DemoteParticipantsIqProtocolEntity
21 | participantList = []
22 | for participantNode in node.getChild("demote").getAllChildren():
23 | participantList.append(participantNode["jid"])
24 | entity.setProps(node.getAttributeValue("to"), participantList)
25 | return entity
26 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants_remove.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups_participants import ParticipantsGroupsIqProtocolEntity
3 |
4 | class RemoveParticipantsIqProtocolEntity(ParticipantsGroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, group_jid, participantList, _id = None):
15 | super(RemoveParticipantsIqProtocolEntity, self).__init__(group_jid, participantList, "remove", _id = _id)
16 |
17 | @staticmethod
18 | def fromProtocolTreeNode(node):
19 | entity = super(RemoveParticipantsIqProtocolEntity, RemoveParticipantsIqProtocolEntity).fromProtocolTreeNode(node)
20 | entity.__class__ = RemoveParticipantsIqProtocolEntity
21 | participantList = []
22 | for participantNode in node.getChild("remove").getAllChildren():
23 | participantList.append(participantNode["jid"])
24 | entity.setProps(node.getAttributeValue("to"), participantList)
25 | return entity
26 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_downloadable_image.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.message_media_downloadable_image \
2 | import ImageDownloadableMediaMessageProtocolEntity
3 | from .test_message_media import MediaMessageProtocolEntityTest
4 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
5 |
6 |
7 | class ImageDownloadableMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
8 | def setUp(self):
9 | super(ImageDownloadableMediaMessageProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = ImageDownloadableMediaMessageProtocolEntity
11 | proto_node = self.node.getChild("proto")
12 | m = Message()
13 | media_message = Message.ImageMessage()
14 | media_message.url = "url"
15 | media_message.mimetype = "image/jpeg"
16 | media_message.caption = "caption"
17 | media_message.file_sha256 = b"SHA256"
18 | media_message.file_length = 123
19 | media_message.height = 20
20 | media_message.width = 20
21 | media_message.media_key = b"MEDIA_KEY"
22 | media_message.jpeg_thumbnail = b"THUMBNAIL"
23 | m.image_message.MergeFrom(media_message)
24 | proto_node.setData(m.SerializeToString())
25 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants_promote.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups_participants import ParticipantsGroupsIqProtocolEntity
3 |
4 | class PromoteParticipantsIqProtocolEntity(ParticipantsGroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, group_jid, participantList, _id = None):
15 | super(PromoteParticipantsIqProtocolEntity, self).__init__(group_jid, participantList, "promote", _id = _id)
16 |
17 | @staticmethod
18 | def fromProtocolTreeNode(node):
19 | entity = super(PromoteParticipantsIqProtocolEntity, PromoteParticipantsIqProtocolEntity).fromProtocolTreeNode(node)
20 | entity.__class__ = PromoteParticipantsIqProtocolEntity
21 | participantList = []
22 | for participantNode in node.getChild("promote").getAllChildren():
23 | participantList.append(participantNode["jid"])
24 | entity.setProps(node.getAttributeValue("to"), participantList)
25 | return entity
26 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_sender_key_distribution_message.py:
--------------------------------------------------------------------------------
1 | class SenderKeyDistributionMessageAttributes(object):
2 | def __init__(self, group_id, axolotl_sender_key_distribution_message):
3 | self._group_id = group_id
4 | self._axolotl_sender_key_distribution_message = axolotl_sender_key_distribution_message
5 |
6 | def __str__(self):
7 | attrs = []
8 | if self.group_id is not None:
9 | attrs.append(("group_id", self.group_id))
10 | if self.axolotl_sender_key_distribution_message is not None:
11 | attrs.append(("axolotl_sender_key_distribution_message", "[binary omitted]"))
12 |
13 | return "[%s]" % " ".join((map(lambda item: "%s=%s" % item, attrs)))
14 |
15 | @property
16 | def group_id(self):
17 | return self._group_id
18 |
19 | @group_id.setter
20 | def group_id(self, value):
21 | self._group_id = value
22 |
23 | @property
24 | def axolotl_sender_key_distribution_message(self):
25 | return self._axolotl_sender_key_distribution_message
26 |
27 | @axolotl_sender_key_distribution_message.setter
28 | def axolotl_sender_key_distribution_message(self, value):
29 | self._axolotl_sender_key_distribution_message = value
30 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_create_success.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_iq.protocolentities import ResultIqProtocolEntity
4 | class SuccessCreateGroupsIqProtocolEntity(ResultIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, groupId):
12 | super(SuccessCreateGroupsIqProtocolEntity, self).__init__(_from = YowConstants.WHATSAPP_GROUP_SERVER, _id = _id)
13 | self.setProps(groupId)
14 |
15 | def setProps(self, groupId):
16 | self.groupId = groupId
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(SuccessCreateGroupsIqProtocolEntity, self).toProtocolTreeNode()
20 | node.addChild(ProtocolTreeNode("group",{"id": self.groupId}))
21 | return node
22 |
23 | @staticmethod
24 | def fromProtocolTreeNode(node):
25 | entity = super(SuccessCreateGroupsIqProtocolEntity, SuccessCreateGroupsIqProtocolEntity).fromProtocolTreeNode(node)
26 | entity.__class__ = SuccessCreateGroupsIqProtocolEntity
27 | entity.setProps(node.getChild("group").getAttributeValue("id"))
28 | return entity
29 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_presence/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
2 | from .protocolentities import *
3 | from yowsup.layers.protocol_iq.protocolentities import ErrorIqProtocolEntity
4 | class YowPresenceProtocolLayer(YowProtocolLayer):
5 | def __init__(self):
6 | handleMap = {
7 | "presence": (self.recvPresence, self.sendPresence),
8 | "iq": (None, self.sendIq)
9 | }
10 | super(YowPresenceProtocolLayer, self).__init__(handleMap)
11 |
12 | def __str__(self):
13 | return "Presence Layer"
14 |
15 | def sendPresence(self, entity):
16 | self.entityToLower(entity)
17 |
18 | def recvPresence(self, node):
19 | self.toUpper(PresenceProtocolEntity.fromProtocolTreeNode(node))
20 |
21 | def sendIq(self, entity):
22 | if entity.getXmlns() == LastseenIqProtocolEntity.XMLNS:
23 | self._sendIq(entity, self.onLastSeenSuccess, self.onLastSeenError)
24 |
25 | def onLastSeenSuccess(self, protocolTreeNode, lastSeenEntity):
26 | self.toUpper(ResultLastseenIqProtocolEntity.fromProtocolTreeNode(protocolTreeNode))
27 |
28 | def onLastSeenError(self, protocolTreeNode, lastSeenEntity):
29 | self.toUpper(ErrorIqProtocolEntity.fromProtocolTreeNode(protocolTreeNode))
30 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_picture_get.py:
--------------------------------------------------------------------------------
1 | from .iq_picture import PictureIqProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | class GetPictureIqProtocolEntity(PictureIqProtocolEntity):
4 | '''
5 |
6 |
7 |
8 | '''
9 | def __init__(self, jid, preview = True, _id = None):
10 | super(GetPictureIqProtocolEntity, self).__init__(jid, _id, "get")
11 | self.setGetPictureProps(preview)
12 |
13 | def setGetPictureProps(self, preview = True):
14 | self.preview = preview
15 |
16 | def isPreview(self):
17 | return self.preview
18 |
19 | def toProtocolTreeNode(self):
20 | node = super(GetPictureIqProtocolEntity, self).toProtocolTreeNode()
21 | pictureNode = ProtocolTreeNode("picture", {"type": "preview" if self.isPreview() else "image" })
22 | node.addChild(pictureNode)
23 | return node
24 |
25 | @staticmethod
26 | def fromProtocolTreeNode(node):
27 | entity = PictureIqProtocolEntity.fromProtocolTreeNode(node)
28 | entity.__class__ = GetPictureIqProtocolEntity
29 | entity.setGetPictureProps(node.getChild("picture").getAttributeValue("type"))
30 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/test_layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayerTest
2 | from yowsup.layers.protocol_contacts import YowContactsIqProtocolLayer
3 | from yowsup.layers.protocol_contacts.protocolentities.test_notification_contact_add import entity as addEntity
4 | from yowsup.layers.protocol_contacts.protocolentities.test_notification_contact_update import entity as updateEntity
5 | from yowsup.layers.protocol_contacts.protocolentities.test_notification_contact_remove import entity as removeEntity
6 | from yowsup.layers.protocol_contacts.protocolentities.test_iq_sync_result import entity as syncResultEntity
7 | from yowsup.layers.protocol_contacts.protocolentities.test_iq_sync_get import entity as syncGetEntity
8 |
9 | class YowContactsIqProtocolLayerTest(YowProtocolLayerTest, YowContactsIqProtocolLayer):
10 | def setUp(self):
11 | YowContactsIqProtocolLayer.__init__(self)
12 |
13 | def test_sync(self):
14 | self.assertSent(syncGetEntity)
15 |
16 | def test_syncResult(self):
17 | self.assertReceived(syncResultEntity)
18 |
19 | def test_notificationAdd(self):
20 | self.assertReceived(addEntity)
21 |
22 | def test_notificationUpdate(self):
23 | self.assertReceived(updateEntity)
24 |
25 | def test_notificationRemove(self):
26 | self.assertReceived(removeEntity)
27 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_contact.py:
--------------------------------------------------------------------------------
1 | class ContactAttributes(object):
2 | def __init__(self, display_name, vcard, context_info=None):
3 | self._display_name = display_name
4 | self._vcard = vcard
5 | self._context_info = context_info
6 |
7 | def __str__(self):
8 | attrs = []
9 | if self.display_name is not None:
10 | attrs.append(("display_name", self.display_name))
11 | if self.vcard is not None:
12 | attrs.append(("vcard", "[binary data]"))
13 | if self.context_info is not None:
14 | attrs.append(("context_info", self.context_info))
15 |
16 | return "[%s]" % " ".join((map(lambda item: "%s=%s" % item, attrs)))
17 |
18 | @property
19 | def display_name(self):
20 | return self._display_name
21 |
22 | @display_name.setter
23 | def display_name(self, value):
24 | self._display_name = value
25 |
26 | @property
27 | def vcard(self):
28 | return self._vcard
29 |
30 | @vcard.setter
31 | def vcard(self, value):
32 | self._vcard = value
33 |
34 | @property
35 | def context_info(self):
36 | return self._context_info
37 |
38 | @context_info.setter
39 | def context_info(self, value):
40 | self.context_info = value
41 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/message_text_broadcast.py:
--------------------------------------------------------------------------------
1 | from .message_text import TextMessageProtocolEntity
2 | from yowsup.structs import ProtocolTreeNode
3 | import time
4 | class BroadcastTextMessage(TextMessageProtocolEntity):
5 | def __init__(self, jids, body):
6 | broadcastTime = int(time.time() * 1000)
7 | super(BroadcastTextMessage, self).__init__(body, to = "%s@broadcast" % broadcastTime)
8 | self.setBroadcastProps(jids)
9 |
10 | def setBroadcastProps(self, jids):
11 | assert type(jids) is list, "jids must be a list, got %s instead." % type(jids)
12 | self.jids = jids
13 |
14 | def toProtocolTreeNode(self):
15 | node = super(BroadcastTextMessage, self).toProtocolTreeNode()
16 | toNodes = [ProtocolTreeNode("to", {"jid": jid}) for jid in self.jids]
17 | broadcastNode = ProtocolTreeNode("broadcast", children = toNodes)
18 | node.addChild(broadcastNode)
19 | return node
20 |
21 | @staticmethod
22 | def fromProtocolTreeNode(node):
23 | entity = TextMessageProtocolEntity.fromProtocolTreeNode(node)
24 | entity.__class__ = BroadcastTextMessage
25 | jids = [toNode.getAttributeValue("jid") for toNode in node.getChild("broadcast").getAllChildren()]
26 | entity.setBroadcastProps(jids)
27 | return entity
28 |
--------------------------------------------------------------------------------
/yowsup/demos/contacts/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
2 | from yowsup.layers.protocol_contacts.protocolentities import GetSyncIqProtocolEntity, ResultSyncIqProtocolEntity
3 | from yowsup.layers.protocol_iq.protocolentities import ErrorIqProtocolEntity
4 | import threading
5 | import logging
6 | logger = logging.getLogger(__name__)
7 |
8 | class SyncLayer(YowInterfaceLayer):
9 |
10 | PROP_CONTACTS = "org.openwhatsapp.yowsup.prop.syncdemo.contacts"
11 |
12 | def __init__(self):
13 | super(SyncLayer, self).__init__()
14 |
15 | #call back function when there is a successful connection to whatsapp server
16 | @ProtocolEntityCallback("success")
17 | def onSuccess(self, successProtocolEntity):
18 | contacts= self.getProp(self.__class__.PROP_CONTACTS, [])
19 | contactEntity = GetSyncIqProtocolEntity(contacts)
20 | self._sendIq(contactEntity, self.onGetSyncResult, self.onGetSyncError)
21 |
22 | def onGetSyncResult(self, resultSyncIqProtocolEntity, originalIqProtocolEntity):
23 | print(resultSyncIqProtocolEntity)
24 | raise KeyboardInterrupt()
25 |
26 | def onGetSyncError(self, errorSyncIqProtocolEntity, originalIqProtocolEntity):
27 | print(errorSyncIqProtocolEntity)
28 | raise KeyboardInterrupt()
29 |
--------------------------------------------------------------------------------
/yowsup/layers/auth/protocolentities/success.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class SuccessProtocolEntity(ProtocolEntity):
3 | def __init__(self, creation, props, t, location):
4 | super(SuccessProtocolEntity, self).__init__("success")
5 | self.location = location
6 | self.creation = int(creation)
7 | self.props = props
8 | self.t = int(t) ##whatever that is !
9 |
10 | def __str__(self):
11 | out = "Account:\n"
12 | out += "Location: %s\n" % self.location
13 | out += "Creation: %s\n" % self.creation
14 | out += "Props: %s\n" % self.props
15 | out += "t: %s\n" % self.t
16 | return out
17 |
18 | def toProtocolTreeNode(self):
19 | attributes = {
20 | "location" : self.location,
21 | "creation" : str(self.creation),
22 | "props" : self.props,
23 | "t" : str(self.t)
24 | }
25 | return self._createProtocolTreeNode(attributes)
26 |
27 | @staticmethod
28 | def fromProtocolTreeNode(node):
29 | return SuccessProtocolEntity(
30 | node.getAttributeValue("creation"),
31 | node.getAttributeValue("props"),
32 | node.getAttributeValue("t"),
33 | node.getAttributeValue("location")
34 | )
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/notification_status.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .notification import NotificationProtocolEntity
3 | class StatusNotificationProtocolEntity(NotificationProtocolEntity):
4 | '''
5 |
7 |
8 | {{STATUS}}
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, _type, _id, _from, status, timestamp, notify, offline = False):
15 | super(StatusNotificationProtocolEntity, self).__init__("status", _id, _from, timestamp, notify, offline)
16 | self.setStatus(status)
17 |
18 | def setStatus(self, status):
19 | self.status = status
20 |
21 | def toProtocolTreeNode(self):
22 | node = super(StatusNotificationProtocolEntity, self).toProtocolTreeNode()
23 | setNode = ProtocolTreeNode("set", {}, None, self.status)
24 | node.addChild(setNode)
25 | return node
26 |
27 | @staticmethod
28 | def fromProtocolTreeNode(node):
29 | entity = NotificationProtocolEntity.fromProtocolTreeNode(node)
30 | entity.__class__ = StatusNotificationProtocolEntity
31 | entity.setStatus(node.getChild("set").getData())
32 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/notificiation_contacts_sync.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from .notification_contact import ContactNotificationProtocolEntity
3 | class ContactsSyncNotificationProtocolEntity(ContactNotificationProtocolEntity):
4 | '''
5 |
6 |
7 |
8 | '''
9 |
10 | def __init__(self, _id, _from, timestamp, notify, offline, after):
11 | super(ContactsSyncNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
12 | self.setData(after)
13 |
14 | def setData(self, after):
15 | self.after = int(after)
16 |
17 | def toProtocolTreeNode(self):
18 | node = super(ContactsSyncNotificationProtocolEntity, self).toProtocolTreeNode()
19 | syncNode = ProtocolTreeNode("sync", {"after": str(self.after)}, None, None)
20 | node.addChild(syncNode)
21 | return node
22 |
23 | @staticmethod
24 | def fromProtocolTreeNode(node):
25 | entity = ContactNotificationProtocolEntity.fromProtocolTreeNode(node)
26 | entity.__class__ = ContactsSyncNotificationProtocolEntity
27 | syncNode = node.getChild("sync")
28 | entity.setData(syncNode.getAttributeValue("after"))
29 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/message_extendedtext.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message_meta import MessageMetaAttributes
2 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_extendedtext import ExtendedTextAttributes
3 | from yowsup.layers.protocol_messages.protocolentities.protomessage import ProtomessageProtocolEntity
4 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message import MessageAttributes
5 |
6 |
7 | class ExtendedTextMessageProtocolEntity(ProtomessageProtocolEntity):
8 | def __init__(self, extended_text_attrs, message_meta_attrs):
9 | # type: (ExtendedTextAttributes, MessageMetaAttributes) -> None
10 | super(ExtendedTextMessageProtocolEntity, self).__init__(
11 | "text", MessageAttributes(extended_text=extended_text_attrs), message_meta_attrs
12 | )
13 |
14 | @property
15 | def text(self):
16 | return self.message_attributes.extended_text.text
17 |
18 | @text.setter
19 | def text(self, value):
20 | self.message_attributes.extended_text.text = value
21 |
22 | @property
23 | def context_info(self):
24 | return self.message_attributes.extended_text.context_info
25 |
26 | @context_info.setter
27 | def context_info(self, value):
28 | self.message_attributes.extended_text.context_info = value
29 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/chatstate_outgoing.py:
--------------------------------------------------------------------------------
1 | from .chatstate import ChatstateProtocolEntity
2 | class OutgoingChatstateProtocolEntity(ChatstateProtocolEntity):
3 | '''
4 | INCOMING
5 |
6 |
7 | <{{composing|paused}}>{{composing|paused}}>
8 |
9 |
10 | OUTGOING
11 |
12 |
13 | <{{composing|paused}}>{{composing|paused}}>
14 |
15 | '''
16 |
17 | def __init__(self, _state, _to):
18 | super(OutgoingChatstateProtocolEntity, self).__init__(_state)
19 | self.setOutgoingData(_to)
20 |
21 | def setOutgoingData(self, _to):
22 | self._to = _to
23 |
24 | def toProtocolTreeNode(self):
25 | node = super(OutgoingChatstateProtocolEntity, self).toProtocolTreeNode()
26 | node.setAttribute("to", self._to)
27 | return node
28 |
29 | def __str__(self):
30 | out = super(OutgoingChatstateProtocolEntity, self).__str__()
31 | out += "To: %s\n" % self._to
32 | return out
33 |
34 | @staticmethod
35 | def fromProtocolTreeNode(node):
36 | entity = ChatstateProtocolEntity.fromProtocolTreeNode(node)
37 | entity.__class__ = OutgoingChatstateProtocolEntity
38 | entity.setOutgoingData(
39 | node.getAttributeValue("to"),
40 | )
41 | return entity
42 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/notification_contact_add.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from .notification_contact import ContactNotificationProtocolEntity
3 | class AddContactNotificationProtocolEntity(ContactNotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, _from, timestamp, notify, offline, contactJid):
12 | super(AddContactNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
13 | self.setData(contactJid)
14 |
15 | def setData(self, jid):
16 | self.contactJid = jid
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(AddContactNotificationProtocolEntity, self).toProtocolTreeNode()
20 | removeNode = ProtocolTreeNode("add", {"jid": self.contactJid}, None, None)
21 | node.addChild(removeNode)
22 | return node
23 |
24 | @staticmethod
25 | def fromProtocolTreeNode(node):
26 | entity = ContactNotificationProtocolEntity.fromProtocolTreeNode(node)
27 | entity.__class__ = AddContactNotificationProtocolEntity
28 | removeNode = node.getChild("add")
29 | entity.setData(removeNode.getAttributeValue("jid"))
30 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/message_media_contact.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message_meta import MessageMetaAttributes
2 | from .message_media import MediaMessageProtocolEntity
3 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_contact import ContactAttributes
4 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message import MessageAttributes
5 |
6 |
7 | class ContactMediaMessageProtocolEntity(MediaMessageProtocolEntity):
8 | def __init__(self, contact_attrs, message_meta_attrs):
9 | # type: (ContactAttributes, MessageMetaAttributes) -> None
10 | super(ContactMediaMessageProtocolEntity, self).__init__(
11 | "contact", MessageAttributes(contact=contact_attrs), message_meta_attrs
12 | )
13 |
14 | @property
15 | def media_specific_attributes(self):
16 | return self.message_attributes.contact
17 |
18 | @property
19 | def display_name(self):
20 | return self.media_specific_attributes.display_name
21 |
22 | @display_name.setter
23 | def display_name(self, value):
24 | self.media_specific_attributes.display_name = value
25 |
26 | @property
27 | def vcard(self):
28 | return self.media_specific_attributes.vcard
29 |
30 | @vcard.setter
31 | def vcard(self, value):
32 | self.media_specific_attributes.vcard = value
33 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/chatstate_incoming.py:
--------------------------------------------------------------------------------
1 | from .chatstate import ChatstateProtocolEntity
2 | class IncomingChatstateProtocolEntity(ChatstateProtocolEntity):
3 | '''
4 | INCOMING
5 |
6 |
7 | <{{composing|paused}}>{{composing|paused}}>
8 |
9 |
10 | OUTGOING
11 |
12 |
13 | <{{composing|paused}}>{{composing|paused}}>
14 |
15 | '''
16 |
17 | def __init__(self, _state, _from):
18 | super(IncomingChatstateProtocolEntity, self).__init__(_state)
19 | self.setIncomingData(_from)
20 |
21 | def setIncomingData(self, _from):
22 | self._from = _from
23 |
24 | def toProtocolTreeNode(self):
25 | node = super(IncomingChatstateProtocolEntity, self).toProtocolTreeNode()
26 | node.setAttribute("from", self._from)
27 | return node
28 |
29 | def __str__(self):
30 | out = super(IncomingChatstateProtocolEntity, self).__str__()
31 | out += "From: %s\n" % self._from
32 | return out
33 |
34 | @staticmethod
35 | def fromProtocolTreeNode(node):
36 | entity = ChatstateProtocolEntity.fromProtocolTreeNode(node)
37 | entity.__class__ = IncomingChatstateProtocolEntity
38 | entity.setIncomingData(
39 | node.getAttributeValue("from"),
40 | )
41 | return entity
42 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_downloadable_video.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.message_media_downloadable_video \
2 | import VideoDownloadableMediaMessageProtocolEntity
3 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
4 | from .test_message_media import MediaMessageProtocolEntityTest
5 |
6 |
7 | class VideoDownloadableMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
8 | def setUp(self):
9 | super(VideoDownloadableMediaMessageProtocolEntityTest, self).setUp()
10 | self.ProtocolEntity = VideoDownloadableMediaMessageProtocolEntity
11 | proto_node = self.node.getChild("proto")
12 | m = Message()
13 | media_message = Message.VideoMessage()
14 | media_message.url = "url"
15 | media_message.mimetype = "video/mp4"
16 | media_message.caption = "caption"
17 | media_message.file_sha256 = b"shaval"
18 | media_message.file_length = 4
19 | media_message.width = 1
20 | media_message.height = 2
21 | media_message.seconds = 3
22 | media_message.media_key = b"MEDIA_KEY"
23 | media_message.jpeg_thumbnail = b"THUMBNAIL"
24 | media_message.gif_attribution = 0
25 | media_message.gif_playback = False
26 | media_message.streaming_sidecar = b''
27 | m.video_message.MergeFrom(media_message)
28 | proto_node.setData(m.SerializeToString())
29 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_chatstate/protocolentities/chatstate.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | class ChatstateProtocolEntity(ProtocolEntity):
3 |
4 | '''
5 | INCOMING
6 |
7 |
8 | <{{composing|paused}}>{{composing|paused}}>
9 |
10 |
11 | OUTGOING
12 |
13 |
14 | <{{composing|paused}}>{{composing|paused}}>
15 |
16 | '''
17 |
18 | STATE_TYPING = "composing"
19 | STATE_PAUSED = "paused"
20 | STATES = (STATE_TYPING, STATE_PAUSED)
21 |
22 | def __init__(self, _state):
23 | super(ChatstateProtocolEntity, self).__init__("chatstate")
24 | assert _state in self.__class__.STATES, "Expected chat state to be in %s, got %s" % (self.__class__.STATES, _state)
25 | self._state = _state
26 |
27 | def getState(self):
28 | return self._state
29 |
30 | def toProtocolTreeNode(self):
31 | node = self._createProtocolTreeNode({}, None, data = None)
32 | node.addChild(ProtocolTreeNode(self._state))
33 | return node
34 |
35 | def __str__(self):
36 | out = "CHATSTATE:\n"
37 | out += "State: %s\n" % self._state
38 | return out
39 |
40 | @staticmethod
41 | def fromProtocolTreeNode(node):
42 | return ChatstateProtocolEntity(
43 | node.getAllChildren()[0].tag,
44 | )
45 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/notification_contact_remove.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from .notification_contact import ContactNotificationProtocolEntity
3 | class RemoveContactNotificationProtocolEntity(ContactNotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, _from, timestamp, notify, offline, contactJid):
12 | super(RemoveContactNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
13 | self.setData(contactJid)
14 |
15 | def setData(self, jid):
16 | self.contactJid = jid
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(RemoveContactNotificationProtocolEntity, self).toProtocolTreeNode()
20 | removeNode = ProtocolTreeNode("remove", {"jid": self.contactJid}, None, None)
21 | node.addChild(removeNode)
22 | return node
23 |
24 | @staticmethod
25 | def fromProtocolTreeNode(node):
26 | entity = ContactNotificationProtocolEntity.fromProtocolTreeNode(node)
27 | entity.__class__ = RemoveContactNotificationProtocolEntity
28 | removeNode = node.getChild("remove")
29 | entity.setData(removeNode.getAttributeValue("jid"))
30 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/protocolentities/notification_contact_update.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from .notification_contact import ContactNotificationProtocolEntity
3 | class UpdateContactNotificationProtocolEntity(ContactNotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, _from, timestamp, notify, offline, contactJid):
12 | super(UpdateContactNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
13 | self.setData(contactJid)
14 |
15 | def setData(self, jid):
16 | self.contactJid = jid
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(UpdateContactNotificationProtocolEntity, self).toProtocolTreeNode()
20 | removeNode = ProtocolTreeNode("update", {"jid": self.contactJid}, None, None)
21 | node.addChild(removeNode)
22 | return node
23 |
24 | @staticmethod
25 | def fromProtocolTreeNode(node):
26 | entity = ContactNotificationProtocolEntity.fromProtocolTreeNode(node)
27 | entity.__class__ = UpdateContactNotificationProtocolEntity
28 | removeNode = node.getChild("update")
29 | entity.setData(removeNode.getAttributeValue("jid"))
30 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/structs/group.py:
--------------------------------------------------------------------------------
1 | class Group(object):
2 | def __init__(self, groupId, creatorJid, subject, subjectOwnerJid, subjectTime, creationTime, participants=None):
3 | self._groupId = groupId
4 | self._creatorJid = creatorJid
5 | self._subject = subject
6 | self._subjectOwnerJid = subjectOwnerJid
7 | self._subjectTime = int(subjectTime)
8 | self._creationTime = int(creationTime)
9 | self._participants = participants or {}
10 |
11 | def getId(self):
12 | return self._groupId
13 |
14 | def getCreator(self):
15 | return self._creatorJid
16 |
17 | def getOwner(self):
18 | return self.getCreator()
19 |
20 | def getSubject(self):
21 | return self._subject
22 |
23 | def getSubjectOwner(self):
24 | return self._subjectOwnerJid
25 |
26 | def getSubjectTime(self):
27 | return self._subjectTime
28 |
29 | def getCreationTime(self):
30 | return self._creationTime
31 |
32 | def __str__(self):
33 | return "ID: %s, Subject: %s, Creation: %s, Creator: %s, Subject Owner: %s, Subject Time: %s\nParticipants: %s" %\
34 | (self.getId(), self.getSubject(), self.getCreationTime(), self.getCreator(), self.getSubjectOwner(), self.getSubjectTime(), ", ".join(self._participants.keys()))
35 |
36 | def getParticipants(self):
37 | return self._participants
38 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/dirty_ib.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .ib import IbProtocolEntity
3 | class DirtyIbProtocolEntity(IbProtocolEntity):
4 | '''
5 |
6 |
7 |
8 | '''
9 | def __init__(self, timestamp, _type):
10 | super(DirtyIbProtocolEntity, self).__init__()
11 | self.setProps(timestamp, _type)
12 |
13 |
14 | def setProps(self, timestamp, _type):
15 | self.timestamp = int(timestamp)
16 | self._type = _type
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(DirtyIbProtocolEntity, self).toProtocolTreeNode()
20 | dirtyNode = ProtocolTreeNode("dirty")
21 | dirtyNode["timestamp"] = str(self.timestamp)
22 | dirtyNode["type"] = self._type
23 | node.addChild(dirtyNode)
24 | return node
25 |
26 | def __str__(self):
27 | out = super(DirtyIbProtocolEntity, self).__str__()
28 | out += "Type: %s\n" % self._type
29 | out += "Timestamp: %s\n" % self.timestamp
30 | return out
31 |
32 | @staticmethod
33 | def fromProtocolTreeNode(node):
34 | entity = IbProtocolEntity.fromProtocolTreeNode(node)
35 | entity.__class__ = DirtyIbProtocolEntity
36 | dirtyChild = node.getChild("dirty")
37 | entity.setProps(dirtyChild["timestamp"], dirtyChild["type"])
38 | return entity
39 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/protocolentities/clean_iq.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | class CleanIqProtocolEntity(IqProtocolEntity):
4 | '''
5 |
6 |
7 |
8 | '''
9 | def __init__(self, cleanType, to, _id = None):
10 | super(CleanIqProtocolEntity, self).__init__(
11 | "urn:xmpp:whatsapp:dirty",
12 | _id = _id,
13 | _type = "set",
14 | to = to
15 | )
16 | self.setProps(cleanType)
17 |
18 | def setProps(self, cleanType):
19 | self.cleanType = cleanType
20 |
21 | def __str__(self):
22 | out = super(CleanIqProtocolEntity, self).__str__()
23 | out += "Clean Type: %s\n" % self.cleanType
24 | return out
25 |
26 | def toProtocolTreeNode(self):
27 | node = super(CleanIqProtocolEntity, self).toProtocolTreeNode()
28 | cleanNode = ProtocolTreeNode("clean", {"type": self.cleanType})
29 | node.addChild(cleanNode)
30 | return node
31 |
32 | @staticmethod
33 | def fromProtocolTreeNode(node):
34 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
35 | entity.__class__ = CleanIqProtocolEntity
36 | entity.setProps(node.getChild("clean").getAttributeValue("type"))
37 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_info.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups import GroupsIqProtocolEntity
3 | class InfoGroupsIqProtocolEntity(GroupsIqProtocolEntity):
4 | '''
5 |
6 |
7 |
8 |
9 |
10 | '''
11 |
12 | def __init__(self, group_jid, _id=None):
13 | super(InfoGroupsIqProtocolEntity, self).__init__(to = group_jid, _id = _id, _type = "get")
14 | self.setProps(group_jid)
15 |
16 | def setProps(self, group_jid):
17 | self.group_jid = group_jid
18 |
19 | def __str__(self):
20 | out = super(InfoGroupsIqProtocolEntity, self).__str__()
21 | out += "Group JID: %s\n" % self.group_jid
22 | return out
23 |
24 | def toProtocolTreeNode(self):
25 | node = super(InfoGroupsIqProtocolEntity, self).toProtocolTreeNode()
26 | node.addChild(ProtocolTreeNode("query", {"request": "interactive"}))
27 | return node
28 |
29 | @staticmethod
30 | def fromProtocolTreeNode(node):
31 | assert node.getChild("query") is not None, "Not a groups info iq node %s" % node
32 | entity = super(InfoGroupsIqProtocolEntity, InfoGroupsIqProtocolEntity).fromProtocolTreeNode(node)
33 | entity.__class__ = InfoGroupsIqProtocolEntity
34 | entity.setProps(node.getAttributeValue("to"))
35 | return entity
36 |
--------------------------------------------------------------------------------
/yowsup/layers/noise/layer_noise_segments.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer
2 |
3 | import logging
4 | import struct
5 |
6 |
7 | logger = logging.getLogger(__name__)
8 |
9 |
10 | class YowNoiseSegmentsLayer(YowLayer):
11 |
12 | PROP_ENABLED = "org.openwhatsapp.yowsup.prop.noise.segmented_enabled"
13 |
14 | def __init__(self):
15 | super(YowNoiseSegmentsLayer, self).__init__()
16 | self._read_buffer = bytearray()
17 |
18 | def __str__(self):
19 | return "Noise Segments Layer"
20 |
21 | def send(self, data):
22 | if len(data) >= 16777216:
23 | raise ValueError("data too large to write; length=%d" % len(data))
24 |
25 | if self.getProp(self.PROP_ENABLED, False):
26 | self.toLower(struct.pack('>I', len(data))[1:])
27 |
28 | self.toLower(data)
29 |
30 | def receive(self, data):
31 | if self.getProp(self.PROP_ENABLED, False):
32 | self._read_buffer.extend(data)
33 |
34 | while len(self._read_buffer) > 3:
35 | read_size = struct.unpack('>I', b"\x00" + self._read_buffer[:3])[0] # type: int
36 | if len(self._read_buffer) >= (3 + read_size):
37 | data = self._read_buffer[3:read_size+3]
38 | self._read_buffer = self._read_buffer[3 + read_size:]
39 | self.toUpper(bytes(data))
40 | else:
41 | break
42 | else:
43 | self.toUpper(data)
44 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/ack_incoming.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .ack import AckProtocolEntity
3 | class IncomingAckProtocolEntity(AckProtocolEntity):
4 |
5 | '''
6 |
7 |
8 | '''
9 |
10 | def __init__(self, _id, _class, _from, timestamp):
11 | super(IncomingAckProtocolEntity, self).__init__(_id, _class)
12 | self.setIncomingData(_from, timestamp)
13 |
14 | def setIncomingData(self, _from, timestamp):
15 | self._from = _from
16 | self.timestamp = timestamp
17 |
18 | def toProtocolTreeNode(self):
19 | node = super(IncomingAckProtocolEntity, self).toProtocolTreeNode()
20 | node.setAttribute("from", self._from)
21 | node.setAttribute("t", self.timestamp)
22 | return node
23 |
24 | def __str__(self):
25 | out = super(IncomingAckProtocolEntity, self).__str__()
26 | out += "From: %s\n" % self._from
27 | out += "timestamp: %s\n" % self.timestamp
28 | return out
29 |
30 | @staticmethod
31 | def fromProtocolTreeNode(node):
32 | entity = AckProtocolEntity.fromProtocolTreeNode(node)
33 | entity.__class__ = IncomingAckProtocolEntity
34 | entity.setIncomingData(
35 | node.getAttributeValue("from"),
36 | node.getAttributeValue("t")
37 | )
38 | return entity
39 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_ib/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowLayer, YowLayerEvent, YowProtocolLayer
2 | from .protocolentities import *
3 | import logging
4 |
5 | logger = logging.getLogger(__name__)
6 |
7 | class YowIbProtocolLayer(YowProtocolLayer):
8 |
9 | def __init__(self):
10 | handleMap = {
11 | "ib": (self.recvIb, self.sendIb),
12 | "iq": (None, self.sendIb)
13 | }
14 | super(YowIbProtocolLayer, self).__init__(handleMap)
15 |
16 | def __str__(self):
17 | return "Ib Layer"
18 |
19 | def sendIb(self, entity):
20 | if entity.__class__ == CleanIqProtocolEntity:
21 | self.toLower(entity.toProtocolTreeNode())
22 |
23 | def recvIb(self, node):
24 | if node.getChild("dirty"):
25 | self.toUpper(DirtyIbProtocolEntity.fromProtocolTreeNode(node))
26 | elif node.getChild("offline"):
27 | self.toUpper(OfflineIbProtocolEntity.fromProtocolTreeNode(node))
28 | elif node.getChild("account"):
29 | self.toUpper(AccountIbProtocolEntity.fromProtocolTreeNode(node))
30 | elif node.getChild("edge_routing"):
31 | logger.debug("ignoring edge_routing ib node for now")
32 | elif node.getChild("attestation"):
33 | logger.debug("ignoring attestation ib node for now")
34 | elif node.getChild("fbip"):
35 | logger.debug("ignoring fbip ib node for now")
36 | else:
37 | logger.warning("Unsupported ib node: %s" % node)
38 |
--------------------------------------------------------------------------------
/yowsup/common/optionalmodules.py:
--------------------------------------------------------------------------------
1 | import importlib
2 | import logging
3 |
4 | logger = logging.getLogger(__name__)
5 |
6 |
7 | class OptionalModule(object):
8 | def __init__(self, modulename, failMessage = None, require = False):
9 | self.modulename = modulename
10 | self.require = require
11 | self.failMessage = failMessage
12 |
13 | def __enter__(self):
14 | return self.importFn
15 |
16 | def importFn(self, what = None):
17 | imp = self.modulename if not what else ("%s.%s" % (self.modulename, what))
18 | return importlib.import_module(imp)
19 |
20 | def __exit__(self, exc_type, exc_val, exc_tb):
21 | if isinstance(exc_val, ImportError):
22 | failMessage = self.failMessage if self.failMessage is not None else ("%s import failed" % self.modulename)
23 | if failMessage:
24 | logger.error(failMessage)
25 | if self.require:
26 | raise
27 | return True
28 |
29 | class PILOptionalModule(OptionalModule):
30 | def __init__(self, failMessage = None, require = False):
31 | super(PILOptionalModule, self).__init__("PIL",
32 | failMessage= failMessage,
33 | require = require)
34 |
35 | class FFVideoOptionalModule(OptionalModule):
36 | def __init__(self, failMessage = None, require = False):
37 | super(FFVideoOptionalModule, self).__init__("ffvideo",
38 | failMessage=failMessage,
39 | require=require)
40 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_pictures_list.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_picture import PictureIqProtocolEntity
3 | class ListPicturesIqProtocolEntity(PictureIqProtocolEntity):
4 | '''
5 |
6 |
7 |
8 |
9 |
10 |
11 | '''
12 |
13 | def __init__(self, selfJid, jids):
14 | super(ListPicturesIqProtocolEntity, self).__init__(jid = selfJid, type = "get")
15 | self.setProps(jids)
16 |
17 | def setProps(self, jids):
18 | assert type(jids) is list and len(jids), "Must specify a list of jids to get the pictures for"
19 | self.jids = jids
20 |
21 | def toProtocolTreeNode(self):
22 | node = super(ListPicturesIqProtocolEntity, self).toProtocolTreeNode()
23 | userNodes = [ProtocolTreeNode("user", {"jid": jid}) for jid in self.jids]
24 | listNode = ProtocolTreeNode("list", {}, userNodes)
25 | node.addChild(listNode)
26 | return node
27 |
28 | @staticmethod
29 | def fromProtocolTreeNode(node):
30 | entity = PictureIqProtocolEntity.fromProtocolTreeNode(node)
31 | entity.__class__ = ListPicturesIqProtocolEntity
32 | jids = [userNode.getAttributeValue("jid") for userNode in node.getChild("list").getAllChildren()]
33 | entity.setProps(jids)
34 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/notification_encrypt_requestkeys.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_notifications.protocolentities import NotificationProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 |
6 | class RequestKeysEncryptNotification(NotificationProtocolEntity):
7 | """
8 |
9 |
10 |
11 |
12 | """
13 | def __init__(self, count, timestamp, _id = None, notify = None, offline = None):
14 | super(RequestKeysEncryptNotification, self).__init__(
15 | "encrypt", _id, YowConstants.WHATSAPP_SERVER, timestamp, notify, offline
16 | )
17 | self._count = count
18 |
19 | @property
20 | def count(self):
21 | return self._count
22 |
23 | @count.setter
24 | def count(self, value):
25 | self._count = value
26 |
27 | def toProtocolTreeNode(self):
28 | node = super(RequestKeysEncryptNotification, self).toProtocolTreeNode()
29 | count_node = ProtocolTreeNode("count", {"value": str(self.count)})
30 | node.addChild(count_node)
31 | return node
32 |
33 | @staticmethod
34 | def fromProtocolTreeNode(node):
35 | entity = NotificationProtocolEntity.fromProtocolTreeNode(node)
36 | entity.__class__ = RequestKeysEncryptNotification
37 | entity.count = node.getChild("count")["value"]
38 | return entity
39 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/iq_key_get.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 |
6 | class GetKeysIqProtocolEntity(IqProtocolEntity):
7 | def __init__(self, jids, reason=None):
8 | super(GetKeysIqProtocolEntity, self).__init__("encrypt", _type="get", to=YowConstants.WHATSAPP_SERVER)
9 | self.jids = jids
10 | self.reason = reason
11 |
12 | @property
13 | def reason(self):
14 | # type: () -> str
15 | return self._reason
16 |
17 | @reason.setter
18 | def reason(self, value):
19 | # type: (str) -> None
20 | self._reason = value
21 |
22 | @property
23 | def jids(self):
24 | # type: () -> list[str]
25 | return self._jids
26 |
27 | @jids.setter
28 | def jids(self, value):
29 | # type: (list[str]) -> None
30 | assert type(value) is list, "expected list of jids, got %s" % type(value)
31 | self._jids = value
32 |
33 | def toProtocolTreeNode(self):
34 | node = super(GetKeysIqProtocolEntity, self).toProtocolTreeNode()
35 | keyNode = ProtocolTreeNode("key")
36 |
37 | for jid in self.jids:
38 | attrs = { "jid": jid }
39 | if self.reason is not None:
40 | attrs["reason"] = self.reason
41 | userNode = ProtocolTreeNode("user", attrs)
42 | keyNode.addChild(userNode)
43 | node.addChild(keyNode)
44 | return node
45 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_status_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 | import logging
5 |
6 | logger = logging.getLogger(__name__)
7 |
8 |
9 | class SetStatusIqProtocolEntity(IqProtocolEntity):
10 | '''
11 |
12 | {{MSG}}
13 |
14 | '''
15 | XMLNS = "status"
16 | def __init__(self, text = None, _id = None):
17 | if type(text) is not bytes:
18 | logger.warning("Passing text as str is deprecated, pass bytes instead")
19 | text = bytes(text, "latin-1")
20 | super(SetStatusIqProtocolEntity, self).__init__(self.__class__.XMLNS, _id, _type = "set", to = YowConstants.WHATSAPP_SERVER)
21 | self.setData(text)
22 |
23 | def setData(self, text):
24 | self.text = text
25 |
26 | def toProtocolTreeNode(self):
27 | node = super(SetStatusIqProtocolEntity, self).toProtocolTreeNode()
28 | statusNode = ProtocolTreeNode("status", {}, [], self.text)
29 | node.addChild(statusNode)
30 | return node
31 |
32 | @staticmethod
33 | def fromProtocolTreeNode(node):
34 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
35 | entity.__class__ = SetStatusIqProtocolEntity
36 | statusNode = node.getChild("status")
37 | entity.setData(statusNode.getData())
38 | return entity
39 |
--------------------------------------------------------------------------------
/yowsup/layers/axolotl/protocolentities/enc.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | import sys
3 | class EncProtocolEntity(ProtocolEntity):
4 | TYPE_PKMSG = "pkmsg"
5 | TYPE_MSG = "msg"
6 | TYPE_SKMSG = "skmsg"
7 | TYPES = (TYPE_PKMSG, TYPE_MSG, TYPE_SKMSG)
8 |
9 | def __init__(self, type, version, data, mediaType = None, jid = None):
10 | assert type in self.__class__.TYPES, "Unknown message enc type %s" % type
11 | super(EncProtocolEntity, self).__init__("enc")
12 | self.type = type
13 | self.version = int(version)
14 | self.data = data
15 | self.mediaType = mediaType
16 | self.jid = jid
17 |
18 | def getType(self):
19 | return self.type
20 |
21 | def getVersion(self):
22 | return self.version
23 |
24 | def getData(self):
25 | return self.data
26 |
27 | def getMediaType(self):
28 | return self.mediaType
29 |
30 | def getJid(self):
31 | return self.jid
32 |
33 | def toProtocolTreeNode(self):
34 | attribs = {"type": self.type, "v": str(self.version)}
35 | if self.mediaType:
36 | attribs["mediatype"] = self.mediaType
37 | encNode = ProtocolTreeNode("enc", attribs, data = self.data)
38 | if self.jid:
39 | return ProtocolTreeNode("to", {"jid": self.jid}, [encNode])
40 | return encNode
41 |
42 | @staticmethod
43 | def fromProtocolTreeNode(node):
44 | return EncProtocolEntity(node["type"], node["v"], node.data, node["mediatype"])
45 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/notification_picture_set.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .notification_picture import PictureNotificationProtocolEntity
3 | class SetPictureNotificationProtocolEntity(PictureNotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 |
10 | '''
11 |
12 | def __init__(self, _id, _from, status, timestamp, notify, offline, setJid, setId):
13 | super(SetPictureNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
14 | self.setData(setJid, setId)
15 |
16 | def setData(self, setJid, setId):
17 | self.setId = setId
18 | self.setJid = setJid
19 |
20 | def toProtocolTreeNode(self):
21 | node = super(SetPictureNotificationProtocolEntity, self).toProtocolTreeNode()
22 | setNode = ProtocolTreeNode("set", {"jid": self.setJid, "id": self.setId}, None, None)
23 | node.addChild(setNode)
24 | return node
25 |
26 | @staticmethod
27 | def fromProtocolTreeNode(node):
28 | entity = PictureNotificationProtocolEntity.fromProtocolTreeNode(node)
29 | entity.__class__ = SetPictureNotificationProtocolEntity
30 | setNode = node.getChild("set")
31 | entity.setData(setNode.getAttributeValue("jid"), setNode.getAttributeValue("id"))
32 | return entity
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_message_key.py:
--------------------------------------------------------------------------------
1 | class MessageKeyAttributes(object):
2 | def __init__(self, remote_jid, from_me, id, participant):
3 | self._remote_jid = remote_jid
4 | self._from_me = from_me
5 | self._id = id
6 | self._participant = participant
7 |
8 | def __str__(self):
9 | attrs = []
10 | if self.remote_jid is not None:
11 | attrs.append(("remote_jid", self.remote_jid))
12 | if self.from_me is not None:
13 | attrs.append(("from_me", self.from_me))
14 | if self.id is not None:
15 | attrs.append(("id", self.id))
16 | if self.participant is not None:
17 | attrs.append(("participant", self.participant))
18 |
19 | return "[%s]" % " ".join((map(lambda item: "%s=%s" % item, attrs)))
20 |
21 | @property
22 | def remote_jid(self):
23 | return self._remote_jid
24 |
25 | @remote_jid.setter
26 | def remote_jid(self, value):
27 | self._remote_jid = value
28 |
29 | @property
30 | def from_me(self):
31 | return self._from_me
32 |
33 | @from_me.setter
34 | def from_me(self, value):
35 | self._from_me = value
36 |
37 | @property
38 | def id(self):
39 | return self._id
40 |
41 | @id.setter
42 | def id(self, value):
43 | self._id = value
44 |
45 | @property
46 | def participant(self):
47 | return self._participant
48 |
49 | @participant.setter
50 | def participant(self, value):
51 | self._participant = value
52 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_notifications/protocolentities/notification_picture_delete.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .notification_picture import PictureNotificationProtocolEntity
3 | class DeletePictureNotificationProtocolEntity(PictureNotificationProtocolEntity):
4 | '''
5 |
7 |
8 |
9 |
10 | '''
11 |
12 | def __init__(self, _id, _from, status, timestamp, notify, offline, deleteJid):
13 | super(DeletePictureNotificationProtocolEntity, self).__init__(_id, _from, timestamp, notify, offline)
14 | self.setData(deleteJid)
15 |
16 | def setData(self, deleteJid):
17 | self.deleteJid = deleteJid
18 |
19 | def __str__(self):
20 | out = super(DeletePictureNotificationProtocolEntity, self).__str__()
21 | out += "Type: Delete"
22 | return out
23 |
24 | def toProtocolTreeNode(self):
25 | node = super(DeletePictureNotificationProtocolEntity, self).toProtocolTreeNode()
26 | deleteNode = ProtocolTreeNode("delete", {"jid": self.deleteJid}, None, None)
27 | node.addChild(deleteNode)
28 | return node
29 |
30 | @staticmethod
31 | def fromProtocolTreeNode(node):
32 | entity = PictureNotificationProtocolEntity.fromProtocolTreeNode(node)
33 | entity.__class__ = DeletePictureNotificationProtocolEntity
34 | deleteNode = node.getChild("delete")
35 | entity.setData(deleteNode.getAttributeValue("jid"))
36 | return entity
37 |
--------------------------------------------------------------------------------
/yowsup/structs/protocolentity.py:
--------------------------------------------------------------------------------
1 | from .protocoltreenode import ProtocolTreeNode
2 | import unittest, time
3 | class ProtocolEntity(object):
4 | __ID_GEN = 0
5 |
6 | def __init__(self, tag):
7 | self.tag = tag
8 |
9 | def getTag(self):
10 | return self.tag
11 |
12 | def isType(self, typ):
13 | return self.tag == typ
14 |
15 | def _createProtocolTreeNode(self, attributes, children = None, data = None):
16 | return ProtocolTreeNode(self.getTag(), attributes, children, data)
17 |
18 |
19 | def _getCurrentTimestamp(self):
20 | return int(time.time())
21 |
22 | def _generateId(self, short = False):
23 | ProtocolEntity.__ID_GEN += 1
24 | return str(ProtocolEntity.__ID_GEN) if short else str(int(time.time())) + "-" + str(ProtocolEntity.__ID_GEN)
25 |
26 |
27 | def toProtocolTreeNode(self):
28 | pass
29 |
30 | @staticmethod
31 | def fromProtocolTreeNode(self, protocolTreeNode):
32 | pass
33 |
34 |
35 | class ProtocolEntityTest(object):
36 | def setUp(self):
37 | self.ProtocolEntity = None
38 | self.node = None
39 |
40 | # def assertEqual(self, entity, node):
41 | # raise AssertionError("Should never execute that")
42 |
43 | def test_generation(self):
44 | if self.ProtocolEntity is None:
45 | raise ValueError("Test case not setup!")
46 | entity = self.ProtocolEntity.fromProtocolTreeNode(self.node)
47 | try:
48 | self.assertEqual(entity.toProtocolTreeNode(), self.node)
49 | except:
50 | print(entity.toProtocolTreeNode())
51 | print("\nNOTEQ\n")
52 | print(self.node)
53 | raise
54 |
55 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_leave_success.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.structs import ProtocolTreeNode
3 | from yowsup.layers.protocol_iq.protocolentities import ResultIqProtocolEntity
4 |
5 |
6 | class SuccessLeaveGroupsIqProtocolEntity(ResultIqProtocolEntity):
7 | '''
8 |
9 |
10 |
11 |
12 |
13 | '''
14 |
15 | def __init__(self, _id, groupId):
16 | super(SuccessLeaveGroupsIqProtocolEntity, self).\
17 | __init__(_from=YowConstants.WHATSAPP_GROUP_SERVER, _id=_id)
18 | self.setProps(groupId)
19 |
20 | def setProps(self, groupId):
21 | self.groupId = groupId
22 |
23 | def __str__(self):
24 | out = super(SuccessLeaveGroupsIqProtocolEntity, self).__str__()
25 | out += "Group Id: %s\n" % self.groupId
26 | return out
27 |
28 | def toProtocolTreeNode(self):
29 | node = super(SuccessLeaveGroupsIqProtocolEntity, self).\
30 | toProtocolTreeNode()
31 | leaveNode = ProtocolTreeNode(
32 | "leave", {}, [ProtocolTreeNode("group", {"id": self.groupId})]
33 | )
34 | node.addChild(leaveNode)
35 | return node
36 |
37 | @staticmethod
38 | def fromProtocolTreeNode(node):
39 | entity = super(SuccessLeaveGroupsIqProtocolEntity, SuccessLeaveGroupsIqProtocolEntity).fromProtocolTreeNode(node)
40 | entity.__class__ = SuccessLeaveGroupsIqProtocolEntity
41 | entity.setProps(
42 | node.getChild("leave").getChild("group").getAttributeValue("id")
43 | )
44 | return entity
45 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | from __future__ import print_function
3 | from setuptools import setup, find_packages
4 | import yowsup
5 | import platform
6 | import sys
7 |
8 | deps = ['consonance==0.1.5', 'argparse', 'python-axolotl==0.2.2', 'six==1.10', 'appdirs', 'protobuf>=3.6.0']
9 |
10 | if sys.version_info < (2, 7):
11 | deps.append('importlib')
12 |
13 | if platform.system().lower() == "windows":
14 | deps.append('pyreadline')
15 | else:
16 | try:
17 | import readline
18 | except ImportError:
19 | deps.append('readline')
20 |
21 | setup(
22 | name='yowsup',
23 | version=yowsup.__version__,
24 | url='http://github.com/tgalal/yowsup/',
25 | license='GPL-3+',
26 | author='Tarek Galal',
27 | tests_require=[],
28 | install_requires = deps,
29 | scripts = ['yowsup-cli'],
30 | #cmdclass={'test': PyTest},
31 | author_email='tare2.galal@gmail.com',
32 | description='The WhatsApp lib',
33 | #long_description=long_description,
34 | packages= find_packages(),
35 | include_package_data=True,
36 | data_files = [('yowsup/common', ['yowsup/common/mime.types'])],
37 | platforms='any',
38 | #test_suite='',
39 | classifiers = [
40 | 'Programming Language :: Python',
41 | 'Development Status :: 4 - Beta',
42 | 'Natural Language :: English',
43 | #'Environment :: Web Environment',
44 | 'Intended Audience :: Developers',
45 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
46 | 'Operating System :: OS Independent',
47 | 'Topic :: Software Development :: Libraries :: Python Modules'
48 | ],
49 | #extras_require={
50 | # 'testing': ['pytest'],
51 | #}
52 | )
53 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_messages/protocolentities/attributes/attributes_sticker.py:
--------------------------------------------------------------------------------
1 | class StickerAttributes(object):
2 | def __init__(self, downloadablemedia_attributes, width, height, png_thumbnail=None):
3 | self._downloadablemedia_attributes = downloadablemedia_attributes
4 | self._width = width
5 | self._height = height
6 | self._png_thumbnail = png_thumbnail
7 |
8 | def __str__(self):
9 | attrs = []
10 | if self.width is not None:
11 | attrs.append(("width", self.width))
12 | if self.height is not None:
13 | attrs.append(("height", self.height))
14 | if self.png_thumbnail is not None:
15 | attrs.append(("png_thumbnail", self.png_thumbnail))
16 | attrs.append(("downloadable", self.downloadablemedia_attributes))
17 |
18 | return "[%s]" % " ".join((map(lambda item: "%s=%s" % item, attrs)))
19 |
20 | @property
21 | def downloadablemedia_attributes(self):
22 | return self._downloadablemedia_attributes
23 |
24 | @downloadablemedia_attributes.setter
25 | def downloadablemedia_attributes(self, value):
26 | self._downloadablemedia_attributes = value
27 |
28 | @property
29 | def width(self):
30 | return self._width
31 |
32 | @width.setter
33 | def width(self, value):
34 | self._width = value
35 |
36 | @property
37 | def height(self):
38 | return self._height
39 |
40 | @height.setter
41 | def height(self, value):
42 | self._height = value
43 |
44 | @property
45 | def png_thumbnail(self):
46 | return self._png_thumbnail
47 |
48 | @png_thumbnail.setter
49 | def png_thumbnail(self, value):
50 | self._png_thumbnail = value
51 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_contacts/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers import YowProtocolLayer
2 | from .protocolentities import *
3 | import logging
4 |
5 | logger = logging.getLogger(__name__)
6 |
7 |
8 | class YowContactsIqProtocolLayer(YowProtocolLayer):
9 | def __init__(self):
10 | handleMap = {
11 | "iq": (self.recvIq, self.sendIq),
12 | "notification": (self.recvNotification, None)
13 | }
14 | super(YowContactsIqProtocolLayer, self).__init__(handleMap)
15 |
16 | def __str__(self):
17 | return "Contact Iq Layer"
18 |
19 | def recvNotification(self, node):
20 | if node["type"] == "contacts":
21 | if node.getChild("remove"):
22 | self.toUpper(RemoveContactNotificationProtocolEntity.fromProtocolTreeNode(node))
23 | elif node.getChild("add"):
24 | self.toUpper(AddContactNotificationProtocolEntity.fromProtocolTreeNode(node))
25 | elif node.getChild("update"):
26 | self.toUpper(UpdateContactNotificationProtocolEntity.fromProtocolTreeNode(node))
27 | elif node.getChild("sync"):
28 | self.toUpper(ContactsSyncNotificationProtocolEntity.fromProtocolTreeNode(node))
29 | else:
30 | logger.warning("Unsupported notification type: %s " % node["type"])
31 | logger.debug("Unsupported notification node: %s" % node)
32 |
33 | def recvIq(self, node):
34 | if node["type"] == "result" and node.getChild("sync"):
35 | self.toUpper(ResultSyncIqProtocolEntity.fromProtocolTreeNode(node))
36 |
37 | def sendIq(self, entity):
38 | if entity.getXmlns() == "urn:xmpp:whatsapp:sync":
39 | self.toLower(entity.toProtocolTreeNode())
40 |
--------------------------------------------------------------------------------
/yowsup/demos/echoclient/layer.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
2 |
3 | class EchoLayer(YowInterfaceLayer):
4 |
5 | @ProtocolEntityCallback("message")
6 | def onMessage(self, messageProtocolEntity):
7 |
8 | if messageProtocolEntity.getType() == 'text':
9 | self.onTextMessage(messageProtocolEntity)
10 | elif messageProtocolEntity.getType() == 'media':
11 | self.onMediaMessage(messageProtocolEntity)
12 |
13 | self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))
14 | self.toLower(messageProtocolEntity.ack())
15 | self.toLower(messageProtocolEntity.ack(True))
16 |
17 |
18 | @ProtocolEntityCallback("receipt")
19 | def onReceipt(self, entity):
20 | self.toLower(entity.ack())
21 |
22 | def onTextMessage(self,messageProtocolEntity):
23 | # just print info
24 | print("Echoing %s to %s" % (messageProtocolEntity.getBody(), messageProtocolEntity.getFrom(False)))
25 |
26 | def onMediaMessage(self, messageProtocolEntity):
27 | # just print info
28 | if messageProtocolEntity.media_type == "image":
29 | print("Echoing image %s to %s" % (messageProtocolEntity.url, messageProtocolEntity.getFrom(False)))
30 |
31 | elif messageProtocolEntity.media_type == "location":
32 | print("Echoing location (%s, %s) to %s" % (messageProtocolEntity.getLatitude(), messageProtocolEntity.getLongitude(), messageProtocolEntity.getFrom(False)))
33 |
34 | elif messageProtocolEntity.media_type == "contact":
35 | print("Echoing contact (%s, %s) to %s" % (messageProtocolEntity.getName(), messageProtocolEntity.getCardData(), messageProtocolEntity.getFrom(False)))
36 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/test_message_media_extendedtext.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.protocol_media.protocolentities.test_message_media import MediaMessageProtocolEntityTest
2 | from yowsup.layers.protocol_media.protocolentities import ExtendedTextMediaMessageProtocolEntity
3 | from yowsup.layers.protocol_messages.proto.e2e_pb2 import Message
4 |
5 |
6 | class ExtendedTextMediaMessageProtocolEntityTest(MediaMessageProtocolEntityTest):
7 | def setUp(self):
8 | super(ExtendedTextMediaMessageProtocolEntityTest, self).setUp()
9 | self.ProtocolEntity = ExtendedTextMediaMessageProtocolEntity
10 |
11 | m = Message()
12 | media_message = Message.ExtendedTextMessage()
13 | media_message.canonical_url = "url"
14 | media_message.text = "text"
15 | media_message.matched_text = "matched_text"
16 | media_message.description = "desc"
17 | media_message.title = "title"
18 | media_message.jpeg_thumbnail = b"thumb"
19 | m.extended_text_message.MergeFrom(media_message)
20 |
21 | proto_node = self.node.getChild("proto")
22 | proto_node["mediatype"] = "url"
23 | proto_node.setData(m.SerializeToString())
24 |
25 | self._entity = ExtendedTextMediaMessageProtocolEntity\
26 | .fromProtocolTreeNode(self.node) # type: ExtendedTextMediaMessageProtocolEntity
27 |
28 | def test_properties(self):
29 | self.assertEqual("url", self._entity.canonical_url)
30 | self.assertEqual("text", self._entity.text)
31 | self.assertEqual("matched_text", self._entity.matched_text)
32 | self.assertEqual("desc", self._entity.description)
33 | self.assertEqual("title", self._entity.title)
34 | self.assertEqual(b"thumb", self._entity.jpeg_thumbnail)
35 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/__init__.py:
--------------------------------------------------------------------------------
1 | from .iq_groups_create import CreateGroupsIqProtocolEntity
2 | from .iq_groups_create_success import SuccessCreateGroupsIqProtocolEntity
3 | from .iq_groups_leave import LeaveGroupsIqProtocolEntity
4 | from .iq_groups_leave_success import SuccessLeaveGroupsIqProtocolEntity
5 | from .iq_groups_list import ListGroupsIqProtocolEntity
6 | from .iq_groups_info import InfoGroupsIqProtocolEntity
7 | from .iq_groups_subject import SubjectGroupsIqProtocolEntity
8 | from .iq_groups_participants import ParticipantsGroupsIqProtocolEntity
9 | from .iq_groups_participants_add import AddParticipantsIqProtocolEntity
10 | from .iq_groups_participants_promote import PromoteParticipantsIqProtocolEntity
11 | from .iq_groups_participants_demote import DemoteParticipantsIqProtocolEntity
12 | from .iq_groups_participants_add_success import SuccessAddParticipantsIqProtocolEntity
13 | from .iq_groups_participants_add_failure import FailureAddParticipantsIqProtocolEntity
14 | from .iq_groups_participants_remove import RemoveParticipantsIqProtocolEntity
15 | from .iq_groups_participants_remove_success import SuccessRemoveParticipantsIqProtocolEntity
16 | from .iq_result_groups_list import ListGroupsResultIqProtocolEntity
17 | from .iq_result_participants_list import ListParticipantsResultIqProtocolEntity
18 | from .iq_result_groups_info import InfoGroupsResultIqProtocolEntity
19 | from .notification_groups import GroupsNotificationProtocolEntity
20 | from .notification_groups_subject import SubjectGroupsNotificationProtocolEntity
21 | from .notification_groups_create import CreateGroupsNotificationProtocolEntity
22 | from .notification_groups_add import AddGroupsNotificationProtocolEntity
23 | from .notification_groups_remove import RemoveGroupsNotificationProtocolEntity
24 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_participants.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
2 | from .iq_groups import GroupsIqProtocolEntity
3 |
4 | class ParticipantsGroupsIqProtocolEntity(GroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 | '''
10 |
11 | modes=["add","promote","remove","demote"]
12 | def __init__(self, jid, participantList, _mode, _id = None):
13 | super(ParticipantsGroupsIqProtocolEntity, self).__init__(to = jid, _id = _id, _type = "set")
14 | self.setProps(group_jid = jid, participantList = participantList, mode = _mode)
15 |
16 | def setProps(self, group_jid, participantList, mode):
17 | assert type(participantList) is list, "Must be a list of jids, got %s instead." % type(participantList)
18 | assert mode in self.modes, "Mode should be in: '" + "', '".join(self.modes) + "' but is '" + mode + "'"
19 | self.group_jid = group_jid
20 | self.participantList = participantList
21 | self.mode = mode
22 |
23 | def toProtocolTreeNode(self):
24 | node = super(ParticipantsGroupsIqProtocolEntity, self).toProtocolTreeNode()
25 | participantNodes = [
26 | ProtocolTreeNode("participant", {
27 | "jid": participant
28 | })
29 | for participant in self.participantList
30 | ]
31 | node.addChild(ProtocolTreeNode(self.mode,{}, participantNodes))
32 | return node
33 |
34 | @staticmethod
35 | def fromProtocolTreeNode(node):
36 | entity = super(ParticipantsGroupsIqProtocolEntity, ParticipantsGroupsIqProtocolEntity).fromProtocolTreeNode(node)
37 | entity.__class__ = ParticipantsGroupsIqProtocolEntity
38 | return entity
39 |
--------------------------------------------------------------------------------
/yowsup/layers/noise/workers/handshake.py:
--------------------------------------------------------------------------------
1 | from consonance.protocol import WANoiseProtocol
2 | from consonance.streams.segmented.segmented import SegmentedStream
3 | from consonance.exceptions.handshake_failed_exception import HandshakeFailedException
4 | from consonance.config.client import ClientConfig
5 | from consonance.structs.keypair import KeyPair
6 | from consonance.structs.publickey import PublicKey
7 |
8 | import threading
9 | import logging
10 |
11 | logger = logging.getLogger(__name__)
12 |
13 |
14 | class WANoiseProtocolHandshakeWorker(threading.Thread):
15 | def __init__(self, wanoiseprotocol, stream, client_config, s, rs=None, finish_callback=None):
16 | """
17 | :param wanoiseprotocol:
18 | :type wanoiseprotocol: WANoiseProtocol
19 | :param stream:
20 | :type stream: SegmentedStream
21 | :param client_config:
22 | :type client_config: ClientConfig
23 | :param s:
24 | :type s: KeyPair
25 | :param rs:
26 | :type rs: PublicKey | None
27 | """
28 | super(WANoiseProtocolHandshakeWorker, self).__init__()
29 | self.daemon = True
30 |
31 | self._protocol = wanoiseprotocol # type: WANoiseProtocol
32 | self._stream = stream # type: SegmentedStream
33 | self._client_config = client_config # type: ClientConfig
34 | self._s = s # type: KeyPair
35 | self._rs = rs # type: PublicKey
36 | self._finish_callback = finish_callback
37 |
38 | def run(self):
39 | self._protocol.reset()
40 | error = None
41 | try:
42 | self._protocol.start(self._stream, self._client_config, self._s, self._rs)
43 | except HandshakeFailedException as e:
44 | error = e
45 |
46 | if self._finish_callback is not None:
47 | self._finish_callback(error)
48 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_result_participants_list.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from yowsup.layers.protocol_iq.protocolentities import ResultIqProtocolEntity
3 | class ListParticipantsResultIqProtocolEntity(ResultIqProtocolEntity):
4 | '''
5 |
6 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _from, participantList):
12 | super(ListParticipantsResultIqProtocolEntity, self).__init__(_from = _from)
13 | self.setParticipants(participantList)
14 |
15 | def __str__(self):
16 | out = super(ListParticipantsResultIqProtocolEntity, self).__str__()
17 | out += "Participants: %s\n" % " ".join(self.participantList)
18 | return out
19 |
20 | def getParticipants(self):
21 | return self.participantList
22 |
23 | def setParticipants(self, participants):
24 | self.participantList = participants
25 |
26 | def toProtocolTreeNode(self):
27 | node = super(ListParticipantsResultIqProtocolEntity, self).toProtocolTreeNode()
28 |
29 | participantNodes = [
30 | ProtocolTreeNode("participant", {
31 | "jid": participant
32 | })
33 | for participant in self.participantList
34 | ]
35 |
36 | node.addChildren(participantNodes)
37 | return node
38 |
39 | @staticmethod
40 | def fromProtocolTreeNode(node):
41 | entity = super(ListParticipantsResultIqProtocolEntity, ListParticipantsResultIqProtocolEntity).fromProtocolTreeNode(node)
42 | entity.__class__ = ListParticipantsResultIqProtocolEntity
43 | entity.setParticipants([ pNode.getAttributeValue("jid") for pNode in node.getAllChildren() ])
44 | return entity
45 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_iq/protocolentities/iq_error.py:
--------------------------------------------------------------------------------
1 | from yowsup.structs import ProtocolTreeNode
2 | from .iq import IqProtocolEntity
3 | class ErrorIqProtocolEntity(IqProtocolEntity):
4 |
5 | '''
6 |
7 |
8 |
9 | '''
10 |
11 | def __init__(self, _id, _from, code, text, backoff= 0 ):
12 | super(ErrorIqProtocolEntity, self).__init__(xmlns = None, _id = _id, _type = "error", _from = _from)
13 | self.setErrorProps(code, text, backoff)
14 |
15 | def setErrorProps(self, code, text, backoff):
16 | self.code = code
17 | self.text = text
18 | self.backoff = int(backoff) if backoff else 0
19 |
20 | def toProtocolTreeNode(self):
21 | node = super(ErrorIqProtocolEntity, self).toProtocolTreeNode()
22 | errorNode = ProtocolTreeNode("error", {"text": self.text, "code": self.code})
23 | if self.backoff:
24 | errorNode.setAttribute("backoff", str(self.backoff))
25 | node.addChild(errorNode)
26 | return node
27 |
28 | def __str__(self):
29 | out = super(ErrorIqProtocolEntity, self).__str__()
30 | out += "Code: %s\n" % self.code
31 | out += "Text: %s\n" % self.text
32 | out += "Backoff: %s\n" % self.backoff
33 | return out
34 |
35 | @staticmethod
36 | def fromProtocolTreeNode(node):
37 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
38 | entity.__class__ = ErrorIqProtocolEntity
39 | errorNode = node.getChild("error")
40 | entity.setErrorProps(errorNode.getAttributeValue("code"),
41 | errorNode.getAttributeValue("text"),
42 | errorNode.getAttributeValue("backoff"))
43 | return entity
44 |
45 |
46 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_profiles/protocolentities/iq_statuses_get.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.layers.protocol_iq.protocolentities import IqProtocolEntity
3 | from yowsup.structs import ProtocolTreeNode
4 |
5 | class GetStatusesIqProtocolEntity(IqProtocolEntity):
6 | XMLNS = "status"
7 |
8 | def __init__(self, jids, _id = None):
9 | """
10 | Request the statuses of users. Should be sent once after login.
11 |
12 | Args:
13 | - jids: A list of jids representing the users whose statuses you are
14 | trying to get.
15 | """
16 | super(GetStatusesIqProtocolEntity, self).__init__(self.__class__.XMLNS, _id, _type = "get", to = YowConstants.WHATSAPP_SERVER)
17 | self.setGetStatusesProps(jids)
18 |
19 | def setGetStatusesProps(self, jids):
20 | assert type(jids) is list, "jids must be a list of jids"
21 | self.jids = jids
22 |
23 | def __str__(self):
24 | out = super(GetStatusesIqProtocolEntity, self).__str__()
25 | out += "Numbers: %s\n" % (",".join(self.numbers))
26 | return out
27 |
28 | def toProtocolTreeNode(self):
29 | users = [ProtocolTreeNode("user", {'jid': jid}) for jid in self.jids]
30 |
31 | node = super(GetStatusesIqProtocolEntity, self).toProtocolTreeNode()
32 | statusNode = ProtocolTreeNode("status", None, users)
33 | node.addChild(statusNode)
34 |
35 | return node
36 |
37 | @staticmethod
38 | def fromProtocolTreeNode(node):
39 | entity = IqProtocolEntity.fromProtocolTreeNode(node)
40 | entity.__class__ = GetStatusesIqProtocolEntity
41 | statusNode = node.getChild("status")
42 | userNodes = statusNode.getAllChildren()
43 | jids = [user['jid'] for user in userNodes]
44 |
45 | entity.setGetStatusesProps(jids)
46 |
47 | return entity
48 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_acks/protocolentities/ack_outgoing.py:
--------------------------------------------------------------------------------
1 | from .ack import AckProtocolEntity
2 | class OutgoingAckProtocolEntity(AckProtocolEntity):
3 |
4 | '''
5 |
6 |
7 |
8 |
9 |
10 |
11 | '''
12 |
13 | def __init__(self, _id, _class, _type, to, participant = None):
14 | super(OutgoingAckProtocolEntity, self).__init__(_id, _class)
15 | self.setOutgoingData(_type, to, participant)
16 |
17 | def setOutgoingData(self, _type, _to, _participant):
18 | self._type = _type
19 | self._to = _to
20 | self._participant = _participant
21 |
22 | def toProtocolTreeNode(self):
23 | node = super(OutgoingAckProtocolEntity, self).toProtocolTreeNode()
24 | if self._type:
25 | node.setAttribute("type", self._type)
26 | node.setAttribute("to", self._to)
27 | if self._participant:
28 | node.setAttribute("participant", self._participant)
29 | return node
30 |
31 | def __str__(self):
32 | out = super(OutgoingAckProtocolEntity, self).__str__()
33 | out += "Type: %s\n" % self._type
34 | out += "To: %s\n" % self._to
35 | if self._participant:
36 | out += "Participant: %s\n" % self._participant
37 | return out
38 |
39 | @staticmethod
40 | def fromProtocolTreeNode(node):
41 | entity = AckProtocolEntity.fromProtocolTreeNode(node)
42 | entity.__class__ = OutgoingAckProtocolEntity
43 | entity.setOutgoingData(
44 | node.getAttributeValue("type"),
45 | node.getAttributeValue("to"),
46 | node.getAttributeValue("participant")
47 | )
48 | return entity
49 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_media/protocolentities/message_media_downloadable_sticker.py:
--------------------------------------------------------------------------------
1 | from .message_media_downloadable import DownloadableMediaMessageProtocolEntity
2 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_sticker import StickerAttributes
3 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message_meta import MessageMetaAttributes
4 | from yowsup.layers.protocol_messages.protocolentities.attributes.attributes_message import MessageAttributes
5 |
6 |
7 | class StickerDownloadableMediaMessageProtocolEntity(DownloadableMediaMessageProtocolEntity):
8 | def __init__(self, sticker_attrs, message_meta_attrs):
9 | # type: (StickerAttributes, MessageMetaAttributes) -> None
10 | super(StickerDownloadableMediaMessageProtocolEntity, self).__init__(
11 | "sticker", MessageAttributes(sticker=sticker_attrs), message_meta_attrs
12 | )
13 |
14 | @property
15 | def media_specific_attributes(self):
16 | return self.message_attributes.sticker
17 |
18 | @property
19 | def downloadablemedia_specific_attributes(self):
20 | return self.message_attributes.sticker.downloadablemedia_attributes
21 |
22 | @property
23 | def width(self):
24 | return self.media_specific_attributes.width
25 |
26 | @width.setter
27 | def width(self, value):
28 | self.media_specific_attributes.width = value
29 |
30 | @property
31 | def height(self):
32 | return self.media_specific_attributes.height
33 |
34 | @height.setter
35 | def height(self, value):
36 | self.media_specific_attributes.height = value
37 |
38 | @property
39 | def png_thumbnail(self):
40 | return self.media_specific_attributes.png_thumbnail
41 |
42 | @png_thumbnail.setter
43 | def png_thumbnail(self, value):
44 | self.media_specific_attributes.png_thumbnail = value
45 |
--------------------------------------------------------------------------------
/yowsup/layers/network/dispatcher/dispatcher_asyncore.py:
--------------------------------------------------------------------------------
1 | from yowsup.layers.network.dispatcher.dispatcher import YowConnectionDispatcher
2 | import asyncore
3 | import logging
4 | import socket
5 | import traceback
6 |
7 | logger = logging.getLogger(__name__)
8 |
9 |
10 | class AsyncoreConnectionDispatcher(YowConnectionDispatcher, asyncore.dispatcher_with_send):
11 | def __init__(self, connectionCallbacks):
12 | super(AsyncoreConnectionDispatcher, self).__init__(connectionCallbacks)
13 | asyncore.dispatcher_with_send.__init__(self)
14 | self._connected = False
15 |
16 | def sendData(self, data):
17 | if self._connected:
18 | self.out_buffer = self.out_buffer + data
19 | self.initiate_send()
20 | else:
21 | logger.warn("Attempted to send %d bytes while still not connected" % len(data))
22 |
23 | def connect(self, host):
24 | logger.debug("connect(%s)" % str(host))
25 | self.connectionCallbacks.onConnecting()
26 | self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
27 | asyncore.dispatcher_with_send.connect(self, host)
28 | asyncore.loop(timeout=1)
29 |
30 | def handle_connect(self):
31 | logger.debug("handle_connect")
32 | if not self._connected:
33 | self._connected = True
34 | self.connectionCallbacks.onConnected()
35 |
36 | def handle_close(self):
37 | logger.debug("handle_close")
38 | self.close()
39 | self._connected = False
40 | self.connectionCallbacks.onDisconnected()
41 |
42 | def handle_error(self):
43 | logger.error(traceback.format_exc())
44 | self.handle_close()
45 |
46 | def handle_read(self):
47 | data = self.recv(1024)
48 | self.connectionCallbacks.onRecvData(data)
49 |
50 | def disconnect(self):
51 | logger.debug("disconnect")
52 | self.handle_close()
53 |
--------------------------------------------------------------------------------
/yowsup/layers/protocol_groups/protocolentities/iq_groups_leave.py:
--------------------------------------------------------------------------------
1 | from yowsup.common import YowConstants
2 | from yowsup.structs import ProtocolEntity, ProtocolTreeNode
3 | from .iq_groups import GroupsIqProtocolEntity
4 | class LeaveGroupsIqProtocolEntity(GroupsIqProtocolEntity):
5 | '''
6 |
7 |
8 |
9 |
10 |
11 |
12 | '''
13 |
14 | def __init__(self, groupList):
15 | super(LeaveGroupsIqProtocolEntity, self).__init__(to = YowConstants.WHATSAPP_GROUP_SERVER, _type = "set")
16 | self.setProps(groupList if type(groupList) is list else [groupList])
17 |
18 | def setProps(self, groupList):
19 | assert type(groupList) is list and len(groupList), "Must specify a list of group jids to leave"
20 | self.groupList = groupList
21 |
22 | def toProtocolTreeNode(self):
23 | node = super(LeaveGroupsIqProtocolEntity, self).toProtocolTreeNode()
24 | groupNodes = [
25 | ProtocolTreeNode("group", {
26 | "id": groupid
27 | })
28 | for groupid in self.groupList
29 | ]
30 | node.addChild(ProtocolTreeNode("leave", {"action": "delete"}, groupNodes))
31 | return node
32 |
33 | @staticmethod
34 | def fromProtocolTreeNode(node):
35 | assert node.getChild("leave") is not None, "Not a group leave iq node %s" % node
36 | assert node.getChild("leave").getAttributeValue("action") == "delete", "Not a group leave action %s" % node
37 | entity = super(LeaveGroupsIqProtocolEntity, LeaveGroupsIqProtocolEntity).fromProtocolTreeNode(node)
38 | entity.__class__ = LeaveGroupsIqProtocolEntity
39 | entity.setProps([group.getAttributeValue("id") for group in node.getChild("leave").getAllChildren()] )
40 | return entity
41 |
--------------------------------------------------------------------------------