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):
# Importa para o escopo local a variável:
nonlocal last_call
# Exibe e atualiza o horário da última chamada:
last_call = time.time()
print("Última chamada:", last_call)
# Chama a função decorada:
function(*args, **kwargs)
return wrapper
@decorator
def foo():
print("Foo executada")
foo()
aW1wb3J0IHRpbWUKCiMgRGVmaW5lIG8gY29udGFkb3IgZGUgZnVuw6fDtWVzIGRlY29yYWRhczoKZGVjb3JhdGVkX2Z1bmN0aW9ucyA9IDAKCiMgRGVmaW5pw6fDo28gZG8gZGVjb3JhZG9yOgpkZWYgZGVjb3JhdG9yKGZ1bmN0aW9uKToKICAgIAogICAgIyBJbXBvcnRhIHBhcmEgbyBlc2NvcG8gbG9jYWwgYSB2YXJpw6F2ZWwgZ2xvYmFsOgogICAgZ2xvYmFsIGRlY29yYXRlZF9mdW5jdGlvbnMKICAgIAogICAgIyBJbmNyZW1lbnRhIG8gY29udGFkb3I6CiAgICBkZWNvcmF0ZWRfZnVuY3Rpb25zICs9IDEKICAgIAogICAgIyBJbmljaWFsaXphIG8gaG9yw6FyaW8gZGEgw7psdGltYSBjaGFtYWRhOgogICAgbGFzdF9jYWxsID0gTm9uZQogICAgCiAgICAjIERlZmluZSBhIGZ1bsOnw6NvIGRlIHJldG9ybm86CiAgICBkZWYgd3JhcHBlcigqYXJncywgKiprd2FyZ3MpOgogICAgICAgIAogICAgICAgICMgSW1wb3J0YSBwYXJhIG8gZXNjb3BvIGxvY2FsIGEgdmFyacOhdmVsOgogICAgICAgIG5vbmxvY2FsIGxhc3RfY2FsbAogICAgICAgIAogICAgICAgICMgRXhpYmUgZSBhdHVhbGl6YSBvIGhvcsOhcmlvIGRhIMO6bHRpbWEgY2hhbWFkYToKICAgICAgICBsYXN0X2NhbGwgPSB0aW1l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