Skip to content

Commit 319c799

Browse files
authored
Merge pull request #717 from ocefpaf/better_is_url
better _is_url
2 parents ebe74cd + a783fd4 commit 319c799

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

folium/utilities.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010

1111
from six import binary_type, text_type
1212

13-
1413
try:
1514
import numpy as np
1615
except ImportError:
1716
np = None
1817

18+
try:
19+
from urllib.parse import uses_relative, uses_netloc, uses_params, urlparse
20+
except ImportError:
21+
from urlparse import uses_relative, uses_netloc, uses_params, urlparse
22+
23+
24+
_VALID_URLS = set(uses_relative + uses_netloc + uses_params)
25+
_VALID_URLS.discard('')
26+
1927

2028
def _validate_location(location):
2129
"""Validates and formats location values before setting."""
@@ -143,8 +151,12 @@ def image_to_url(image, colormap=None, origin='upper'):
143151
return url.replace('\n', ' ')
144152

145153

146-
def _is_url(name):
147-
return any(scheme in name for scheme in ['http://', 'https://'])
154+
def _is_url(url):
155+
"""Check to see if `url` has a valid protocol."""
156+
try:
157+
return urlparse(url).scheme in _VALID_URLS
158+
except:
159+
return False
148160

149161

150162
def write_png(data, origin='upper', colormap=None):

0 commit comments

Comments
 (0)