import time
# Define o contador de funções decoradas:
decorated_functions = 0
# Definição do decorador:
def decorator( function) :
# Importa para o escopo local a variável global:
global decorated_functions
# Incrementa o contador:
decorated_functions += 1
# Inicializa o horário da última chamada:
last_call = None
# Define a função de retorno:
def wrapper( *args, **kwargs) :
# Exibe e atualiza o horário da última chamada:
print ( "Última chamada:" , last_call)
last_call = time .time ( )
# Chama a função decorada:
function( *args, **kwargs)
return wrapper
@ decorator
def foo( ) :
print ( "Foo executada" )
foo( )
aW1wb3J0IHRpbWUKCiMgRGVmaW5lIG8gY29udGFkb3IgZGUgZnVuw6fDtWVzIGRlY29yYWRhczoKZGVjb3JhdGVkX2Z1bmN0aW9ucyA9IDAKCiMgRGVmaW5pw6fDo28gZG8gZGVjb3JhZG9yOgpkZWYgZGVjb3JhdG9yKGZ1bmN0aW9uKToKCiAgICAjIEltcG9ydGEgcGFyYSBvIGVzY29wbyBsb2NhbCBhIHZhcmnDoXZlbCBnbG9iYWw6CiAgICBnbG9iYWwgZGVjb3JhdGVkX2Z1bmN0aW9ucwoKICAgICMgSW5jcmVtZW50YSBvIGNvbnRhZG9yOgogICAgZGVjb3JhdGVkX2Z1bmN0aW9ucyArPSAxCgogICAgIyBJbmljaWFsaXphIG8gaG9yw6FyaW8gZGEgw7psdGltYSBjaGFtYWRhOgogICAgbGFzdF9jYWxsID0gTm9uZQoKICAgICMgRGVmaW5lIGEgZnVuw6fDo28gZGUgcmV0b3JubzoKICAgIGRlZiB3cmFwcGVyKCphcmdzLCAqKmt3YXJncyk6CgogICAgICAgICMgRXhpYmUgZSBhdHVhbGl6YSBvIGhvcsOhcmlvIGRhIMO6bHRpbWEgY2hhbWFkYToKICAgICAgICBwcmludCgiw5psdGltYSBjaGFtYWRhOiIsIGxhc3RfY2FsbCkKICAgICAgICBsYXN0X2NhbGwgPSB0aW1lLnRpbWUoKQoKICAgICAgICAjIENoYW1hIGEgZnVuw6fDo28gZGVjb3JhZGE6CiAgICAgICAgZnVuY3Rpb24oKmFyZ3MsICoqa3dhcmdzKQoKICAgIHJldHVybiB3cmFwcGVyCiAgICAgICAgCkBkZWNvcmF0b3IKZGVmIGZvbygpOgogICAgcHJpbnQoIkZvbyBleGVjdXRhZGEiKQogCmZvbygp