Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: holgern/beem
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.20.22
Choose a base ref
...
head repository: holgern/beem
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.20.23
Choose a head ref
  • 3 commits
  • 15 files changed
  • 1 contributor

Commits on Jul 31, 2019

  1. Prepare next release

    Switch to next node when ApiNotSupported and node returns Client returned invalid format. Expected JSON!
    * enforce utf-8 on node reply parser
    holgern committed Jul 31, 2019
    Copy the full SHA
    64cdac3 View commit details
  2. Add more fixes and checks

    holgern committed Jul 31, 2019
    Copy the full SHA
    d0357be View commit details
  3. Add disable node function

    holgern committed Jul 31, 2019
    Copy the full SHA
    209bc66 View commit details
Showing with 47 additions and 31 deletions.
  1. +15 −12 beem/account.py
  2. +3 −3 beem/blockchain.py
  3. +1 −1 beem/cli.py
  4. +1 −1 beem/comment.py
  5. +1 −1 beem/nodelist.py
  6. +1 −1 beem/version.py
  7. +1 −1 beem/vote.py
  8. +1 −1 beemapi/graphenerpc.py
  9. +5 −0 beemapi/node.py
  10. +13 −5 beemapi/steemnoderpc.py
  11. +1 −1 beemapi/version.py
  12. +1 −1 beembase/version.py
  13. +1 −1 beemgraphenebase/version.py
  14. +1 −1 setup.py
  15. +1 −1 tests/beem/test_account.py
