Exemple #1
0
 def setAttribute(self, name, value):
     if not IsDOMString(value):
         raise SyntaxErr()
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     attr = self.attributes.getNamedItem(name)
     if attr:
         attr.value = value
     else:
         attr = self.ownerDocument.createAttribute(name)
         attr.value = value
         self.setAttributeNode(attr)
Exemple #2
0
    def createProcessingInstruction(self, target, data):
        if not get_name_pattern().match(target):
            raise InvalidCharacterErr()

        #FIXME: Unicode support
        # Technically, chacters from the unicode surrogate blocks are illegal.
        #for c in target:
        #    if c in unicode_surrogate_blocks:
        #        raise InvalidCharacterErr()

        from ProcessingInstruction import ProcessingInstruction
        return ProcessingInstruction(self, target, data)
Exemple #3
0
 def createElementNS(self, namespaceURI, qualifiedName):
     from Element import Element
     if not get_name_pattern().match(qualifiedName):
         raise InvalidCharacterErr()
     (prefix, localName) = SplitQName(qualifiedName)
     if prefix == 'xml' and namespaceURI != XML_NAMESPACE:
         raise NamespaceErr()
     if prefix and not namespaceURI:
         raise NamespaceErr()
     elif namespaceURI == '':
         raise NamespaceErr("Use None instead of '' for empty namespace")
     return Element(self, qualifiedName, namespaceURI, prefix, localName)
Exemple #4
0
    def createProcessingInstruction(self, target, data):
        if not get_name_pattern().match(target):
            raise InvalidCharacterErr()

        #FIXME: Unicode support
        # Technically, chacters from the unicode surrogate blocks are illegal.
        #for c in target:
        #    if c in unicode_surrogate_blocks:
        #        raise InvalidCharacterErr()

        from ProcessingInstruction import ProcessingInstruction
        return ProcessingInstruction(self, target, data);
Exemple #5
0
 def createElementNS(self, namespaceURI, qualifiedName):
     from Element import Element
     if not get_name_pattern().match(qualifiedName):
         raise InvalidCharacterErr()
     (prefix, localName) = SplitQName(qualifiedName)
     if prefix == 'xml' and namespaceURI != XML_NAMESPACE:
         raise NamespaceErr()
     if prefix and not namespaceURI:
         raise NamespaceErr()
     elif namespaceURI == '':
         raise NamespaceErr("Use None instead of '' for empty namespace")
     return Element(self, qualifiedName, namespaceURI, prefix, localName)
Exemple #6
0
 def setAttribute(self, name, value):
     if not IsDOMString(value):
         raise SyntaxErr()
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     attr = self.attributes.getNamedItem(name)
     if attr:
         attr.value = value
     else:
         attr = self.ownerDocument.createAttribute(name)
         attr.value = value
         self.setAttributeNode(attr)
Exemple #7
0
    def setAttributeNS(self, namespaceURI, qualifiedName, value):
        if not IsDOMString(value):
            raise SyntaxErr()
        if not get_name_pattern().match(qualifiedName):
            raise InvalidCharacterErr()

        prefix, localName = SplitQName(qualifiedName)
        attr = self.attributes.getNamedItemNS(namespaceURI, localName)
        if attr:
            attr.value = value
        else:
            attr = self.ownerDocument.createAttributeNS(namespaceURI, qualifiedName)
            attr.value = value
            self.setAttributeNodeNS(attr)
        return
Exemple #8
0
    def setAttributeNS(self, namespaceURI, qualifiedName, value):
        if not IsDOMString(value):
            raise SyntaxErr()
        if not get_name_pattern().match(qualifiedName):
            raise InvalidCharacterErr()

        prefix, localName = SplitQName(qualifiedName)
        attr = self.attributes.getNamedItemNS(namespaceURI, localName)
        if attr:
            attr.value = value
        else:
            attr = self.ownerDocument.createAttributeNS(
                namespaceURI, qualifiedName)
            attr.value = value
            self.setAttributeNodeNS(attr)
        return
Exemple #9
0
 def createAttributeNS(self, namespaceURI, qualifiedName):
     if not get_name_pattern().match(qualifiedName):
         raise InvalidCharacterErr()
     from Attr import Attr
     (prefix, localName) = SplitQName(qualifiedName)
     if prefix == 'xml' and namespaceURI != XML_NAMESPACE:
         raise NamespaceErr()
     if localName == 'xmlns':
         if namespaceURI != XMLNS_NAMESPACE:
             raise NamespaceErr()
         return Attr(self, qualifiedName, XMLNS_NAMESPACE, 'xmlns', prefix)
     elif namespaceURI == '':
         raise NamespaceErr("Use None instead of '' for empty namespace")
     else:
         if (not namespaceURI and prefix) or (not prefix and namespaceURI):
             raise NamespaceErr()
         return Attr(self, qualifiedName, namespaceURI, prefix, localName)
Exemple #10
0
 def createAttributeNS(self, namespaceURI, qualifiedName):
     if not get_name_pattern().match(qualifiedName):
         raise InvalidCharacterErr()
     from Attr import Attr
     (prefix, localName) = SplitQName(qualifiedName)
     if prefix == 'xml' and namespaceURI != XML_NAMESPACE:
         raise NamespaceErr()
     if localName == 'xmlns':
         if namespaceURI != XMLNS_NAMESPACE:
             raise NamespaceErr()
         return Attr(self, qualifiedName, XMLNS_NAMESPACE, 'xmlns', prefix)
     elif namespaceURI == '':
         raise NamespaceErr("Use None instead of '' for empty namespace")
     else:
         if (not namespaceURI and prefix) or (not prefix and namespaceURI):
             raise NamespaceErr()
         return Attr(self, qualifiedName, namespaceURI, prefix, localName)
Exemple #11
0
 def createEntityReference(self, name):
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     from EntityReference import EntityReference
     return EntityReference(self, name)
Exemple #12
0
 def createElement(self, tagname):
     if not get_name_pattern().match(tagname):
         raise InvalidCharacterErr()
     from Element import Element
     return Element(self, tagname, EMPTY_NAMESPACE, None, None)
Exemple #13
0
 def createAttribute(self, name):
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     import Attr
     return Attr.Attr(self, name, EMPTY_NAMESPACE, None, None)
Exemple #14
0
 def createEntityReference(self, name):
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     from EntityReference import EntityReference
     return EntityReference(self, name)
Exemple #15
0
 def createElement(self, tagname):
     if not get_name_pattern().match(tagname):
         raise InvalidCharacterErr()
     from Element import Element
     return Element(self, tagname, EMPTY_NAMESPACE, None, None)
Exemple #16
0
 def createAttribute(self, name):
     if not get_name_pattern().match(name):
         raise InvalidCharacterErr()
     import Attr
     return Attr.Attr(self, name, EMPTY_NAMESPACE, None, None)