Exemplo n.º 1
0
def UnorderedIteratorMixin(class_name):
    class UIM(object):
        @classmethod
        def __typesig__(cls, obj):
            if isinstance(obj, cls):
                return _UnorderedIteratorMixin(class_name, obj)

        def __repr__(self):
            return "%s%s" % (class_name, str(tuple(e for e in self)))

    # We register each produced class anew
    # If someone needs to unregister these classes, they should
    # save a copy of it before including it in the class-definition:
    #
    # my_UIM = UnorderedIteratorMixin("FooClass")
    # class FooClass(my_UIM):
    #   ...
    #
    # Alternatively, you could just look in FooClass.__bases__ later; whatever
    register_type(UIM)
    return UIM
Exemplo n.º 2
0
def UnorderedIteratorMixin(class_name):
    class UIM(object):
        @classmethod
        def __typesig__(cls, obj):
            if isinstance(obj, cls):
                return _UnorderedIteratorMixin(class_name, obj)

        def __repr__(self):
            return "%s%s" % (class_name, str(tuple(e for e in self)))

    # We register each produced class anew
    # If someone needs to unregister these classes, they should
    # save a copy of it before including it in the class-definition:
    #
    # my_UIM = UnorderedIteratorMixin("FooClass")
    # class FooClass(my_UIM):
    #   ...
    #
    # Alternatively, you could just look in FooClass.__bases__ later; whatever
    register_type(UIM)
    return UIM
Exemplo n.º 3
0
###  class MyClass(UnorderedIteratorMixin("MyClass")):
###    blah blah blah
###
### This serves as a class factory, whose produced classes
### attempt to mask the fact they exist. Their purpose
### is to redirect __typesig__ calls to appropriate
### instances of _UnorderedIteratorMixin
def UnorderedIteratorMixin(class_name):
    class UIM(object):
        @classmethod
        def __typesig__(cls, obj):
            if isinstance(obj, cls):
                return _UnorderedIteratorMixin(class_name, obj)

        def __repr__(self):
            return "%s%s" % (class_name, str(tuple(e for e in self)))

    # We register each produced class anew
    # If someone needs to unregister these classes, they should
    # save a copy of it before including it in the class-definition:
    #
    # my_UIM = UnorderedIteratorMixin("FooClass")
    # class FooClass(my_UIM):
    #   ...
    #
    # Alternatively, you could just look in FooClass.__bases__ later; whatever
    register_type(UIM)
    return UIM
    
register_type(_UnorderedIteratorMixin)
Exemplo n.º 4
0
###    blah blah blah
###
### This serves as a class factory, whose produced classes
### attempt to mask the fact they exist. Their purpose
### is to redirect __typesig__ calls to appropriate
### instances of _UnorderedIteratorMixin
def UnorderedIteratorMixin(class_name):
    class UIM(object):
        @classmethod
        def __typesig__(cls, obj):
            if isinstance(obj, cls):
                return _UnorderedIteratorMixin(class_name, obj)

        def __repr__(self):
            return "%s%s" % (class_name, str(tuple(e for e in self)))

    # We register each produced class anew
    # If someone needs to unregister these classes, they should
    # save a copy of it before including it in the class-definition:
    #
    # my_UIM = UnorderedIteratorMixin("FooClass")
    # class FooClass(my_UIM):
    #   ...
    #
    # Alternatively, you could just look in FooClass.__bases__ later; whatever
    register_type(UIM)
    return UIM


register_type(_UnorderedIteratorMixin)
Exemplo n.º 5
0
            raise _TC_LengthError(len(to_check), 0)
            
        for obj in to_check:
            error = False
            for type in self._types:
                try:
                    check_type(type, func, obj)
                except _TC_Exception:
                    error = True
                    continue
                else:
                    error = False
                    break
            if error:
                raise _TC_KeyError(obj, _TC_TypeError(obj, self._type))

    def __eq__(self, other):
        if self.__class__ is not other.__class__:
            return False
        return self.type == other.type
        
    def __hash__(self):
        return hash(str(hash(self.__class__)) + str(hash(frozenset(self.type))))
            
    @classmethod
    def __typesig__(self, obj):
        if isinstance(obj, set):
            return Set(obj)

register_type(Set)