diff options
Diffstat (limited to 'powerline/lib/url.py')
-rw-r--r-- | powerline/lib/url.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/powerline/lib/url.py b/powerline/lib/url.py new file mode 100644 index 0000000..f25919c --- /dev/null +++ b/powerline/lib/url.py @@ -0,0 +1,17 @@ +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +try: + from urllib.error import HTTPError # NOQA + from urllib.request import urlopen # NOQA + from urllib.parse import urlencode as urllib_urlencode # NOQA +except ImportError: + from urllib2 import urlopen, HTTPError # NOQA + from urllib import urlencode as urllib_urlencode # NOQA + + +def urllib_read(url): + try: + return urlopen(url, timeout=10).read().decode('utf-8') + except HTTPError: + return |