Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core


Commits:
e4d9e520 by Mark Sapiro at 2019-06-27T15:52:58Z
Fixed nntp runner to use BytesIO rather than StringIO.

- - - - -
7b914322 by Mark Sapiro at 2019-06-27T15:52:58Z
Merge branch 'fix_613' into 'master'

Fixed nntp runner to use BytesIO rather than StringIO.

Closes #613

See merge request mailman/mailman!532
- - - - -


4 changed files:

- src/mailman/docs/NEWS.rst
- src/mailman/runners/nntp.py
- src/mailman/runners/tests/test_nntp.py
- src/mailman/testing/helpers.py


Changes:

=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -31,6 +31,8 @@ Bugs
   already pending are now handled properly.  (Closes #577 and #583)
 * It is no longer possible to add the list's posting address with any role to
   a list.  (Closes #599)
+* Fixed the nntp runner which was calling the ``nntplib.NNTP.post()`` method
+  with a string object instead of bytes.  (Closes #613)
 
 Command line
 ------------


=====================================
src/mailman/runners/nntp.py
=====================================
@@ -23,7 +23,7 @@ import socket
 import logging
 import nntplib
 
-from io import StringIO
+from io import BytesIO
 from mailman.config import config
 from mailman.core.runner import Runner
 from mailman.interfaces.nntp import NewsgroupModeration
@@ -66,8 +66,8 @@ class NNTPRunner(Runner):
         # Make sure we have the most up-to-date state
         if not msgdata.get('prepped'):
             prepare_message(mlist, msg, msgdata)
-        # Flatten the message object, sticking it in a StringIO object
-        fp = StringIO(msg.as_string())
+        # Flatten the message object, sticking it in a BytesIO object
+        fp = BytesIO(msg.as_bytes())
         conn = None
         try:
             conn = nntplib.NNTP(host, port,


=====================================
src/mailman/runners/tests/test_nntp.py
=====================================
@@ -21,6 +21,7 @@ import socket
 import nntplib
 import unittest
 
+from email import message_from_bytes
 from mailman.app.lifecycle import create_list
 from mailman.config import config
 from mailman.interfaces.nntp import NewsgroupModeration
@@ -274,7 +275,7 @@ Testing
         self.assertEqual(len(args[0]), 1)
         # No keyword arguments.
         self.assertEqual(len(args[1]), 0)
-        msg = mfs(args[0][0].read())
+        msg = message_from_bytes(args[0][0].read())
         self.assertEqual(msg['subject'], 'A newsgroup posting')
 
     @mock.patch('nntplib.NNTP')


=====================================
src/mailman/testing/helpers.py
=====================================
@@ -30,7 +30,7 @@ import datetime
 import threading
 
 from contextlib import contextmanager, suppress
-from email import message_from_string
+from email import message_from_bytes, message_from_string
 from lazr.config import as_timedelta
 from mailman.bin.master import Loop as Master
 from mailman.config import config
@@ -250,7 +250,7 @@ def get_nntp_server(cleanups):
     class NNTPProxy:                                              # noqa: E306
         def get_message(self):
             args = nntpd.post.call_args
-            return specialized_message_from_string(args[0][0].read())
+            return message_from_bytes(args[0][0].read())
     return NNTPProxy()
 
 



View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/441634d92e46bd610abe61e4a9ac3c089e8305ab...7b9143229c3b8417556fcf96dd7ae23b8b316747

-- 
View it on GitLab: 
https://gitlab.com/mailman/mailman/compare/441634d92e46bd610abe61e4a9ac3c089e8305ab...7b9143229c3b8417556fcf96dd7ae23b8b316747
You're receiving this email because of your account on gitlab.com.


_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to