Skip to content

Commit f228058

Browse files
committed
Update Entry object to accept existing xml, dump content on connection error, add
-Entry object can now take existing xml as its starting point -fixed a bug in service_document that prevented connections to DSpace (and DASH) sword servers.
1 parent bdff8b4 commit f228058

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ dist/
44
sword2.egg-info/
55
*.pyc
66
*.py~
7-
7+
*.conf
88

99
.DS_Store

sword2/atom_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,15 @@ class Entry(object):
156156
xmlns:dcterms="http://purl.org/dc/terms/">
157157
<generator uri="http://bitbucket.org/beno/python-sword2" version="%s"/>
158158
</entry>""" % __version__
159-
def __init__(self, **kw):
159+
def __init__(self, atomEntryXml=None, **kw):
160160
"""Create a basic `Entry` document, setting the generator and a timestamp for the updated element value.
161161
162162
Any keyword parameters passed in will be passed to the add_fields method and added to the entry
163163
bootstrap document. It's currently not possible to add a namespace and use it within the init call."""
164164

165165
# create a namespace map which we'll use in all of the elements
166166
self.nsmap = {"dcterms" : "http://purl.org/dc/terms/", "atom" : "http://www.w3.org/2005/Atom"}
167-
self.entry = etree.fromstring(self.bootstrap)
167+
self.entry = etree.fromstring(self.bootstrap if not atomEntryXml else atomEntryXml)
168168
if not 'updated' in kw.keys():
169169
kw['updated'] = datetime.now().isoformat()
170170
self.add_fields(**kw)

sword2/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def _return_error_or_exception(self, cls, resp, content):
257257
258258
`self.raise_except` can be altered at any time to affect this methods behaviour."""
259259
if self.raise_except:
260-
raise cls(resp)
260+
raise cls(resp, content)
261261
else:
262262
# content type can contain both the mimetype and the charset (e.g. text/xml; charset=utf-8)
263263
if resp['content-type'].startswith("text/xml") or resp['content-type'].startswith("application/xml"):
@@ -312,7 +312,7 @@ def _handle_error_response(self, resp, content):
312312
conn_l.error("Server error occured. Response headers from the server:\n%s" % resp)
313313
return self._return_error_or_exception(ServerError, resp, content)
314314
else:
315-
conn_l.error("Unknown error occured. Response headers from the server:\n%s" % resp)
315+
conn_l.error("Unknown error occured. Response headers from the server:\n%s\n%s" % (resp, content))
316316
return self._return_error_or_exception(HTTPResponseError, resp, content)
317317

318318
def _cache_deposit_receipt(self, d):

sword2/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
class HTTPResponseError(Exception):
88
"""Generic exception for http codes greater than 399 and less than 599 """
9-
def __init__(self, response=None):
9+
def __init__(self, response=None, content=None):
1010
self.response = response
11+
self.content = content
1112

1213
class ServerError(HTTPResponseError):
1314
""" for http error codes 500 and up """

sword2/service_document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def validate(self):
149149
for accept in accepts:
150150
multipart = accept.get("alternate")
151151
if multipart is not None:
152-
if multipart != "multipart-related":
152+
if multipart != "multipart-related" and multipart != "multipart/related":
153153
multipart_accept_valid = False
154154
sd_l.debug("Multipart accept alternate is incorrect: " + str(multipart))
155155
else:

0 commit comments

Comments
 (0)