move IPPort to rpc.py
This commit is contained in:
parent
8d957a15dd
commit
16d7e73fe1
3 changed files with 28 additions and 28 deletions
27
mmgen/obj.py
27
mmgen/obj.py
|
|
@ -514,33 +514,6 @@ class MMGenPWIDString(MMGenLabel):
|
|||
forbidden = list(' :/\\')
|
||||
trunc_ok = False
|
||||
|
||||
class IPPort(str,Hilite,InitErrors,MMGenObject):
|
||||
color = 'yellow'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
min_len = 9 # 0.0.0.0:0
|
||||
max_len = 21 # 255.255.255.255:65535
|
||||
def __new__(cls,s):
|
||||
if type(s) == cls:
|
||||
return s
|
||||
try:
|
||||
m = re.fullmatch(r'{q}\.{q}\.{q}\.{q}:(\d{{1,10}})'.format(q=r'([0-9]{1,3})'),s)
|
||||
assert m is not None, f'{s!r}: invalid IP:HOST specifier'
|
||||
for e in m.groups():
|
||||
if len(e) != 1 and e[0] == '0':
|
||||
raise ValueError(f'{e}: leading zeroes not permitted in dotted decimal element or port number')
|
||||
res = [int(e) for e in m.groups()]
|
||||
for e in res[:4]:
|
||||
assert e <= 255, f'{e}: dotted decimal element > 255'
|
||||
assert res[4] <= 65535, f'{res[4]}: port number > 65535'
|
||||
me = str.__new__(cls,s)
|
||||
me.ip = '{}.{}.{}.{}'.format(*res)
|
||||
me.ip_num = sum( res[i] * ( 2 ** (-(i-3)*8) ) for i in range(4) )
|
||||
me.port = res[4]
|
||||
return me
|
||||
except Exception as e:
|
||||
return cls.init_fail(e,s)
|
||||
|
||||
from collections import namedtuple
|
||||
ati = namedtuple('addrtype_info',
|
||||
['name','pubkey_type','compressed','gen_method','addr_fmt','wif_label','extra_attrs','desc'])
|
||||
|
|
|
|||
28
mmgen/rpc.py
28
mmgen/rpc.py
|
|
@ -57,6 +57,33 @@ def dmsg_rpc(fs,data=None,is_json=False):
|
|||
fs.format(pp_fmt(json.loads(data) if is_json else data))
|
||||
)
|
||||
|
||||
class IPPort(str,Hilite,InitErrors):
|
||||
color = 'yellow'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
min_len = 9 # 0.0.0.0:0
|
||||
max_len = 21 # 255.255.255.255:65535
|
||||
def __new__(cls,s):
|
||||
if type(s) == cls:
|
||||
return s
|
||||
try:
|
||||
m = re.fullmatch(r'{q}\.{q}\.{q}\.{q}:(\d{{1,10}})'.format(q=r'([0-9]{1,3})'),s)
|
||||
assert m is not None, f'{s!r}: invalid IP:HOST specifier'
|
||||
for e in m.groups():
|
||||
if len(e) != 1 and e[0] == '0':
|
||||
raise ValueError(f'{e}: leading zeroes not permitted in dotted decimal element or port number')
|
||||
res = [int(e) for e in m.groups()]
|
||||
for e in res[:4]:
|
||||
assert e <= 255, f'{e}: dotted decimal element > 255'
|
||||
assert res[4] <= 65535, f'{res[4]}: port number > 65535'
|
||||
me = str.__new__(cls,s)
|
||||
me.ip = '{}.{}.{}.{}'.format(*res)
|
||||
me.ip_num = sum( res[i] * ( 2 ** (-(i-3)*8) ) for i in range(4) )
|
||||
me.port = res[4]
|
||||
return me
|
||||
except Exception as e:
|
||||
return cls.init_fail(e,s)
|
||||
|
||||
class json_encoder(json.JSONEncoder):
|
||||
def default(self,obj):
|
||||
if isinstance(obj,Decimal):
|
||||
|
|
@ -691,7 +718,6 @@ class MoneroRPCClient(RPCClient):
|
|||
|
||||
def __init__(self,host,port,user,passwd,test_connection=True,proxy=None,daemon=None):
|
||||
if proxy is not None:
|
||||
from .obj import IPPort
|
||||
self.proxy = IPPort(proxy)
|
||||
test_connection = False
|
||||
if host.endswith('.onion'):
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ from mmgen.addrlist import *
|
|||
from mmgen.addrdata import *
|
||||
from mmgen.amt import *
|
||||
from mmgen.key import *
|
||||
from mmgen.rpc import IPPort
|
||||
|
||||
opts_data = {
|
||||
'sets': [('super_silent', True, 'silent', True)],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue