Example #1
1
def get_treasury_source():
    url = """\
http://data.treasury.gov/feed.svc/DailyTreasuryYieldCurveRateData\
"""
    res = requests.get(url, stream=True)
    stream = iter_to_stream(res.text.splitlines())

    elements = ET.iterparse(stream, ("end", "start-ns", "end-ns"))

    namespaces = OrderedDict()
    properties_xpath = [""]

    def updated_namespaces():
        if "" in namespaces and "m" in namespaces:
            properties_xpath[0] = "{%s}content/{%s}properties" % (namespaces[""], namespaces["m"])
        else:
            properties_xpath[0] = ""

    for event, element in elements:
        if event == "end":
            tag = get_localname(element)
            if tag == "entry":
                properties = element.find(properties_xpath[0])
                datum = {get_localname(node): node.text for node in properties if ET.iselement(node)}
                # clear the element after we've dealt with it:
                element.clear()
                yield datum

        elif event == "start-ns":
            namespaces[element[0]] = element[1]
            updated_namespaces()

        elif event == "end-ns":
            namespaces.popitem()
            updated_namespaces()
    def __eq__(self, request_call):
        """Tests that the given SOAP request is equivalent to the expected request.

    In our context, equivalent means:
    1) With the exception of the SOAP header and its descendants, all XML is
       exactly identical, including the ordering of elements. AdWords enforces
       that all elements are in a proper order.
    2) The SOAP headers contain the same number of children, these children have
       identical tags, and all grandchildren of the two SOAP headers are
       identical, but the order of the children and grandchildren does not have
       to be identical.

    Args:
      request_call: mock.call The method call made by the library.

    Returns:
      boolean: Whether the given SOAP request XML is equivalent to the expected
      SOAP request.
    """
        request_args, request_kargs = request_call
        if len(request_args) != 1 or request_kargs:
            return False
        actual_xml = request_args[0]
        actual_tree = ElementTree.fromstring(actual_xml)
        expected_tree = ElementTree.fromstring(self.expected_xml)

        actual_request_header = actual_tree.find("{%s}Header" % self.SOAP_ENV_NS)
        expected_request_header = expected_tree.find("{%s}Header" % self.SOAP_ENV_NS)

        actual_tree.remove(actual_request_header)
        expected_tree.remove(expected_request_header)

        return self._CompareSoapHeaders(
            actual_request_header, expected_request_header
        ) and self._CompareRequestMinusHeader(actual_tree, expected_tree)
Example #3
0
    def _edit_pom(pom_path, java_version, hadoop_version):
        """
        Edits the pom file in place, inserting the Java and Hadoop versions
        that we're using to build our software.
        """
        # Handling the XML namespace gave me some grief. If you simply load the
        # XML, edit and then write ElementTree inserts a new namespace alias in the
        # pom.xml file (e.g., ns0:project). Although formally correct, mvn barfs; I get
        # the feeling that it doesn't understand namespaces.  The way I found that no
        # namespace alias is inserted by ElementTree when writing the XML is to use an
        # empty prefix (see 'ns = {...}' below). However, this causes some grief when
        # writing the element queries (root.find etc.) since, not having an alias, ElementTree
        # expects the tag names to be prefixed with the entire namespace name in Clark's
        # notation -- hence the use tag_prefix + tag name when forming the queries.
        ns = {"": "http://maven.apache.org/POM/4.0.0"}
        tag_prefix = "{%s}" % ns[""]
        ET.register_namespace("", ns[""])
        pom_tree = ET.parse(pom_path)
        root = pom_tree.getroot()
        props = root.find(tag_prefix + "properties", namespaces=ns)

        java_version_elem = props.find(tag_prefix + "java.version", ns)
        if java_version_elem is None:
            raise RuntimeError("%s is missing <java.version> property" % pom_path)
        java_version_elem.text = java_version

        hadoop_version_elem = props.find(tag_prefix + "hadoop.version", ns)
        if hadoop_version_elem is None:
            raise RuntimeError("%s is missing <hadoop.version> property" % pom_path)
        hadoop_version_elem.text = hadoop_version
        pom_tree.write(pom_path)
    def ex_undeploy_vm(self, node, vm):
        undeploy_xml = ET.Element("UndeployVAppParams", {"xmlns": "http://www.vmware.com/vcloud/v1.5"})
        undeploy_power_action_xml = ET.SubElement(undeploy_xml, "UndeployPowerAction")
        undeploy_power_action_xml.text = "shutdown"

        try:
            res = self.requestLoop(
                "%s/action/undeploy" % get_url_path(vm["id"]),
                data=ET.tostring(undeploy_xml),
                method="POST",
                headers={"Content-Type": "application/vnd.vmware.vcloud.undeployVAppParams+xml"},
            )
            self._wait_for_task_completion(res.object.get("href"))
        except Exception:
            undeploy_power_action_xml.text = "powerOff"
            res = self.requestLoop(
                "%s/action/undeploy" % get_url_path(vm["id"]),
                data=ET.tostring(undeploy_xml),
                method="POST",
                headers={"Content-Type": "application/vnd.vmware.vcloud.undeployVAppParams+xml"},
            )
            self._wait_for_task_completion(res.object.get("href"))

        res = self.requestLoop(get_url_path(node.id))
        return self._to_node(res.object)
