mirror of
https://github.com/powerline/powerline.git
synced 2025-07-05 21:14:55 +02:00
Refactor powerline.lib.url
This commit is contained in:
parent
df19981f65
commit
6f679e08aa
@ -1,26 +1,16 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
|
|
||||||
|
try:
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
from urllib.request import urlopen
|
||||||
|
from urllib.parse import urlencode as urllib_urlencode # NOQA
|
||||||
|
except ImportError:
|
||||||
|
from urllib2 import urlopen, HTTPError
|
||||||
|
from urllib import urlencode as urllib_urlencode # NOQA
|
||||||
|
|
||||||
|
|
||||||
def urllib_read(url):
|
def urllib_read(url):
|
||||||
try:
|
try:
|
||||||
import urllib.error
|
return urlopen(url, timeout=100).read().decode('utf-8')
|
||||||
import urllib.request
|
except HTTPError:
|
||||||
try:
|
|
||||||
return urllib.request.urlopen(url, timeout=5).read().decode('utf-8')
|
|
||||||
except:
|
|
||||||
return
|
return
|
||||||
except ImportError:
|
|
||||||
import urllib2
|
|
||||||
try:
|
|
||||||
return urllib2.urlopen(url, timeout=5).read()
|
|
||||||
except:
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def urllib_urlencode(string):
|
|
||||||
try:
|
|
||||||
import urllib.parse
|
|
||||||
return urllib.parse.urlencode(string)
|
|
||||||
except ImportError:
|
|
||||||
import urllib
|
|
||||||
return urllib.urlencode(string)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user