From 94c582a4a0dcc313f6df3f46508586b6ce8e7b38 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 27 Dec 2014 11:37:16 -0800 Subject: [PATCH] DDG/FML/Isup: work towards PEP8 compliancy Skipping the config options in config.py since the indented version looks just as bad (not enough space to write the text without making it use 5 lines). From: https://github.com/jlu5/SupyPlugins/commit/4a62b4ad13c3d6f40f914f0bf8037e097d675c80 --- config.py | 3 ++- plugin.py | 17 ++++++++++------- test.py | 4 +++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config.py b/config.py index 2e8b3da9d..8f642f610 100644 --- a/config.py +++ b/config.py @@ -36,7 +36,8 @@ try: except: # Placeholder that allows to run the plugin on a bot # without the i18n module - _ = lambda x:x + _ = lambda x: x + def configure(advanced): # This will be called by supybot to configure this module. advanced is diff --git a/plugin.py b/plugin.py index 4522acbcd..c0d7886e6 100644 --- a/plugin.py +++ b/plugin.py @@ -39,18 +39,20 @@ try: except ImportError: # Placeholder that allows to run the plugin on a bot # without the i18n module - _ = lambda x:x + _ = lambda x: x -try: # Python 3 + +try: # Python 3 from urllib.parse import urlencode -except ImportError: # Python 2 +except ImportError: # Python 2 from urllib import urlencode try: from bs4 import BeautifulSoup except ImportError: raise ImportError("Beautiful Soup 4 is required for this plugin: get it" - " at http://www.crummy.com/software/BeautifulSoup/bs4/doc/" - "#installing-beautiful-soup") + " at http://www.crummy.com/software/BeautifulSoup/bs4" + "/doc/#installing-beautiful-soup") + class DDG(callbacks.Plugin): """Searches for results on DuckDuckGo.""" @@ -60,7 +62,7 @@ class DDG(callbacks.Plugin): """ Searches for on DuckDuckGo (web search).""" - url = "https://duckduckgo.com/lite?" + urlencode({"q":text}) + url = "https://duckduckgo.com/lite?" + urlencode({"q": text}) try: data = utils.web.getUrl(url).decode("utf-8") except utils.web.Error as e: @@ -75,7 +77,8 @@ class DDG(callbacks.Plugin): continue try: # 1) Get a result snippet. - snippet = res.parent.next_sibling.next_sibling.find_all("td")[-1] + snippet = res.parent.next_sibling.next_sibling.\ + find_all("td")[-1] # 2) Fetch the result link. link = res.a.get('href') snippet = snippet.text.strip() diff --git a/test.py b/test.py index 3eea5c218..abfed70b8 100644 --- a/test.py +++ b/test.py @@ -30,11 +30,13 @@ from supybot.test import * + class DDGTestCase(PluginTestCase): plugins = ('DDG',) def testSearch(self): - self.assertRegexp('ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/') + self.assertRegexp( + 'ddg search wikipedia', 'Wikipedia.*? - .*?https?\:\/\/') # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: