[issue7644] bug in nntplib.body() method with possible fix

2010-01-06 Thread Michael Mullins

New submission from Michael Mullins :

When using NNTP.body(id,file) I get the following repeatable error:

Traceback (most recent call last):
  File "", line 1, in 
  File "nntplib.py", line 436, in body
return self.artcmd('BODY {0}'.format(id), file)
  File "nntplib.py", line 410, in artcmd
resp, list = self.longcmd(line, file)
  File "nntplib.py", line 267, in longcmd
return self.getlongresp(file)
  File "nntplib.py", line 249, in getlongresp
file.write(line + b'\n')
  File "/usr/lib/python3.0/io.py", line 1478, in write
s.__class__.__name__)
TypeError: can't write bytes to text stream


But by simply changing the line

openedFile = file = open(file, "w")

...to...

openedFile = file = open(file, "wb")

...in the following code:

def getlongresp(self, file=None):
"""Internal: get a response plus following text from the server.
Raise various errors if the response indicates an error."""

openedFile = None
try:
# If a string was passed then open a file with that name
if isinstance(file, str):
openedFile = file = open(file, "wb")

...it seems to fix the problem. I discovered this in 3.0, but downloading and 
inspecting the source for 3.1 shows the same problem.

MDMullins

--
messages: 97301
nosy: mdmullins
severity: normal
status: open
title: bug in nntplib.body() method with possible fix
versions: Python 3.1

___
Python tracker 
<http://bugs.python.org/issue7644>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7644] bug in nntplib.body() method with possible fix

2010-01-06 Thread Michael Mullins

Changes by Michael Mullins :


--
components: +Library (Lib)
type:  -> crash

___
Python tracker 
<http://bugs.python.org/issue7644>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7644] bug in nntplib.body() method with possible fix

2010-01-06 Thread Michael Mullins

Michael Mullins  added the comment:

"('crash' is for the interpreter crashing)"

Sorry.

 "Unless someone feels like creating an nntp test framework..."

This sounds like it is beyond me. But given the evidence, specifically the 
previous line:

 "file.write(line + b'\n')"

...the module is obviously writing as binary. I know that opening the files 
created by this method in 3.0 requires the 'rb' flag so it seems a safe bet. 
And I am actually using this module (as revised above) to get work done.

...

I apologise if this isn't the place for this (should I open another ticket?) 
but as a larger issue with 3.x in general, it was very confusing about when to 
use binary data and when to use strings when using nntplib. It took a lot of 
trial and error. If there was someway to make this more clear, or perhaps the 
methods themselves could be made flexible, excepting both types but always 
outputing in binary. (Liberal with input but conservative in output.) This 
would allow anyone working with nntplib to interact with the module in a 
completely binary way, understanding that all output will be explicitly binary, 
and that if strings are necessary, it's for the user to decode().

Just a thought.

MDMullins

--

___
Python tracker 
<http://bugs.python.org/issue7644>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com