All pastes #246497 Raw Edit

Cody Brocious

public python v1 · immutable
#246497 ·published 2006-11-12 07:50 UTC
rendered paste body
#!/usr/bin/env python# encoding: utf-8"""interface.pyCreated by Cody Brocious on 2006-11-11.Copyright (c) 2006 MP3tunes, LLC. All rights reserved."""class interface(object):    __public__ = {}        def __new__(cls, *args, **kwargs):        obj = object.__new__(cls, *args, **kwargs)                obj.collectInterfaces()                return obj        @classmethod    def addInterface(cls, func, interface):        try:            __interface__ = func.__interface__        except:            __interface__ = func.__interface__ = []                __interface__.append(interface)        @classmethod    def public(cls, func):        interface.addInterface(func, interface.public)        return func        @classmethod    def protected(cls, func):        interface.addInterface(func, interface.protected)        return func        @classmethod    def secure(cls, func):        interface.addInterface(func, interface.secure)        return func        def collectInterfaces(self):        for name in dir(self):            obj = object.__getattribute__(self, name)            try:                if interface.public in obj.__interface__:                    self.__public__[name] = obj            except (KeyError, AttributeError):                pass        def __getitem__(self, name):        return self.__public__[name]        def __getattribute__(self, name):        __public__ = object.__getattribute__(self, '__public__')                if name in __public__:            return __public__[name]                try:            if object.__getattribute__(interface, name) or name == '__public__':                return object.__getattribute__(self, name)        except:            raise AttributeError, '%s object has no attribute %s' % (str(self.__class__.__name__), repr(name))                return None