Skip to content

Commit 68c2e00

Browse files
committed
fixed a bug that prevented protocolless urls from being parsed
1 parent d0735c7 commit 68c2e00

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ v0.2.0, 2014-12-22 --
5757
- _score was called multiple times when it shouldn't have been
5858
- connections were not explicitly closed which caused performance
5959
issues
60+
- Fixed URLs specified without protocol
6061
- Removed README.md and moved README.txt to README.rst.

imageresolver/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
ImageResolver
3-
Copyright 2014 Constituent Voice
3+
Copyright 2014 Constituent Voice LLC
4+
http://constituentvoice.com/
5+
http://github.com/constituentvoice
46
57
ImageResolver is a port of the excellent ImageResolver
68
javascript library by Maurice Svay
@@ -115,7 +117,7 @@ def fetch_image_info(self,url):
115117
return ext,width,height
116118
else:
117119
logger.debug('Fetch failed with status code ' + str(r.status_code))
118-
raise HTTPException('Fetch image failed with status code ' + str(r.status_code))
120+
raise HTTPException('Fetch image %s failed with status code %d' % (url,r.status_code))
119121

120122

121123
def register(self,f):
@@ -251,6 +253,9 @@ def resolve(self,url,**kwargs):
251253
src_cache = {}
252254

253255
logger.debug('Found ' + str( len(images) ) + ' candidate images')
256+
257+
# get url parts for building image srcs
258+
parts = urlparse(url)
254259

255260
for i in images:
256261
surface = 0
@@ -269,10 +274,13 @@ def resolve(self,url,**kwargs):
269274
# skip data urls
270275
continue
271276
else:
272-
parts = urlparse(url)
273277

274278
if src[0] == '/':
275-
src = parts.scheme + '://' + parts.netloc + src
279+
# check protocol-less urls
280+
if src[1] == '/':
281+
src = parts.scheme + ':' + src
282+
else:
283+
src = parts.scheme + '://' + parts.netloc + src
276284
else:
277285
path = os.path.dirname(parts.path)
278286
src = parts.scheme + '://' + parts.netloc + path + '/' + src

0 commit comments

Comments
 (0)