Skip to content

Commit

Permalink
Update for requests 2.11 compatibility; document requests version
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Aug 8, 2016
1 parent de36a95 commit 1f7275d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The following is a summary of changes and improvements to

.. New features in each version should be listed, with any necessary information about installation or upgrade notes.
1.8 (prelim)
------------

* Fix UTF-8 issue introduced in 1.5 (see discussion on
`PR #21 <https://github.com/emory-libraries/eulfedora/pull/22>`_)
* Updated for compatibility with requests 2.11

1.7.1
-----

Expand Down Expand Up @@ -74,6 +81,7 @@ The following is a summary of changes and improvements to
and better handling for large objects.
* Upload API method (:meth:`eulfedoa.api.REST_API.upload`) now supports
iterable content with known size.
* Updated to require requests 2.9 or greater.

1.4
---
Expand Down
11 changes: 8 additions & 3 deletions eulfedora/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def __init__(self, base_url, username=None, password=None, retries=None):
# NOTE: only headers that will be common for *all* requests
# to this fedora should be set in the session
# (i.e., do NOT include auth information here)

# NOTE: ssl verification is turned on by default

self.session.headers = {
# use requests-toolbelt user agent
'User-Agent': user_agent('eulfedora', eulfedora_version),
# 'user-agent': 'eulfedora/%s (python-requests/%s)' % \
# (eulfedora_version, requests.__version__),
'verify': True, # verify SSL certs by default
}
# no retries is requests current default behavior, so only
# customize if a value is set
Expand Down Expand Up @@ -865,7 +866,11 @@ def upload(self, data, callback=None, content_type=None,
menc = MultipartEncoderMonitor(menc, callback)

headers = {'Content-Type': menc.content_type}

if size:
# latest version of requests requires str or bytes, not int
if not isinstance(size, six.string_types):
size = str(size)
headers['Content-Length'] = size

try:
Expand Down
3 changes: 2 additions & 1 deletion test/test_fedora/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,8 @@ def data_generator():
content_md5 = md5sum(text_content)
size = len(text_content)

upload_id = self.rest_api.upload(data_generator(), size=size, content_type='text/plain')
upload_id = self.rest_api.upload(data_generator(), size=size,
content_type='text/plain')
pattern = re.compile('uploaded://[0-9]+')
self.assertTrue(pattern.match(upload_id))

Expand Down

0 comments on commit 1f7275d

Please sign in to comment.