Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh harchandani <lovesh.bond@gmail.com>
  • Loading branch information
lovesh committed Apr 26, 2019
1 parent d547b1e commit dd5cd77
Show file tree
Hide file tree
Showing 44 changed files with 207 additions and 158 deletions.
5 changes: 5 additions & 0 deletions .pytest_cache/v/cache/lastfailed
@@ -0,0 +1,5 @@
{
"basicmessage.manual": true,
"connection.manual": true,
"trustping.manual": true
}
1 change: 1 addition & 0 deletions .pytest_cache/v/cache/nodeids
@@ -0,0 +1 @@
[]
Empty file added python/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions python/agent.py
Expand Up @@ -10,10 +10,10 @@
import aiohttp
from indy import wallet, did, error, crypto, pairwise

import indy_sdk_utils as utils
from message import Message
from router.family_router import FamilyRouter
from serializer import json_serializer as Serializer
import python.indy_sdk_utils as utils
from python.serializer import json_serializer as Serializer
from python.message import Message
from python.router.family_router import FamilyRouter


class WalletConnectionException(Exception):
Expand Down
19 changes: 10 additions & 9 deletions python/indy-agent.py
Expand Up @@ -14,15 +14,16 @@
import aiohttp_jinja2
from aiohttp import web

from modules.connection import Connection, AdminConnection
from modules.admin import Admin, root
from modules.admin_walletconnection import AdminWalletConnection
from modules.basicmessage import AdminBasicMessage, BasicMessage
from modules.trustping import AdminTrustPing, TrustPing
from post_message_handler import PostMessageHandler
from websocket_message_handler import WebSocketMessageHandler
from agent import Agent
from message import Message
from python.modules.connection import Connection, AdminConnection
from python.modules.admin import Admin, root
from python.modules.admin_walletconnection import AdminWalletConnection
from python.modules.basicmessage import AdminBasicMessage, BasicMessage
from python.modules.trustping import AdminTrustPing, TrustPing
from python.post_message_handler import PostMessageHandler
from python.websocket_message_handler import WebSocketMessageHandler
from python.agent import Agent
from python.message import Message


if __name__ == "__main__":

Expand Down
4 changes: 3 additions & 1 deletion python/indy_sdk_utils.py
Expand Up @@ -3,6 +3,7 @@
import json
from indy import did, crypto, non_secrets, error


async def create_and_store_my_did(wallet_handle):
""" Create and store my DID, adding a map from verkey to DID using the
non_secrets API.
Expand All @@ -17,7 +18,8 @@ async def create_and_store_my_did(wallet_handle):
'{}'
)

return (my_did, my_vk)
return my_did, my_vk


async def store_their_did(wallet_handle, their_did, their_vk):
""" Store their did, adding a map from verkey to DID using the non_secrets
Expand Down
1 change: 0 additions & 1 deletion python/message.py
Expand Up @@ -25,7 +25,6 @@ def __init__(self, *args, **kwargs):
if '@id' not in self.data:
self.data['@id'] = str(uuid.uuid4())


def to_dict(self):
return self.data

Expand Down
2 changes: 1 addition & 1 deletion python/modules/__init__.py
@@ -1,2 +1,2 @@
class Module():
class Module:
pass
9 changes: 5 additions & 4 deletions python/modules/admin.py
Expand Up @@ -3,13 +3,14 @@
import json
import socket
from indy import did, wallet, non_secrets, pairwise
from indy_sdk_utils import get_wallet_records
from python.indy_sdk_utils import get_wallet_records

from router.simple_router import SimpleRouter
from agent import Agent
from message import Message
from python.router.simple_router import SimpleRouter
from python.agent import Agent
from python.message import Message
from . import Module


class Admin(Module):
FAMILY_NAME = "admin"
VERSION = "1.0"
Expand Down
10 changes: 5 additions & 5 deletions python/modules/admin_walletconnection.py
Expand Up @@ -3,12 +3,13 @@
import json
from indy import did, wallet

