From: W. Trevor King Date: Thu, 4 Oct 2012 13:42:24 +0000 (-0400) Subject: More global constant and configuration cleanups. X-Git-Tag: v3.0~72^2~46 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=30869a30a4c6b4acf073cab2bbcd5cd46b643050;p=rss2email.git More global constant and configuration cleanups. --- diff --git a/rss2email.py b/rss2email.py index 976323b..76cdcdc 100755 --- a/rss2email.py +++ b/rss2email.py @@ -71,8 +71,12 @@ LOG = _logging.getLogger('rss2email') LOG.addHandler(_logging.StreamHandler()) LOG.setLevel(_logging.ERROR) - +_feedparser.USER_AGENT = 'rss2email/{} +{}'.format(__version__, __url__) _urllib_request.install_opener(_urllib_request.build_opener()) +_SOCKET_ERRORS = [] +for e in ['error', 'gaierror']: + if hasattr(_socket, e): + _SOCKET_ERRORS.append(getattr(_socket, e)) class RSS2EmailError (Exception): @@ -404,23 +408,6 @@ def send(sender, recipient, message, config=None, section='DEFAULT'): else: sendmail_send(sender, recipient, message) -### Load the Options ### - -# Read options from config file if present. -sys.path.insert(0,".") -try: - from config import * -except: - pass - -warn = sys.stderr - -socket_errors = [] -for e in ['error', 'gaierror']: - if hasattr(socket, e): socket_errors.append(getattr(socket, e)) - -feedparser.USER_AGENT = "rss2email/"+__version__+ " +http://www.allthingsrss.com/rss2email/" - ### Utility Functions ### @@ -715,12 +702,12 @@ def run(num=None): elif hasattr(feedparser, 'zlib') and exc_type == feedparser.zlib.error: print >>warn, "W: broken compression [%d] %s" % (feednum, f.url) - elif exc_type in socket_errors: + elif exc_type in _SOCKET_ERRORS: exc_reason = r.bozo_exception.args[1] print >>warn, "W: %s [%d] %s" % (exc_reason, feednum, f.url) elif exc_type == urllib2.URLError: - if r.bozo_exception.reason.__class__ in socket_errors: + if r.bozo_exception.reason.__class__ in _SOCKET_ERRORS: exc_reason = r.bozo_exception.reason.args[1] else: exc_reason = r.bozo_exception.reason