Example #5
0
File: api.py Project: dudarev/cghub
 def call(self):
     """
     Makes a request to cghub server.
     Returns generator that returns Result objects.
     """
     self.patch_input_data()
     query = self.build_query()
     url = "%s%s" % (self.server_url, self.uri)
     if query:
         url = "%s?%s" % (url, query)
     xml = self.get_source_file(url)
     if self.format == self.FORMAT_JSON:
         results = ijson.items(xml, "result_set.results.item")
         for result in results:
             yield self.patch_result(result, None)
     else:
         # http://docs.python.org/dev/library/xml.dom.pulldom.html
         doc = pulldom.parse(xml)
         for event, node in doc:
             if event == pulldom.START_ELEMENT:
                 if node.tagName == "Result":
                     doc.expandNode(node)
                     # convert to python object
                     # http://docs.python.org/2/library/xml.etree.elementtree.html
                     result_xml = node.toxml(encoding="utf-8")
                     tree = ElementTree.fromstring(result_xml)
                     result = Result(tree)
                     yield self.patch_result(result, result_xml)
                 elif node.tagName == "Hits":
                     doc.expandNode(node)
                     tree = ElementTree.fromstring(node.toxml())
                     self.hits = int(tree.text)
Example #6
0
    def test_get_weather(self):
        data = reply.process_reply(
            ElementTree.fromstring(
                """
                 <xml>
         <ToUserName><![CDATA[toUser]]></ToUserName>
         <FromUserName><![CDATA[fromUser]]></FromUserName>
         <CreateTime>1348831860</CreateTime>
         <MsgType><![CDATA[text]]></MsgType>
         <Content><![CDATA[天气]]></Content>
         <MsgId>1234567890123456</MsgId>
         </xml>
        """
            )
        )

        print(data)

        data = reply.process_reply(
            ElementTree.fromstring(
                """
                 <xml>
         <ToUserName><![CDATA[toUser]]></ToUserName>
         <FromUserName><![CDATA[fromUser]]></FromUserName>
         <CreateTime>1348831860</CreateTime>
         <MsgType><![CDATA[text]]></MsgType>
         <Content><![CDATA[南京天气]]></Content>
         <MsgId>1234567890123456</MsgId>
         </xml>
        """
            )
        )

        print(data)
Example #7
0
def readFile(filename):
    """
    Open svg file and return root xml object
    """
    GZIPMAGIC = "\037\213"

    try:
        fh = open(filename, "rb")
    except IOError:
        raise SVGError("could not open file '%s' for reading" % filename)

    # test for gzip compression
    magic = fh.read(2)
    fh.close()

    if magic == GZIPMAGIC:
        svg = etree.parse(GzipFile(filename, "r"))
    else:
        svg = etree.parse(filename)

    root = svg.getroot()

    if not root.tag == Renderer.SVG_ROOT:
        raise SVGError("Expected SVG fragment as root object")

    return root
