mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Use MSIE user-agent, allow passing of headers in.
This commit is contained in:
parent
64b7d0d735
commit
f901a8773a
@ -70,13 +70,16 @@ def strError(e):
|
|||||||
else:
|
else:
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
def getUrlFd(url):
|
_headers = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0)'}
|
||||||
|
def getUrlFd(url, headers=None):
|
||||||
"""Gets a file-like object for a url."""
|
"""Gets a file-like object for a url."""
|
||||||
|
if headers is None:
|
||||||
|
headers = _headers
|
||||||
try:
|
try:
|
||||||
if not isinstance(url, urllib2.Request):
|
if not isinstance(url, urllib2.Request):
|
||||||
if '#' in url:
|
if '#' in url:
|
||||||
url = url[:url.index('#')]
|
url = url[:url.index('#')]
|
||||||
request = urllib2.Request(url)
|
request = urllib2.Request(url, headers=headers)
|
||||||
else:
|
else:
|
||||||
request = url
|
request = url
|
||||||
httpProxy = conf.supybot.protocols.http.proxy()
|
httpProxy = conf.supybot.protocols.http.proxy()
|
||||||
@ -88,14 +91,14 @@ def getUrlFd(url):
|
|||||||
raise WebError, TIMED_OUT
|
raise WebError, TIMED_OUT
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
raise WebError, strError(e)
|
raise WebError, strError(e)
|
||||||
except urllib2.URLError, e:
|
|
||||||
raise WebError, strError(e.reason[1])
|
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
raise WebError, strError(e)
|
raise WebError, strError(e)
|
||||||
|
except urllib2.URLError, e:
|
||||||
|
raise WebError, strError(e.reason[1])
|
||||||
|
|
||||||
def getUrl(url, size=None):
|
def getUrl(url, size=None, headers=None):
|
||||||
"""Gets a page. Returns a string that is the page gotten."""
|
"""Gets a page. Returns a string that is the page gotten."""
|
||||||
fd = getUrlFd(url)
|
fd = getUrlFd(url, headers=headers)
|
||||||
try:
|
try:
|
||||||
if size is None:
|
if size is None:
|
||||||
text = fd.read()
|
text = fd.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user