-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
611 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import contextlib | ||
|
||
|
||
class PinManager(): | ||
|
||
def __init__(self): | ||
self._pins = {} | ||
|
||
def set_pin(self, serial_number, pin): | ||
self._pins[serial_number] = pin | ||
|
||
def get_pin(self, serial_number): | ||
return self._pins.get(serial_number) | ||
|
||
def clear_pins(self): | ||
for key in list(self._pins.keys()): | ||
self._pins[key] = None | ||
self._pins.clear() | ||
|
||
|
||
|
||
@contextlib.contextmanager | ||
def manage_pins(): | ||
pin_manager = PinManager() | ||
try: | ||
yield pin_manager | ||
finally: | ||
pin_manager.clear_pins() | ||
|
||
|
||
def pin_managed(func): | ||
def wrapper(*args, **kwargs): | ||
with manage_pins() as pin_manager: | ||
kwargs['pin_manager'] = pin_manager | ||
return func(*args, **kwargs) | ||
return wrapper |
Oops, something went wrong.