mirror of https://github.com/Mikaela/Limnoria.git
Web: Implement protocols.http.requestLanguage
This commit is contained in:
parent
62f8b47e61
commit
ae5ad2ceab
|
@ -146,12 +146,20 @@ class Web(callbacks.PluginRegexp):
|
||||||
def noIgnore(self, irc, msg):
|
def noIgnore(self, irc, msg):
|
||||||
return not self.registryValue('checkIgnored', msg.channel, irc.network)
|
return not self.registryValue('checkIgnored', msg.channel, irc.network)
|
||||||
|
|
||||||
def getTitle(self, irc, url, raiseErrors):
|
def getTitle(self, irc, url, raiseErrors, msg):
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
timeout = self.registryValue('timeout')
|
timeout = self.registryValue('timeout')
|
||||||
|
headers = dict(utils.web.defaultHeaders)
|
||||||
|
language = conf.supybot.protocols.http.requestLanguage.getSpecific(
|
||||||
|
irc.network, msg.channel)()
|
||||||
|
lkey = 'Accept-Language'
|
||||||
|
if language:
|
||||||
|
headers[lkey] = language
|
||||||
|
elif lkey in headers:
|
||||||
|
del headers[lkey]
|
||||||
try:
|
try:
|
||||||
(target, text) = utils.web.getUrlTargetAndContent(url, size=size,
|
(target, text) = utils.web.getUrlTargetAndContent(url, size=size,
|
||||||
timeout=timeout)
|
timeout=timeout, headers=headers)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if raiseErrors:
|
if raiseErrors:
|
||||||
irc.error(_('That URL raised <' + str(e)) + '>',
|
irc.error(_('That URL raised <' + str(e)) + '>',
|
||||||
|
@ -217,7 +225,7 @@ class Web(callbacks.PluginRegexp):
|
||||||
if r and r.search(url):
|
if r and r.search(url):
|
||||||
self.log.debug('Not titleSnarfing %q.', url)
|
self.log.debug('Not titleSnarfing %q.', url)
|
||||||
return
|
return
|
||||||
r = self.getTitle(irc, url, False)
|
r = self.getTitle(irc, url, False, msg)
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
(target, title) = r
|
(target, title) = r
|
||||||
|
@ -342,7 +350,7 @@ class Web(callbacks.PluginRegexp):
|
||||||
if not self._checkURLWhitelist(url):
|
if not self._checkURLWhitelist(url):
|
||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
r = self.getTitle(irc, url, True)
|
r = self.getTitle(irc, url, True, msg)
|
||||||
if not r:
|
if not r:
|
||||||
return
|
return
|
||||||
(target, title) = r
|
(target, title) = r
|
||||||
|
|
Loading…
Reference in New Issue