Example #1
0
File: obj.py Project: mmgen/mmgen
	def __new__(cls,seed=None,sid=None,on_fail='die'):
		if type(sid) == cls: return sid
		cls.arg_chk(on_fail)
		try:
			if seed:
				from mmgen.seed import Seed,SubSeed
				assert type(seed) in (Seed,SubSeed),'not a Seed or SubSeed instance'
				from mmgen.util import make_chksum_8
				return str.__new__(cls,make_chksum_8(seed.data))
			elif sid:
				assert set(sid) <= set(hexdigits.upper()),'not uppercase hex digits'
				assert len(sid) == cls.width,'not {} characters wide'.format(cls.width)
				return str.__new__(cls,sid)
			raise ValueError('no arguments provided')
		except Exception as e:
			return cls.init_fail(e,seed or sid)
Example #2
0
	def __new__(cls,seed=None,sid=None,on_fail='die'):
		if type(sid) == cls: return sid
		cls.arg_chk(cls,on_fail)
		try:
			if seed:
				from mmgen.seed import Seed
				assert type(seed) == Seed,'not a Seed instance'
				from mmgen.util import make_chksum_8
				return str.__new__(cls,make_chksum_8(seed.get_data()))
			elif sid:
				assert set(sid) <= set(hexdigits.upper()),'not uppercase hex digits'
				assert len(sid) == cls.width,'not {} characters wide'.format(cls.width)
				return str.__new__(cls,sid)
			raise ValueError,'no arguments provided'
		except Exception as e:
			m = "{!r}: value cannot be converted to SeedID ({})"
			return cls.init_fail(m.format(seed or sid,e[0]),on_fail)
Example #3
0
 def __new__(cls, seed=None, sid=None, on_fail='die'):
     if type(sid) == cls: return sid
     cls.arg_chk(on_fail)
     try:
         if seed:
             from mmgen.seed import SeedBase
             assert isinstance(seed, SeedBase), 'not a subclass of SeedBase'
             from mmgen.util import make_chksum_8
             return str.__new__(cls, make_chksum_8(seed.data))
         elif sid:
             assert set(sid) <= set(
                 hexdigits.upper()), 'not uppercase hex digits'
             assert len(sid) == cls.width, 'not {} characters wide'.format(
                 cls.width)
             return str.__new__(cls, sid)
         raise ValueError('no arguments provided')
     except Exception as e:
         return cls.init_fail(e, seed or sid)