Example #8
0
def load_xml(content):
    NAMESPACES = {"mml": "http://www.w3.org/TR/MathML3/"}
    for prefix, uri in NAMESPACES.items():
        etree.register_namespace(prefix, uri)

    if not "<" in content:
        # is a file
        try:
            print("parse " + content)
            r = etree.parse(content)
        except Exception as e:
            print("read " + content)
            content = open(content, "r").read()

    if "<" in content:
        print("normalize xml")
        content = normalize_space(handle_entities(content))

        try:
            r = etree.parse(StringIO(content))
        except Exception as e:
            print("XML is not well formed")
            print(e)
            r = None
    return r
Example #9
0
def get_fixtures(request, domain, user_id, fixture_id=None):
    try:
        user = CommCareUser.get_by_user_id(user_id)
    except CouchUser.AccountTypeError:
        err = (
            ("You can't use case sharing or fixtures as a %s. " "Login as a mobile worker and try again.")
            % settings.WEB_USER_TERM,
        )
        return HttpResponse(err, status=412, content_type="text/plain")

    if not user:
        raise Http404

    assert user.is_member_of(domain)
    restore_user = user.to_ota_restore_user()
    if not fixture_id:
        ret = ElementTree.Element("fixtures")
        for fixture in generator.get_fixtures(restore_user, version=V2):
            ret.append(fixture)
        return HttpResponse(ElementTree.tostring(ret), content_type="text/xml")
    else:
        fixture = generator.get_fixture_by_id(fixture_id, restore_user, version=V2)
        if not fixture:
            raise Http404
        assert len(fixture.getchildren()) == 1, "fixture {} expected 1 child but found {}".format(
            fixture_id, len(fixture.getchildren())
        )
        return HttpResponse(ElementTree.tostring(fixture.getchildren()[0]), content_type="text/xml")
Example #10
0
def transform(fin, fout, options):
    """
        Read svg from file object fin, write output to file object fout

        options.png (boolean)   Try to produce PNG output
        options.font (string)   Font family to use (Ubuntu: Purisa)
    """
    etree.register_namespace("", "http://www.w3.org/2000/svg")
    root = etree.parse(fin).getroot()

    w, h = root.attrib.get("width", ""), root.attrib.get("height", "")
    if w.endswith("in") or h.endswith("in"):
        global gCoordinates
        gCoordinates = "in"

    _transform(root, options)

    scruffySvg = etree.tostring(root) + "\n"

    if options.png:
        import subprocess

        png = subprocess.Popen(
            ["rsvg-convert", "-f", "png"], stdin=subprocess.PIPE, stdout=subprocess.PIPE
        ).communicate(input=scruffySvg)[0]
        fout.write(png)
    else:
        fout.write(scruffySvg)
Example #11
0
    def generate(self, outdir):
        if not outdir:
            outdir = "xml"

        try:
            fs.fs.makedirs(outdir)
        except OSError:
            pass

        ElementTree.register_namespace("gobject", "http://jessevdk.github.com/cldoc/gobject/1.0")
        ElementTree.register_namespace("cldoc", "http://jessevdk.github.com/cldoc/1.0")

        self.index = ElementTree.Element("index")
        self.written = {}

        self.indexmap = {self.tree.root: self.index}

        cm = self.tree.root.comment

        if cm:
            if cm.brief:
                self.index.append(self.doc_to_xml(self.tree.root, cm.brief, "brief"))

            if cm.doc:
                self.index.append(self.doc_to_xml(self.tree.root, cm.doc))

        Generator.generate(self, outdir)

        if self.options.report:
            self.add_report()

        self.write_xml(self.index, "index.xml")

        print("Generated `{0}'".format(outdir))
    def start(self, lv, cbfnc=None):
        player_status_xml = self.opener.open(self.LIVE_API_URL + "getplayerstatus?v=" + lv).read()
        player_status = ElementTree.fromstring(player_status_xml)
        addr = player_status.find("ms/addr").text
        port = int(player_status.find("ms/port").text)
        thread = player_status.find("ms/thread").text

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((addr, port))
        sock.send('<thread thread="{thread}" version="20061206" res_from="-1"/>\0'.format(thread=thread))

        data = ""
        while True:
            while data.find("\0") == -1:
                data += sock.recv(1024)
            p = data.find("\0")
            d = ElementTree.fromstring(data[:p])
            data = data[p + 1 :]
            if d.tag == "chat":
                num = int(d.get("no") or "-1")
                vpos = int(d.get("vpos") or "-1")
                mail = d.get("mail")
                user_id = d.get("user_id")
                comment = d.text
                if comment == u"/disconnect":
                    break
                if comment.startswith("/"):
                    continue
                if cbfnc != None:
                    cbfnc({"comment": comment, "no": num, "mail": mail, "vpos": vpos, "user_id": user_id})
                else:
                    print(comment)
