예제 #1
0
 def children(self, obj):
     for p in rtti.properties(obj):
         if not primitive(p.type):
             yield getattr(obj, p.name)
     
     for v in getattr(obj, '_definitions', {}).itervalues():
         yield v
예제 #2
0
    def getTypeInfo(self):
        types = {}
        self.pushAllReferences()
        for obj in self._id2obj.itervalues():
            
            if '_constructAs' in dir(obj):
                ctor = obj._constructAs
            else:
                cls = obj.__class__
                ctor = cls.__module__ + "." + cls.__name__
                
            if ctor not in types:

                props = { p.name : 
                            {
                                'type'     : self._dumpPropertyConstraint(p.type), 
                                'hidden'   : p.hidden or p.name[0] == '_',
                                'collapsed': p.collapsed,
                            } 
                            for p in rtti.properties(obj)}
    
                castsTo = map(self._dumpPropertyConstraint, rtti.types(obj))
                    
                types[ctor] = { "castsTo"      : castsTo, 
                                "properties"   : props, 
                                "description"  : utils.rst2html(trim(obj.__doc__)) }
            
        return types
예제 #3
0
 def children(self, obj):
     for p in rtti.properties(obj):
         if not primitive(p.type):
             yield getattr(obj, p.name)
     
     for v in getattr(obj, '_definitions', {}).itervalues():
         yield v
예제 #4
0
 def typecheck(self):
     for obj in self._id2obj.itervalues():
         for p in rtti.properties(obj):
             try:
                 rtti.typecheck(p.type, getattr(obj, p.name))
             except exception.Constraint, err:
                 print err
                 print '    at ', repr(obj), '.', p.name
예제 #5
0
 def typecheck(self):
     for obj in self._id2obj.itervalues():
         for p in rtti.properties(obj):
             try:
                 rtti.typecheck(p.type, getattr(obj, p.name))
             except exception.Constraint, err:
                 print err
                 print '    at ', repr(obj), '.', p.name
예제 #6
0
 def save_state_before_changes(self):
     self._id2savedfields = {}
     for k,v in self._id2obj.iteritems():
         fields = {}
         for p in rtti.properties(v):
             x = getattr(v, p.name)
             if type(x) == int or type(x) == float or type(x) == str:
                 # we'd better to check here also that this field is "mutable"
                 fields[p.name] = x
         if fields != {}:
             self._id2savedfields[k] = fields
예제 #7
0
    def dump(self, Id):
        obj = self._id2obj.get(Id)
        if obj is None:
            return None

        ctor = getCtor(obj)

        props     = dict([(p.name, (p.type, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj))) \
                                                for p in rtti.properties(obj)])

        return [ctor, props]
예제 #8
0
    def dump(self, Id):
        obj = self._id2obj.get(Id)
        if obj is None:
            return None

        ctor = getCtor(obj)
            
        props     = dict([(p.name, (p.type, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj))) \
                                                for p in rtti.properties(obj)])
        
        return [ctor, props]
예제 #9
0
 def save_state_before_changes(self):
     self._id2savedfields = {}
     for k, v in self._id2obj.iteritems():
         fields = {}
         for p in rtti.properties(v):
             x = getattr(v, p.name)
             if type(x) == int or type(x) == float or type(x) == str:
                 # we'd better to check here also that this field is "mutable"
                 fields[p.name] = x
         if fields != {}:
             self._id2savedfields[k] = fields
예제 #10
0
 def get_changes(self):
     changes = []
     for k,v in self._id2obj.iteritems():
         if k in self._id2savedfields:
             saved = self._id2savedfields[k]
             for p in rtti.properties(v):
                 x = getattr(v, p.name)
                 if type(x) == int or type(x) == float or type(x) == str:
                     # we'd better to check here also that this field is "mutable"
                     if x != saved[p.name]:
                         changes.append((k, p.name, x))
     return changes
예제 #11
0
 def get_changes(self):
     changes = []
     for k, v in self._id2obj.iteritems():
         if k in self._id2savedfields:
             saved = self._id2savedfields[k]
             for p in rtti.properties(v):
                 x = getattr(v, p.name)
                 if type(x) == int or type(x) == float or type(x) == str:
                     # we'd better to check here also that this field is "mutable"
                     if x != saved[p.name]:
                         changes.append((k, p.name, x))
     return changes
예제 #12
0
    def setAttr(self, Id, propname, value):
        obj = self._id2obj[Id]

        if propname == '_alias':
            obj._alias = value
            return

        props = rtti.properties(obj)
        # try:
        value = self._convert(props, propname, value)
        # except:

        setattr(obj, propname, value)
예제 #13
0
    def setAttr(self, Id, propname, value):
        obj = self._id2obj[Id]
        
        if propname == '_alias':
            obj._alias = value
            return
        
        props = rtti.properties(obj)
        # try:
        value = self._convert(props, propname, value)
        # except: 

        setattr(obj, propname, value)
예제 #14
0
 def getUsedTypes(self):
     types = set()
     usedTypes = set()
     constraints = {}
     
     for obj in self._id2obj.itervalues():
         if type(obj) not in types:
             types.add(type(obj))
             for p in rtti.properties(obj):
                 for t in rtti.usedTypes(p.type):
                     usedTypes.add(t)
                 for t in rtti.usedConstraints(p.type):
                     constraints[t] = set()
                 
     return usedTypes, constraints
예제 #15
0
    def getUsedTypes(self):
        types = set()
        usedTypes = set()
        constraints = {}

        for obj in self._id2obj.itervalues():
            if type(obj) not in types:
                types.add(type(obj))
                for p in rtti.properties(obj):
                    for t in rtti.usedTypes(p.type):
                        usedTypes.add(t)
                    for t in rtti.usedConstraints(p.type):
                        constraints[t] = set()

        return usedTypes, constraints
