示例#1
0
 def xml_parse(self):
     from koXMLTreeService import getService
     path = self.path
     if isUnsavedPath(self.path):
         # The "<Unsaved>/..." special path can *crash* Python if trying to
         # open it. Besides, the "<Unsaved>" business is an internal
         # codeintel detail.
         path = None
     content = self.accessor.text
     if hasattr(self, "text_chunks_from_lang"):
         # Grab only the text that's in markup regions; this skils scripts
         # that might have things that look like tags, see bug 101280
         stripped = ""
         was_unicode = isinstance(content, unicode)
         if was_unicode:
             content = content.encode("utf-8")
         trans_tbl = self.__blank_out_non_new_line_table
         for offset, text in self.text_chunks_from_lang(self.m_lang):
             if isinstance(text, unicode):
                 text = text.encode("utf-8")
             skipped_text = content[len(stripped):offset]
             stripped += string.translate(skipped_text, trans_tbl) + text
         content = stripped
         if was_unicode:
             content = content.decode("utf-8")
     self._xml_tree_cache = getService().getTreeForURI(path, content)
 def getOpenTagName(text, uri=None):
     """getOpenTagName
     return the current tag name
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     return tree.tagname(tree.current)
示例#3
0
 def getOpenTagName(text, uri=None):
     """getOpenTagName
     return the current tag name
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     return tree.tagname(tree.current)
示例#4
0
    def xml_parse(self):
        from koXMLTreeService import getService

        path = self.path
        if isUnsavedPath(self.path):
            # The "<Unsaved>/..." special path can *crash* Python if trying to
            # open it. Besides, the "<Unsaved>" business is an internal
            # codeintel detail.
            path = None
        self._xml_tree_cache = getService().getTreeForURI(path, self.accessor.text)
示例#5
0
 def xml_parse(self):
     from koXMLTreeService import getService
     path = self.path
     if isUnsavedPath(self.path):
         # The "<Unsaved>/..." special path can *crash* Python if trying to
         # open it. Besides, the "<Unsaved>" business is an internal
         # codeintel detail.
         path = None
     self._xml_tree_cache = getService().getTreeForURI(
         path, self.accessor.text)
示例#6
0
 def getValidAttributeValues(text, attr, uri=None, lang=None):
     """getValidAttributeValues
     get the current attribute, and return the values that are allowed in that
     attribute
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     handlerclass = get_tree_handler(tree, tree.current, default_completion.get(lang))
     values = handlerclass.values(attr, tree)
     if not values:
         return None
     values.sort()
     return values
示例#7
0
 def getValidTagNames(text, uri=None, lang=None):
     """getValidTagNames
     return a list of valid element names that can be inserted at the end
     of the text segment
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     default_dataset_info = getDefaultCompletion(tree, tree.current, lang)
     handlerclass = get_tree_handler(tree, tree.current, default_dataset_info)
     tagnames = handlerclass.tagnames(tree)
     if not tagnames:
         return None
     tagnames.sort()
     return tagnames
示例#8
0
 def getValidAttributeValues(text, attr, uri=None, lang=None):
     """getValidAttributeValues
     get the current attribute, and return the values that are allowed in that
     attribute
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     handlerclass = get_tree_handler(tree, tree.current, default_completion.get(lang))
     values = handlerclass.values(attr, tree)
     if not values:
         return None
     values.sort()
     return values
示例#9
0
 def getValidTagNames(text, uri=None, lang=None):
     """getValidTagNames
     return a list of valid element names that can be inserted at the end
     of the text segment
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     default_dataset_info = getDefaultCompletion(tree, tree.current, lang)
     handlerclass = get_tree_handler(tree, tree.current, default_dataset_info)
     tagnames = handlerclass.tagnames(tree)
     if not tagnames:
         return None
     tagnames.sort()
     return tagnames