from router.simple_router import SimpleRouter
from agent import Agent, WalletConnectionException
from modules.admin import Admin
from message import Message
from python.router.simple_router import SimpleRouter
from python.agent import Agent, WalletConnectionException
from python.modules.admin import Admin
from python.message import Message
from . import Module


class AdminWalletConnection(Module):
FAMILY_NAME = "admin_walletconnection"
VERSION = "1.0"
Expand All @@ -18,7 +19,6 @@ class AdminWalletConnection(Module):
DISCONNECT = FAMILY + "disconnect"
USER_ERROR = FAMILY + "user_error"


def __init__(self, agent):
self.agent = agent
self.router = SimpleRouter()
Expand Down
11 changes: 6 additions & 5 deletions python/modules/basicmessage.py
Expand Up @@ -8,13 +8,14 @@
import uuid
from indy import did, wallet, pairwise, crypto, non_secrets

from helpers import str_to_bytes, serialize_bytes_json, bytes_to_str
from router.simple_router import SimpleRouter
import serializer.json_serializer as Serializer
from agent import Agent, WalletConnectionException
from message import Message
from python.helpers import str_to_bytes, serialize_bytes_json, bytes_to_str
from python.router.simple_router import SimpleRouter
import python.serializer.json_serializer as Serializer
from python.agent import Agent, WalletConnectionException
from python.message import Message
from . import Module


class AdminBasicMessage(Module):
FAMILY_NAME = "admin_basicmessage"
VERSION = "1.0"
Expand Down
17 changes: 8 additions & 9 deletions python/modules/connection.py
Expand Up @@ -12,17 +12,19 @@
import aiohttp
from indy import crypto, did, pairwise, non_secrets, error

import indy_sdk_utils as utils
import serializer.json_serializer as Serializer
from router.simple_router import SimpleRouter
import python.indy_sdk_utils as utils
import python.serializer.json_serializer as Serializer
from python.router.simple_router import SimpleRouter
from . import Module
from message import Message
from helpers import serialize_bytes_json, bytes_to_str, str_to_bytes
from python.message import Message
from python.helpers import serialize_bytes_json, bytes_to_str, str_to_bytes


class BadInviteException(Exception):
def __init__(self, msg):
super().__init__(msg)


class AdminConnection(Module):
FAMILY_NAME = "admin_connections"
VERSION = "1.0"
Expand Down Expand Up @@ -352,6 +354,7 @@ async def send_response(self, msg: Message) -> Message:
'invitations',
pairwise_meta['connection_key'])


class Connection(Module):

FAMILY_NAME = "connections"
Expand All @@ -362,7 +365,6 @@ class Connection(Module):
REQUEST = FAMILY + "request"
RESPONSE = FAMILY + "response"


def __init__(self, agent):
self.agent = agent
self.router = SimpleRouter()
Expand Down Expand Up @@ -466,9 +468,6 @@ async def request_received(self, msg: Message) -> Message:
raise indy_error
await self.agent.send_admin_message(pending_connection)




async def response_received(self, msg: Message) -> Message:
""" Process response
Expand Down
11 changes: 6 additions & 5 deletions python/modules/trustping.py
Expand Up @@ -7,13 +7,14 @@
import uuid
from indy import did, wallet, pairwise, crypto, non_secrets

from helpers import str_to_bytes, serialize_bytes_json, bytes_to_str
from router.simple_router import SimpleRouter
import serializer.json_serializer as Serializer
from agent import Agent, WalletConnectionException
from message import Message
from python.helpers import str_to_bytes, serialize_bytes_json, bytes_to_str
from python.router.simple_router import SimpleRouter
import python.serializer.json_serializer as Serializer
from python.agent import Agent, WalletConnectionException
from python.message import Message
from . import Module


class AdminTrustPing(Module):
FAMILY_NAME = "admin_trustping"
VERSION = "1.0"
Expand Down
1 change: 1 addition & 0 deletions python/post_message_handler.py
Expand Up @@ -4,6 +4,7 @@
from aiohttp import web
import asyncio


class PostMessageHandler():
""" Simple message queue interface for receiving messages.
"""
Expand Down
6 changes: 4 additions & 2 deletions python/router/__init__.py
Expand Up @@ -3,9 +3,10 @@
"""

