Exemplo n.º 1
0
    def __init__(self, xml):

        #If it's a file, we call .read() on it so that it can be consumed twice - once by XMLValidator, and once by
        #beautiful soup
        if not (isinstance(xml, str) or isinstance(xml, unicode)):
            try:
                xml = xml.read()
            except AttributeError as e:
                _logger.critical(repr(e))
                raise error.FlmxCriticalError(repr(e))

        validate_XML(
            xml,
            os.path.join(os.path.dirname(__file__), u'schema',
                         u'schema_facility.xsd'))

        flm = BeautifulSoup(xml, u'xml')

        if flm.FLMPartial and get_boolean(flm.FLMPartial):
            msg = u"Partial FLMs not supported"
            _logger.error(msg)
            raise error.FlmxPartialError(
                u"Partial FLMs are not supported by this parser.")

        self.setup_facility(flm)
Exemplo n.º 2
0
    def __init__(self, xml):

        #If it's a file, we call .read() on it so that it can be consumed twice - once by XMLValidator, and once by
        #beautiful soup
        if not (isinstance(xml, str) or isinstance(xml, unicode)):
            try:
                xml = xml.read()
            except AttributeError as e:
                _logger.critical(repr(e))
                raise error.FlmxCriticalError(repr(e))

        validate_XML(xml, os.path.join(os.path.dirname(__file__), u'schema', u'schema_facility.xsd'))

        flm = BeautifulSoup(xml, u'xml')

        if flm.FLMPartial and get_boolean(flm.FLMPartial):
            msg = u"Partial FLMs not supported"
            _logger.error(msg)
            raise error.FlmxPartialError(u"Partial FLMs are not supported by this parser.")

        self.setup_facility(flm)
Exemplo n.º 3
0
    def __init__(self, xml):
        """Parses an XML sitelist, and constructs a container holding the the XML document's data.

        :param string xml: Either the contents of an XML file, or a file handle.
            This will parse the contents and construct ``sites``.
        :param boolean validate: Defaults to true. If set, will validate the given
            XML file against the Sitelist XML Schema xsd file, as found on the `FLM-x Homepage`.

        """

        #If it's a file, we call .read() on it so that it can be consumed twice - once by XMLValidator, and once by
        #beautiful soup
        if not (isinstance(xml, str) or isinstance(xml, unicode)):
            try:
                xml = xml.read()
            except AttributeError as e:
                _logger.critical(repr(e))
                raise FlmxCriticalError(repr(e))

        validate_XML(
            xml,
            os.path.join(os.path.dirname(__file__), u'schema',
                         u'schema_sitelist.xsd'))

        soup = BeautifulSoup(xml, u"xml")

        self.originator = soup.SiteList.Originator.string
        self.system_name = soup.SiteList.SystemName.string
        facilities = []
        for facility in soup.find_all(u'Facility'):
            facLink = FacilityLink()
            facLink.id_code = facility[u'id']
            # strip the timezone from the ISO timecode
            facLink.last_modified = get_datetime(facility[u'modified'])
            facLink.xlink_href = facility[u'xlink:href']
            facLink.xlink_type = facility[u'xlink:type']

            facilities.append(facLink)
        self.facilities = sorted(facilities, key=attrgetter(u'last_modified'))
Exemplo n.º 4
0
    def __init__(self, xml):
        """Parses an XML sitelist, and constructs a container holding the the XML document's data.

        :param string xml: Either the contents of an XML file, or a file handle.
            This will parse the contents and construct ``sites``.
        :param boolean validate: Defaults to true. If set, will validate the given
            XML file against the Sitelist XML Schema xsd file, as found on the `FLM-x Homepage`.

        """

        #If it's a file, we call .read() on it so that it can be consumed twice - once by XMLValidator, and once by
        #beautiful soup
        if not (isinstance(xml, str) or isinstance(xml, unicode)):
            try:
                xml = xml.read()
            except AttributeError as e:
                _logger.critical(repr(e))
                raise FlmxCriticalError(repr(e))

        validate_XML(xml, os.path.join(os.path.dirname(__file__), os.pardir, u'schema', u'flmx', u'schema_sitelist.xsd'))

        soup = BeautifulSoup(xml, u"xml")

        self.originator = soup.SiteList.Originator.string
        self.system_name = soup.SiteList.SystemName.string
        facilities = []
        for facility in soup.find_all(u'Facility'):
            facLink = FacilityLink()
            facLink.id_code = facility[u'id']
            # strip the timezone from the ISO timecode
            facLink.last_modified = get_datetime(facility[u'modified'])
            facLink.xlink_href = facility[u'xlink:href']
            facLink.xlink_type = facility[u'xlink:type']

            facilities.append(facLink)
        self.facilities = sorted(facilities, key=attrgetter(u'last_modified'))