示例#10
0
 def getValidAttributes(text, uri=None, lang=None):
     """getValidAttributes
     get the current tag, and return the attributes that are allowed in that
     element
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     already_supplied = tree.current.attrib.keys()
     handlerclass = get_tree_handler(tree, tree.current, default_completion.get(lang))
     attrs = handlerclass.attrs(tree)
     if not attrs:
         return None
     attrs = [name for name in attrs if name not in already_supplied]
     attrs.sort()
     return attrs
示例#11
0
 def getValidAttributes(text, uri=None, lang=None):
     """getValidAttributes
     get the current tag, and return the attributes that are allowed in that
     element
     """
     tree = koXMLTreeService.getService().getTreeForURI(uri, text)
     if tree.current is None: return None
     already_supplied = list(tree.current.attrib.keys())
     handlerclass = get_tree_handler(tree, tree.current, default_completion.get(lang))
     attrs = handlerclass.attrs(tree)
     if not attrs:
         return None
     attrs = [name for name in attrs if name not in already_supplied]
     attrs.sort()
     return attrs
示例#12
0
                        log.warn("unknown emacs mode: '%s'", mode)
                    else:
                        langs = [langName]
                        modelineLangs = [langName]

        # Detect if this is an XML file.
        if self._globalPrefs.getBooleanPref('xmlDeclDetection') and \
            (not langs or 'XML' in langs):
            # it may be an XHTML file
            lhead = head.lower()
            if lhead.startswith(u'<?xml'):
                langs.append("XML")

            try:
                # find the primary namespace of the first node
                tree = koXMLTreeService.getService().getTreeForContent(head)
                if tree and tree.root is not None:
                    ns = tree.namespace(tree.root)
                    #print "XML NS [%s]" % ns
                    if ns in self._namespaceMap:
                        #print "language is [%s]" % self._namespaceMap[ns]
                        langs.append(self._namespaceMap[ns])

                # use the doctype decl if one exists
                if tree and tree.doctype:
                    #print "XML doctype [%s]" % repr(tree.doctype)
                    if tree.doctype[2] in self._publicIdMap:
                        langs.append(self._publicIdMap[tree.doctype[2]])
                    if tree.doctype[3] in self._systemIdMap:
                        langs.append(self._systemIdMap[tree.doctype[3]])
                    if tree.doctype[0].lower() == "html":
示例#13
0
    def xml_parse(self):
        log.debug(">> MXMLBuffer.xml_parse")
        from koXMLTreeService import getService

        text = self.accessor.text.replace("<![CDATA[", "         ").replace("]]>", "   ")
        self._xml_tree_cache = getService().getTreeForURI(self.path, text)
示例#14
0
                        log.warn("unknown emacs mode: '%s'", mode)
                    else:
                        langs = [langName]
                        modelineLangs = [langName]

        # Detect if this is an XML file.
        if self._globalPrefs.getBooleanPref('xmlDeclDetection') and \
            (not langs or 'XML' in langs):
            # it may be an XHTML file
            lhead = head.lower()
            if lhead.startswith(u'<?xml'):
                langs.append("XML")

            try:
                # find the primary namespace of the first node
                tree = koXMLTreeService.getService().getTreeForContent(head)
                if tree and tree.root is not None:
                    ns = tree.namespace(tree.root)
                    #print "XML NS [%s]" % ns
                    if ns in self._namespaceMap:
                        #print "language is [%s]" % self._namespaceMap[ns]
                        langs.append(self._namespaceMap[ns])
    
                # use the doctype decl if one exists
                if tree and tree.doctype:
                    #print "XML doctype [%s]" % repr(tree.doctype)
                    if tree.doctype[2] in self._publicIdMap:
                        langs.append(self._publicIdMap[tree.doctype[2]])
                    if tree.doctype[3] in self._systemIdMap:
                        langs.append(self._systemIdMap[tree.doctype[3]])
                    if tree.doctype[0].lower() == "html":
示例#15
0
 def xml_parse(self):
     log.debug(">> MXMLBuffer.xml_parse")
     from koXMLTreeService import getService
     text = self.accessor.text.replace("<![CDATA[",
                                       "         ").replace("]]>", "   ")
     self._xml_tree_cache = getService().getTreeForURI(self.path, text)