[Python-ideas] asyncore: included batteries don't fit
Guido van Rossum
guido at python.org
Mon Oct 8 04:49:29 CEST 2012
On Sun, Oct 7, 2012 at 7:16 PM, Duncan McGreggor
<duncan.mcgreggor at gmail.com> wrote:
>
>
> On Sun, Oct 7, 2012 at 5:52 PM, Guido van Rossum <guido at python.org> wrote:
>>
>> On Sat, Oct 6, 2012 at 9:09 PM, Duncan M. McGreggor
>> <duncan.mcgreggor at gmail.com> wrote:
>> > We're here ;-)
>> >
>> > I'm forwarding this to the rest of the Twisted cabal...
>>
>> Quick question. I'd like to see how Twisted typically implements a
>> protocol parser. Where would be a good place to start reading example
>> code?
>
>
> I'm not exactly sure what you're looking for (e.g., I'm not sure what your
> exact definition of a protocol parser is), but this might be getting close
> to what you want:
>
> * https://github.com/twisted/twisted/blob/master/twisted/mail/pop3.py
> * https://github.com/twisted/twisted/blob/master/twisted/protocols/basic.py
>
> The POP3 protocol implementation in Twisted is a pretty good example of how
> one should create a protocol. It's a subclass of the
> twisted.protocol.basic.LineOnlyReceiver, and I'm guessing when you said
> "parsing" you're wanting to look at what's in the dataReceived method of
> that class.
>
> Hopefully that's what you were after...
Yes, those are perfect. The term I used came from one of Josiah's
previous messages in this thread, but I think he really meant protocol
handler.
My current goal is to see if it would be possible to come up with an
abstraction that makes it possible to write protocol handlers that are
independent from the rest of the infrastructure (e.g. transport,
reactor). I honestly have no idea if this is a sane idea but I'm going
to look into it anyway; if it works it would be cool to be able to
reuse the same POP3 logic in different environments (e.g. synchronous
thread-based, Twisted) without having to pul in all of Twisted. I.e.
Twisted could contribute the code to the stdlib and the stdlib could
make it work with SocketServer but Twisted could still use it
(assuming Twisted ever gets ported to Py3k :-).
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list