]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/mcp/__init__.py
Update README.rst
[Adafruit_Blinka-hackapet.git] / python / mcp / __init__.py
1 """Module providing runtime utility objects to support the Micro/CircuitPython api"""
2
3 class Enum(object):
4     """
5         Object supporting CircuitPython-style of static symbols
6         as seen with Direction.OUTPUT, Pull.UP
7     """
8
9     def __repr__(self):
10         """
11         Assumes instance will be found as attribute of own class.
12         Returns dot-subscripted path to instance
13         (assuming absolute import of containing package)
14         """
15         cls = type(self)
16         for key in dir(cls):
17             if getattr(cls, key) is self:
18                 return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key)
19         return repr(self)
20
21     @classmethod
22     def iteritems(cls):
23         """
24             Inspects attributes of the class for instances of the class
25             and returns as key,value pairs mirroring dict#iteritems
26         """
27         for key in dir(cls):
28             val = getattr(cls, key)
29             if type(val) is cls:
30                 yield (key, val)
31
32
33 class Pin(Enum):
34     def __init__(self, id):
35         """ id type is likely platform-specific"""
36         self.id = id
37     pass