1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-16 11:28:14 +00:00

New decorators unimport_func, unimport_dec

This commit is contained in:
slush0 2016-04-28 07:44:15 +02:00 committed by Pavol Rusnak
parent 66d10668ac
commit cb52fdedc3
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -1,18 +1,31 @@
import sys
import gc
from TrezorUtils import Utils
_utils = Utils()
type_gen = type((lambda: (yield))())
def memaccess(address, length):
return _utils.memaccess(address, length)
def unimport(func):
def unimport_func(func):
def inner(*args, **kwargs):
mods = set(sys.modules)
ret = func(*args, **kwargs)
for to_remove in set(sys.modules) - mods:
print(to_remove)
del sys.modules[to_remove]
try:
ret = func(*args, **kwargs)
finally:
for to_remove in set(sys.modules) - mods:
del sys.modules[to_remove]
return ret
return inner
def unimport_gen(gen):
def inner(*args, **kwargs):
mods = set(sys.modules)
try:
ret = yield from gen(*args, **kwargs)
finally:
for to_remove in set(sys.modules) - mods:
del sys.modules[to_remove]
return ret
return inner