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
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
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
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
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]
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
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
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
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)
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
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, {}]
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
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]
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]
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
def children(self, obj): for p in rtti.properties(obj): if not primitive(p.type): yield getattr(obj, p.name)