comparison sword2-libraries-pyinstaller-compatible/sword2/error_document.py @ 16:8b69bba225c9

Added pyinstaller compatible sword2 python libraries
author Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk>
date Tue, 29 May 2012 12:42:49 +0100
parents
children
comparison
equal deleted inserted replaced
15:e24aea2d14a4 16:8b69bba225c9
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Provides a convenience class for handling and parsing Error Document responses.
5 """
6
7 from deposit_receipt import Deposit_Receipt
8 from server_errors import SWORD2ERRORSBYIRI, get_error
9
10 class Error_Document(Deposit_Receipt):
11 """
12 Example Error document:
13
14 <?xml version="1.0" encoding="utf-8"?>
15 <sword:error xmlns="http://www.w3.org/2005/Atom"
16 xmlns:sword="http://purl.org/net/sword/"
17 xmlns:arxiv="http://arxiv.org/schemas/atom"
18 href="http://example.org/errors/BadManifest">
19 <author>
20 <name>Example repository</name>
21 </author>
22 <title>ERROR</title>
23 <updated>2008-02-19T09:34:27Z</updated>
24
25 <generator uri="https://example.org/sword-app/"
26 version="0.9">sword@example.org</generator>
27
28 <summary>The manifest could be parsed, but was not valid -
29 no technical metadata was provided.</summary>
30 <sword:treatment>processing failed</sword:treatment>
31 <sword:verboseDescription>
32 Exception at [ ... ]
33 </sword:verboseDescription>
34 <link rel="alternate" href="https://arxiv.org/help" type="text/html"/>
35
36 </sword:error>
37
38
39 Error document is an AtomPub extension:
40
41 The sword:error element MAY contain any of the elements normally used in the Deposit Receipt, but all fields are OPTIONAL.
42
43 The error document SHOULD contain an atom:summary element with a short description of the error.
44
45 The error document MAY contain a sword:verboseDescription element with a long description of the problem or any other appropriate software-level debugging output (e.g. a stack trace). Server implementations may wish to provide this for client developers' convenience, but may wish to disable such output in any production systems.
46
47 The server SHOULD specify that the Content-Type of the is text/xml or application/xml.
48 """
49 def __init__(self, xml_deposit_receipt=None, code=None, resp=None):
50 if xml_deposit_receipt:
51 super(Error_Document, self).__init__(xml_deposit_receipt)
52 else:
53 super(Error_Document, self).__init__("""<?xml version="1.0" encoding="utf-8"?>
54 <sword:error xmlns:sword="http://purl.org/net/sword/"/>""")
55 self.error_href = None
56 self.error_info = None
57 self.verboseDescription = None
58 self.content = None # for parity with the ContentWrapper
59 self.code = code
60 self.response_headers = resp
61 self._characterise_error()
62
63 def _characterise_error(self):
64 if "sword_verboseDescription" in self.metadata.keys():
65 self.verboseDescription = self.metadata['sword_verboseDescription']
66 if "href" in self.dom.attrib.keys():
67 self.error_href = self.dom.attrib['href']
68 self.error_info = get_error(self.error_href, self.code)