]> Repositories - Adafruit_Blinka-hackapet.git/blob - python/mcp/__init__.py
Updated for new testing structure
[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     @classmethod
10     def iteritems(cls):
11         """
12             Inspects attributes of the class for instances of the class
13             and returns as key,value pairs mirroring dict#iteritems
14         """
15         for key in dir(cls):
16             val = getattr(cls, key)
17             if type(val) is cls:
18                 yield (key, val)
19
20
21     def __repr__(self):
22         """
23         Assumes instance will be found as attribute of own class.
24         Returns dot-subscripted path to instance
25         (assuming absolute import of containing package)
26         """
27         cls = type(self)
28         for key in dir(cls):
29             if getattr(cls, key) is self:
30                 return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key)
31         return repr(self)
32
33 class Pin(Enum):
34     def __init__(self, id):
35         """ id type is likely platform-specific"""
36         self.id = id
37     pass