27 changes: 15 additions & 12 deletions beem/account.py
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ class Account(BlockchainObject):
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("gtg", steem_instance=stm)
>>> print(account)
<Account gtg>
@@ -311,7 +311,7 @@ def print_info(self, force_refresh=False, return_str=False, use_table=False, **k
self.refresh()
self.steem.refresh_data(True)
bandwidth = self.get_bandwidth()
if bandwidth["allocated"] > 0:
if bandwidth is not None and bandwidth["allocated"] is not None and bandwidth["allocated"] > 0:
remaining = 100 - bandwidth["used"] / bandwidth["allocated"] * 100
used_kb = bandwidth["used"] / 1024
allocated_mb = bandwidth["allocated"] / 1024 / 1024
@@ -334,7 +334,7 @@ def print_info(self, force_refresh=False, return_str=False, use_table=False, **k
t.add_row(["Full in ", "%s" % (self.get_recharge_time_str())])
t.add_row(["Steem Power", "%.2f %s" % (self.get_steem_power(), self.steem.steem_symbol)])
t.add_row(["Balance", "%s, %s" % (str(self.balances["available"][0]), str(self.balances["available"][1]))])
if False and bandwidth["allocated"] > 0:
if False and bandwidth is not None and bandwidth["allocated"] is not None and bandwidth["allocated"] > 0:
t.add_row(["Remaining Bandwidth", "%.2f %%" % (remaining)])
t.add_row(["used/allocated Bandwidth", "(%.0f kb of %.0f mb)" % (used_kb, allocated_mb)])
if rc_mana is not None:
@@ -610,7 +610,7 @@ def get_feed(self, start_entry_id=0, limit=100, raw_data=False, short_entries=Fa
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("steemit", steem_instance=stm)
>>> account.get_feed(0, 1, raw_data=True)
[]
@@ -666,7 +666,7 @@ def get_feed_entries(self, start_entry_id=0, limit=100, raw_data=True,
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("steemit", steem_instance=stm)
>>> account.get_feed_entries(0, 1)
[]
@@ -689,7 +689,7 @@ def get_blog_entries(self, start_entry_id=0, limit=100, raw_data=True,
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("steemit", steem_instance=stm)
>>> entry = account.get_blog_entries(0, 1, raw_data=True)[0]
>>> print("%s - %s - %s - %s" % (entry["author"], entry["permlink"], entry["blog"], entry["reblog_on"]))
@@ -713,7 +713,7 @@ def get_blog(self, start_entry_id=0, limit=100, raw_data=False, short_entries=Fa
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("steemit", steem_instance=stm)
>>> account.get_blog(0, 1)
[<Comment @steemit/firstpost>]
@@ -773,7 +773,7 @@ def get_blog_authors(self, account=None):
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("steemit", steem_instance=stm)
>>> account.get_blog_authors()
[]
@@ -868,9 +868,9 @@ def _get_followers(self, direction="follower", last_user="", what="blog", limit=
followers = self.steem.rpc.get_following(self.name, last_user, what, limit, api='follow')
if cnt == 0:
followers_list = followers
elif len(followers) > 1:
elif followers is not None and len(followers) > 1:
followers_list += followers[1:]
if len(followers) >= limit:
if followers is not None and len(followers) >= limit:
last_user = followers[-1][direction]
limit_reached = True
cnt += 1
@@ -1082,6 +1082,9 @@ def get_bandwidth(self):
else:
received_vesting_shares = 0
vesting_shares = self["vesting_shares"].amount
if reserve_ratio is None or reserve_ratio["max_virtual_bandwidth"] is None:
return {"used": None,
"allocated": None}
max_virtual_bandwidth = float(reserve_ratio["max_virtual_bandwidth"])
total_vesting_shares = Amount(global_properties["total_vesting_shares"], steem_instance=self.steem).amount
allocated_bandwidth = (max_virtual_bandwidth * (vesting_shares + received_vesting_shares) / total_vesting_shares)
@@ -1352,7 +1355,7 @@ def get_tags_used_by_author(self, account=None):
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("beem.app", steem_instance=stm)
>>> account.get_tags_used_by_author()
[]
@@ -1410,7 +1413,7 @@ def get_account_votes(self, account=None):
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> account = Account("beem.app", steem_instance=stm)
>>> account.get_account_votes()
[]
6 changes: 3 additions & 3 deletions beem/blockchain.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
import logging
from datetime import datetime, timedelta
from .utils import formatTimeString, addTzInfo
from .block import Block
from .block import Block, BlockHeader
from beemapi.node import Nodes
from beemapi.steemnoderpc import SteemNodeRPC
from .exceptions import BatchedCallsNotSupported, BlockDoesNotExistsException, BlockWaitTimeExceeded, OfflineHasNoRPCException
@@ -325,7 +325,7 @@ def get_estimated_block_num(self, date, estimateForwards=False, accurate=True):
date = addTzInfo(date)
if estimateForwards:
block_offset = 10
first_block = Block(block_offset, steem_instance=self.steem)
first_block = BlockHeader(block_offset, steem_instance=self.steem)
time_diff = date - first_block.time()
block_number = math.floor(time_diff.total_seconds() / self.block_interval + block_offset)
else:
@@ -343,7 +343,7 @@ def get_estimated_block_num(self, date, estimateForwards=False, accurate=True):
second_last_block_time_diff_seconds = 10

while block_time_diff.total_seconds() > self.block_interval or block_time_diff.total_seconds() < -self.block_interval:
block = Block(block_number, steem_instance=self.steem)
block = BlockHeader(block_number, steem_instance=self.steem)
second_last_block_time_diff_seconds = last_block_time_diff_seconds
last_block_time_diff_seconds = block_time_diff.total_seconds()
block_time_diff = date - block.time()
2 changes: 1 addition & 1 deletion beem/cli.py
Original file line number Diff line number Diff line change
@@ -431,7 +431,7 @@ def updatenodes(show, test, only_https, only_wss, only_appbase, only_non_appbase
t.align = "l"
nodelist = NodeList()
nodelist.update_nodes(steem_instance=stm)
nodes = nodelist.get_nodes(normal=not only_appbase, appbase=not only_non_appbase, wss=not only_https, https=not only_wss)
nodes = nodelist.get_nodes(exclude_limited=False, normal=not only_appbase, appbase=not only_non_appbase, wss=not only_https, https=not only_wss)
if show or test:
sorted_nodes = sorted(nodelist, key=lambda node: node["score"], reverse=True)
for node in sorted_nodes:
2 changes: 1 addition & 1 deletion beem/comment.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ class Comment(BlockchainObject):
>>> from beem.comment import Comment
>>> from beem.account import Account
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> acc = Account("gtg", steem_instance=stm)
>>> authorperm = acc.get_blog(limit=1)[0]["authorperm"]
>>> c = Comment(authorperm)
2 changes: 1 addition & 1 deletion beem/nodelist.py
Original file line number Diff line number Diff line change
@@ -375,7 +375,7 @@ def update_nodes(self, weights=None, steem_instance=None):
new_nodes.append(new_node)
super(NodeList, self).__init__(new_nodes)

def get_nodes(self, exclude_limited=True, dev=False, testnet=False, testnetdev=False, wss=True, https=True, not_working=False, normal=True, appbase=True):
def get_nodes(self, exclude_limited=False, dev=False, testnet=False, testnetdev=False, wss=True, https=True, not_working=False, normal=True, appbase=True):
""" Returns nodes as list
:param bool exclude_limited: When True, limited nodes are excluded
2 changes: 1 addition & 1 deletion beem/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.20.22'
version = '0.20.23'
2 changes: 1 addition & 1 deletion beem/vote.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ class Vote(BlockchainObject):
>>> from beem.vote import Vote
>>> from beem import Steem
>>> stm = Steem("https://steemd.minnowsupportproject.org")
>>> stm = Steem()
>>> v = Vote("@gtg/steem-pressure-4-need-for-speed|gandalf", steem_instance=stm)
"""
2 changes: 1 addition & 1 deletion beemapi/graphenerpc.py
Original file line number Diff line number Diff line change
@@ -414,7 +414,7 @@ def rpcexec(self, payload):

ret = {}
try:
ret = json.loads(reply, strict=False)
ret = json.loads(reply, strict=False, encoding="utf-8")
except ValueError:
self._check_for_server_error(reply)

5 changes: 5 additions & 0 deletions beemapi/node.py
Original file line number Diff line number Diff line change
@@ -120,6 +120,11 @@ def error_cnt_call(self):
def num_retries_call_reached(self):
return self.error_cnt_call >= self.num_retries_call

def disable_node(self):
"""Disable current node"""
if self.node is not None and self.num_retries_call >= 0:
self.node.error_cnt_call = self.num_retries_call

def increase_error_cnt(self):
"""Increase node error count for current node"""
if self.node is not None:
18 changes: 13 additions & 5 deletions beemapi/steemnoderpc.py
Original file line number Diff line number Diff line change
@@ -117,8 +117,12 @@ def _check_error_message(self, e, cnt):
raise exceptions.NoMethodWithName(msg)
elif re.search("Could not find API", msg):
if self._check_api_name(msg):
# self._switch_to_next_node(msg, "ApiNotSupported")
raise exceptions.ApiNotSupported(msg)
if self.nodes.working_nodes_count > 1 and self.nodes.num_retries > -1:
self.nodes.disable_node()
self._switch_to_next_node(msg, "ApiNotSupported")
doRetry = True
else:
raise exceptions.ApiNotSupported(msg)
else:
raise exceptions.NoApiWithName(msg)
elif re.search("irrelevant signature included", msg):
@@ -146,9 +150,13 @@ def _check_error_message(self, e, cnt):
raise exceptions.UnkownKey(msg)
elif re.search("Assert Exception:v.is_object(): Input data have to treated as object", msg):
raise exceptions.UnhandledRPCError("Use Operation(op, appbase=True) to prevent error: " + msg)
# elif re.search("Client returned invalid format. Expected JSON!", msg):
# self._switch_to_next_node(msg)
# doRetry = True
elif re.search("Client returned invalid format. Expected JSON!", msg):
if self.nodes.working_nodes_count > 1 and self.nodes.num_retries > -1:
self.nodes.disable_node()
self._switch_to_next_node(msg)
doRetry = True
else:
raise exceptions.UnhandledRPCError(msg)
elif msg:
raise exceptions.UnhandledRPCError(msg)
else:
2 changes: 1 addition & 1 deletion beemapi/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.20.22'
version = '0.20.23'
2 changes: 1 addition & 1 deletion beembase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.20.22'
version = '0.20.23'
2 changes: 1 addition & 1 deletion beemgraphenebase/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""THIS FILE IS GENERATED FROM beem SETUP.PY."""
version = '0.20.22'
version = '0.20.23'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
ascii = codecs.lookup('ascii')
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == 'mbcs'))

VERSION = '0.20.22'
VERSION = '0.20.23'

tests_require = ['mock >= 2.0.0', 'pytest', 'pytest-mock', 'parameterized']

2 changes: 1 addition & 1 deletion tests/beem/test_account.py
Original file line number Diff line number Diff line change
@@ -284,7 +284,7 @@ def test_account_props(self):
vv = account.get_voting_value_SBD()
self.assertTrue(vv >= 0)
bw = account.get_bandwidth()
self.assertTrue(bw['used'] <= bw['allocated'])
# self.assertTrue(bw['used'] <= bw['allocated'])
followers = account.get_followers()
self.assertTrue(isinstance(followers, list))
following = account.get_following()