示例#1
0
def fake_gcn(notice_type):
    # Check the real GCN notice, which is valid.
    payload = resources.read_binary(data, 'G298048-1-Initial.xml')
    root = lxml.etree.fromstring(payload)
    notice_type = str(int(notice_type))
    root.find(".//Param[@name='Packet_Type']").attrib['value'] = notice_type
    return xml_document(root)
示例#2
0
文件: gcn.py 项目: lpsinger/gwcelery
def send(self, message):
    """Send a VOEvent to GCN.

    This task will be retried several times if the VOEvent cannot be sent. See
    the Raises section below for circumstances that cause a retry.

    Parameters
    ----------
    message : bytes
        The raw VOEvent file contents.

    Raises
    ------
    SendingError
        If the VOEvent could not be sent because there were no network peers
        connected to the VOEvent broadcaster.

    """
    broadcasters = self.app.conf['voevent_broadcaster_factory'].broadcasters
    if broadcasters:
        event = xml_document(message)
        for broadcaster in broadcasters:
            reactor.callFromThread(broadcaster.send_event, event)
    elif self.app.conf['voevent_broadcaster_whitelist']:
        raise SendingError('Not sending the event because there are no '
                           'subscribers connected to the GCN broker.')
示例#3
0
def broker_test_message(ivo):
    """
    Test message which is regularly broadcast to all subscribers.
    """
    root_element = ElementTree.Element("{http://www.ivoa.net/xml/VOEvent/v2.0}VOEvent",
        attrib={
            "ivorn": ivo + "#TestEvent-%s" % datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"),
            "role": "test",
            "version": "2.0",
            "{http://www.w3.org/2001/XMLSchema-instance}schemaLocation": "http://www.ivoa.net/xml/VOEvent/v2.0 http://www.ivoa.net/xml/VOEvent/VOEvent-v2.0.xsd"
        }
    )
    who = ElementTree.SubElement(root_element, "Who")
    author_ivorn = ElementTree.SubElement(who, "AuthorIVORN")
    author_ivorn.text = ivo
    date = ElementTree.SubElement(who, "Date")
    date.text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%f")
    what = ElementTree.SubElement(root_element, "What")
    description =  ElementTree.SubElement(what, "Description")
    description.text = "Broker test event generated by Comet %s." % (__version__,)
    ElementTree.SubElement(what, "Reference", uri=__url__)
    return xml_document(root_element)
示例#4
0
文件: voevent.py 项目: sipior/Comet
def broker_test_message(ivo):
    """
    Test message which is regularly broadcast to all subscribers.
    """
    root_element = ElementTree.Element("{http://www.ivoa.net/xml/VOEvent/v2.0}VOEvent",
        attrib={
            "ivorn": ivo + "#TestEvent-%s" % datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
            "role": "test",
            "version": "2.0",
            "{http://www.w3.org/2001/XMLSchema-instance}schemaLocation": "http://www.ivoa.net/xml/VOEvent/v2.0 http://www.ivoa.net/xml/VOEvent/VOEvent-v2.0.xsd"
        }
    )
    who = ElementTree.SubElement(root_element, "Who")
    author_ivoid = ElementTree.SubElement(who, "AuthorIVORN")
    author_ivoid.text = ivo
    date = ElementTree.SubElement(who, "Date")
    date.text = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
    what = ElementTree.SubElement(root_element, "What")
    description =  ElementTree.SubElement(what, "Description")
    description.text = "Broker test event generated by Comet %s." % (__version__,)
    ElementTree.SubElement(what, "Reference", uri=__url__)
    return xml_document(root_element)