matplotlib/matplotlib — pull request #1650 by mdboom (2013-01-10 15:12:22+00:00)
Title: _png.read_png crashes on Python 3 with urllib.request object

The following code crashes on Python 3.x but not on Python 2.x (verified on Windows with mpl 1.2.0):

```
url = 'http://www.libpng.org/pub/png/img_png/pngnow.png'
try:
import urllib2
data = urllib2.urlopen(url)
except Exception:
import urllib.request
data = urllib.request.urlopen(url)

from matplotlib import pyplot

image = pyplot.imread(data) # crash on py3.x
pyplot.imshow(image)
pyplot.show()
```

The crash is at [_png.cpp line 328](https://github.com/matplotlib/matplotlib/blob/master/src/_png.cpp#L328)

Maybe using [numpy's `npy_PyFile_*` functions](https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/npy_3kcompat.h#L141) could help. A lot of thought has gone into those functions.