]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Demo/metaclasses/Meta.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Demo / metaclasses / Meta.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Demo/metaclasses/Meta.py b/AppPkg/Applications/Python/Python-2.7.2/Demo/metaclasses/Meta.py
deleted file mode 100644 (file)
index b262a80..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-"""Generic metaclass.\r
-\r
-XXX This is very much a work in progress.\r
-\r
-"""\r
-\r
-import types\r
-\r
-class MetaMethodWrapper:\r
-\r
-    def __init__(self, func, inst):\r
-        self.func = func\r
-        self.inst = inst\r
-        self.__name__ = self.func.__name__\r
-\r
-    def __call__(self, *args, **kw):\r
-        return apply(self.func, (self.inst,) + args, kw)\r
-\r
-class MetaHelper:\r
-\r
-    __methodwrapper__ = MetaMethodWrapper # For derived helpers to override\r
-\r
-    def __helperinit__(self, formalclass):\r
-        self.__formalclass__ = formalclass\r
-\r
-    def __getattr__(self, name):\r
-        # Invoked for any attr not in the instance's __dict__\r
-        try:\r
-            raw = self.__formalclass__.__getattr__(name)\r
-        except AttributeError:\r
-            try:\r
-                ga = self.__formalclass__.__getattr__('__usergetattr__')\r
-            except (KeyError, AttributeError):\r
-                raise AttributeError, name\r
-            return ga(self, name)\r
-        if type(raw) != types.FunctionType:\r
-            return raw\r
-        return self.__methodwrapper__(raw, self)\r
-\r
-class MetaClass:\r
-\r
-    """A generic metaclass.\r
-\r
-    This can be subclassed to implement various kinds of meta-behavior.\r
-\r
-    """\r
-\r
-    __helper__ = MetaHelper             # For derived metaclasses to override\r
-\r
-    __inited = 0\r
-\r
-    def __init__(self, name, bases, dict):\r
-        try:\r
-            ga = dict['__getattr__']\r
-        except KeyError:\r
-            pass\r
-        else:\r
-            dict['__usergetattr__'] = ga\r
-            del dict['__getattr__']\r
-        self.__name__ = name\r
-        self.__bases__ = bases\r
-        self.__realdict__ = dict\r
-        self.__inited = 1\r
-\r
-    def __getattr__(self, name):\r
-        try:\r
-            return self.__realdict__[name]\r
-        except KeyError:\r
-            for base in self.__bases__:\r
-                try:\r
-                    return base.__getattr__(name)\r
-                except AttributeError:\r
-                    pass\r
-            raise AttributeError, name\r
-\r
-    def __setattr__(self, name, value):\r
-        if not self.__inited:\r
-            self.__dict__[name] = value\r
-        else:\r
-            self.__realdict__[name] = value\r
-\r
-    def __call__(self, *args, **kw):\r
-        inst = self.__helper__()\r
-        inst.__helperinit__(self)\r
-        try:\r
-            init = inst.__getattr__('__init__')\r
-        except AttributeError:\r
-            init = lambda: None\r
-        apply(init, args, kw)\r
-        return inst\r
-\r
-\r
-Meta = MetaClass('Meta', (), {})\r
-\r
-\r
-def _test():\r
-    class C(Meta):\r
-        def __init__(self, *args):\r
-            print "__init__, args =", args\r
-        def m1(self, x):\r
-            print "m1(x=%r)" % (x,)\r
-    print C\r
-    x = C()\r
-    print x\r
-    x.m1(12)\r
-    class D(C):\r
-        def __getattr__(self, name):\r
-            if name[:2] == '__': raise AttributeError, name\r
-            return "getattr:%s" % name\r
-    x = D()\r
-    print x.foo\r
-    print x._foo\r
-##     print x.__foo\r
-##     print x.__foo__\r
-\r
-\r
-if __name__ == '__main__':\r
-    _test()\r