Skip to content
Snippets Groups Projects
Commit c1dff293 authored by Holger's avatar Holger
Browse files

Add d.tube format to resolve_authorperm,

disable_chain_detection added to graphenerpc (for testing hivemind e.g.)
parent d3c86505
No related branches found
No related tags found
No related merge requests found
......@@ -133,10 +133,31 @@ def resolve_authorperm(identifier):
Splits the string into author and permlink with the
following separator: ``/``.
Examples:
.. code-block:: python
>>> from beem.utils import resolve_authorperm
>>> print(resolve_authorperm('https://d.tube/#!/v/pottlund/m5cqkd1a'))
('pottlund', 'm5cqkd1a')
>>> print(resolve_authorperm("https://steemit.com/witness-category/@gtg/24lfrm-gtg-witness-log"))
('gtg', '24lfrm-gtg-witness-log')
>>> print(resolve_authorperm("@gtg/24lfrm-gtg-witness-log"))
('gtg', '24lfrm-gtg-witness-log')
>>> print(resolve_authorperm("https://busy.org/@gtg/24lfrm-gtg-witness-log"))
('gtg', '24lfrm-gtg-witness-log')
"""
# without any http(s)
match = re.match("@?([\w\-\.]*)/([\w\-]*)", identifier)
if hasattr(match, "group"):
return match.group(1), match.group(2)
# dtube url
match = re.match("([\w\-\.]+[^#?\s]+)/#!/v/?([\w\-\.]*)/([\w\-]*)", identifier)
if hasattr(match, "group"):
return match.group(2), match.group(3)
# url
match = re.match("([\w\-\.]+[^#?\s]+)/@?([\w\-\.]*)/([\w\-]*)", identifier)
if not hasattr(match, "group"):
raise ValueError("Invalid identifier")
......
......@@ -133,6 +133,7 @@ class GrapheneRPC(object):
num_retries = kwargs.get("num_retries", -1)
num_retries_call = kwargs.get("num_retries_call", 5)
self.use_condenser = kwargs.get("use_condenser", False)
self.disable_chain_detection = kwargs.get("disable_chain_detection", False)
self.known_chains = known_chains
custom_chain = kwargs.get("custom_chains", {})
if len(custom_chain) > 0:
......@@ -218,6 +219,13 @@ class GrapheneRPC(object):
if self.ws:
self.ws.connect(self.url)
self.rpclogin(self.user, self.password)
if self.disable_chain_detection:
# Set to appbase rpc format
if self.current_rpc == self.rpc_methods['ws']:
self.current_rpc = self.rpc_methods['wsappbase']
else:
self.current_rpc = self.rpc_methods['appbase']
break
try:
props = None
if not self.use_condenser:
......
......@@ -75,7 +75,7 @@ def get_api_name(appbase, *args, **kwargs):
else:
# Sepcify the api to talk to
if ("api" in kwargs) and len(kwargs["api"]) > 0:
if kwargs["api"] != "jsonrpc":
if kwargs["api"] not in ["jsonrpc", "hive"]:
api_name = kwargs["api"].replace("_api", "") + "_api"
else:
api_name = kwargs["api"]
......
......@@ -40,12 +40,16 @@ class Testcases(unittest.TestCase):
self.assertEqual(assets_from_string('BTSBOTS.S1:BTS'), ['BTSBOTS.S1', 'BTS'])
def test_authorperm_resolve(self):
self.assertEqual(resolve_authorperm('theaussiegame/cryptokittie-giveaway-number-2'),
('theaussiegame', 'cryptokittie-giveaway-number-2'))
self.assertEqual(resolve_authorperm('holger80/virtuelle-cloud-mining-ponzi-schemen-auch-bekannt-als-hypt'),
('holger80', 'virtuelle-cloud-mining-ponzi-schemen-auch-bekannt-als-hypt'))
self.assertEqual(resolve_authorperm('https://steemit.com/deutsch/holger80/virtuelle-cloud-mining-ponzi-schemen-auch-bekannt-als-hypt'),
('holger80', 'virtuelle-cloud-mining-ponzi-schemen-auch-bekannt-als-hypt'))
self.assertEqual(resolve_authorperm('https://d.tube/#!/v/pottlund/m5cqkd1a'),
('pottlund', 'm5cqkd1a'))
self.assertEqual(resolve_authorperm("https://steemit.com/witness-category/@gtg/24lfrm-gtg-witness-log"),
('gtg', '24lfrm-gtg-witness-log'))
self.assertEqual(resolve_authorperm("@gtg/24lfrm-gtg-witness-log"),
('gtg', '24lfrm-gtg-witness-log'))
self.assertEqual(resolve_authorperm("https://busy.org/@gtg/24lfrm-gtg-witness-log"),
('gtg', '24lfrm-gtg-witness-log'))
self.assertEqual(resolve_authorperm('https://dlive.io/livestream/atnazo/61dd94c1-8ff3-11e8-976f-0242ac110003'),
('atnazo', '61dd94c1-8ff3-11e8-976f-0242ac110003'))
def test_authorpermvoter_resolve(self):
self.assertEqual(resolve_authorpermvoter('theaussiegame/cryptokittie-giveaway-number-2|test'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment