Merge branch 'testing' of github.com:ProgVal/Limnoria into testing

This commit is contained in:
Valentin Lorentz 2013-11-26 16:59:05 +01:00
commit b673cdb037
8 changed files with 57 additions and 27 deletions

View File

@ -7,7 +7,7 @@ python:
- "pypy" - "pypy"
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: install:
- pip install pytz feedparser charade sqlalchemy python-gnupg --use-mirrors - pip install pytz feedparser charade sqlalchemy python-gnupg python-dateutil --use-mirrors
# command to run tests, e.g. python setup.py test # command to run tests, e.g. python setup.py test
script: script:
- echo $TRAVIS_PYTHON_VERSION - echo $TRAVIS_PYTHON_VERSION

View File

@ -358,9 +358,11 @@ class ChannelStats(callbacks.Plugin):
Returns the statistics for <channel>. <channel> is only necessary if Returns the statistics for <channel>. <channel> is only necessary if
the message isn't sent on the channel itself. the message isn't sent on the channel itself.
""" """
if msg.nick not in irc.state.channels[channel].users: if channel not in irc.state.channels:
irc.error(format('You must be in %s to use this command.', channel)) irc.error(_('I am not in %s.', channel), Raise=True)
return elif msg.nick not in irc.state.channels[channel].users:
irc.error(_('You must be in %s to use this command.') % channel,
Raise=True)
try: try:
channeldb = conf.supybot.databases.plugins.channelSpecific. \ channeldb = conf.supybot.databases.plugins.channelSpecific. \
getChannelLink(channel) getChannelLink(channel)

View File

@ -254,6 +254,10 @@ repositories = {
'Jonimoose', 'Jonimoose',
'Supybot-plugins', 'Supybot-plugins',
), ),
'skgsergio': GithubRepository(
'skgsergio',
'Limnoria-plugins',
),
} }
class PluginDownloader(callbacks.Plugin): class PluginDownloader(callbacks.Plugin):

View File

@ -31,8 +31,6 @@ import time
TIME = time # For later use. TIME = time # For later use.
from datetime import datetime from datetime import datetime
from dateutil import parser
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
@ -40,6 +38,9 @@ import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Time') _ = PluginInternationalization('Time')
try:
from dateutil import parser
def parse(s): def parse(s):
todo = [] todo = []
s = s.replace('noon', '12:00') s = s.replace('noon', '12:00')
@ -54,6 +55,8 @@ def parse(s):
for f in todo: for f in todo:
i = f(i) i = f(i)
return i return i
except ImportError:
parse = None
class Time(callbacks.Plugin): class Time(callbacks.Plugin):
@internationalizeDocstring @internationalizeDocstring
@ -99,6 +102,9 @@ class Time(callbacks.Plugin):
<time string> can be any number of natural formats; just try something <time string> can be any number of natural formats; just try something
and see if it will work. and see if it will work.
""" """
if not parse:
irc.error(_('This command is not available on this bot, ask the '
'owner to install the python-dateutil library.'), Raise=True)
now = int(time.time()) now = int(time.time())
new = parse(s) new = parse(s)
if new != now: if new != now:
@ -113,6 +119,9 @@ class Time(callbacks.Plugin):
Returns the number of seconds until <time string>. Returns the number of seconds until <time string>.
""" """
if not parse:
irc.error(_('This command is not available on this bot, ask the '
'owner to install the python-dateutil library.'), Raise=True)
now = int(time.time()) now = int(time.time())
new = parse(s) new = parse(s)
if new != now: if new != now:

View File

@ -52,6 +52,10 @@ conf.registerChannelValue(Web, 'titleSnarfer',
conf.registerChannelValue(Web, 'snarferReportIOExceptions', conf.registerChannelValue(Web, 'snarferReportIOExceptions',
registry.Boolean(False, _("""Determines whether the bot will notfiy the user registry.Boolean(False, _("""Determines whether the bot will notfiy the user
about network exceptions like hostnotfound, timeout ...."""))) about network exceptions like hostnotfound, timeout ....""")))
conf.registerChannelValue(Web, 'snarferShowTargetDomain',
registry.Boolean(False, _("""Determines whether the domain name displayed
by the snarfer will be the original one (posted on IRC) or the target one
(got after following redirects, if any).""")))
conf.registerChannelValue(Web, 'nonSnarfingRegexp', conf.registerChannelValue(Web, 'nonSnarfingRegexp',
registry.Regexp(None, _("""Determines what URLs matching the given regexp registry.Regexp(None, _("""Determines what URLs matching the given regexp
will not be snarfed. Give the empty string if you have no URLs that you'd will not be snarfed. Give the empty string if you have no URLs that you'd

View File

@ -131,11 +131,13 @@ class Web(callbacks.PluginRegexp):
return return
try: try:
size = conf.supybot.protocols.http.peekSize() size = conf.supybot.protocols.http.peekSize()
text = utils.web.getUrl(url, size=size) fd = utils.web.getUrlFd(url)
except utils.web.Error, e: text = fd.read(size)
fd.close()
except socket.timeout, e:
self.log.info('Couldn\'t snarf title of %u: %s.', url, e) self.log.info('Couldn\'t snarf title of %u: %s.', url, e)
if self.registryValue('snarferReportIOExceptions', channel): if self.registryValue('snarferReportIOExceptions', channel):
irc.reply(url+" : "+utils.web.strError(e), prefixNick=False) irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False)
return return
try: try:
text = text.decode(utils.web.getEncoding(text) or 'utf8', text = text.decode(utils.web.getEncoding(text) or 'utf8',
@ -149,7 +151,9 @@ class Web(callbacks.PluginRegexp):
self.log.debug('Encountered a problem parsing %u. Title may ' self.log.debug('Encountered a problem parsing %u. Title may '
'already be set, though', url) 'already be set, though', url)
if parser.title: if parser.title:
domain = utils.web.getDomain(url) domain = utils.web.getDomain(fd.geturl()
if self.registryValue('snarferShowTargetDomain', channel)
else url)
title = utils.web.htmlToText(parser.title.strip()) title = utils.web.htmlToText(parser.title.strip())
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
if isinstance(title, unicode): if isinstance(title, unicode):

View File

@ -226,8 +226,8 @@ def banmask(hostmask):
else: else:
return '*!*@' + host return '*!*@' + host
_plusRequireArguments = 'ovhblkqe' _plusRequireArguments = 'ovhblkqeI'
_minusRequireArguments = 'ovhbkqe' _minusRequireArguments = 'ovhbkqeI'
def separateModes(args): def separateModes(args):
"""Separates modelines into single mode change tuples. Basically, you """Separates modelines into single mode change tuples. Basically, you
should give it the .args of a MODE IrcMsg. should give it the .args of a MODE IrcMsg.

View File

@ -199,7 +199,14 @@ class HtmlToText(HTMLParser, object):
self.data.append(data) self.data.append(data)
def handle_entityref(self, data): def handle_entityref(self, data):
if data in htmlentitydefs.name2codepoint:
self.data.append(unichr(htmlentitydefs.name2codepoint[data])) self.data.append(unichr(htmlentitydefs.name2codepoint[data]))
elif sys.version_info[0] >= 3 and isinstance(data, bytes):
self.data.append(data.decode())
elif sys.version_info[0] < 3 and isinstance(data, str):
self.data.append(data.decode('utf8', errors='replace'))
else:
self.data.append(data)
def getText(self): def getText(self):
text = ''.join(self.data).strip() text = ''.join(self.data).strip()