nntplib and xover

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Sep 21 10:59:33 EDT 2001


Gerhard =?ISO-8859-1?Q?H=E4ring?= <g.haering at ___skynamics.com.invalid> writes:

> > this just adds an xref element to the tuple, right? i bet many
> > people unpack the returned tuple into variables straight away,
> > so the change would cause some code breakage.
> 
> 
> Ups. Didn't think of that. Then I guess there's no way to modify the 
> xover function that is also backwards compatible. I also didn't check 
> any RFCs, this was just a quick shot.

It certainly is possible. You could return an instance of

 class XOver(tuple):
     __dynamic__ = 1

by writing

                 line = XOver((elem[0],
                               elem[1],
                               elem[2],
                               elem[3],
                               elem[4],
                               elem[5].split(),
                               elem[6],
                               elem[7]))
                 line.ref = ref
                 xover_lines.append(line)

That is the simplest solution; an advanced solution may add a
getheader method that takes a MIME header field name, to access the
headers in a manner similar to rfc822.Message, while preserving the
tuple properties. That solution could also support arbitrary
additional headers being returned from XOVER, not just Xref.

Regards,
Martin


P.S. Inheriting from tuple will require Python 2.2. For earlier
versions, you'll need to return a class that implements __getitem__,
__len__ etc - perhaps by inheriting from UserList.UserList.



More information about the Python-list mailing list