Skip to content

Commit

Permalink
[find, bugzilla, reddit, url, youtube] Use WillieMemory objects
Browse files Browse the repository at this point in the history
Rather than dicts, for thread safety. Issue sopel-irc#294
  • Loading branch information
embolalia committed Jun 24, 2013
1 parent 39e3012 commit 12dbb50
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
from lxml import etree
import re
from willie import web
from willie import web, tools
from willie.module import rule
import urllib
import urllib2
Expand All @@ -35,7 +35,7 @@ def setup(bot):
and bot.config.bugzilla.get_list('domains')):
return
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = {}
bot.memory['url_callbacks'] = tools.WillieMemory()

domains = '|'.join(bot.config.bugzilla.get_list('domains'))
regex = re.compile((r'https?://(%s)'
Expand Down
6 changes: 3 additions & 3 deletions find.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"""

import re
from willie.tools import Nick
from willie.tools import Nick, WillieMemory
from willie.module import rule, priority


def setup(bot):
bot.memory['find_lines'] = dict()
bot.memory['find_lines'] = WillieMemory()


@rule('.*')
Expand All @@ -31,7 +31,7 @@ def collectlines(bot, trigger):

# Add a log for the channel and nick, if there isn't already one
if trigger.sender not in bot.memory['find_lines']:
bot.memory['find_lines'][trigger.sender] = dict()
bot.memory['find_lines'][trigger.sender] = WillieMemory()
if Nick(trigger.nick) not in bot.memory['find_lines'][trigger.sender]:
bot.memory['find_lines'][trigger.sender][Nick(trigger.nick)] = list()

Expand Down
3 changes: 2 additions & 1 deletion reddit-info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from willie.module import commands, rule, example, NOLIMIT
from willie import tools
import praw
import re
domain = r'https?://(?:www\.|np\.)?reddit\.com'
Expand All @@ -18,7 +19,7 @@ def setup(bot):
post_regex = re.compile(post_url)
user_regex = re.compile(user_url)
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = {}
bot.memory['url_callbacks'] = tools.WillieMemory()
bot.memory['url_callbacks'][post_regex] = rpost_info
bot.memory['url_callbacks'][user_regex] = redditor_info

Expand Down
6 changes: 3 additions & 3 deletions url.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import re
from htmlentitydefs import name2codepoint
import willie.web as web
from willie import web, tools
from willie.module import commands, rule
import urllib2
import urlparse
Expand Down Expand Up @@ -64,9 +64,9 @@ def setup(bot):

# Ensure that url_callbacks and last_seen_url are in memory
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = {}
bot.memory['url_callbacks'] = tools.WillieMemory()
if not bot.memory.contains('last_seen_url'):
bot.memory['last_seen_url'] = {}
bot.memory['last_seen_url'] = tools.WillieMemory()

if bot.config.has_option('url', 'exclusion_char'):
exclusion_char = bot.config.url.exclusion_char
Expand Down
9 changes: 3 additions & 6 deletions youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
This module will respond to .yt and .youtube commands and searches the youtubes.
"""

from willie import web
from willie import web, tools
from willie.module import rule, commands, example
import json
import re
Expand All @@ -21,11 +21,8 @@
def setup(bot):
regex = re.compile('(youtube.com/watch\S*v=|youtu.be/)([\w-]+)')
if not bot.memory.contains('url_callbacks'):
bot.memory['url_callbacks'] = {regex, ytinfo}
else:
exclude = bot.memory['url_callbacks']
exclude[regex] = ytinfo
bot.memory['url_callbacks'] = exclude
bot.memory['url_callbacks'] = tools.WillieMemory()
bot.memory['url_callbacks'][regex] = exclude


def ytget(bot, trigger, uri):
Expand Down

0 comments on commit 12dbb50

Please sign in to comment.