# Path: pyledger/client/repl.py
# def disconnect(*args, protocol=None):
# def contracts(*args, protocol=None):
# def api(*args, protocol=None):
# def broadcast(*args, protocol=None):
# def call(*args, protocol=None):
# def general_parser(line, protocol=None, instruction_dict=None,
#                    user_instruction_dict=None):
# 
# Path: pyledger/client/lib.py
# def handle_response(bin_response, callback=None):
#     response = PyledgerResponse()
#     response.ParseFromString(bin_response)
# 
#     if response.successful:
#         if callback:
#             response_data = pickle.loads(response.data)
#             print('Executing callback...')
#             callback(response_data)
#             return True, response_data
#         else:
#             return True, pickle.loads(response.data)
# 
#     else:
#         return False, response.data.decode('utf-8')


from autobahn.asyncio.websocket import WebSocketClientProtocol, \
    WebSocketClientFactory
from asyncio.streams import StreamWriter, FlowControlMixin
from pyledger.client.repl import parse
from pyledger.client.lib import handle_response
from uuid import uuid4
from pprint import pprint
import os
import sys
import asyncio
                print(message)

            if message == 'Successfully closed, you can kill this with Ctrl-C':
                break

            await asyncio.sleep(0.1)

    def onMessage(self, payload, isBinary):
        topic = payload[:36]
        payload = payload[36:]

        # 36 zero-bytes means broadcast
        if topic in self.topics or topic == 36*b'0':
            if topic != 36*b'0':
                self.topics.remove(topic)
            success, response = handle_response(payload)
            pprint(response)
        else:
            pprint(topic)

    def onClose(self, wasClean, code, reason):
        print("WebSocket connection closed: {}; {}".format(code, reason))


if __name__ == '__main__':
    factory = WebSocketClientFactory('ws://127.0.0.1:9000')
    factory.protocol = MyClientProtocol

    loop = asyncio.get_event_loop()
    coro = loop.create_connection(factory, '127.0.0.1', 9000)

# Path: pyledger/client/repl.py
# def disconnect(*args, protocol=None):
# def contracts(*args, protocol=None):
# def api(*args, protocol=None):
# def broadcast(*args, protocol=None):
# def call(*args, protocol=None):
# def general_parser(line, protocol=None, instruction_dict=None,
#                    user_instruction_dict=None):
# 
# Path: pyledger/client/lib.py
# def handle_response(bin_response, callback=None):
#     response = PyledgerResponse()
#     response.ParseFromString(bin_response)
# 
#     if response.successful:
#         if callback:
#             response_data = pickle.loads(response.data)
#             print('Executing callback...')
#             callback(response_data)
#             return True, response_data
#         else:
#             return True, pickle.loads(response.data)
# 
#     else:
#         return False, response.data.decode('utf-8')


# Path: pyledger/client/ws.py
from autobahn.asyncio.websocket import WebSocketClientProtocol, \
    WebSocketClientFactory
from asyncio.streams import StreamWriter, FlowControlMixin
from pyledger.client.repl import parse
from pyledger.client.lib import handle_response
from uuid import uuid4
from pprint import pprint
import os
import sys
import asyncio

                print(message)

            if message == 'Successfully closed, you can kill this with Ctrl-C':
                break

            await asyncio.sleep(0.1)

    def onMessage(self, payload, isBinary):
        topic = payload[:36]
        payload = payload[36:]

        # 36 zero-bytes means broadcast
        if topic in self.topics or topic == 36*b'0':
            if topic != 36*b'0':
                self.topics.remove(topic)
            success, response = handle_response(payload)
            pprint(response)
        else:
            pprint(topic)

    def onClose(self, wasClean, code, reason):
        print("WebSocket connection closed: {}; {}".format(code, reason))


if __name__ == '__main__':
    factory = WebSocketClientFactory('ws://127.0.0.1:9000')
    factory.protocol = MyClientProtocol

    loop = asyncio.get_event_loop()
    coro = loop.create_connection(factory, '127.0.0.1', 9000)

    loop.run_until_complete(coro)