コード例 #1
0
ファイル: repl.py プロジェクト: stkubr/iota_async.lib.py
    def execute(self, api, **arguments):
        # type: (Iota, ...) -> int
        debug_requests = arguments['debug_requests']
        pow_uri = arguments['pow_uri']

        # If ``pow_uri`` is specified, route POW requests to a separate
        # node.
        if pow_uri:
            pow_adapter = resolve_adapter(pow_uri)

            api.adapter = RoutingWrapper(api.adapter)
            api.adapter.add_route('attachToTangle', pow_adapter)
            api.adapter.add_route('interruptAttachingToTangle', pow_adapter)

        # If ``debug_requests`` is specified, log HTTP requests/responses.
        if debug_requests:
            # Inject a logger into the IOTA HTTP adapter.
            basicConfig(level=DEBUG, stream=stderr)

            logger = getLogger(__name__)
            logger.setLevel(DEBUG)

            api.adapter.set_logger(logger)

            # Turn on debugging for the underlying HTTP library.
            http_client.HTTPConnection.debuglevel = 1

        try:
            self._start_repl(api)
        except KeyboardInterrupt:
            pass

        return 0
コード例 #2
0
ファイル: wrappers.py プロジェクト: stkubr/iota_async.lib.py
    def __init__(self, adapter):
        # type: (AdapterSpec) -> None
        super(BaseWrapper, self).__init__()

        if not isinstance(adapter, BaseAdapter):
            adapter = resolve_adapter(adapter)

        self.adapter = adapter  # type: BaseAdapter
コード例 #3
0
    def __init__(self, adapter, testnet=False):
        # type: (AdapterSpec, bool) -> None
        """
        :param adapter:
            URI string or BaseAdapter instance.

        :param testnet:
            Whether to use testnet settings for this instance.
        """
        super(StrictIota, self).__init__()

        if not isinstance(adapter, BaseAdapter):
            adapter = resolve_adapter(adapter)

        self.adapter = adapter  # type: BaseAdapter
        self.testnet = testnet
コード例 #4
0
ファイル: wrappers.py プロジェクト: stkubr/iota_async.lib.py
    def add_route(self, command, adapter):
        # type: (Text, AdapterSpec) -> RoutingWrapper
        """
        Adds a route to the wrapper.

        :param command:
            The name of the command to route (e.g., "attachToTangle").

        :param adapter:
            The adapter object or URI to route requests to.
        """
        if not isinstance(adapter, BaseAdapter):
            try:
                adapter = self.adapter_aliases[adapter]
            except KeyError:
                self.adapter_aliases[adapter] = adapter = resolve_adapter(
                    adapter
                )

        self.routes[command] = adapter

        return self
コード例 #5
0
 def test_unknown_protocol(self):
     """
 The URI references a protocol that has no associated adapter.
 """
     with self.assertRaises(InvalidUri):
         resolve_adapter('foobar://localhost:14265')
コード例 #6
0
 def test_missing_protocol(self):
     """
 The URI does not include a protocol.
 """
     with self.assertRaises(InvalidUri):
         resolve_adapter('localhost:14265')
コード例 #7
0
 def test_https(self):
     """
 Resolving a valid ``https://`` URI.
 """
     adapter = resolve_adapter('https://localhost:14265/')
     self.assertIsInstance(adapter, HttpAdapter)
コード例 #8
0
 def test_adapter_instance(self):
     """
 Resolving an adapter instance.
 """
     adapter = MockAdapter()
     self.assertIs(resolve_adapter(adapter), adapter)