Exemplo n.º 1
0
    def __new__(cls, *args):
        """Create a new ElementRef

        ref - Referenced Element, or Id
        base - Context providing Element

        """

        ref = None
        base = None
        if len(args) == 1:
            ref = args[0]
        elif len(args) == 2:
            base = args[0]
            ref = args[1]
        else:
            raise TypeError(
                "%s.__new__() takes either 1 or 2 arguments, %d given",
                cls.__name__, len(args))

        try:
            ref = ref.id
        except AttributeError:
            if not isinstance(ref, Id):
                raise TypeError("Expected Element, ElementRef or Id, not %s" %
                                type(id))

        # Id.__new__(Id('foo')) short-circuits to directly return Id('foo'),
        # have to kludge around that.
        self = Id.__new__(cls, ref)

        self.base = base
        if self.base is not None:
            self.base.connects.add(self)

        return self
Exemplo n.º 2
0
    def __new__(cls,*args):
        """Create a new ElementRef

        ref - Referenced Element, or Id
        base - Context providing Element

        """

        ref = None
        base = None
        if len(args) == 1:
            ref = args[0]
        elif len(args) == 2:
            base = args[0]
            ref = args[1]
        else:
            raise TypeError("%s.__new__() takes either 1 or 2 arguments, %d given",
                    cls.__name__,
                    len(args))

        try:
            ref = ref.id
        except AttributeError:
            if not isinstance(ref,Id):
                raise TypeError("Expected Element, ElementRef or Id, not %s" %
                                type(id))

        # Id.__new__(Id('foo')) short-circuits to directly return Id('foo'),
        # have to kludge around that.
        self = Id.__new__(cls,ref)

        self.base = base
        if self.base is not None:
            self.base.connects.add(self)

        return self
Exemplo n.º 3
0
Arquivo: id.py Projeto: SiggyF/tuke
 def __new__(cls, s, bar):
     self = Id.__new__(cls, s)
     self.bar = bar
     return self
Exemplo n.º 4
0
Arquivo: id.py Projeto: SiggyF/tuke
 def __new__(cls, s):
     return Id.__new__(cls, 'foo' + s)
Exemplo n.º 5
0
 def __new__(cls,s,bar):
     self = Id.__new__(cls,s)
     self.bar = bar
     return self
Exemplo n.º 6
0
 def __new__(cls,s):
     return Id.__new__(cls,'foo' + s)