Example #1
0
    def hashValue(self, value):
        
        view = self.itsView
        hash = _hash(str(self.itsPath))
        for k, v in value.iteritems():
            hash = _combine(hash, TypeHandler.hashValue(view, k))
            hash = _combine(hash, TypeHandler.hashValue(view, v))

        return hash
Example #2
0
    def hashValue(self, value):

        view = self.itsView
        hash = _hash(str(self.itsPath))
        for v in value:
            hash = _combine(hash, TypeHandler.hashValue(view, v))

        return hash
Example #3
0
    def type(self, value):

        if 'types' in self._references:
            for t in self._references['types']:
                if t.recognizes(value):
                    return t
        else:
            return TypeHandler.typeHandler(self.itsView, value)

        return None
Example #4
0
    def _fieldXML(self, repository, value, fieldName, field, generator):

        fieldValue = getattr(value, fieldName, Nil)

        if fieldValue is not Nil:
            typeHandler = field.get('type', None)

            if typeHandler is None:
                typeHandler = TypeHandler.typeHandler(repository, fieldValue)

            attrs = { 'name': fieldName, 'typeid': typeHandler._uuid.str64() }
            generator.startElement('field', attrs)
            generator.characters(typeHandler.makeString(fieldValue))
            generator.endElement('field')
Example #5
0
    def _hashValues(self):

        item = self._item
        kind = item._kind
        view = item.itsView
        hash = 0

        names = self.keys()
        names.sort()

        for name in names:
            if kind is not None:
                attribute = kind.getAttribute(name, False, item)
            else:
                attribute = None

            if attribute is not None:
                persisted = attribute.getAspect('persisted', True)
            else:
                persisted = True

            if persisted:
                persisted = self._getFlags(name) & Values.TRANSIENT == 0

            if persisted:
                hash = _combine(hash, _hash(name))
                value = self[name]

                if attribute is not None:
                    attrType = attribute.getAspect('type')
                else:
                    attrType = None

                if attrType is not None:
                    hash = _combine(hash, attrType.hashValue(value))
                else:
                    hash = _combine(hash, TypeHandler.hashValue(view, value))

        return hash
Example #6
0
    def hashValue(self, value):

        view = self.itsView
        hash = _hash(str(self.itsPath))

        fields = self.getAttributeValue('fields', self._values, None, None)
        if fields:
            for fieldName, field in fields.iteritems():
                default = self.getDefaultValue(fieldName) 
                fieldValue = self.getFieldValue(value, fieldName, default)
                if fieldValue == default:
                    continue
            
                fieldType = field.get('type', None)
                hash = _combine(hash, _hash(fieldName))
                if fieldType is not None:
                    hash = _combine(hash, fieldType.hashValue(fieldValue))
                else:
                    hash = _combine(hash, TypeHandler.hashValue(view,
                                                                fieldValue))

        return hash
Example #7
0
    def _hashValues(self):

        item = self._item
        kind = item._kind
        view = item.itsView
        hash = 0

        names = self.keys()
        names.sort()
        
        for name in names:
            if kind is not None:
                attribute = kind.getAttribute(name, False, item)
            else:
                attribute = None

            if attribute is not None:
                persisted = attribute.getAspect('persisted', True)
            else:
                persisted = True

            if persisted:
                persisted = self._getFlags(name) & Values.TRANSIENT == 0

            if persisted:
                hash = _combine(hash, _hash(name))
                value = self[name]
                
                if attribute is not None:
                    attrType = attribute.getAspect('type')
                else:
                    attrType = None

                if attrType is not None:
                    hash = _combine(hash, attrType.hashValue(value))
                else:
                    hash = _combine(hash, TypeHandler.hashValue(view, value))

        return hash
Example #8
0
    def _type(self, buffer, flags, item, value, verify, withSchema, attrType):

        if attrType is None:
            if verify:
                attrType = TypeHandler.typeHandler(item.itsView, value)
                typeId = attrType._uuid
            else:
                typeId = None

        elif attrType.isAlias():
            if verify:
                aliasType = attrType.type(value)
                if aliasType is None:
                    raise TypeError, "%s does not alias type of value '%s' of type %s" % (
                        attrType.itsPath, value, type(value))
                attrType = aliasType
                typeId = attrType._uuid
            else:
                typeId = None

        else:
            if verify and not attrType.recognizes(value):
                raise TypeError, "value '%s' of type %s is not recognized by type %s" % (
                    value, type(value), attrType.itsPath)

            if withSchema:
                typeId = attrType._uuid
            else:
                typeId = None

        if typeId is None:
            buffer.write(chr(flags))
        else:
            flags |= DBItemWriter.TYPED
            buffer.write(chr(flags))
            buffer.write(typeId._uuid)

        return attrType
Example #9
0
    def _type(self, buffer, flags, item, value, verify, withSchema, attrType):

        if attrType is None:
            if verify:
                attrType = TypeHandler.typeHandler(item.itsView, value)
                typeId = attrType._uuid
            else:
                typeId = None

        elif attrType.isAlias():
            if verify:
                aliasType = attrType.type(value)
                if aliasType is None:
                    raise TypeError, "%s does not alias type of value '%s' of type %s" %(attrType.itsPath, value, type(value))
                attrType = aliasType
                typeId = attrType._uuid
            else:
                typeId = None
            
        else:
            if verify and not attrType.recognizes(value):
                raise TypeError, "value '%s' of type %s is not recognized by type %s" %(value, type(value), attrType.itsPath)

            if withSchema:
                typeId = attrType._uuid
            else:
                typeId = None

        if typeId is None:
            buffer.write(chr(flags))
        else:
            flags |= DBItemWriter.TYPED
            buffer.write(chr(flags))
            buffer.write(typeId._uuid)

        return attrType
Example #10
0
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(itemref)</b> "
            result += "<a href=%s>%s</a><br>" % (toLink(value.itsPath),
              value.getItemDisplayName())
            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, URL):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
            result += ' <a href="%s">%s</a><br>' %(value, value)
            result += "</td></tr>\n"
            count += 1

        else:

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
Example #11
0
def RenderItem(repoView, item):

    result = ""

    # For Kinds, display their attributes (except for the internal ones
    # like notFoundAttributes):
    isKind = item.isItemOf(repoView.findPath("//Schema/Core/Kind"))

    isBlock = item.isItemOf(repoView.findPath("//parcels/osaf/framework/blocks/Block"))

    path = "<a href=%s>[top]</a>" % toLink("/")
    i = 2
    for part in item.itsPath[1:-1]:
        path += " &gt; <a href=%s>%s</a>" % (toLink(item.itsPath[:i]), part)
        i += 1

    name = item.itsName
    if name is None:
        name = unicode(item.itsPath[-1])
    result += "<div class='path'>%s &gt; <span class='itemname'>%s</span>" % (path, name)

    try:
        result += " (<a href=%s>%s</a>)" % (toLink(item.itsKind.itsPath), item.itsKind.itsName)
    except:
        pass

    if isKind:
        result += " | Run a <a href=%s?mode=kindquery>Kind Query</a>" % toLink(item.itsPath)

    if isBlock:
        result += " | <a href=%s?mode=blocks>Render block tree</a>" % toLink(item.itsPath)

    result += "</div>\n"

    try:
        displayName = item.displayName
        result += "<div class='subheader'><b>Display Name:</b> %s</div>\n" % displayName
    except:
        pass

    try:
        issues = item.issues
        result += "<div class='subheader'><b>Issues:</b>\n<ul></div>\n"
        for issue in issues:
            result += "<li>%s\n" % issue
        result += "</ul></p>\n"
    except:
        pass

    result += "<div class='children'><b>Child items:</b><br> "
    children = {}
    for child in item.iterChildren():
        name = child.itsName
        if name is None:
            name = unicode(child.itsUUID)
        children[name] = child
    keys = children.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    output = []
    for key in keys:
        child = children[key]
        name = child.itsName
        displayName = ""
        if name is None:
            name = unicode(child.itsUUID)
            displayName = child.getItemDisplayName()
        children[name] = child
        output.append(" &nbsp; <a href=%s>%s </a> %s" % (toLink(child.itsPath), key, displayName))
    if not output:
        result += " &nbsp; None"
    else:
        result += "<br>".join(output)
    result += "</div>\n"

    if isKind:
        result += "<table width=100% border=0 cellpadding=4 cellspacing=0>\n"
        result += "<tr class='toprow'>"
        result += "<td colspan=7><b>Attributes defined for this kind:</b></td>"
        result += "</tr>\n"

        result += "<tr class='headingsrow'>\n"
        result += "<td valign=top><b>Attribute</b> (inherited from)</td>\n"
        result += "<td valign=top><b>Description / Issues</b></td>\n"
        result += "<td valign=top><b>Cardinality</b></td>\n"
        result += "<td valign=top><b>Type</b></td>\n"
        result += "<td valign=top><b>Initial&nbsp;Value</b></td>\n"
        # result += "<td valign=top><b>Required?</b></td>\n"
        result += "<td valign=top><b>RedirectTo</b></td>\n"
        result += "</tr>\n"
        count = 0
        displayedAttrs = {}
        for name, attr, kind in item.iterAttributes():
            if name is None:
                name = "Anonymous"
            displayedAttrs[name] = (attr, kind)
        keys = displayedAttrs.keys()
        keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
        for key in keys:
            attribute, kind = displayedAttrs[key]
            result += oddEvenRow(count)
            other = attribute.getAttributeValue("otherName", default="")
            if other:
                other = " (inverse: '%s')" % other
            else:
                other = ""
            if kind is not item:
                inherited = " (from <a href=%s>%s</a>)" % (toLink(kind.itsPath), kind.itsName)
            else:
                inherited = ""
            result += "<td valign=top><a href=%s>%s</a>%s%s</td>\n" % (toLink(attribute.itsPath), key, inherited, other)
            result += "<td valign=top>%s" % (attribute.getAttributeValue("description", default="&nbsp;"))
            try:
                issues = attribute.issues
                result += "<p>Issues:<ul>"
                for issue in issues:
                    result += "<li>%s\n" % issue
                result += "</ul></p>"
            except:
                pass
            result += "</td>\n"
            cardinality = attribute.getAttributeValue("cardinality", default="single")
            result += "<td valign=top>%s</td>\n" % (cardinality)
            attrType = attribute.getAttributeValue("type", default=None)
            if attrType:
                result += "<td valign=top><a href=%s>%s</a></td>\n" % (toLink(attrType.itsPath), attrType.itsName)
            else:
                result += "<td valign=top>N/A</td>\n"
            if attribute.hasLocalAttributeValue("initialValue"):
                result += "<td valign=top>%s</td>\n" % (attribute.initialValue,)
            else:
                result += "<td valign=top>N/A</td>\n"

            # if attribute.required: result += "<td valign=top>Yes</td>\n"
            # else: result += "<td valign=top>No</td>\n"

            redirectTo = attribute.getAttributeValue("redirectTo", default="&nbsp;")
            result += "<td valign=top>%s</td>\n" % redirectTo

            result += "</tr>\n"
            count += 1
        result += "</table>\n"
        result += "<br />\n"

    result += "<table width=100% border=0 cellpadding=4 cellspacing=0>\n"
    result += "<tr class='toprow'>\n"
    result += "<td colspan=2><b>Attribute values for this item:</b></td>\n"
    result += "</tr>\n"
    result += "<tr class='headingsrow'>\n"
    result += "<td valign=top><b>Attribute</b></td>\n"
    result += "<td valign=top><b>Value</b></td>\n"
    result += "</tr>\n"
    count = 0

    displayedAttrs = {}
    for (name, value) in item.iterAttributeValues():
        if name is None:
            name = "Anonymous"
        displayedAttrs[name] = value

    keys = displayedAttrs.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    for name in keys:
        value = displayedAttrs[name]

        if name == "attributes" or name == "notFoundAttributes" or name == "inheritedAttributes":
            pass

        elif name == "originalValues":
            pass

        elif isinstance(value, RefList):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(ref coll)</b> "
            output = []
            for j in value:
                output.append(
                    "<a href=%s>%s</a>" % (toLink(j.itsPath), getattr(j, "blockName", j.getItemDisplayName()))
                )
            result += ", ".join(output)

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, list):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<ul>"
            for j in value:
                try:
                    result += "<li>%s <a href=%s>%s</a><br>\n" % (j.itsName, toLink(j.itsPath), j.itsPath)
                except:
                    result += "<li>%s (%s)<br>\n" % (clean(j), clean(type(j)))
            result += "</ul>"
            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, dict):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            for key in value.keys():
                try:
                    result += "%s: %s <a href=%s>%s</a><br>" % (
                        key,
                        value[key].itsName,
                        toLink(value[key].itsPath),
                        value[key].itsPath,
                    )
                except:
                    try:
                        result += "%s: %s (%s)<br>" % (key, clean(value[key]), clean(type(value[key])))
                    except:
                        result += "%s: <i>(Can't display)</i> (%s)<br>" % (key, clean(type(value[key])))

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, Lob):
            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            mimeType = value.mimetype
            if mimeType.startswith("image/"):
                result += "<img src=/lobs/%s/%s><br>" % (item.itsUUID, name)
                result += "(%s)<br>" % mimeType
            else:
                try:
                    theType = TypeHandler.typeHandler(repoView, value)
                    typeName = theType.getImplementationType().__name__
                    result += "<b>(%s)</b> " % typeName
                    uStr = value.getReader().read()
                    content = uStr.encode("ascii", "replace")
                    result += clean(content)

                except Exception, e:
                    result += clean(e)
                    result += "(Couldn't read Lob content)"

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, Item):
            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(itemref)</b> "
            result += "<a href=%s>%s</a><br>" % (toLink(value.itsPath), value.getItemDisplayName())
            result += "</td></tr>\n"
            count += 1
Example #12
0
def RenderObject(repoView, theObject, objectPath, label="Object"):
    result = "&nbsp;<br><table width=100% border=0 cellpadding=4 cellspacing=0>\n"
    result += "<tr class='toprow'>\n"
    result += "<td colspan=2><b>%s: %s</b></td>\n" % (clean(label), clean(theObject))
    result += "</tr>\n"
    result += "<tr class='headingsrow'>\n"
    result += "<td valign=top><b>Attribute</b></td>\n"
    result += "<td valign=top><b>Value</b></td>\n"
    result += "</tr>\n"
    count = 0

    displayedAttrs = {}
    for name in dir(theObject):
        if name is None:
            continue
        try:
            attr = getattr(theObject, name)
        except AttributeError:
            continue
        if callable(attr):
            if name.endswith("Tuple") or not (
                name.startswith("Get") or name.startswith("Has") or name.startswith("Is")
            ):
                continue
            displayName = "%s()" % name
        elif name in ("__class__", "__dict__", "__doc__", "__module__", "__weakref__", "this", "thisown"):
            continue
        else:
            displayName = name
        value = _getObjectValue(theObject, name)

        displayedAttrs[displayName] = (name, value)

    keys = displayedAttrs.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    for displayName in keys:
        (name, value) = displayedAttrs[displayName]

        result += oddEvenRow(count)
        result += "<td valign=top>"
        result += "%s" % displayName
        result += "</td><td valign=top>"
        try:
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
        except:
            result += "<b>(%s)</b> " % value.__class__.__name__

        if isinstance(value, list):
            results = []
            for i in range(len(value)):
                v = value[i]
                if isinstance(v, object):
                    results.append(
                        "<a href=%s?mode=object>%s</a>" % (toLink("%s/%s[%d]" % (objectPath[1:], name, i)), clean(v))
                    )
                else:
                    results.append("%s" % (clean(v)))
                    # if isinstance(v, object): # str(v).find("; proxy of C++ ") != -1:

            result += ", ".join(results) + "<br>"
        else:
            if isinstance(value, object):
                result += "<a href=%s?mode=object>%s</a><br>" % (toLink("%s/%s" % (objectPath[1:], name)), clean(value))
            else:
                result += "%s<br>" % (clean(value))
        result += "</td></tr>\n"
        count += 1

    result += "</table>\n"
    return result
