1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 
   3 # SPDX-License-Identifier: MIT
 
   5 `adafruit_blinka` - Runtime utility objects for re-implementation of CircuitPython API
 
   6 ======================================================================================
 
  14     Object supporting CircuitPython-style of static symbols
 
  15     as seen with Direction.OUTPUT, Pull.UP
 
  20         Assumes instance will be found as attribute of own class.
 
  21         Returns dot-subscripted path to instance
 
  22         (assuming absolute import of containing package)
 
  26             if getattr(cls, key) is self:
 
  27                 return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key)
 
  33         Inspects attributes of the class for instances of the class
 
  34         and returns as key,value pairs mirroring dict#iteritems
 
  37             val = getattr(cls, key)
 
  38             if isinstance(cls, val):
 
  43     """An object that automatically deinitializes hardware with a context manager."""
 
  48     def __exit__(self, exc_type, exc_value, traceback):
 
  51     # pylint: disable=no-self-use
 
  53         """Free any hardware used by the object."""
 
  56     # pylint: enable=no-self-use
 
  59 class Lockable(ContextManaged):
 
  60     """An object that must be locked to prevent collisions on a microcontroller resource."""
 
  65         """Attempt to grab the lock. Return True on success, False if the lock is already taken."""
 
  72         """Release the lock so others may use the resource."""
 
  76             raise ValueError("Not locked")
 
  80     """Patch modules that may be different due to the platform."""
 
  81     # pylint: disable=import-outside-toplevel
 
  83     from adafruit_blinka.agnostic import time
 
  85     # pylint: enable=import-outside-toplevel
 
  87     sys.modules["time"] = time