예제 #1
0
    def return_service_descriptors(self):
        '''
        basic service information

        title
        abtract

        note: what to do about keywords (thesaurus + list + type)?
        keywords

        '''
        service_elements = {}
        for k, v in self._service_descriptors.iteritems():
            # v can be a list of possible xpaths where we want
            # to keep all returned values from any xpath within
            items = []
            xpaths = v if isinstance(v, list) else [v]
            for xp in xpaths:
                if '@' in xp[-1]:
                    items = extract_attribs(self.parser.xml, xp)
                else:
                    items += extract_items(self.parser.xml, xp)

            service_elements[k] = items

        endpoints = self.parse_endpoints()
        if endpoints:
            service_elements['endpoints'] = endpoints
        return service_elements
    def return_service_descriptors(self):
        '''
        basic service information

        title
        abtract

        note: what to do about keywords (thesaurus + list + type)?
        keywords

        '''
        service_elements = {}
        for k, v in self._service_descriptors.iteritems():
            # v can be a list of possible xpaths where we want
            # to keep all returned values from any xpath within
            items = []
            xpaths = v if isinstance(v, list) else [v]
            for xp in xpaths:
                if '@' in xp[-1]:
                    items = extract_attribs(self.parser.xml, xp)
                else:
                    items += extract_items(self.parser.xml, xp)

            service_elements[k] = items

        endpoints = self.parse_endpoints()
        if endpoints:
            service_elements['endpoints'] = endpoints
        return service_elements
    def _pull_schemas(self, xml):
        xpaths = [["//*", "@schemaLocation"], ["//*", "@noNamespaceSchemaLocation"]]
        schemas = []
        for xp in xpaths:
            schemas += extract_attribs(xml, xp)

        # and, for older fgdc, try to get the dtd
        try:
            docinfo = xml.getroottree().docinfo
            sys_url = docinfo.system_url
            if sys_url:
                schemas.append(sys_url)
        except:
            pass

        # TODO: this might not split everything successfully
        return [a.strip() for s in schemas for a in s.split() if s] if schemas else []
    def _pull_schemas(self, xml):
        xpaths = [['//*', '@schemaLocation'],
                  ['//*', '@noNamespaceSchemaLocation']]
        schemas = []
        for xp in xpaths:
            schemas += extract_attribs(xml, xp)

        # and, for older fgdc, try to get the dtd
        try:
            docinfo = xml.getroottree().docinfo
            sys_url = docinfo.system_url
            if sys_url:
                schemas.append(sys_url)
        except:
            pass

        # TODO: this might not split everything successfully
        return [a.strip() for s in schemas for a in s.split()
                if s] if schemas else []