Exemple #1
0
 def _getRecord(self):
     for oaiid in self.idcache:
         s = "%sverb=GetRecord&%s" % (self.server, urllib.urlencode({'metadataPrefix': self.metadataPrefix, 'identifier': oaiid}))
         resp = self._fetchStream(s)
         data = resp.read()
         doc = StringDocument(data, self.id, mimeType='text/xml')
         rec = BSParser.process_document(None, doc)
         dom = rec.get_dom(session)
         for top in dom.childNodes:
             if top.nodeType == elementType:
                 break
         for c in top.childNodes:
             if (c.nodeType == elementType and c.localName == 'GetRecord'):
                 for c2 in c.childNodes:        
                     if (c2.nodeType == elementType and c2.localName == 'record'):
                         for c3 in c2.childNodes:
                             if (c3.nodeType == elementType and c3.localName == 'metadata'):
                                 for c4 in c3.childNodes:
                                     if (c4.nodeType == elementType):
                                         data = c4.toxml()
                                         yield StringDocument(data, self.id, mimeType='text/xml')
                                         break
                         break
                 break
     raise StopIteration
Exemple #2
0
    def _listIdentifiers(self):
        s = "%sverb=ListIdentifiers&" % (self.server)
        s += urllib.urlencode(self.params)
        resp = self._fetchStream(s)
        data = resp.read()

        # self.lastResponse = resp
        # Now use existing infrastructure to parse
        doc = StringDocument(data, self.id, mimeType='text/xml')
        rec = BSParser.process_document(None, doc)
        dom = rec.get_dom(session)
        for top in dom.childNodes:
            if (top.nodeType == elementType):
                break
        for c in top.childNodes:
            if (c.nodeType == elementType and c.localName == 'ListIdentifiers'):
                for c2 in c.childNodes:
                    if (c2.nodeType == elementType and c2.localName == 'header'):
                        for c3 in c2.childNodes:
                            if (c3.nodeType == elementType and c3.localName == 'identifier'):
                                self.ids.append(getFirstData(c3))
                    elif (c2.nodeType == elementType and c2.localName == 'resumptionToken'):
                        t = getFirstData(c2)
                        if (t):
                            self.token = t
                        try:
                            self.total = c2.getAttr('completeListSize')
                        except:
                            pass
 def _getRecord(self):
     for oaiid in self.idcache:
         s = "%sverb=GetRecord&%s" % (
             self.server,
             urllib.urlencode({
                 'metadataPrefix': self.metadataPrefix,
                 'identifier': oaiid
             }))
         resp = self._fetchStream(s)
         data = resp.read()
         doc = StringDocument(data, self.id, mimeType='text/xml')
         rec = BSParser.process_document(None, doc)
         dom = rec.get_dom(session)
         for top in dom.childNodes:
             if top.nodeType == elementType:
                 break
         for c in top.childNodes:
             if (c.nodeType == elementType and c.localName == 'GetRecord'):
                 for c2 in c.childNodes:
                     if (c2.nodeType == elementType
                             and c2.localName == 'record'):
                         for c3 in c2.childNodes:
                             if (c3.nodeType == elementType
                                     and c3.localName == 'metadata'):
                                 for c4 in c3.childNodes:
                                     if (c4.nodeType == elementType):
                                         data = c4.toxml()
                                         yield StringDocument(
                                             data,
                                             self.id,
                                             mimeType='text/xml')
                                         break
                         break
                 break
     raise StopIteration
    def _listIdentifiers(self):
        s = "%sverb=ListIdentifiers&" % (self.server)
        s += urllib.urlencode(self.params)
        resp = self._fetchStream(s)
        data = resp.read()

        # self.lastResponse = resp
        # Now use existing infrastructure to parse
        doc = StringDocument(data, self.id, mimeType='text/xml')
        rec = BSParser.process_document(None, doc)
        dom = rec.get_dom(session)
        for top in dom.childNodes:
            if (top.nodeType == elementType):
                break
        for c in top.childNodes:
            if (c.nodeType == elementType
                    and c.localName == 'ListIdentifiers'):
                for c2 in c.childNodes:
                    if (c2.nodeType == elementType
                            and c2.localName == 'header'):
                        for c3 in c2.childNodes:
                            if (c3.nodeType == elementType
                                    and c3.localName == 'identifier'):
                                self.ids.append(getFirstData(c3))
                    elif (c2.nodeType == elementType
                          and c2.localName == 'resumptionToken'):
                        t = getFirstData(c2)
                        if (t):
                            self.token = t
                        try:
                            self.total = c2.getAttr('completeListSize')
                        except:
                            pass
