Decode a private key for ecdsa signature

def decode_privkey_hex(privkey_hex):
    """
    Decode a private key for ecdsa signature
    """
    if not isinstance(privkey_hex, (str, unicode)):
        raise ValueError("private key is not a string")

    # force uncompressed
    priv = str(privkey_hex)
    if len(priv) > 64:
        if priv[-2:] != '01':
            raise ValueError("private key does not end in '01'")

        priv = priv[:64]

    pk_i = int(priv, 16)
    return pk_i