From: W. Trevor King Date: Fri, 10 May 2013 08:39:33 +0000 (-0400) Subject: rss2email/post_process/downcase.py: Move my test hook into Arun's directory X-Git-Tag: v3.4~8^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b87ef0ccb42a8f49d7d56471c63bff6fd9bee0f;p=rss2email.git rss2email/post_process/downcase.py: Move my test hook into Arun's directory All the built-in hooks should live in the same sub-package. The `post_process` name Arun used is more descriptive than my `hook`, so move my downcase code there. Signed-off-by: W. Trevor King --- diff --git a/rss2email/config.py b/rss2email/config.py index 2b94719..6eba7ec 100644 --- a/rss2email/config.py +++ b/rss2email/config.py @@ -93,7 +93,7 @@ CONFIG['DEFAULT'] = _collections.OrderedDict(( # first character set that works. ('encodings', 'US-ASCII, ISO-8859-1, UTF-8, BIG5, ISO-2022-JP'), # User processing hooks. Note the space after the module name. - # Example: post-process = 'rss2email.hook downcase_message' + # Example: post-process = 'rss2email.post_process.downcase downcase_message' ('post-process', ''), ## HTML conversion # True: Send text/html messages when possible. diff --git a/rss2email/hook.py b/rss2email/hook.py deleted file mode 100644 index 45542d5..0000000 --- a/rss2email/hook.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright - -"""Useful hooks for post processing messages - -Along with some less useful hooks for testing the post-processing -infrastructure. The hook, when set, is called by ``Feed._process()`` -with the following keyword arguments: - -feed: - The ``rss2email.feed.Feed`` instance that generated the message. -parsed: - The parsed feed as returned by ``feedparser.parse`` -entry: - The entry from ``parsed`` that lead to the current message. -guid: - The feed's view of the identity of the current entry. -message: - The ``email.message.Message`` instance that rss2email would send if - the post-processing hook were disabled. - -Post processing hooks should return the possibly altered message, or -return ``None`` to indicate that the message should not be sent. -""" - -def _downcase_payload(part): - if part.get_content_type() != 'text/plain': - return - payload = part.get_payload() - part.set_payload(payload.lower()) - -def downcase_message(message, **kwargs): - """Downcase the message body (for testing) - """ - if message.is_multipart(): - for part in message.walk(): - if part.get_content_type() == 'text/plain': - _downcase_payload(part) - else: - _downcase_payload(message) - return message diff --git a/rss2email/post_process/__init__.py b/rss2email/post_process/__init__.py index d011b39..3632dbb 100644 --- a/rss2email/post_process/__init__.py +++ b/rss2email/post_process/__init__.py @@ -1,4 +1,22 @@ # Copyright -"""Post processing functions for manipulating entry messages +"""Post-processing functions for manipulating entry messages + +A post-processing hook, when set, is called by ``Feed._process()`` +with the following keyword arguments: + +feed: + The ``rss2email.feed.Feed`` instance that generated the message. +parsed: + The parsed feed as returned by ``feedparser.parse`` +entry: + The entry from ``parsed`` that lead to the current message. +guid: + The feed's view of the identity of the current entry. +message: + The ``email.message.Message`` instance that rss2email would send if + the post-processing hook were disabled. + +Post-processing hooks should return the possibly altered message, or +return ``None`` to indicate that the message should not be sent. """ diff --git a/rss2email/post_process/downcase.py b/rss2email/post_process/downcase.py new file mode 100644 index 0000000..fbaa899 --- /dev/null +++ b/rss2email/post_process/downcase.py @@ -0,0 +1,21 @@ +# Copyright + +"""A text-manipulation hook for testing the post-processing infrastructure +""" + +def _downcase_payload(part): + if part.get_content_type() != 'text/plain': + return + payload = part.get_payload() + part.set_payload(payload.lower()) + +def downcase_message(message, **kwargs): + """Downcase the message body (for testing) + """ + if message.is_multipart(): + for part in message.walk(): + if part.get_content_type() == 'text/plain': + _downcase_payload(part) + else: + _downcase_payload(message) + return message diff --git a/test/allthingsrss/2.config b/test/allthingsrss/2.config index 59a4427..8c80dc7 100644 --- a/test/allthingsrss/2.config +++ b/test/allthingsrss/2.config @@ -1,4 +1,4 @@ [DEFAULT] to = a@b.com date-header = True -post-process = rss2email.hook downcase_message +post-process = rss2email.post_process.downcase downcase_message