From 47b78360888604b30999dda600da0b4d9807e918 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 5 Sep 2012 10:11:12 +1200 Subject: [PATCH] Rewrote retry loop in execute.py --- plugins/util/execute.py | 17 +++++++++++------ plugins/util/http.py | 6 +----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/util/execute.py b/plugins/util/execute.py index 3043f9a..a51f42e 100644 --- a/plugins/util/execute.py +++ b/plugins/util/execute.py @@ -1,14 +1,19 @@ import http, web -import json, urllib2, sys def eval_py(code, paste_multiline=True): + attempts = 0 + while True: - output = http.get("http://eval.appspot.com/eval", statement=code).rstrip('\n') - if output: - break - else: - pass + try: + output = http.get("http://eval.appspot.com/eval", statement=code).rstrip('\n') + except http.HTTPError: + if attempts > 2: + return "Failed to execute code." + else: + attempts += 1 + continue + break if "Traceback (most recent call last):" in output: status = "Python error: " diff --git a/plugins/util/http.py b/plugins/util/http.py index 7135e28..a91a5f6 100755 --- a/plugins/util/http.py +++ b/plugins/util/http.py @@ -6,7 +6,7 @@ import urllib import urllib2 import urlparse -from urllib import quote as _quote, quote_plus as _quote_plus +from urllib import quote, quote_plus as _quote_plus from lxml import etree, html @@ -99,10 +99,6 @@ def quote_plus(s): return _quote_plus(to_utf8(s)) -def quote(s): - return _quote(to_utf8(s)) - - def unescape(s): if not s.strip(): return s