Skip to content

Commit

Permalink
Merge pull request #1706 from half-duplex/verify-ssl-please
Browse files Browse the repository at this point in the history
plugins: remove nonsense uses of core.verify_ssl
  • Loading branch information
dgw committed Nov 11, 2019
2 parents 33c153b + 8d75612 commit 04a530b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion sopel/modules/find_updates.py
Expand Up @@ -45,7 +45,7 @@ def check_version(bot):

# TODO: Python3 specific. Disable urllib warning from config file.
# requests.packages.urllib3.disable_warnings()
info = requests.get(version_url, verify=bot.config.core.verify_ssl).json()
info = requests.get(version_url).json()
if version.releaselevel == 'final':
latest = info['version']
notes = info['release_notes']
Expand Down
2 changes: 1 addition & 1 deletion sopel/modules/meetbot.py
Expand Up @@ -432,7 +432,7 @@ def meetinglink(bot, trigger):
if not link.startswith("http"):
link = "http://" + link
try:
title = find_title(link, verify=bot.config.core.verify_ssl)
title = find_title(link)
except Exception: # TODO: Be specific
title = ""
log_plain("LINK: %s [%s]" % (link, title), trigger.sender)
Expand Down
17 changes: 6 additions & 11 deletions sopel/modules/translate.py
Expand Up @@ -25,7 +25,7 @@
mangle_lines = {}


def translate(text, in_lang='auto', out_lang='en', verify_ssl=True):
def translate(text, in_lang='auto', out_lang='en'):
raw = False
if unicode(out_lang).endswith('-raw'):
out_lang = out_lang[:-4]
Expand All @@ -45,8 +45,7 @@ def translate(text, in_lang='auto', out_lang='en', verify_ssl=True):
"q": text,
}
url = "https://translate.googleapis.com/translate_a/single"
result = requests.get(url, params=query, timeout=40, headers=headers,
verify=verify_ssl).text
result = requests.get(url, params=query, timeout=40, headers=headers).text

if result == '[,,""]':
return None, in_lang
Expand Down Expand Up @@ -88,8 +87,7 @@ def tr(bot, trigger):
out_lang = out_lang or 'en'

if in_lang != out_lang:
msg, in_lang = translate(phrase, in_lang, out_lang,
verify_ssl=bot.config.core.verify_ssl)
msg, in_lang = translate(phrase, in_lang, out_lang)
if not in_lang:
return bot.say("Translation failed, probably because of a rate-limit.")
if sys.version_info.major < 3 and isinstance(msg, str):
Expand Down Expand Up @@ -142,8 +140,7 @@ def langcode(p):

src, dest = args
if src != dest:
msg, src = translate(phrase, src, dest,
verify_ssl=bot.config.core.verify_ssl)
msg, src = translate(phrase, src, dest)
if not src:
return bot.say("Translation failed, probably because of a rate-limit.")
if sys.version_info.major < 3 and isinstance(msg, str):
Expand Down Expand Up @@ -172,7 +169,6 @@ def get_random_lang(long_list, short_list):
@commands('mangle', 'mangle2')
def mangle(bot, trigger):
"""Repeatedly translate the input until it makes absolutely no sense."""
verify_ssl = bot.config.core.verify_ssl
global mangle_lines
long_lang_list = ['fr', 'de', 'es', 'it', 'no', 'he', 'la', 'ja', 'cy', 'ar', 'yi', 'zh', 'nl', 'ru', 'fi', 'hi', 'af', 'jw', 'mr', 'ceb', 'cs', 'ga', 'sv', 'eo', 'el', 'ms', 'lv']
lang_list = []
Expand All @@ -193,16 +189,15 @@ def mangle(bot, trigger):
for lang in lang_list:
backup = phrase
try:
phrase = translate(phrase[0], 'en', lang,
verify_ssl=verify_ssl)
phrase = translate(phrase[0], 'en', lang)
except Exception: # TODO: Be specific
phrase = False
if not phrase:
phrase = backup
break

try:
phrase = translate(phrase[0], lang, 'en', verify_ssl=verify_ssl)
phrase = translate(phrase[0], lang, 'en')
except Exception: # TODO: Be specific
phrase = backup
continue
Expand Down
2 changes: 1 addition & 1 deletion sopel/modules/url.py
Expand Up @@ -233,7 +233,7 @@ def process_urls(bot, trigger, urls):
continue

# Call the URL to get a title, if possible
title = find_title(url, verify=bot.config.core.verify_ssl)
title = find_title(url)
if not title:
# No title found: don't handle this URL
continue
Expand Down
21 changes: 9 additions & 12 deletions sopel/modules/xkcd.py
Expand Up @@ -34,12 +34,12 @@
sites_query = ' site:xkcd.com -site:' + ' -site:'.join(ignored_sites)


def get_info(number=None, verify_ssl=True):
def get_info(number=None):
if number:
url = 'https://xkcd.com/{}/info.0.json'.format(number)
else:
url = 'https://xkcd.com/info.0.json'
data = requests.get(url, verify=verify_ssl).json()
data = requests.get(url).json()
data['url'] = 'https://xkcd.com/' + str(data['num'])
return data

Expand All @@ -65,16 +65,14 @@ def xkcd(bot, trigger):
* If non-numeric input is provided it will return the first search result
for those keywords on the xkcd.com site
"""
verify_ssl = bot.config.core.verify_ssl
# get latest comic for rand function and numeric input
latest = get_info(verify_ssl=verify_ssl)
latest = get_info()
max_int = latest['num']

# if no input is given (pre - lior's edits code)
if not trigger.group(2): # get rand comic
random.seed()
requested = get_info(random.randint(1, max_int + 1),
verify_ssl=verify_ssl)
requested = get_info(random.randint(1, max_int + 1))
else:
query = trigger.group(2).strip()

Expand All @@ -93,12 +91,12 @@ def xkcd(bot, trigger):
if not number:
bot.say('Could not find any comics for that query.')
return
requested = get_info(number, verify_ssl=verify_ssl)
requested = get_info(number)

say_result(bot, requested)


def numbered_result(bot, query, latest, verify_ssl=True):
def numbered_result(bot, query, latest):
max_int = latest['num']
if query > max_int:
bot.say(("Sorry, comic #{} hasn't been posted yet. "
Expand All @@ -114,10 +112,10 @@ def numbered_result(bot, query, latest, verify_ssl=True):
bot.say("404 - Not Found") # don't error on that one
return
elif query > 0:
requested = get_info(query, verify_ssl=verify_ssl)
requested = get_info(query)
else:
# Negative: go back that many from current
requested = get_info(max_int + query, verify_ssl=verify_ssl)
requested = get_info(max_int + query)

say_result(bot, requested)

Expand All @@ -130,6 +128,5 @@ def say_result(bot, result):

@url(r'xkcd.com/(\d+)')
def get_url(bot, trigger, match):
verify_ssl = bot.config.core.verify_ssl
latest = get_info(verify_ssl=verify_ssl)
latest = get_info()
numbered_result(bot, int(match.group(1)), latest)

0 comments on commit 04a530b

Please sign in to comment.