Example #13
0
    def test_add_package_environment_unit_metadata_complex(self):
        unit = self._generate_environment_unit("environment_name")
        unit.unit_key["id"] = None
        unit.metadata["translated_name"] = {u"af": u"af_name", u"ze": u"ze_name"}
        unit.metadata["translated_description"] = {u"af": u"af_desc", u"ze": u"ze_desc"}
        unit.metadata["group_ids"] = [u"package2", u"package1"]
        unit.metadata["options"] = [{"group": "package3", "default": False}, {"group": u"package4", "default": True}]
        self.context.add_package_environment_unit_metadata(unit)
        source_str = (
            "<environment><id>environment_name</id><display_order>0</display_order>"
            "<name>environment_name</name>"
            '<name xml:lang="af">af_name</name>'
            '<name xml:lang="ze">ze_name</name>'
            "<description>environment_name – description</description>"
            '<description xml:lang="af">af_desc</description>'
            '<description xml:lang="ze">ze_desc</description>'
            "<grouplist><groupid>package1</groupid><groupid>package2</groupid>"
            "</grouplist><optionlist>"
            "<groupid>package3</groupid>"
            '<groupid default="true">package4</groupid>'
            "</optionlist></environment>"
        )

        source_element = ElementTree.fromstring(source_str)
        xml_str = self.context.metadata_file_handle.write.call_args[0][0]
        target_element = ElementTree.fromstring(xml_str)
        compare_element(source_element, target_element)
Example #14
0
 def test_add_package_category_unit_metadata_complex(self):
     unit = self._generate_category_unit("category_name")
     unit.unit_key["id"] = None
     unit.metadata["translated_name"] = {u"af": u"af_name", u"ze": u"ze_name"}
     unit.metadata["translated_description"] = {u"af": u"af_desc", u"ze": u"ze_desc"}
     unit.metadata["packagegroupids"] = [u"package2", u"package1"]
     self.context.add_package_category_unit_metadata(unit)
     source_str = (
         "<category><id>category_name</id><display_order>0</display_order>"
         "<name>category_name</name>"
         '<name xml:lang="af">af_name</name>'
         '<name xml:lang="ze">ze_name</name>'
         "<description>category_name – description</description>"
         '<description xml:lang="af">af_desc</description>'
         '<description xml:lang="ze">ze_desc</description>'
         "<grouplist>"
         "<groupid>package1</groupid>"
         "<groupid>package2</groupid>"
         "</grouplist>"
         "</category>"
     )
     source_element = ElementTree.fromstring(source_str)
     xml_str = self.context.metadata_file_handle.write.call_args[0][0]
     target_element = ElementTree.fromstring(xml_str)
     compare_element(source_element, target_element)
