X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/dd4f50c67a9add29c85a981101e3df07e90dfee3..aeb8c0eac6635a886947e73c20ad0a08aaf9da53:/python/mcp/__init__.py?ds=sidebyside diff --git a/python/mcp/__init__.py b/python/mcp/__init__.py index d52c0b9..799f336 100644 --- a/python/mcp/__init__.py +++ b/python/mcp/__init__.py @@ -1,21 +1,37 @@ +"""Module providing runtime utility objects to support the Micro/CircuitPython api""" + class Enum(object): + """ + Object supporting CircuitPython-style of static symbols + as seen with Direction.OUTPUT, Pull.UP + """ + def __repr__(self): + """ + Assumes instance will be found as attribute of own class. + Returns dot-subscripted path to instance + (assuming absolute import of containing package) + """ + cls = type(self) + for key in dir(cls): + if getattr(cls, key) is self: + return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key) + return repr(self) @classmethod def iteritems(cls): + """ + Inspects attributes of the class for instances of the class + and returns as key,value pairs mirroring dict#iteritems + """ for key in dir(cls): val = getattr(cls, key) if type(val) is cls: yield (key, val) - def __repr__(self): - """ - Assumes instance will be found as attribute of own - class. Returns dot-subscripted path to instance - """ - cls = type(self) - for key in dir(cls): - if getattr(cls, key) is self: - return "{}.{}.{}".format(cls.__module__, cls.__qualname__, key) - return repr(self) \ No newline at end of file +class Pin(Enum): + def __init__(self, id): + """ id type is likely platform-specific""" + self.id = id + pass