Ejemplo n.º 1
0
        def get_session_xml(self, session_id):
            """ Returns data on a session """
            session = self.get_session(session_id)
            # return id as xml
            xml = xmlwrapper()
            xml.add(self._get_session_xml(xml, session_id))

            self._set_content_type()
            return str(xml)
Ejemplo n.º 2
0
        def get_lines_xml(self, session_id, line_numbers=None):
            """ Returns data on a session """
            if line_numbers is not None:
                line_numbers = [int(l) for l in line_numbers]
                lines = self.get_lines(session_id, line_numbers)
            elif line_numbers is None:
                # get all the lines
                lines = self.get_all_lines(session_id)
                line_numbers = range(0, len(lines))
            else:
                raise ValueError, "Must specify either line_numbers or lines"

            # return line as xml
            xml = xmlwrapper()

            elem = xml.xml.createElement("lines")
            k = 0
            for item in lines:
                ln = line_numbers[k]
                k += 1
                # if command or response are empty, just ignore them
                # should never happen that they are both empty
                line = xml.xml.createElement("line")
                line.setAttribute("number", str(ln))
                status = item["status"]
                line.setAttribute("status", str(status))
                command = item.get("input", None)
                response = item.get("output", None)

                if command is None and response is None:
                    raise ValueError, "Both the command, and the response is None, this should not happen"

                if command is not None:
                    command_node = xml.xml.createElement("command")
                    command_text = xml.xml.createTextNode(command)
                    command_node.appendChild(command_text)

                    line.appendChild(command_node)

                # only give a response
                if response is not None:
                    response_node = xml.xml.createElement("response")
                    response_text = xml.xml.createTextNode(response)
                    response_node.appendChild(response_text)

                    line.appendChild(response_node)

                elem.appendChild(line)

            xml.add(self._get_session_xml(xml, session_id))
            xml.add(elem)

            self._set_content_type()
            return str(xml)
Ejemplo n.º 3
0
        def get_tip_xml(self, session_id, text):
            """ returns a tooltip given it's session_id """
            session = self.get_session(session_id)
            data = session.getTip(text)

            xml = xmlwrapper()
            elem = xml.xml.createElement("tips")

            if data is None:
                return

            for key, value in data:
                elem.appendChild(self._createTextNode(xml, "tip", str(value), str(key)))

            xml.add(elem)
            self._set_content_type()
            return str(xml)