Example #15
0
    def send_money(self, to, amount, currency, description=None, order_id=None):
        request_el = ET.Element("request")
        ET.SubElement(request_el, "version").text = "1.2"
        ET.SubElement(request_el, "action").text = "send_money"
        ET.SubElement(request_el, "merchant_id").text = self.merchant_id

        ET.SubElement(request_el, "kind").text = "phone"

        ET.SubElement(request_el, "to").text = to
        ET.SubElement(request_el, "amount").text = unicode(amount)
        ET.SubElement(request_el, "currency").text = currency
        ET.SubElement(request_el, "description").text = description or ""

        if order_id:
            ET.SubElement(request_el, "order_id").text = unicode(order_id)

        response_text = self._send_request(ET.tostring(request_el, "utf-8"))
        response_el = ET.fromstring(response_text)

        logger.debug("send_money response: %r" % response_text)

        status_el = response_el.find("status")
        if status_el is not None and status_el.text == "failure":
            description_el = response_el.find("response_description")
            if description_el is None:
                raise LiqpayOperationError("Operation failed")
            else:
                raise LiqpayOperationError(description_el.text.strip())

        transaction_el = response_el.find("transaction_id")
        if transaction_el is None:
            raise LiqpayResponseError("Send money response had no <transaction_id> tag")

        return transaction_el.text
def update_configs(handle, job_name):
    print "Updating %s" % job_name
    job = handle.get_job(job_name)
    tree = ET.parse("%s/%s/config.xml" % (new_config_dir, job_name))
    root = tree.getroot()
    print "Updating %s" % job_name
    job.update_config(ET.tostring(root))
Example #17
0
    def __load_mtg(self, file_name):

        try:
            self.tree = xml.parse(MONTAGES_PATH + self.file_name.split("/")[-1])  # load xml-file with montage
        except:
            self.tree = xml.parse(self.file_name)

        root = self.tree.getroot()
        self.derivations = (
            []
        )  # List of [[channelname 1, weight in derivation], [channelname 2, weight in derivation], ..]
        self.channels = []  # Contains individual channel names
        self.derivation_names = []  # Contains derivation names

        for signalcomposition in root.iter("signalcomposition"):
            self.derivations.append([])
            self.derivation_names.append("")

            for signal in signalcomposition.iter("signal"):
                signal_label = signal.find("label").text.strip()
                self.derivations[-1].append(
                    [signal_label, float(signal.find("factor").text)]
                )  # derivation[i] = [...[channel, weight]...]

                self.derivation_names[-1] += "-" + signal_label

                try:
                    self.channels.index(signal_label)
                except:
                    self.channels.append(signal_label)

            self.derivation_names[-1] = self.derivation_names[-1][1:]
Example #18
0
 def hack_mediaserver_response(self, request, response_data):
     request.setResponseCode(response_data["code"])
     request.responseHeaders = response_data["headers"]
     if "xml" not in response_data["headers"].getRawHeaders("Content-Type", [""])[0]:
         request.responseHeaders.setRawHeaders("Content-Length", [len(response_data["content"])])
         request.write(response_data["content"])
         request.finish()
         return
     request.responseHeaders.removeHeader("Content-Length")
     request.responseHeaders.removeHeader("Content-Encoding")
     # get the device that we're talking to, and its ip
     # load up response
     didl = "urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
     upnp = "urn:schemas-upnp-org:metadata-1-0/upnp/"
     root = ElementTree.fromstring(response_data["content"])
     for result in root.iter("Result"):
         resultdoc = ElementTree.fromstring(result.text.encode("utf-8"))
         for uritag in resultdoc.iter("{%s}albumArtURI" % (upnp,)):
             uritag.text = self.get_altport_url(uritag.text).decode("utf-8")
         for uritag in resultdoc.iter("{%s}res" % (didl,)):
             uritag.text = self.get_altport_url(uritag.text).decode("utf-8")
         result.text = ElementTree.tostring(resultdoc, encoding="utf-8").decode("utf-8")
         # write out
     doc = ElementTree.ElementTree(root)
     docout = StringIO.StringIO()
     doc.write(docout, encoding="utf-8", xml_declaration=True)
     docoutstr = docout.getvalue()
     request.responseHeaders.setRawHeaders("Content-Length", [len(docoutstr)])
     request.write(docoutstr)
     request.finish()
Example #19
0
    def to_string(self, endpoints):
        """
        Converts the given endpoint description beans into a string

        :param endpoints: A list of EndpointDescription beans
        :return: A string containing an XML document
        """
        # Make the ElementTree
        root = self._make_xml(endpoints)
        tree = ElementTree.ElementTree(root)

        # Force the default name space
        ElementTree.register_namespace("", EDEF_NAMESPACE)

        # Make the XML
        for encoding in ("unicode", "UTF-8"):
            # Prepare a StringIO output
            output = StringIO()

            try:
                # Try to write with a correct encoding
                tree.write(output, encoding=encoding, xml_declaration=True, method="xml")
                break

            except LookupError:
                # 'unicode' is needed in Python 3, but unknown in Python 2...
                continue

        else:
            raise LookupError("Couldn't find a valid encoding")

        return output.getvalue()
Example #20
0
    def _create_html_file(self, sourcefile, htmlfile, errors):
        name = self.generator.get_name()
        root = ElementTree.fromstring(CPPCHECK_HTML_FILE)
        title = root.find("head/title")
        title.text = "cppcheck - report - %s" % name

        body = root.find("body")
        for div in body.findall("div"):
            if div.get("id") == "page":
                page = div
                break
        for div in page.findall("div"):
            if div.get("id") == "header":
                h1 = div.find("h1")
                h1.text = "cppcheck report - %s" % name
            if div.get("id") == "content":
                content = div
                srcnode = self.generator.bld.root.find_node(sourcefile)
                hl_lines = [e["line"] for e in errors if e.has_key("line")]
                formatter = CppcheckHtmlFormatter(linenos=True, style="colorful", hl_lines=hl_lines, lineanchors="line")
                formatter.errors = [e for e in errors if e.has_key("line")]
                css_style_defs = formatter.get_style_defs(".highlight")
                lexer = pygments.lexers.guess_lexer_for_filename(sourcefile, "")
                s = pygments.highlight(srcnode.read(), lexer, formatter)
                table = ElementTree.fromstring(s)
                content.append(table)

        s = ElementTree.tostring(root, method="html")
        s = CCPCHECK_HTML_TYPE + s
        node = self.generator.path.get_bld().find_or_declare(htmlfile)
        node.write(s)
        return css_style_defs
Example #21
0
def __GetServiceVersionDescription(protocol, server, port, path):
    """
   Private method that returns a root from an ElementTree describing the API versions
   supported by the specified server.  The result will be vimServiceVersions.xml
   if it exists, otherwise vimService.wsdl if it exists, otherwise None.

   @param protocol: What protocol to use for the connection (e.g. https or http).
   @type  protocol: string
   @param server: Which server to connect to.
   @type  server: string
   @param port: Port
   @type  port: int
   @param path: Path
   @type  path: string
   """

    url = "%s://%s:%s/%s/vimServiceVersions.xml" % (protocol, server, port, path)
    try:
        sock = requests.get(url, verify=False)
        if sock.status_code == 200:
            tree = ElementTree.fromstring(sock.content)
            return tree
    except ExpatError:
        pass

    url = "%s://%s:%s/%s/vimService.wsdl" % (protocol, server, port, path)
    try:
        sock = requests.get(url, verify=False)
        if sock.status_code == 200:
            tree = ElementTree.fromstring(sock.content)
            return tree
    except ExpatError:
        pass
    return None
Example #22
0
    def handle_message(self, channel, msg):
        """Handle message."""

        res = FlowExpression.handle_message(self, channel, msg)
        if res:
            return res

        result = "consumed"
        if self._is_start_message(msg):
            self.state = "active"
            LOG.debug("Calling a subprocess process")

            assert self.process_name.startswith("$"), "Only process defs referenced from message are supported."
            ref = self.process_name[1:]
            root = ET.fromstring(self.context.get(ref))
            assert root.tag == "process"
            root.set("parent", self.id)
            pdef = ET.tostring(root)
            channel._ch.basic_publish(
                exchange="",  # TODO: refactor to avoid private attribute
                routing_key="bureaucrat",
                body=pdef,
                properties=pika.BasicProperties(delivery_mode=2),
            )
        elif self._is_complete_message(msg):
            LOG.debug("Subprocess initiated in %s has completed", self.id)
            self.state = "completed"
            # reply to parent that the child is done
            channel.send(Message(name="completed", origin=self.id, target=self.parent_id))
        else:
            LOG.debug("%r ignores %r", self, msg)
            result = "ignored"

        return result
