pylint integration: class Hilite -> Hilite, HiliteStr
This commit is contained in:
parent
0a1e3c3c98
commit
2fa3d97c54
12 changed files with 51 additions and 49 deletions
|
|
@ -22,14 +22,14 @@ addr: MMGen address-related types
|
|||
|
||||
from collections import namedtuple
|
||||
|
||||
from .objmethods import Hilite,InitErrors,MMGenObject
|
||||
from .objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
from .obj import ImmutableAttr,MMGenIdx,get_obj
|
||||
from .seed import SeedID
|
||||
|
||||
ati = namedtuple('addrtype_info',
|
||||
['name','pubkey_type','compressed','gen_method','addr_fmt','wif_label','extra_attrs','desc'])
|
||||
|
||||
class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
|
||||
class MMGenAddrType(HiliteStr,InitErrors,MMGenObject):
|
||||
width = 1
|
||||
trunc_ok = False
|
||||
color = 'blue'
|
||||
|
|
@ -93,7 +93,7 @@ class AddrIdx(MMGenIdx):
|
|||
def is_addr_idx(s):
|
||||
return get_obj( AddrIdx, n=s, silent=True, return_bool=True )
|
||||
|
||||
class AddrListID(str,Hilite,InitErrors,MMGenObject):
|
||||
class AddrListID(HiliteStr,InitErrors,MMGenObject):
|
||||
width = 10
|
||||
trunc_ok = False
|
||||
color = 'yellow'
|
||||
|
|
@ -120,7 +120,7 @@ class AddrListID(str,Hilite,InitErrors,MMGenObject):
|
|||
def is_addrlist_id(proto,s):
|
||||
return get_obj( AddrListID, proto=proto, id_str=s, silent=False, return_bool=True )
|
||||
|
||||
class MMGenID(str,Hilite,InitErrors,MMGenObject):
|
||||
class MMGenID(HiliteStr,InitErrors,MMGenObject):
|
||||
color = 'orange'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
|
|
@ -144,7 +144,7 @@ class MMGenID(str,Hilite,InitErrors,MMGenObject):
|
|||
def is_mmgen_id(proto,s):
|
||||
return get_obj( MMGenID, proto=proto, id_str=s, silent=True, return_bool=True )
|
||||
|
||||
class CoinAddr(str,Hilite,InitErrors,MMGenObject):
|
||||
class CoinAddr(HiliteStr,InitErrors,MMGenObject):
|
||||
color = 'cyan'
|
||||
hex_width = 40
|
||||
width = 1
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ addrlist: Address list classes for the MMGen suite
|
|||
"""
|
||||
|
||||
from .util import suf,make_chksum_N,Msg,die
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,HiliteStr,InitErrors
|
||||
from .obj import MMGenListItem,ListItemAttr,MMGenDict,TwComment,WalletPassword
|
||||
from .key import PrivKey
|
||||
from .addr import MMGenID,MMGenAddrType,CoinAddr,AddrIdx,AddrListID,ViewKey
|
||||
|
|
@ -88,7 +88,7 @@ class AddrListEntry(AddrListEntryBase):
|
|||
viewkey = ListItemAttr(ViewKey,include_proto=True)
|
||||
wallet_passwd = ListItemAttr(WalletPassword)
|
||||
|
||||
class AddrListChksum(str,Hilite):
|
||||
class AddrListChksum(HiliteStr):
|
||||
color = 'pink'
|
||||
trunc_ok = False
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class AddrListChksum(str,Hilite):
|
|||
) for e in addrlist.data]
|
||||
return str.__new__(cls,make_chksum_N(' '.join(lines), nchars=16, sep=True))
|
||||
|
||||
class AddrListIDStr(str,Hilite):
|
||||
class AddrListIDStr(HiliteStr):
|
||||
color = 'green'
|
||||
trunc_ok = False
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
key: MMGen public and private key objects
|
||||
"""
|
||||
|
||||
from .objmethods import Hilite,InitErrors,MMGenObject
|
||||
from .objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
from .obj import ImmutableAttr,get_obj
|
||||
|
||||
class WifKey(str,Hilite,InitErrors):
|
||||
class WifKey(HiliteStr,InitErrors):
|
||||
"""
|
||||
Initialize a WIF key, checking its well-formedness.
|
||||
The numeric validity of the private key it encodes is not checked.
|
||||
|
|
@ -54,7 +54,7 @@ class PubKey(bytes,InitErrors,MMGenObject): # TODO: add some real checks
|
|||
except Exception as e:
|
||||
return cls.init_fail(e,s)
|
||||
|
||||
class PrivKey(bytes,Hilite,InitErrors,MMGenObject):
|
||||
class PrivKey(bytes,InitErrors,MMGenObject):
|
||||
"""
|
||||
Input: a) raw, non-preprocessed bytes; or b) WIF key.
|
||||
Output: preprocessed key bytes, plus WIF key in 'wif' attribute
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ msg: base message signing classes
|
|||
|
||||
import os,importlib,json
|
||||
from .cfg import gc
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,HiliteStr,InitErrors
|
||||
from .util import msg,die,make_chksum_6,fmt_list,remove_dups
|
||||
from .color import red,orange,grnbg
|
||||
from .protocol import init_proto
|
||||
from .fileutil import get_data_from_file,write_data_to_file
|
||||
from .addr import MMGenID,CoinAddr
|
||||
|
||||
class MMGenIDRange(str,Hilite,InitErrors,MMGenObject):
|
||||
class MMGenIDRange(HiliteStr,InitErrors,MMGenObject):
|
||||
"""
|
||||
closely based on MMGenID
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ obj: MMGen native classes
|
|||
|
||||
import unicodedata
|
||||
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,Hilite,HiliteStr,InitErrors
|
||||
|
||||
def get_obj(objname,*args,**kwargs):
|
||||
"""
|
||||
|
|
@ -303,10 +303,10 @@ class MMGenIdx(Int):
|
|||
class ETHNonce(Int):
|
||||
min_val = 0
|
||||
|
||||
class Str(str,Hilite):
|
||||
class Str(HiliteStr):
|
||||
pass
|
||||
|
||||
class HexStr(str,Hilite,InitErrors):
|
||||
class HexStr(HiliteStr,InitErrors):
|
||||
color = 'red'
|
||||
width = None
|
||||
hexcase = 'lower'
|
||||
|
|
@ -343,7 +343,7 @@ class WalletPassword(HexStr):
|
|||
class MMGenTxID(HexStr):
|
||||
color,width,hexcase = ('red',6,'upper')
|
||||
|
||||
class MMGenLabel(str,Hilite,InitErrors):
|
||||
class MMGenLabel(HiliteStr,InitErrors):
|
||||
color = 'pink'
|
||||
allowed = []
|
||||
forbidden = []
|
||||
|
|
|
|||
|
|
@ -48,14 +48,6 @@ class Hilite:
|
|||
width = 0
|
||||
trunc_ok = True
|
||||
|
||||
# supports single-width characters only
|
||||
def fmt( self, width, color=False ):
|
||||
if len(self) > width:
|
||||
assert self.trunc_ok, "If 'trunc_ok' is false, 'width' must be >= width of string"
|
||||
return self.colorize( self[:width].ljust(width), color=color )
|
||||
else:
|
||||
return self.colorize( self.ljust(width), color=color )
|
||||
|
||||
# class method equivalent of fmt()
|
||||
@classmethod
|
||||
def fmtc( cls, s, width, color=False ):
|
||||
|
|
@ -65,6 +57,28 @@ class Hilite:
|
|||
else:
|
||||
return cls.colorize( s.ljust(width), color=color )
|
||||
|
||||
@classmethod
|
||||
def hlc(cls,s,color=True):
|
||||
return getattr( color_mod, cls.color )(s) if color else s
|
||||
|
||||
@classmethod
|
||||
def colorize(cls,s,color=True):
|
||||
return getattr( color_mod, cls.color )(s) if color else s
|
||||
|
||||
@classmethod
|
||||
def colorize2(cls,s,color=True,color_override=''):
|
||||
return getattr( color_mod, color_override or cls.color )(s) if color else s
|
||||
|
||||
class HiliteStr(str,Hilite):
|
||||
|
||||
# supports single-width characters only
|
||||
def fmt( self, width, color=False ):
|
||||
if len(self) > width:
|
||||
assert self.trunc_ok, "If 'trunc_ok' is false, 'width' must be >= width of string"
|
||||
return self.colorize( self[:width].ljust(width), color=color )
|
||||
else:
|
||||
return self.colorize( self.ljust(width), color=color )
|
||||
|
||||
# an alternative to fmt(), with double-width char support and other features
|
||||
def fmt2(
|
||||
self,
|
||||
|
|
@ -99,21 +113,9 @@ class Hilite:
|
|||
else:
|
||||
return self.colorize2( s.ljust(width-s_wide_count), color=color, color_override=color_override )
|
||||
|
||||
@classmethod
|
||||
def colorize(cls,s,color=True):
|
||||
return getattr( color_mod, cls.color )(s) if color else s
|
||||
|
||||
@classmethod
|
||||
def colorize2(cls,s,color=True,color_override=''):
|
||||
return getattr( color_mod, color_override or cls.color )(s) if color else s
|
||||
|
||||
def hl(self,color=True):
|
||||
return getattr( color_mod, self.color )(self) if color else self
|
||||
|
||||
@classmethod
|
||||
def hlc(cls,s,color=True):
|
||||
return getattr( color_mod, cls.color )(s) if color else s
|
||||
|
||||
# an alternative to hl(), with enclosure and color override
|
||||
# can be called as an unbound method with class as first argument
|
||||
def hl2(self,s=None,color=True,encl='',color_override=''):
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from collections import namedtuple
|
|||
from .util import msg,die,fmt,fmt_list,pp_fmt,oneshot_warning
|
||||
from .base_obj import AsyncInit
|
||||
from .obj import NonNegativeInt
|
||||
from .objmethods import Hilite,InitErrors,MMGenObject
|
||||
from .objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
|
||||
auth_data = namedtuple('rpc_auth_data',['user','passwd'])
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ def dmsg_rpc_backend(host_url,host_path,payload):
|
|||
def noop(*args,**kwargs):
|
||||
pass
|
||||
|
||||
class IPPort(str,Hilite,InitErrors):
|
||||
class IPPort(HiliteStr,InitErrors):
|
||||
color = 'yellow'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ seed: Seed-related classes and methods for the MMGen suite
|
|||
"""
|
||||
|
||||
from .util import make_chksum_8,hexdigits_uc,die
|
||||
from .objmethods import Hilite,InitErrors,MMGenObject
|
||||
from .objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
from .obj import ImmutableAttr,get_obj
|
||||
|
||||
class SeedID(str,Hilite,InitErrors):
|
||||
class SeedID(HiliteStr,InitErrors):
|
||||
color = 'blue'
|
||||
width = 8
|
||||
trunc_ok = False
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ seedsplit: Seed split classes and methods for the MMGen suite
|
|||
|
||||
from .color import yellow
|
||||
from .util import msg,die
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,HiliteStr,InitErrors
|
||||
from .obj import ImmutableAttr,MMGenPWIDString,MMGenIdx,get_obj,IndexedDict
|
||||
from .seed import Seed,SeedBase
|
||||
from .subseed import SubSeedList,SubSeedIdx,SubSeed
|
||||
|
|
@ -37,7 +37,7 @@ class SeedShareCount(SeedShareIdx):
|
|||
class MasterShareIdx(MMGenIdx):
|
||||
max_val = 1024
|
||||
|
||||
class SeedSplitSpecifier(str,Hilite,InitErrors,MMGenObject):
|
||||
class SeedSplitSpecifier(HiliteStr,InitErrors,MMGenObject):
|
||||
color = 'red'
|
||||
def __new__(cls,s):
|
||||
if isinstance(s,cls):
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ subseed: Subseed classes and methods for the MMGen suite
|
|||
|
||||
from .color import green
|
||||
from .util import msg_r,msg,die,make_chksum_8
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,HiliteStr,InitErrors
|
||||
from .obj import MMGenRange,IndexedDict,ImmutableAttr
|
||||
from .seed import SeedBase,SeedID
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ class SubSeedIdxRange(MMGenRange):
|
|||
min_idx = 1
|
||||
max_idx = 1000000
|
||||
|
||||
class SubSeedIdx(str,Hilite,InitErrors):
|
||||
class SubSeedIdx(HiliteStr,InitErrors):
|
||||
color = 'red'
|
||||
trunc_ok = False
|
||||
def __new__(cls,s):
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
tw.shared: classes and functions shared by all tracking wallet classes
|
||||
"""
|
||||
|
||||
from ..objmethods import Hilite,InitErrors,MMGenObject
|
||||
from ..objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
from ..obj import TwComment
|
||||
from ..addr import MMGenID
|
||||
|
||||
class TwMMGenID(str,Hilite,InitErrors,MMGenObject):
|
||||
class TwMMGenID(HiliteStr,InitErrors,MMGenObject):
|
||||
color = 'orange'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import re,time,json,atexit
|
|||
from collections import namedtuple
|
||||
from pathlib import Path
|
||||
|
||||
from .objmethods import MMGenObject,Hilite,InitErrors
|
||||
from .objmethods import MMGenObject,HiliteStr,InitErrors
|
||||
from .obj import CoinTxID
|
||||
from .color import red,yellow,green,blue,cyan,pink,orange,purple
|
||||
from .util import (
|
||||
|
|
@ -76,7 +76,7 @@ xmrwallet_uarg_info = (
|
|||
r'(?:[^:]+):(?:\d+)'
|
||||
)
|
||||
|
||||
class XMRWalletAddrSpec(str,Hilite,InitErrors,MMGenObject):
|
||||
class XMRWalletAddrSpec(HiliteStr,InitErrors,MMGenObject):
|
||||
color = 'cyan'
|
||||
width = 0
|
||||
trunc_ok = False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue