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:
parent
66d10668ac
commit
cb52fdedc3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user