This is an alternative implementation for `Image.open()`
to support opening of images from HttpResponse objects. It
uses `.seekable()` to determine whether the file supports
seeking (with failover for this attribute not being supported
e.g. in `urllib2` response objects).
The prefix is chopped off as normal and pre-pended back onto
the bytes fed into the `io.IOBytes` object. This avoids loading
the image object totally (duplicating it in memory) until
we are sure we have a factory for the file.
Add AttributeError exception catch; add io.IOBytes wrapper only once
Add callable .seek test for Python2.x
No ci skip here because let's see CI run w/new version numbers. I'm starting to think (again) this bump should happen immediately after the release instead of right before the next? But I know @wiredfool had some objection to this at some point. As a compromise, maybe we could change to 2.9.0dev immediately following the release of 2.8.0.
HTTP response objects returned from `urllib2.urlopen(url)` or
`requests.get(url, stream=True).raw` are 'file-like' but do not
support `.seek()` operations. As a result PIL is unable to
open them as images, requiring a wrap in `cStringIO` or `BytesIO`.
This commit adds this functionality to `Image.open()` by way of
an `.seek(0)` check and catch on exception
`AttributeError` or `io.UnsupportedOperation`. If this is caught
we attempt to wrap the object using `io.BytesIO` (which will
only work on buffer-file-like objects).
This allows opening of files using both `urllib2` and `requests`, e.g.
Image.open(urllib2.urlopen(url))
Image.open(requests.get(url, stream=True).raw)
I've not liked the "plain" readme for the last few releases, so I've adjusted things hopefully for the better:
- Rename/add section headers
- Divide content into two sections
- Provide bulleted list with most important links e.g. "install"