Example #23
0
    def test_parseHydroXML(self):
        import xml.etree.ElementTree as ET

        tree = ET.parse("filename.xml")
        root = tree.getroot()
        test_result = parseHydroXML("idname", root)
        self.assertEqual(
            {"date_time": "01 September 8Uhr", "wasserstand": "-", "wassertemperatur": "-", "abfluss": "141100"},
            test_result,
        )

        tree2 = ET.parse("filename2.xml")
        root2 = tree2.getroot()
        test_result2 = parseHydroXML("idname", root2)
        self.assertEqual(
            {"date_time": "04 Oktober 11 Uhr", "wasserstand": "59900", "wassertemperatur": "-", "abfluss": "-"},
            test_result2,
        )

        tree3 = ET.parse("filename3.xml")
        root3 = tree3.getroot()
        test_result3 = parseHydroXML("idname", root3)
        self.assertEqual(
            {"date_time": "16 Mai 18 Uhr", "wasserstand": "-", "wassertemperatur": "59900", "abfluss": "-"},
            test_result3,
        )
Example #24
0
    def check_block(case_block):
        case_block.set("xmlns", XMLNS)
        case_block = RestoreCaseBlock(ElementTree.fromstring(ElementTree.tostring(case_block)), version=version)
        case_id = case_block.get_case_id()
        n = 0

        def extra_info():
            return "\n%s\n%s" % (case_block.to_string(), map(lambda b: b.to_string(), blocks))

        match = None
        for block in blocks:
            if block.get_case_id() == case_id:
                if should_have:
                    if line_by_line:
                        check_xml_line_by_line(testcase, case_block.to_string(), block.to_string())
                    match = block
                    n += 1
                    if n == 2:
                        testcase.fail(
                            "Block for case_id '%s' appears twice"
                            " in ota restore for user '%s':%s" % (case_id, user.username, extra_info())
                        )
                else:
                    testcase.fail(
                        "User '%s' gets case '%s' " "but shouldn't:%s" % (user.username, case_id, extra_info())
                    )
        if not n and should_have:
            testcase.fail(
                "Block for case_id '%s' doesn't appear in ota restore for user '%s':%s"
                % (case_id, user.username, extra_info())
            )

        return match
    def _del_vm_disk(self, vm, disk_id):
        # ディスクIDが指定されていない場合は何もしない
        if disk_id is None:
            return

        rasd_ns = "{http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData}"

        # virtualHardwareSection/disks 取得
        res = self.requestLoop("%s/virtualHardwareSection/disks" % get_url_path(vm["id"]))

        for item in res.object.findall(fixxpath(res.object, "Item")):
            if item.find("%sHostResource" % rasd_ns) is not None:
                name = item.find("%sInstanceID" % rasd_ns).text
                if str(name) == str(disk_id):
                    res.object.remove(item)

        self.logger.info(ET.tostring(res.object))

        res = self.requestLoop(
            "%s/virtualHardwareSection/disks" % get_url_path(vm["id"]),
            data=ET.tostring(res.object),
            method="PUT",
            headers={"Content-Type": "application/vnd.vmware.vcloud.rasditemslist+xml"},
        )
        self._wait_for_task_completion(res.object.get("href"))
Example #26
0
def gen_vs_props_file(ccx_root, out_folder):
    vs_xml_namespace = "http://schemas.microsoft.com/developer/msbuild/2003"
    eT.register_namespace("", vs_xml_namespace)

    # props
    props_filename = os.path.join(out_folder, "Library.props")
    shutil.copyfile(os.path.join(os.getcwd(), "Library.props"), props_filename)
    props_tree = eT.parse(props_filename)
    props_root = props_tree.getroot()

    info_occurrences = [0] * 2
    for ccx_root_param in props_root.iter(
        "{%s}CCX_ROOT" % vs_xml_namespace
    ):  # todo - change to find (only one entrance in this file)
        ccx_root_param.text = ccx_root
        info_occurrences[0] += 1
    for gaf_sources_param in props_root.iter("{%s}GAF_SOURCES_ROOT" % vs_xml_namespace):
        gaf_sources_param.text = os.path.join(os.getcwd(), "Sources")
        info_occurrences[1] += 1

    props_tree.write(props_filename)

    print " ** Props file changed. Replaced occurrences: [Cocos2d-x root] - %d, [GAF Sources] - %d" % (
        info_occurrences[0],
        info_occurrences[1],
    )
 def callback(results):
     reactor.stop()
     for success, result in results:
         if success:
             print ElementTree.dump(result)
         else:
             print result.printTraceback()