from typing import Callable
from message import Message
from ..message import Message

class BaseRouter(object):

class BaseRouter:
""" Router Base Class. Provide basic interface for additional routers.
"""

Expand All @@ -27,5 +28,6 @@ class RouteAlreadyRegisteredException(Exception):
"""
pass


class UnparsableMessageFamilyException(Exception):
pass
10 changes: 5 additions & 5 deletions python/router/family_router.py
Expand Up @@ -2,10 +2,10 @@
"""

import re
from typing import Callable
from modules import Module
from message import Message
from . import BaseRouter, RouteAlreadyRegisteredException
from python.modules import Module
from python.message import Message
from . import BaseRouter, RouteAlreadyRegisteredException, UnparsableMessageFamilyException


class FamilyRouter(BaseRouter):
""" Simple router for handling Indy Messages.
Expand Down Expand Up @@ -35,7 +35,7 @@ async def route(self, msg: Message):

@staticmethod
def family_from_type(msg_type: str) -> str:
matches = re.match("(.+/.+/\d.\d/).+", msg_type)
matches = re.match("(.+/.+/\d+.\d+/).+", msg_type)
if not matches:
raise UnparsableMessageFamilyException()

Expand Down
3 changes: 2 additions & 1 deletion python/router/simple_router.py
Expand Up @@ -2,9 +2,10 @@
"""

from typing import Callable
from message import Message
from python.message import Message
from . import BaseRouter, RouteAlreadyRegisteredException


class SimpleRouter(BaseRouter):
""" Simple router for handling Sovrin Messages.
Expand Down
4 changes: 3 additions & 1 deletion python/serializer/__init__.py
Expand Up @@ -7,7 +7,8 @@
of serialization to another.
"""

from message import Message
from python.message import Message


def unpack(msg: bytes) -> Message: #pylint: disable=unused-argument
""" Deserialize to Message.
Expand All @@ -17,6 +18,7 @@ def unpack(msg: bytes) -> Message: #pylint: disable=unused-argument
is not implemented. Use the methods contained in a submodule of \
serializer, such as json_serializer.")


def pack(msg: Message) -> bytes: #pylint: disable=unused-argument
""" Serialize to bytes.
"""
Expand Down
2 changes: 1 addition & 1 deletion python/serializer/json_serializer.py
Expand Up @@ -4,7 +4,7 @@

import json

from message import Message
from python.message import Message


def unpack_dict(dictionary: dict) -> Message:
Expand Down
3 changes: 2 additions & 1 deletion python/websocket_message_handler.py
Expand Up @@ -2,7 +2,8 @@
import aiohttp
from aiohttp import web

class WebSocketMessageHandler(object):

class WebSocketMessageHandler:
def __init__(self, inbound_queue, outbound_queue):
self.recv_q = inbound_queue
self.send_q = outbound_queue
Expand Down
1 change: 1 addition & 0 deletions test-suite/.gitignore → test_suite/.gitignore
@@ -1,3 +1,4 @@
env
__pycache__
.pytest_cache
tests/*/.testing-wallets/
File renamed without changes.
Empty file added test_suite/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion test-suite/config.py → test_suite/config.py
Expand Up @@ -8,13 +8,14 @@
import os
import sys


class InvalidConfigurationException(Exception):
""" Exception raise on absent required configuration value
"""
pass


class Config():
class Config:
""" Configuration class used to store and update configuration information.
"""

Expand Down
File renamed without changes.

0 comments on commit dd5cd77

Please sign in to comment.