コード例 #1
0
ファイル: client.py プロジェクト: gosiqueira/oai-crawler
 def makeRequestErrorHandling(self, **kw):
     xml = self.makeRequest(**kw)
     try:
         tree = self.parse(xml)
     except SyntaxError:
         raise error.XMLSyntaxError(kw)
     # check whether there are errors first
     e_errors = tree.xpath('/oai:OAI-PMH/oai:error',
                           namespaces=self.getNamespaces())
     if e_errors:
         # XXX right now only raise first error found, does not
         # collect error info
         for e_error in e_errors:
             code = e_error.get('code')
             msg = e_error.text
             if code not in ['badArgument', 'badResumptionToken',
                             'badVerb', 'cannotDisseminateFormat',
                             'idDoesNotExist', 'noRecordsMatch',
                             'noMetadataFormats', 'noSetHierarchy']:
                 raise error.UnknownError(
                       "Unknown error code from server: %s, message: %s" % (
                     code, msg))
             # find exception in error module and raise with msg
             raise getattr(error, code[0].upper() + code[1:] + 'Error')(msg)
     return tree
コード例 #2
0
def test_document(filepath):
    xml = open(os.path.join(directory, "fake6/" + filepath))
    try:
        tree = fakeclient.parse(xml.read())
    except SyntaxError, e:
        raise error.XMLSyntaxError(e)