Overloaded Functions

Tim Henderson tim.tadh at gmail.com
Tue Jul 29 11:18:48 EDT 2008


Hi,

So this may have been asked before but i haven't found the answer by
googling so far. My situation is this:

I want this structure for my code:

@overloaded
def sign_auth(secret, salt, auth_normalized):
    return __sign_auth(saltedhash_bin(secret, salt), auth_normalized)

@sign_auth.register(str, str)
def sign_auth(secret_hash_normalized, auth_normalized):
    return __sign_auth(qcrypt.denormalize(secret_hash_normalized),
auth_normalized)

def __sign_auth(secret_hash_bin, auth_normalized):
    auth = qcrypt.denormalize(auth_normalized)
    aes = AES.new(secret_hash_bin, AES.MODE_CBC)
    plaintext = aes.decrypt(auth)
    ciphertext = qcrypt.normalize(xor_in_pi(plaintext))
    if debug:
        print '\n------sign_auth------'
        print qcrypt.normalize(secret_hash_bin)
        print qcrypt.normalize(plaintext)
        print ciphertext
        print '-----sign_auth-------\n'
    return ciphertext

I am using the overloading module from:
http://svn.python.org/view/sandbox/trunk/overload/overloading.py?rev=43727&view=log

However it doesn't actually support this functionality. Does any one
know of a decorator that does this? It would be really nice to have a
unified interface into the __sign_auth function for the two different
use cases.

Tim Henderson



More information about the Python-list mailing list