Merge pull request #1928 from kived/loader-url-fix-py3k

Loader: fix for py3k, allow override via URL fragment
This commit is contained in:
akshayaurora 2014-03-04 13:28:35 +05:30
commit de3ea73ec3
1 changed files with 21 additions and 11 deletions

View File

@ -281,8 +281,14 @@ class LoaderBase(object):
temporary file, and pass it to _load_local().'''
if PY2:
import urllib2 as urllib_request
def gettype(info):
return info.gettype()
else:
import urllib.request as urllib_request
def gettype(info):
return info.get_content_type()
proto = filename.split(':', 1)[0]
if proto == 'smb':
try:
@ -305,7 +311,11 @@ class LoaderBase(object):
# read from internet
fd = urllib_request.urlopen(filename)
ctype = fd.info().gettype()
if '#.' in filename:
# allow extension override from URL fragment
suffix = '.' + filename.split('#.')[-1]
else:
ctype = gettype(fd.info())
suffix = mimetypes.guess_extension(ctype)
if not suffix:
# strip query string and split on path