Skip to content

Commit

Permalink
Sync changes from python-graphenelib
Browse files Browse the repository at this point in the history
  • Loading branch information
holgern committed Mar 30, 2018
1 parent 1f018ba commit e9f07b4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
28 changes: 28 additions & 0 deletions beemgrapheneapi/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals


class UnauthorizedError(Exception):
"""UnauthorizedError Exception."""

pass


class RPCConnection(Exception):
"""RPCConnection Exception."""

pass


class RPCError(Exception):
"""RPCError Exception."""

pass


class NumRetriesReached(Exception):
"""NumRetriesReached Exception."""

pass
19 changes: 16 additions & 3 deletions beemgrapheneapi/graphenerpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import threading
import time
import warnings
from .exceptions import (
UnauthorizedError, RPCConnection, RPCError, NumRetriesReached
)
from .rpcutils import (
is_network_appbase_ready, sleep_and_check_retries,
get_api_name, get_query, UnauthorizedError,
RPCConnection, RPCError, NumRetriesReached
get_api_name, get_query
)

WEBSOCKET_MODULE = None
Expand Down Expand Up @@ -107,6 +109,16 @@ def get_request_id(self):
self._request_id += 1
return self._request_id

def next(self):
"""Switches to the next node url"""
if self.ws:
try:
self.ws.close()
except Exception as e:
log.warning(str(e))
self.rpcconnect()
self.register_apis()

def is_appbase_ready(self):
"""Check if node is appbase ready"""
return self.current_rpc >= 2
Expand All @@ -124,7 +136,8 @@ def rpcconnect(self, next_url=True):
if self.url[:3] == "wss":
if WEBSOCKET_MODULE is None:
raise Exception()
sslopt_ca_certs = {'cert_reqs': ssl.CERT_NONE}
ssl_defaults = ssl.get_default_verify_paths()
sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile}
self.ws = websocket.WebSocket(sslopt=sslopt_ca_certs, enable_multithread=True)
self.current_rpc = self.rpc_methods["ws"]
elif self.url[:3] == "ws":
Expand Down
28 changes: 3 additions & 25 deletions beemgrapheneapi/rpcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,13 @@
import time
import json
import logging

from .exceptions import (
UnauthorizedError, RPCConnection, RPCError, NumRetriesReached
)

log = logging.getLogger(__name__)


class UnauthorizedError(Exception):
"""UnauthorizedError Exception."""

pass


class RPCConnection(Exception):
"""RPCConnection Exception."""

pass


class RPCError(Exception):
"""RPCError Exception."""

pass


class NumRetriesReached(Exception):
"""NumRetriesReached Exception."""

pass


def is_network_appbase_ready(props):
"""Checks if the network is appbase ready"""
network_version = '0.0.0'
Expand Down

0 comments on commit e9f07b4

Please sign in to comment.