Merge branch 'opmlimport-feed-name-slugging'
authorW. Trevor King <wking@tremily.us>
Sun, 20 Oct 2013 21:54:33 +0000 (14:54 -0700)
committerW. Trevor King <wking@tremily.us>
Sun, 20 Oct 2013 21:54:33 +0000 (14:54 -0700)
* opmlimport-feed-name-slugging:
  CHANGELOG: Document this branch
  feed: Adjust Feed._name_regexp to allow non-ASCII characters
  command: Sluggify feed names on opmlimport

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

index 62f5ccdda3b3a1a9977eb36526d6a20a77677e2f..03b42cb008df7bedd6436714adb3e2e87038b7f1 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+v3.8 (unreleased)
+    * Sluggify feed names on opmlimport.
+    * Allow Unicode letters and digits in feed names, instead of just ASCII lettters and digits.
+
 v3.7 (2013-10-11)
     * Fix fallback for titles that contain malformed HTML.
     * Fix atomic saves to avoid garbling config and data files if the disk is full.
index 54c080836a5df07365e1829699748af741bae63a..038b83f7e5adf3af93bf0179a32d08678c04aae9 100644 (file)
@@ -17,6 +17,7 @@
 """rss2email commands
 """
 
+import re as _re
 import sys as _sys
 import xml.dom.minidom as _minidom
 import xml.sax.saxutils as _saxutils
@@ -131,6 +132,7 @@ def opmlimport(feeds, args):
         raise _error.OPMLReadError() from e
     if args.file:
         f.close()
+    name_slug_regexp = _re.compile('[^\w\d.-]+')
     for feed in new_feeds:
         if feed.hasAttribute('xmlUrl'):
             url = _saxutils.unescape(feed.getAttribute('xmlUrl'))
@@ -138,7 +140,7 @@ def opmlimport(feeds, args):
             if feed.hasAttribute('text'):
                 text = _saxutils.unescape(feed.getAttribute('text'))
                 if text != url:
-                    name = text
+                    name = name_slug_regexp.sub('-', text)
             feed = feeds.new_feed(name=name, url=url)
             _LOG.info('add new feed {}'.format(feed))
     feeds.save()
index 259807c3315569a569f9bc00e34d6f866c37c10d..a11f6c7bfb2edb5042bd2eae42bf7b107546f342 100644 (file)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (C) 2004-2013 Aaron Swartz
 #                         Brian Lalor
 #                         Dean Jackson
@@ -110,7 +111,7 @@ class Feed (object):
     >>> feed.url
     'http://example.com/feed.atom'
 
-    Names can only contain ASCII letters, digits, and '._-'.  Here the
+    Names can only contain letters, digits, and '._-'.  Here the
     invalid space causes an exception:
 
     >>> Feed(name='invalid name')
@@ -118,6 +119,11 @@ class Feed (object):
       ...
     rss2email.error.InvalidFeedName: invalid feed name 'invalid name'
 
+    However, you aren't restricted to ASCII letters:
+
+    >>> Feed(name='Αθήνα')
+    <Feed Αθήνα (None -> )>
+
     You must define a URL:
 
     >>> Feed(name='feed-without-a-url', to='a@b.com').run(send=False)
@@ -130,8 +136,9 @@ class Feed (object):
 
     >>> CONFIG['DEFAULT']['to'] = ''
     >>> test_section = CONFIG.pop('feed.test-feed')
+
     """
-    _name_regexp = _re.compile('^[a-zA-Z0-9._-]+$')
+    _name_regexp = _re.compile('^[\w\d.-]+$')
 
     # saved/loaded from feed.dat using __getstate__/__setstate__.
     _dynamic_attributes = [