Example #28
0
def gen_win32_js_bindings_proj(ccx_root, out_folder):
    print " * Generating JS Bindings project"

    vs_xml_namespace = "http://schemas.microsoft.com/developer/msbuild/2003"
    eT.register_namespace("", vs_xml_namespace)
    proj_filters_src = os.path.abspath("../js_bindings/proj.win32/libGAFJSBinding.vcxproj.filters")
    proj_filters_dst = os.path.join(out_folder, "libGAFJSBinding.vcxproj.filters")
    shutil.copyfile(proj_filters_src, proj_filters_dst)

    # project
    proj_src = os.path.abspath("../js_bindings/proj.win32/libGAFJSBinding.vcxproj")
    proj_dst = os.path.join(out_folder, "libGAFJSBinding.vcxproj")
    shutil.copyfile(proj_src, proj_dst)

    vcx_tree = eT.parse(proj_dst)
    vcx_root = vcx_tree.getroot()
    info_occurrences = 0
    for sources_info in vcx_root.iter("{%s}ClCompile" % vs_xml_namespace):
        file_path = sources_info.get("Include")
        if file_path:
            file_path = file_path.replace("..\\bindings", os.path.abspath("../js_bindings/bindings"))
            sources_info.set("Include", file_path)
            info_occurrences += 1

    for includes_info in vcx_root.iter("{%s}ClInclude" % vs_xml_namespace):
        file_path = includes_info.get("Include")
        if file_path:
            file_path = file_path.replace("..\\bindings", os.path.abspath("../js_bindings/bindings"))
            includes_info.set("Include", file_path)
            info_occurrences += 1

    vcx_tree.write(proj_dst)

    print " ** Replaced occurrences [Source Files] - %d" % info_occurrences
    print " * JS Bindings project generated\n"
Example #29
0
    def filter(self, text, user):
        wanted_dm = [
            "created_at",
            "id",
            "text",
            "source",
            "sender_id",
            "recipient_id",
            "sender_screen_name",
            "recipient_screen_name",
        ]
        root = ET.fromstring(text)
        dm = root.find("direct_message")
        builder = ET.TreeBuilder()
        builder.start("direct_message", {})
        for tag in wanted_dm:
            copy_element(builder, dm, tag)

        sender = status.find("sender")
        builder.start("sender", {})
        copy_element(builder, sender, "profile_image_url")
        builder.end("sender")

        recipient = status.find("recipient")
        builder.start("recipient", {})
        copy_element(builder, recipient, "profile_image_url")
        builder.end("recipient")

        builder.end("direct_message")
        return ET.tostring(builder.close())
Example #30
0
def files(archive_id):
    url = base + archive_id + "/" + archive_id + "_files.xml"
    for i in range(5):
        try:
            tree = et.parse(urlopen_keep_trying(url))
            break
        except xml.parsers.expat.ExpatError:
            sleep(2)
    try:
        tree = et.parse(urlopen_keep_trying(url))
    except:
        print "error reading", url
        raise
    assert tree
    for i in tree.getroot():
        assert i.tag == "file"
        name = i.attrib["name"]
        if (
            name == "wfm_bk_marc"
            or name.endswith(".mrc")
            or name.endswith(".marc")
            or name.endswith(".out")
            or name.endswith(".dat")
            or name.endswith(".records.utf8")
        ):
            size = i.find("size")
            if size is not None:
                yield name, int(size.text)
            else:
                yield name, None