コード例 #1
0
ファイル: registry.py プロジェクト: aoboturov/marketsimulator
    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
コード例 #2
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
コード例 #3
0
ファイル: registry.py プロジェクト: aoboturov/marketsimulator
 def _convert(self, dst_properties, k, v):
     
     def lookup(id):
         if '_metaToCreate' in dir(self):
             self.createFromMetaEx(id)                    
         return self._id2obj[id]
     
     id = getObjRef(v)
     if id != -1:
         v = lookup(id)
         
     if type(v) == list:
         for i in range(len(v)):
             id = getObjRef(v[i])
             if id != -1:
                 v[i] = lookup(id)
             # we should check that all elements meet the constraint
         return v
     
     for p in dst_properties:
         if p.name == k:        
             typeinfo = p.type
     
     if '_casts_to' in dir(v):
         if not v._casts_to(typeinfo):
             a = 1
         assert v._casts_to(typeinfo)
         return v
     
     if typeinfo in rtti.types(v):
         return v
     
    
     if inspect.isclass(typeinfo) and issubclass(type(v), typeinfo):
         # we just checked that our object is a subclass for the constraint
         return v# so we may leave it
     
     if typeinfo is not None: # consider it as a converter
         return typeinfo(v)
     
     return v
コード例 #4
0
    def _convert(self, dst_properties, k, v):
        def lookup(id):
            if '_metaToCreate' in dir(self):
                self.createFromMetaEx(id)
            return self._id2obj[id]

        id = getObjRef(v)
        if id != -1:
            v = lookup(id)

        if type(v) == list:
            for i in range(len(v)):
                id = getObjRef(v[i])
                if id != -1:
                    v[i] = lookup(id)
                # we should check that all elements meet the constraint
            return v

        for p in dst_properties:
            if p.name == k:
                typeinfo = p.type

        if typeinfo in rtti.types(v):
            return v

        if inspect.isclass(typeinfo) and issubclass(type(v), typeinfo):
            # we just checked that our object is a subclass for the constraint
            return v  # so we may leave it

        if '_casts_to' in dir(v):
            if not v._casts_to(typeinfo):
                a = 1
            assert v._casts_to(typeinfo)
            return v

        if typeinfo is not None:  # consider it as a converter
            return typeinfo(v)

        return v
コード例 #5
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
コード例 #6
0
 def check_constraint(self, x):
     for e in rtti.types(x):
         if e == self:
             return
     raise exception.Constraint(self, x)
コード例 #7
0
ファイル: meta.py プロジェクト: xiaobozi/marketsimulator
 def check_constraint(self, x):
     for e in rtti.types(x):
         if e == self:
             return
     raise exception.Constraint(self, x)