Exemple #5
0
    def _getDomFromFile(self, session, fileName, parser=''):
        """Read, parse and return configuration from a file.
        
        Read in an XML file from disk to get the configuration for this 
        object.
        """
        # We need to be able to read in configurations from disk
        if not os.path.exists(fileName):
            raise FileDoesNotExistException(fileName)
        
        f = open(fileName, 'r')
        doc = BootstrapDocument(f)

        # Look on self for instantiated parser, otherwise use bootstrap
        p = self.get_path(session, 'parser', None)
        try:
            if (p is not None):
                record = p.process_document(session, doc)
            elif parser == 'minidom':
                record = BSParser.process_document(session, doc)
            else:
                record = BSLxmlParser.process_document(session, doc)
        except Exception as e:
            raise ConfigFileException("Cannot parse %s: %s" % (fileName, e))
        dom = record.get_dom(session)
        f.close()
        return dom
Exemple #6
0
    def _getDomFromFile(self, session, fileName, parser=''):
        """Read, parse and return configuration from a file.
        
        Read in an XML file from disk to get the configuration for this 
        object.
        """
        # We need to be able to read in configurations from disk
        if not os.path.exists(fileName):
            raise FileDoesNotExistException(fileName)

        f = open(fileName, 'r')
        doc = BootstrapDocument(f)

        # Look on self for instantiated parser, otherwise use bootstrap
        p = self.get_path(session, 'parser', None)
        try:
            if (p is not None):
                record = p.process_document(session, doc)
            elif parser == 'minidom':
                record = BSParser.process_document(session, doc)
            else:
                record = BSLxmlParser.process_document(session, doc)
        except Exception as e:
            raise ConfigFileException("Cannot parse %s: %s" % (fileName, e))
        dom = record.get_dom(session)
        f.close()
        return dom
    def _getDomFromUrl(self, session, url, parser=''):
        """Read, parse and return configuration from a file.

        Read in an XML file to get the configuration for this object.
        """
        # We need to be able to read in configurations
        urlparts = urlsplit(url)
        if urlparts.scheme in ('http', 'https'):
            f = urllib2.urlopen(url)
        elif urlparts.scheme == "irods":
            try:
                from cheshire3.grid.irods_utils import open_irodsUrl
            except ImportError:
                self.log_error(session,
                               "Unable to include file at {0}, "
                               "Missing Dependency: irods (PyRods)"
                               )
                return
            else:
                f = open_irodsUrl(url)
            if not f:
                self.log_error(session,
                               "Unable to include file at {0}, "
                               "File not found".format(url)
                               )
                return
        else:
            if not os.path.isfile(urlparts.path):
                raise FileDoesNotExistException(urlparts.path)
            f = open(urlparts.path, 'r')
        doc = BootstrapDocument(f)
        # Look on self for instantiated parser, otherwise use bootstrap
        p = self.get_path(session, 'parser', None)
        try:
            if (p is not None):
                record = p.process_document(session, doc)
            elif parser == 'minidom':
                record = BSParser.process_document(session, doc)
            else:
                record = BSLxmlParser.process_document(session, doc)
        except Exception as e:
            raise ConfigFileException("Cannot parse %s: %s" % (url, e))
        dom = record.get_dom(session)
        f.close()
        return dom