Example #13
0
            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(itemref)</b> "
            result += "<a href=%s>%s</a><br>" % (toLink(value.itsPath), value.getItemDisplayName())
            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, URL):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
            result += ' <a href="%s">%s</a><br>' % (value, value)
            result += "</td></tr>\n"
            count += 1

        else:

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
Example #14
0
    def onViewClear(self, view):

        TypeHandler.clear(view)
Example #15
0
    def hashValue(self, value):

        if value is None:
            return 0

        return TypeHandler.hashValue(self.itsView, SingleRef(value.itsUUID))
Example #16
0
    def __init__(self, repository):

        ContentHandler.__init__(self)
        TypeHandler.__init__(self)
        
        self.repository = repository
Example #17
0
class DBItemWriter(ItemWriter):
    def __init__(self, store):

        super(DBItemWriter, self).__init__()

        self.store = store
        self.valueBuffer = StringIO()
        self.dataBuffer = StringIO()

    def writeItem(self, item, version):

        self.values = []
        self.uParent = DBItemWriter.NOITEM

        if not ((item._status &
                 (Item.NEW | Item.MERGED)) != 0 or item._version == 0):
            self.oldValues = self.store._items.getItemValues(
                item._version, item._uuid)
            if self.oldValues is None:
                raise AssertionError, ("Record not found for %s, version %s" %
                                       (item._repr_(), item._version))
        else:
            self.oldValues = None

        size = super(DBItemWriter, self).writeItem(item, version)
        size += self.store._items.saveItem(self.valueBuffer, item._uuid,
                                           version, self.uKind,
                                           item._status & Item.SAVEMASK,
                                           self.uParent, self.name,
                                           self.moduleName, self.className,
                                           self.values,
                                           item._values._getDirties(),
                                           item._references._getDirties())

        return size

    def writeString(self, buffer, value):

        if isinstance(value, unicode):
            value = value.encode('utf-8')
            buffer.write(pack('>i', len(value)))
        else:
            buffer.write(pack('>i', -len(value)))

        buffer.write(value)

        return 4 + len(value)

    def writeSymbol(self, buffer, value):

        if isinstance(value, unicode):
            value = value.encode('ascii')

        buffer.write(pack('>H', len(value)))
        buffer.write(value)

        return 2 + len(value)

    def writeBoolean(self, buffer, value):

        if value is None:
            buffer.write('\2')
        elif value:
            buffer.write('\1')
        else:
            buffer.write('\0')

        return 1

    def writeInteger(self, buffer, value):

        buffer.write(pack('>i', value))
        return 4

    def writeLong(self, buffer, value):

        buffer.write(pack('>q', value))
        return 8

    def writeFloat(self, buffer, value):

        buffer.write(pack('>d', value))
        return 8

    def writeUUID(self, buffer, value):

        buffer.write(value._uuid)
        return 16

    def writeValue(self, buffer, item, version, value, withSchema, attrType):

        flags = DBItemWriter.SINGLE | DBItemWriter.VALUE
        attrType = self._type(buffer, flags, item, value, True, withSchema,
                              attrType)
        return attrType.writeValue(self, buffer, item, version, value,
                                   withSchema)

    def writeList(self, buffer, item, version, value, withSchema, attrType):

        flags = DBItemWriter.LIST | DBItemWriter.VALUE
        attrType = self._type(buffer, flags, item, value, False, withSchema,
                              attrType)
        buffer.write(pack('>I', len(value)))
        size = 4
        for v in value:
            size += self.writeValue(buffer, item, version, v, withSchema,
                                    attrType)

        return size

    def writeSet(self, buffer, item, version, value, withSchema, attrType):

        flags = DBItemWriter.SET | DBItemWriter.VALUE
        attrType = self._type(buffer, flags, item, value, False, withSchema,
                              attrType)
        buffer.write(pack('>I', len(value)))
        size = 4
        for v in value:
            size += self.writeValue(buffer, item, version, v, withSchema,
                                    attrType)

        return size

    def writeDict(self, buffer, item, version, value, withSchema, attrType):

        flags = DBItemWriter.DICT | DBItemWriter.VALUE
        attrType = self._type(buffer, flags, item, value, False, withSchema,
                              attrType)
        buffer.write(pack('>I', len(value)))
        size = 4
        for k, v in value._iteritems():
            size += self.writeValue(buffer, item, version, k, False, None)
            size += self.writeValue(buffer, item, version, v, withSchema,
                                    attrType)

        return size

    def writeIndexes(self, buffer, item, version, value):

        if value._indexes:
            buffer.write(pack('>H', len(value._indexes)))
            size = 2 + value._saveIndexes(self, buffer, version)
        else:
            buffer.write('\0\0')
            size = 2

        return size

    def _kind(self, kind):

        if kind is None:
            self.uKind = DBItemWriter.NOITEM
        else:
            self.uKind = kind._uuid

        return 0

    def _parent(self, parent, isContainer):

        if parent is None:
            self.uParent = DBItemWriter.NOITEM
        else:
            self.uParent = parent.itsUUID

        return 0

    def _name(self, name):

        self.name = name
        return 0

    def _className(self, moduleName, className):

        self.moduleName = moduleName
        self.className = className

        return 0

    def _children(self, item, version, all):

        if item._children is not None:
            return item._children._saveValues(version)

        return 0

    def _acls(self, item, version, all):

        size = 0
        if item._status & Item.ADIRTY:
            store = self.store
            uuid = item._uuid
            for name, acl in item._acls.iteritems():
                size += store.saveACL(version, uuid, name, acl)

        return size

    def _values(self, item, version, withSchema, all):

        return item._values._writeValues(self, version, withSchema, all)

    def _references(self, item, version, withSchema, all):

        return item._references._writeValues(self, version, withSchema, all)

    def _value(self, item, name, value, version, flags, withSchema, attribute):

        uValue = UUID()
        self.values.append((name, uValue))

        if attribute is None:
            uAttr = DBItemWriter.NOITEM
            attrCard = 'single'
            attrType = None
            indexed = False
        else:
            uAttr = attribute._uuid
            attrCard = attribute.getAspect('cardinality', 'single')
            attrType = attribute.getAspect('type', None)
            indexed = attribute.getAspect('indexed', False)

        buffer = self.dataBuffer
        buffer.truncate(0)
        buffer.seek(0)

        buffer.write(pack('>I', flags))
        if withSchema:
            self.writeSymbol(buffer, name)

        try:
            if attrCard == 'single':
                self.writeValue(buffer, item, version, value, withSchema,
                                attrType)
            elif attrCard == 'list':
                self.writeList(buffer, item, version, value, withSchema,
                               attrType)
            elif attrCard == 'set':
                self.writeSet(buffer, item, version, value, withSchema,
                              attrType)
            elif attrCard == 'dict':
                self.writeDict(buffer, item, version, value, withSchema,
                               attrType)
        except Exception, e:
            raise SaveValueError, (item, name, e)

        if indexed:

            if attrType is None:
                valueType = TypeHandler.typeHandler(item.itsView, value)
            elif attrType.isAlias():
                valueType = attrType.type(value)
            else:
                valueType = attrType

            valueType.indexValue(self, item, name, version, value)

        return self.store._values.saveValue(self.store.txn, item._uuid,
                                            version, uAttr, uValue,
                                            buffer.getvalue())
