def test_different_string_types(self): """ Test the various types of strings found in the wild get converted to native_str type. """ # get native bytes try: # this is required on python 3 nbytes = native_bytes('HHZ', 'utf8') except TypeError: # this works on py 2.7 nbytes = native_bytes('HHZ') the_strs = [native_str('HHZ'), nbytes, u'HHZ'] stats = Stats() for a_str in the_strs: for nslc in self.nslc: setattr(stats, nslc, a_str) self.assertIsInstance(getattr(stats, nslc), (str, native_str))
def test_different_string_types(self): """ Test the various types of strings found in the wild get converted to native_str type. """ # get native bytes try: # this is required on python 3 nbytes = native_bytes('HHZ', 'utf8') except TypeError: # this works on py 2.7 nbytes = native_bytes('HHZ') the_strs = [native_str('HHZ'), nbytes, u'HHZ'] stats = Stats() for a_str in the_strs: for nslc in self.nslc: with warnings.catch_warnings(record=True): setattr(stats, nslc, a_str) self.assertIsInstance(getattr(stats, nslc), (str, native_str))
def privkey_to_pubkey_inner(priv, usehex): '''Take 32/33 byte raw private key as input. If 32 bytes, return compressed (33 byte) raw public key. If 33 bytes, read the final byte as compression flag, and return compressed/uncompressed public key as appropriate.''' compressed, priv = read_privkey(priv) #secp256k1 checks for validity of key value. if sys.version_info >= (3, 0): newpriv = secp256k1.PrivateKey(secret=native_bytes(priv)) else: newpriv = secp256k1.PrivateKey(secret=bytes_to_native_str(priv)) return newpriv.public_key.format(compressed)
def multiply(s, pub, usehex, rawpub=True, return_serialized=True): '''Input binary compressed pubkey P(33 bytes) and scalar s(32 bytes), return s*P. The return value is a binary compressed public key, or a PublicKey object if return_serialized is False. Note that the called function does the type checking of the scalar s. ('raw' options passed in) ''' newpub = secp256k1.PublicKey(pub) #see note to "tweak_mul" function in podle.py if sys.version_info >= (3, 0): res = newpub.multiply(native_bytes(s)) else: res = newpub.multiply(bytes_to_native_str(s)) if not return_serialized: return res return res.format()