1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00
trezor-firmware/src/trezor/utils.py

32 lines
769 B
Python
Raw Normal View History

2016-04-26 23:32:57 +00:00
import sys
2016-04-27 19:07:37 +00:00
from TrezorUtils import Utils
_utils = Utils()
type_gen = type((lambda: (yield))())
2016-04-27 19:07:37 +00:00
def memaccess(address, length):
return _utils.memaccess(address, length)
2016-04-11 17:39:01 +00:00
def unimport_func(func):
def inner(*args, **kwargs):
mods = set(sys.modules)
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):
2016-04-26 23:32:57 +00:00
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]
2016-04-26 23:32:57 +00:00
return ret
return inner