From 97eadb6febed972d015521ae0d5194a350820770 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 20 Jan 2004 04:32:23 +0000 Subject: [PATCH] Can actually search with Google now that google.setLicense is being called. Also, maxiumum-results -> maxiumumResults to prettify the function calls. --- plugins/Google.py | 24 ++++++++++++++++++------ test/test_Google.py | 8 ++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/plugins/Google.py b/plugins/Google.py index 83f965987..2ee9755bb 100644 --- a/plugins/Google.py +++ b/plugins/Google.py @@ -73,7 +73,7 @@ def configure(onStart, afterConnect, advanced): break if key: onStart.append('load Google') - conf.supybot.plugins.Google.licenseKey.set(key) + conf.supybot.plugins.Google.licenseKey.setValue(key) print 'The Google plugin has the functionality to watch for URLs' print 'that match a specific pattern (we call this a snarfer).' print 'When supybot sees such a URL, he will parse the web page' @@ -84,10 +84,10 @@ def configure(onStart, afterConnect, advanced): print if yn('Do you want the Google Groups link snarfer enabled by ' 'default?') == 'y': - conf.supybot.plugins.Google.groupsSnarfer.set(True) + conf.supybot.plugins.Google.groupsSnarfer.setValue(True) if yn('Do you want the Google search snarfer enabled by default?') \ == 'y': - conf.supybot.plugins.Google.searchSnarfer.set(True) + conf.supybot.plugins.Google.searchSnarfer.setValue(True) if 'load Alias' not in onStart: print 'Google depends on the Alias module for some extra commands.' if yn('Would you like to load the Alias module now?') == 'y': @@ -132,6 +132,17 @@ def search(log, *args, **kwargs): raise callbacks.Error, 'Google returned an unparseable response. ' \ 'The full traceback has been logged.' +class LicenseKey(registry.String): + def set(self, s): + original = getattr(self, 'value', self.default) + registry.String.set(self, s) + if self.value and len(self.value) != 32: + setattr(self, 'value', original) + google.setLicense(self.value) + raise registry.InvalidRegistryValue, 'Invalid Google license key.' + if self.value: + google.setLicense(self.value) + conf.registerPlugin('Google') conf.registerChannelValue(conf.supybot.plugins.Google, 'groupsSnarfer', registry.Boolean(False, """Determines whether the groups snarfer is @@ -144,13 +155,14 @@ conf.registerChannelValue(conf.supybot.plugins.Google, 'searchSnarfer', channel.""")) conf.registerChannelValue(conf.supybot.plugins.Google, 'bold', registry.Boolean(True, """Determines whether results are bolded.""")) -conf.registerChannelValue(conf.supybot.plugins.Google, 'maximum-results', +conf.registerChannelValue(conf.supybot.plugins.Google, 'maximumResults', registry.PositiveInteger(10, """Determines the maximum number of results returned from the google command.""")) conf.registerGlobalValue(conf.supybot.plugins.Google, 'licenseKey', - registry.String('', """Sets the Google license key for using Google's Web + LicenseKey('', """Sets the Google license key for using Google's Web Services API. This is necessary before you can do any searching with this module.""")) + class Google(callbacks.PrivmsgCommandAndRegexp): threaded = True regexps = sets.Set(['googleSnarfer', 'googleGroups']) @@ -210,7 +222,7 @@ class Google(callbacks.PrivmsgCommandAndRegexp): irc.error(str(e)) return bold = conf.supybot.plugins.Google.bold() - max = conf.supybot.plugins.Google.get('maximum-results') + max = conf.supybot.plugins.Google.maximumResults() irc.reply(self.formatData(data, bold=bold, max=max)) def metagoogle(self, irc, msg, args): diff --git a/test/test_Google.py b/test/test_Google.py index 1b42aa7fb..c80910da6 100644 --- a/test/test_Google.py +++ b/test/test_Google.py @@ -35,12 +35,12 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation): plugins = ('Google',) if network: def testNoNoLicenseKeyError(self): - conf.supybot.plugins.Google.groupsSnarfer.set('on') + conf.supybot.plugins.Google.groupsSnarfer.setValue(True) self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'google blah')) self.assertNoResponse(' ') def testGroupsSnarfer(self): - conf.supybot.plugins.Google.groupsSnarfer.set('on') + conf.supybot.plugins.Google.groupsSnarfer.setValue(True) self.assertRegexp('http://groups.google.com/groups?dq=&hl=en&' 'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.' '0310132012.738e22fc%40posting.google.com', @@ -65,11 +65,11 @@ class GoogleTestCase(ChannelPluginTestCase, PluginDocumentation): r'comp\.lang\.python.*What exactly are bound') def testConfig(self): - conf.supybot.plugins.Google.groupsSnarfer.set('off') + conf.supybot.plugins.Google.groupsSnarfer.setValue(False) self.assertNoResponse('http://groups.google.com/groups?dq=&hl=en&' 'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.' '0310132012.738e22fc%40posting.google.com') - conf.supybot.plugins.Google.groupsSnarfer.set('on') + conf.supybot.plugins.Google.groupsSnarfer.setValue(True) self.assertNotError('http://groups.google.com/groups?dq=&hl=en&' 'lr=lang_en&ie=UTF-8&oe=UTF-8&selm=698f09f8.' '0310132012.738e22fc%40posting.google.com')