mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 11:12:47 +01:00
Revert "Web: Disable @title and @doctype for non-HTML documents." (incompatible with Python 2)
This reverts commit 34b0e5faad
.
This commit is contained in:
parent
8d7b06efd1
commit
18cc1ff3bb
@ -210,15 +210,8 @@ class Web(callbacks.PluginRegexp):
|
|||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
fd = utils.web.getUrlFd(url)
|
s = utils.web.getUrl(url, size=size) \
|
||||||
content_type = fd.getheader('Content-type', 'text/html') \
|
.decode('utf8')
|
||||||
.split(';', 1)[0]
|
|
||||||
if content_type not in ('text/html', 'application/xhtml+xml',
|
|
||||||
'application/xhtml'):
|
|
||||||
irc.error(_('This is not an HTML page (content type is %r)') %
|
|
||||||
content_type)
|
|
||||||
return
|
|
||||||
s = fd.read(size).decode('utf8')
|
|
||||||
m = self._doctypeRe.search(s)
|
m = self._doctypeRe.search(s)
|
||||||
if m:
|
if m:
|
||||||
s = utils.str.normalizeWhitespace(m.group(0))
|
s = utils.str.normalizeWhitespace(m.group(0))
|
||||||
@ -271,15 +264,7 @@ class Web(callbacks.PluginRegexp):
|
|||||||
irc.error("This url is not on the whitelist.")
|
irc.error("This url is not on the whitelist.")
|
||||||
return
|
return
|
||||||
size = conf.supybot.protocols.http.peekSize()
|
size = conf.supybot.protocols.http.peekSize()
|
||||||
fd = utils.web.getUrlFd(url)
|
text = utils.web.getUrl(url, size=size)
|
||||||
content_type = fd.getheader('Content-type', 'text/html') \
|
|
||||||
.split(';', 1)[0]
|
|
||||||
if content_type not in ('text/html', 'application/xhtml+xml',
|
|
||||||
'application/xhtml'):
|
|
||||||
irc.error(_('This is not an HTML page (content type is %r)') %
|
|
||||||
content_type)
|
|
||||||
return
|
|
||||||
text = fd.read(size)
|
|
||||||
try:
|
try:
|
||||||
text = text.decode(utils.web.getEncoding(text) or 'utf8',
|
text = text.decode(utils.web.getEncoding(text) or 'utf8',
|
||||||
'replace')
|
'replace')
|
||||||
|
@ -40,8 +40,6 @@ class WebTestCase(ChannelPluginTestCase):
|
|||||||
def testDoctype(self):
|
def testDoctype(self):
|
||||||
self.assertError('doctype ftp://ftp.cdrom.com/pub/linux')
|
self.assertError('doctype ftp://ftp.cdrom.com/pub/linux')
|
||||||
self.assertNotError('doctype http://www.slashdot.org/')
|
self.assertNotError('doctype http://www.slashdot.org/')
|
||||||
self.assertRegexp('doctype http://www.google.com/favicon.ico',
|
|
||||||
'Error.*not an HTML page')
|
|
||||||
m = self.getMsg('doctype http://moobot.sf.net/')
|
m = self.getMsg('doctype http://moobot.sf.net/')
|
||||||
self.failUnless(m.args[1].endswith('>'))
|
self.failUnless(m.args[1].endswith('>'))
|
||||||
|
|
||||||
@ -53,8 +51,6 @@ class WebTestCase(ChannelPluginTestCase):
|
|||||||
def testTitle(self):
|
def testTitle(self):
|
||||||
self.assertRegexp('title http://www.slashdot.org/',
|
self.assertRegexp('title http://www.slashdot.org/',
|
||||||
'News for nerds, stuff that matters')
|
'News for nerds, stuff that matters')
|
||||||
self.assertRegexp('doctype http://www.google.com/favicon.ico',
|
|
||||||
'Error.*not an HTML page')
|
|
||||||
# Checks for @title not-working correctly
|
# Checks for @title not-working correctly
|
||||||
self.assertResponse('title '
|
self.assertResponse('title '
|
||||||
'http://www.catb.org/~esr/jargon/html/F/foo.html',
|
'http://www.catb.org/~esr/jargon/html/F/foo.html',
|
||||||
|
Loading…
Reference in New Issue
Block a user