command: Fix opmlexport crash due to orphaned feed data
authorW. Trevor King <wking@tremily.us>
Tue, 14 May 2013 11:03:32 +0000 (07:03 -0400)
committerW. Trevor King <wking@tremily.us>
Tue, 14 May 2013 11:03:32 +0000 (07:03 -0400)
When you remove a feed from your config file by hand, you might leave
the dynamic 'seen' data in the JSON data file by accident.  If you
have such orphan data, the feed is loaded by Feeds._load_feeds() with
the default configuration (since you removed the config file entry).
This can lead to opmlexport errors like:

  Traceback (most recent call last):
    File "./r2e", line 5, in <module>
      rss2email.main.run()
    File "/.../rss2email/rss2email/main.py", line 163, in run
      args.func(feeds=feeds, args=args)
    File "/.../rss2email/rss2email/command.py", line 157, in opmlexport
      url = _saxutils.escape(feed.url)
    File "/usr/lib64/python3.2/xml/sax/saxutils.py", line 34, in escape
      data = data.replace("&", "&amp;")
  AttributeError: 'NoneType' object has no attribute 'replace'

because the feeds lack the per-feed 'url' setting that had been
defined in the config file.  With this commit, opmlexport drops these
URL-less feeds, instead of choking to death trying to format them ;).

Signed-off-by: W. Trevor King <wking@tremily.us>
CHANGELOG
rss2email/command.py

index 2f8d32581454d08df37d30716a07aa4a7a1965e9..d7e6c312cc905d85253b90904771ed90a823f9f9 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 v3.5 (unreleased)
     * Fix html2text configuration (ignored since 2012-10-04).
 v3.5 (unreleased)
     * Fix html2text configuration (ignored since 2012-10-04).
+    * Fix opmlexport crash due to orphaned feed data.
 
 v3.4 (2013-05-14)
     * Added post-processing hooks for user-specified message manipulation.
 
 v3.4 (2013-05-14)
     * Added post-processing hooks for user-specified message manipulation.
index 8d8fc82e5683450acef014286f4832f1385387c4..c43e4ad113ebb2f1ba54ed83705f1eb4f77ddd6d 100644 (file)
@@ -154,6 +154,9 @@ def opmlexport(feeds, args):
         '</head>\n'
         '<body>\n')
     for feed in feeds:
         '</head>\n'
         '<body>\n')
     for feed in feeds:
+        if not feed.url:
+            _LOG.debug('dropping {}'.format(feed))
+            continue
         url = _saxutils.escape(feed.url)
         f.write('<outline type="rss" text="{0}" xmlUrl="{0}"/>'.format(url))
     f.write(
         url = _saxutils.escape(feed.url)
         f.write('<outline type="rss" text="{0}" xmlUrl="{0}"/>'.format(url))
     f.write(