Example #18
0
 def hashValue(hash, type, value):
     if type is not None:
         return _combine(hash, type.hashValue(value))
     else:
         return _combine(hash, TypeHandler.hashValue(view, value))
Example #19
0
def RenderItem(repoView, item):

    result = ""

    # For Kinds, display their attributes (except for the internal ones
    # like notFoundAttributes):
    isKind = item.isItemOf(repoView.findPath("//Schema/Core/Kind"))

    isBlock = item.isItemOf(repoView.findPath("//parcels/osaf/framework/blocks/Block"))

    path = "<a href=%s>[top]</a>" % toLink("/")
    i = 2
    for part in item.itsPath[1:-1]:
        path += " &gt; <a href=%s>%s</a>" % (toLink(item.itsPath[:i]), part)
        i += 1

    name = item.itsName
    if name is None:
        name = unicode(item.itsPath[-1])
    result += "<div class='path'>%s &gt; <span class='itemname'>%s</span>" % (path, name)

    try: result += " (<a href=%s>%s</a>)" % (toLink(item.itsKind.itsPath), item.itsKind.itsName)
    except: pass

    if isKind:
        result += " | Run a <a href=%s?mode=kindquery>Kind Query</a>" % toLink(item.itsPath)

    if isBlock:
        result += " | <a href=%s?mode=blocks>Render block tree</a>" % toLink(item.itsPath)

    result += "</div>\n"

    try:
        displayName = item.displayName
        result += "<div class='subheader'><b>Display Name:</b> %s</div>\n" % displayName
    except:
        pass

    try:
        issues = item.issues
        result += "<div class='subheader'><b>Issues:</b>\n<ul></div>\n"
        for issue in issues:
            result += "<li>%s\n" % issue
        result += "</ul></p>\n"
    except: pass

    result += "<div class='children'><b>Child items:</b><br> "
    children = {}
    for child in item.iterChildren():
        name = child.itsName
        if name is None:
            name = unicode(child.itsUUID)
        children[name] = child
    keys = children.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    output = []
    for key in keys:
        child = children[key]
        name = child.itsName
        displayName = ""
        if name is None:
            name = unicode(child.itsUUID)
            displayName = child.getItemDisplayName()
        children[name] = child
        output.append(" &nbsp; <a href=%s>%s </a> %s" % (toLink(child.itsPath), key, displayName))
    if not output:
        result += " &nbsp; None"
    else:
        result += ("<br>".join(output))
    result += "</div>\n"


    if isKind:
        result += "<table width=100% border=0 cellpadding=4 cellspacing=0>\n"
        result += "<tr class='toprow'>"
        result += "<td colspan=7><b>Attributes defined for this kind:</b></td>"
        result += "</tr>\n"

        result += "<tr class='headingsrow'>\n"
        result += "<td valign=top><b>Attribute</b> (inherited from)</td>\n"
        result += "<td valign=top><b>Description / Issues</b></td>\n"
        result += "<td valign=top><b>Cardinality</b></td>\n"
        result += "<td valign=top><b>Type</b></td>\n"
        result += "<td valign=top><b>Initial&nbsp;Value</b></td>\n"
        # result += "<td valign=top><b>Required?</b></td>\n"
        result += "<td valign=top><b>RedirectTo</b></td>\n"
        result += "</tr>\n"
        count = 0
        displayedAttrs = { }
        for name, attr, kind in item.iterAttributes():
            if name is None: name = "Anonymous"
            displayedAttrs[name] = (attr, kind)
        keys = displayedAttrs.keys()
        keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
        for key in keys:
            attribute, kind = displayedAttrs[key]
            result += oddEvenRow(count)
            other = attribute.getAttributeValue('otherName', default="")
            if other: other = " (inverse: '%s')" % other
            else: other = ""
            if kind is not item:
                inherited = " (from <a href=%s>%s</a>)" % (toLink(kind.itsPath), kind.itsName)
            else:
                inherited = ""
            result += "<td valign=top><a href=%s>%s</a>%s%s</td>\n" % \
             (toLink(attribute.itsPath), key, inherited, other)
            result += "<td valign=top>%s" % \
             (attribute.getAttributeValue('description', default = "&nbsp;"))
            try:
                issues = attribute.issues
                result += "<p>Issues:<ul>"
                for issue in issues:
                    result += "<li>%s\n" % issue
                result += "</ul></p>"
            except: pass
            result += "</td>\n"
            cardinality = attribute.getAttributeValue('cardinality',
             default='single')
            result += "<td valign=top>%s</td>\n" % ( cardinality )
            attrType = attribute.getAttributeValue('type', default=None)
            if attrType:
                result += "<td valign=top><a href=%s>%s</a></td>\n" % \
                 (toLink(attrType.itsPath), attrType.itsName)
            else:
                result += "<td valign=top>N/A</td>\n"
            if attribute.hasLocalAttributeValue('initialValue'):
                result += "<td valign=top>%s</td>\n" % (attribute.initialValue,)
            else:
                result += "<td valign=top>N/A</td>\n"

            # if attribute.required: result += "<td valign=top>Yes</td>\n"
            # else: result += "<td valign=top>No</td>\n"

            redirectTo = attribute.getAttributeValue('redirectTo',
             default="&nbsp;")
            result += "<td valign=top>%s</td>\n" % redirectTo

            result += "</tr>\n"
            count += 1
        result += "</table>\n"
        result += "<br />\n"

    result += "<table width=100% border=0 cellpadding=4 cellspacing=0>\n"
    result += "<tr class='toprow'>\n"
    result += "<td colspan=2><b>Attribute values for this item:</b></td>\n"
    result += "</tr>\n"
    result += "<tr class='headingsrow'>\n"
    result += "<td valign=top><b>Attribute</b></td>\n"
    result += "<td valign=top><b>Value</b></td>\n"
    result += "</tr>\n"
    count = 0

    displayedAttrs = { }
    for (name, value) in item.iterAttributeValues():
        if name is None: name = "Anonymous"
        displayedAttrs[name] = value

    keys = displayedAttrs.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    for name in keys:
        value = displayedAttrs[name]

        if name == "attributes" or \
           name == "notFoundAttributes" or \
           name == "inheritedAttributes":
            pass

        elif name == "originalValues":
            pass

        elif isinstance(value, RefList):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(ref coll)</b> "
            output = []
            for j in value:
                output.append("<a href=%s>%s</a>" % \
                 (toLink(j.itsPath), getattr(j, "blockName", j.getItemDisplayName())))
            result += (", ".join(output))

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, list):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<ul>"
            for j in value:
                try:
                    result += "<li>%s <a href=%s>%s</a><br>\n" % (j.itsName,
                     toLink(j.itsPath), j.itsPath)
                except:
                    result += "<li>%s (%s)<br>\n" % (clean(j), clean(type(j)))
            result += "</ul>"
            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, dict):

            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            for key in value.keys():
                try:
                    result += "%s: %s <a href=%s>%s</a><br>" % \
                     (key, value[key].itsName, toLink( value[key].itsPath),
                      value[key].itsPath)
                except:
                    try:
                        result += "%s: %s (%s)<br>" % (key, clean(value[key]),
                         clean(type(value[key])))
                    except:
                        result += "%s: <i>(Can't display)</i> (%s)<br>" % \
                            (key, clean(type(value[key])))

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, Lob):
            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            mimeType = value.mimetype
            if mimeType.startswith("image/"):
                result += "<img src=/lobs/%s/%s><br>" % (item.itsUUID, name)
                result += "(%s)<br>" % mimeType
            else:
                try:
                    theType = TypeHandler.typeHandler(repoView,
                     value)
                    typeName = theType.getImplementationType().__name__
                    result += "<b>(%s)</b> " % typeName
                    uStr = value.getReader().read()
                    content = uStr.encode('ascii', 'replace')
                    result += clean(content)

                except Exception, e:
                    result += clean(e)
                    result += "(Couldn't read Lob content)"

            result += "</td></tr>\n"
            count += 1

        elif isinstance(value, Item):
            result += oddEvenRow(count)
            result += "<td valign=top>"
            result += "%s" % name
            result += "</td><td valign=top>"
            result += "<b>(itemref)</b> "
            result += "<a href=%s>%s</a><br>" % (toLink(value.itsPath),
              value.getItemDisplayName())
            result += "</td></tr>\n"
            count += 1
Example #20
0
def RenderObject(repoView, theObject, objectPath, label="Object"):
    result = "&nbsp;<br><table width=100% border=0 cellpadding=4 cellspacing=0>\n"
    result += "<tr class='toprow'>\n"
    result += "<td colspan=2><b>%s: %s</b></td>\n" % (clean(label), clean(theObject))
    result += "</tr>\n"
    result += "<tr class='headingsrow'>\n"
    result += "<td valign=top><b>Attribute</b></td>\n"
    result += "<td valign=top><b>Value</b></td>\n"
    result += "</tr>\n"
    count = 0
    
    displayedAttrs = { }
    for name in dir(theObject):
        if name is None:
            continue
        try:
            attr = getattr(theObject, name)
        except AttributeError:
            continue
        if callable(attr):
            if (name.endswith("Tuple") or not (name.startswith('Get') or name.startswith('Has') or name.startswith('Is'))):
                continue
            displayName = "%s()" % name
        elif name in ('__class__', '__dict__', '__doc__', '__module__', '__weakref__', 'this', 'thisown'):
            continue
        else:
            displayName = name
        value = _getObjectValue(theObject, name)
        
        displayedAttrs[displayName] = (name, value)

    keys = displayedAttrs.keys()
    keys.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
    for displayName in keys:
        (name, value) = displayedAttrs[displayName]

        result += oddEvenRow(count)
        result += "<td valign=top>"
        result += "%s" % displayName
        result += "</td><td valign=top>"
        try:
            theType = TypeHandler.typeHandler(repoView, value)
            typeName = theType.getImplementationType().__name__
            result += "<b>(%s)</b> " % typeName
        except:
            result += "<b>(%s)</b> " % value.__class__.__name__

        if isinstance(value, list):
            results = []
            for i in range(len(value)):
                v = value[i]
                if isinstance(v, object):
                    results.append("<a href=%s?mode=object>%s</a>" % (toLink("%s/%s[%d]" % (objectPath[1:], name, i)), clean(v)))
                else:
                    results.append("%s" % (clean(v)))
                    # if isinstance(v, object): # str(v).find("; proxy of C++ ") != -1:

            result += ", ".join(results) + "<br>"
        else:            
            if isinstance(value, object):
                result += "<a href=%s?mode=object>%s</a><br>" % (toLink("%s/%s" % (objectPath[1:], name)), clean(value))
            else:
                result += "%s<br>" % (clean(value))    
        result += "</td></tr>\n"
        count += 1

    result += "</table>\n"
    return result
Example #21
0
    def __init__(self, repository):

        ContentHandler.__init__(self)
        TypeHandler.__init__(self)

        self.repository = repository