Exemplo n.º 1
0
    def __init__(cls, *args, **kw):
        BasicMeta.__init__(cls, *args, **kw)

        # we are going to inject singletonic __new__, here it is:
        def cls_new(cls):
            try:
                obj = getattr(SingletonFactory, cls.__name__)

            except AttributeError:
                obj = Basic.__new__(cls, *(), **{})
                setattr(SingletonFactory, cls.__name__, obj)

            return obj

        cls_new.__name__ = '%s.__new__' % (cls.__name__)

        assert not cls.__dict__.has_key('__new__'), \
                'Singleton classes are not allowed to redefine __new__'

        # inject singletonic __new__
        cls.__new__      = staticmethod(cls_new)

        # Inject pickling support.
        def cls_getnewargs(self):
            return ()
        cls_getnewargs.__name__ = '%s.__getnewargs__' % cls.__name__

        assert not cls.__dict__.has_key('__getnewargs__'), \
                'Singleton classes are not allowed to redefine __getnewargs__'
        cls.__getnewargs__ = cls_getnewargs


        # tag the class appropriately (so we could verify it later when doing
        # S.<something>
        cls.is_Singleton = True
Exemplo n.º 2
0
 def __new__(cls, arg1, arg2, arg3=None, **options):
     assert not options,`options`
     if isinstance(arg1, type):
         # the following code gets executed when one types
         # FunctionClass(Function, "f")
         # i.e. cls = FunctionClass, arg1 = Function, arg2 = "f"
         # and we simply do an equivalent of:
         # class f(Function):
         #     ...
         # return f
         ftype, name, signature = arg1, arg2, arg3
         #XXX this probably needs some fixing:
         assert ftype.__name__.endswith('Function'),`ftype`
         attrdict = ftype.__dict__.copy()
         attrdict['undefined_Function'] = True
         if signature is not None:
             attrdict['signature'] = signature
         bases = (ftype,)
         return BasicMeta.__new__(cls, name, bases, attrdict)
     else:
         name, bases, attrdict = arg1, arg2, arg3
         return BasicMeta.__new__(cls, name, bases, attrdict)
Exemplo n.º 3
0
 def __new__(mcl, name):
     return BasicMeta.__new__(mcl, name, (AppliedUndef,), {})
Exemplo n.º 4
0
 def __new__(mcl, name):
     attrdict = {'undefined_Function': True}
     bases = (Function, )
     return BasicMeta.__new__(mcl, name, bases, attrdict)
Exemplo n.º 5
0
 def __new__(mcl, name, signature=None):
     attrdict = {'undefined_Function': True}
     if signature is not None:
         attrdict['signature'] = signature
     bases = (Function, )
     return BasicMeta.__new__(mcl, name, bases, attrdict)
Exemplo n.º 6
0
 def __new__(mcl, name):
     attrdict = {'undefined_Function': True}
     bases = (Function,)
     return BasicMeta.__new__(mcl, name, bases, attrdict)
Exemplo n.º 7
0
 def __new__(mcl, name, signature=None):
     attrdict = {'undefined_Function': True}
     if signature is not None:
         attrdict['signature'] = signature
     bases = (Function,)
     return BasicMeta.__new__(mcl, name, bases, attrdict)
Exemplo n.º 8
0
 def __new__(mcl, name):
     return BasicMeta.__new__(mcl, name, (AppliedUndef, ), {})