[Python-3000] Question about PEP 3001 and fixing API flaws

Jack Diederich jackdied at jackdied.com
Thu Mar 22 19:00:28 CET 2007


On Wed, Mar 21, 2007 at 01:38:32PM -0600, Steven Bethard wrote:
> On 3/14/07, BJörn Lindqvist <bjourne at gmail.com> wrote:
> > For another example, take the Telnet class in the telnetlib module. It
> > has a method set_option_negotiation_callback() which takes a function
> > that will be called for each telnet option read. The default behaviour
> > for the Telnet class is to refuse all negotiation requests, but using
> > a negotiation callback you can override that.
> >
> > However, using a callback does not work so well because the function
> > acting on the telnet options read still needs to reference the Telnet
> > class to get hold of negotiation data using read_sb_data(). The
> > problem is non-lethal but a small annoyance to advanced Telnet
> > users. See SourceForge patches #1520081, #664020 and #1678077.
> >
> > The right design would have been to have a method (handle_option) in
> > the class that handles all options and, by default, refuses
> > them. Users of the Telnet class could then subclass Telnet and
> > override the handle_option method to implement their application
> > specific option handling.
> 
> Seems like this could be done now (for Python 2.6), no?  Just factor
> out the code that decides whether or not to call self.option_callback
> into a handle_option() method and call that.  I'm not sure I see how
> Python 3000 comes into it...
> 

[I meant to reply too but hadn't gotten back to it]

telnetlib isn't usable for anything that isn't extremely simple.
It needs a rewrite or at least some major surgery.   Lots of people 
(including me) have written subclasses that extend it but I don't know 
how compatible they are (see google code search for a half dozen 
examples).  There are a number of outstanding patches in SourceForge 
but there are no unit tests so it is hard to know if they break stuff.
At least a couple of the patches address negotiation.

Off the top of my head its two biggest deficiencies are negotiation
and being able to manipulate the raw IO.  Negotiation is easy to
improve for most cases but harder for two-way communication like
NAWS (terminal resizing) messages.  Manipulating the raw IO is
required for telnet extensions like MCCP which expects the raw
stream to be gzip'd starting the byte immediately after the SB clause.

If someone wrote a test module the SF patches could be applied and
tested easily and even major changes to the implementation would be
possible.  I've been meaning to do that for a couple years now but
it never gets near the top of my list.  Consider that an invitation!

-Jack


More information about the Python-3000 mailing list