예제 #16
0
 def impl(obj):
     if obj is None:
         return None
     ctor = getCtor(obj)
         
     if '_alias' not in dir(obj):
         obj._alias = self._findAlias(obj)
         
     alias = obj._alias
         
     props     = dict([(p.name, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj)) \
                                        for p in rtti.properties(obj)])
                              
     if props is None:
         props = {}
         
     return [ctor, props, alias, {}]
예제 #17
0
        def impl(obj):
            if obj is None:
                return None
            ctor = getCtor(obj)

            if '_alias' not in dir(obj):
                obj._alias = self._findAlias(obj)

            alias = obj._alias

            props     = dict([(p.name, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj)) \
                                               for p in rtti.properties(obj)])

            if props is None:
                props = {}

            return [ctor, props, alias, {}]
예제 #18
0
    def getTypeInfo(self):
        self.pushAllReferences()
        types = {}
        usedTypes, constraints = self.getUsedTypes()

        with utils.rst.Cache():

            for obj in self._id2obj.itervalues():

                ctor = getCtor(obj)

                if ctor not in types:

                    props = dict([
                        (p.name,
                         union({'type': self._dumpPropertyConstraint(p.type)},
                               ({
                                   'hidden': True
                               } if p.isHidden else {}), ({
                                   'collapsed': True
                               } if p.collapsed else {})))
                        for p in rtti.properties(obj)
                    ])

                    castsTo = filter(lambda t: t in usedTypes, rtti.types(obj))

                    for t in castsTo:
                        constraints[t].add(ctor)

                    castsTo = map(self._dumpPropertyConstraint, castsTo)

                    types[ctor] = {
                        "castsTo": sorted(castsTo),
                        "properties": props,
                        "description": utils.rst2html(trim(obj.__doc__))
                    }

        for constraint, matching_types in constraints.iteritems():
            if self.objectConstraint(constraint):
                if len(matching_types) == 0:
                    print "No types matching to constraint ", constraint

        return types, constraints
예제 #19
0
        def impl(obj):
            if obj is None:
                return None
            ctor = getCtor(obj)

            if '_alias' not in dir(obj):
                obj._alias = self._findAlias(obj)

            alias = obj._alias

            props     = dict([(p.name, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj)) \
                                               for p in rtti.properties(obj)])

            if props is None:
                props = {}

            definitions = dict([( k, self._dumpPropertyValue("", v, obj))\
                                    for k,v in getattr(obj, '_definitions', {}).iteritems()])

            return [ctor, props, alias, definitions]
예제 #20
0
 def impl(obj):
     if obj is None:
         return None
     ctor = getCtor(obj)
         
     if '_alias' not in dir(obj):
         obj._alias = self._findAlias(obj)
         
     alias = obj._alias
         
     props     = dict([(p.name, self._dumpPropertyValue(p.type, getattr(obj, p.name), obj)) \
                                        for p in rtti.properties(obj)])
                              
     if props is None:
         props = {}
         
     definitions = dict([( k, self._dumpPropertyValue("", v, obj))\
                             for k,v in getattr(obj, '_definitions', {}).iteritems()])
     
     return [ctor, props, alias, definitions]
예제 #21
0
 def impl(obj):
     if obj is None:
         return None
     if '_constructAs' in dir(obj):
         ctor = obj._constructAs
     else:
         cls = obj.__class__
         ctor = cls.__module__ + "." + cls.__name__
         
     if '_alias' not in dir(obj):
         obj._alias = self._findAlias(obj)
         
     alias = obj._alias
         
     props     = {p.name : self._dumpPropertyValue(p.type, getattr(obj, p.name), obj) \
                                        for p in rtti.properties(obj)}
                              
     if props is None:
         props = {}
         
     definitions = { k: self._dumpPropertyValue("", v, obj)\
                             for k,v in getattr(obj, '_definitions', {}).iteritems()}
     
     return [ctor, props, alias, definitions]
예제 #22
0
 def getTypeInfo(self):
     self.pushAllReferences()
     types = {}
     usedTypes, constraints = self.getUsedTypes()
     
     with utils.rst.Cache():
     
         for obj in self._id2obj.itervalues():
             
             ctor = getCtor(obj)
                 
             if ctor not in types:
 
                 props = dict([( p.name, 
                             union({'type'      : self._dumpPropertyConstraint(p.type) },
                                  ({'hidden'    : True} if p.isHidden else {}), 
                                  ({'collapsed' : True} if p.collapsed else {}))) 
                             for p in rtti.properties(obj)])
                 
                 castsTo = filter(lambda t: t in usedTypes, rtti.types(obj))
                 
                 for t in castsTo:
                     constraints[t].add(ctor)
     
                 castsTo = map(self._dumpPropertyConstraint, castsTo)
                     
                 types[ctor] = { "castsTo"      : sorted(castsTo), 
                                 "properties"   : props, 
                                 "description"  : utils.rst2html(trim(obj.__doc__)) }
     
     for constraint, matching_types in constraints.iteritems():
         if self.objectConstraint(constraint):
             if len(matching_types) == 0:
                 print "No types matching to constraint ", constraint
     
     return types, constraints
예제 #23
0
 def children(self, obj):
     for p in rtti.properties(obj):
         if not primitive(p.type):
             yield getattr(obj, p.name)
예제 #24
0
 def children(self, obj):
     for p in rtti.properties(obj):
         if not primitive(p.type):
             yield getattr(obj, p.name)