Beispiel #1
0
    def __init__(self,
                 stream,
                 encoding,
                 nsHints=None,
                 isHtml=False,
                 indent=False,
                 canonical=False,
                 addedAttributes=None,
                 removedNsDecls=None):
        """
        Initializes an instance of the class, selecting the appropriate
        printer to use, depending on the isHtml and indent flags.
        nsHints, if given, is a dictionary of namespace mappings that
        help determine if namespace declarations need to be emitted when
        visiting the first Element node.
        """
        if indent and isHtml:
            self.writer = HtmlPrettyPrinter.HtmlPrettyPrinter(stream, encoding)
        elif indent:
            self.writer = XmlPrettyPrinter.XmlPrettyPrinter(stream, encoding)
        elif isHtml:
            self.writer = HtmlPrinter.HtmlPrinter(stream, encoding)
        elif canonical:
            self.writer = XmlPrinter.CanonicalXmlPrinter(stream, encoding)
        else:
            self.writer = XmlPrinter.XmlPrinter(stream, encoding)

        # Namespaces
        self._namespaces = [{'xml': XML_NAMESPACE}]
        self._nsHints = nsHints
        self._addedAttributes = addedAttributes or {}
        self._removedNsDecls = removedNsDecls or []
        return
Beispiel #2
0
    def report(self):
        """
        Create the report in XML and send it
        """

        # Create the report
        doc = xml.dom.minidom.Document()
        root = doc.createElement("nextsharedata")
        doc.appendChild(root)

        # Create the header
        header = doc.createElement("header")
        root.appendChild(header)
        header.appendChild(self.new_element(doc, "deviceid", self.device_id))
        header.appendChild(
            self.new_element(doc, "timestamp", long(round(time.time()))))

        # ProxyService 90s Test_
        #        try:
        #            from Tribler.Core.Session import Session
        #            session = Session.get_instance()
        #            if session.lm.overlay_apps.proxy_peer_manager.connectable:
        #                    connectable = 1
        #            else:
        #                    connectable = 0
        #
        #            start_time = long(round(session.start_time))
        #
        #            my_permid = show_permid_short(session.get_permid())
        #        except Exception,e:
        #            connectable = 0
        #            start_time = 0
        #            my_permid = 0
        #
        #        header.appendChild(self.new_element(doc, "connectable", connectable))
        #        header.appendChild(self.new_element(doc, "startuptime", start_time))
        #        header.appendChild(self.new_element(doc, "clientpermid", my_permid))
        # _ProxyService 90s Test

        version = "cs_v2a"
        header.appendChild(self.new_element(doc, "swversion", version))

        elements = self.get_elements()
        if len(elements) > 0:

            # Now add the status elements
            if len(elements) > 0:
                report = doc.createElement("event")
                root.appendChild(report)

                report.appendChild(
                    self.new_element(doc, "attribute", "statusreport"))
                report.appendChild(
                    self.new_element(doc, "timestamp",
                                     long(round(time.time()))))
                for element in elements:
                    print element.__class__
                    report.appendChild(
                        self.new_element(doc, element.get_name(),
                                         element.get_value()))

        events = self.get_events()
        if len(events) > 0:
            for event in events:
                report = doc.createElement(event.get_type())
                root.appendChild(report)
                report.appendChild(
                    self.new_element(doc, "attribute", event.get_name()))
                if event.__class__ == Status.EventElement:
                    report.appendChild(
                        self.new_element(doc, "timestamp", event.get_time()))
                elif event.__class__ == Status.RangeElement:
                    report.appendChild(
                        self.new_element(doc, "starttimestamp",
                                         event.get_start_time()))

                    report.appendChild(
                        self.new_element(doc, "endtimestamp",
                                         event.get_end_time()))
                for value in event.get_values():
                    report.appendChild(self.new_element(doc, "value", value))

        if len(elements) == 0 and len(events) == 0:
            return  # Was nothing here for us

        # all done
        xml_printer = XmlPrinter.XmlPrinter(root)
        if self.print_post:
            print >> sys.stderr, xml_printer.to_pretty_xml()
        xml_str = xml_printer.to_xml()

        # Now we send this to the service using a HTTP POST
        self.post(xml_str)
Beispiel #3
0
    def report(self):
        """
        Create the report in XML and send it
        """

        # Create the report
        doc = xml.dom.minidom.Document()
        root = doc.createElement("nextsharedata")
        doc.appendChild(root)

        # Create the header
        header = doc.createElement("header")
        root.appendChild(header)
        header.appendChild(self.new_element(doc, "deviceid", self.device_id))
        header.appendChild(self.new_element(doc, "timestamp",
                                            long(round(time.time()))))

        version = "cs_v2a"
        header.appendChild(self.new_element(doc, "swversion", version))

        # Now add the status elements
        elements = self.get_elements()
        if len(elements) > 0:
            report = doc.createElement("event")
            root.appendChild(report)

            report.appendChild(self.new_element(doc, "attribute",
                                               "statusreport"))
            report.appendChild(self.new_element(doc, "timestamp",
                                               long(round(time.time()))))
            for element in elements:
                print element.__class__
                report.appendChild(self.new_element(doc,
                                                   element.get_name(),
                                                   element.get_value()))

        events = self.get_events()
        if len(events) > 0:
            for event in events:
                report = doc.createElement(event.get_type())
                root.appendChild(report)
                report.appendChild(self.new_element(doc, "attribute",
                                                   event.get_name()))
                if event.__class__ == Status.EventElement:
                    report.appendChild(self.new_element(doc, "timestamp",
                                                       event.get_time()))
                elif event.__class__ == Status.RangeElement:
                    report.appendChild(self.new_element(doc, "starttimestamp",
                                                       event.get_start_time()))

                    report.appendChild(self.new_element(doc, "endtimestamp",
                                                       event.get_end_time()))
                for value in event.get_values():
                    report.appendChild(self.new_element(doc, "value", value))

        if len(elements) == 0 and len(events) == 0:
            return  # Was nothing here for us

        # all done
        xml_printer = XmlPrinter.XmlPrinter(root)
        if self.print_post:
            print >> sys.stderr, xml_printer.to_pretty_xml()
        xml_str = xml_printer.to_xml()

        # Now we send this to the service using a HTTP POST
        self.post(xml_str)