[Twisted-Python] Request for help with Twisted bindings in M2Crypto

Daniel Sank sank.daniel at gmail.com
Mon Jul 25 04:10:27 MDT 2016


I realize this is not the main point of this thread, but I'd like to make a
comment regarding Twisted being opaque.

> Twisted is open source, so none of the data types are opaque.

That's a non sequitur. A bunch of open source text in a language you don't
understand is opaque, or perhaps better called "obscure". Among other
things, Twisted's use of interfaces makes the code very hard to understand.

> Twisted is probably the best open source project I have worked with
> in terms of having documentation which is generated from the code

I agree that the documentation is generally excellent and that the tests
coverage is similarly excellent. However, I still find large fractions of
the code very hard to comprehend. A while ago I made a serious effort to
understand PB and fix some bugs, but the interface stuff combined with some
very odd contortions of python class innards eventually lead me to give up.
This is despite the friendly helpful attitude of the main developers both
here and in IRC (seriously, thanks everyone for your help back then!).

I just randomly clicked through the docs to this:
https://twistedmatrix.com/documents/current/api/twisted._threads.IWorker.html

Note that:

1. It is an interface, and I still don't _really_ understand what that
means in Twisted.

2. I have no idea what a "task" is. I realize this is python and yay
duck-typing but not specifying the expected behavior of an argument seems
like a big omission.

So, while the Twisted docs are great, consider not faulting people for
being confused/daunted.


On Mon, Jul 25, 2016 at 2:55 AM, Craig Rodrigues <rodrigc at crodrigues.org>
wrote:

> On Mon, Jul 25, 2016 at 2:03 AM, Matěj Cepl <mcepl at cepl.eu> wrote:
>
>>
>> 2) Even more pressing is that the Twisted module breaks my tests when
>> porting to py3k (https://travis-ci.org/mcepl/M2Crypto/jobs/146633964).
>> Given the opaque and complicated data types in Twisted, I see horribly
>> complicated task of diving into it in front of me and I am not eager.
>>
>
> I call shenanigans on you.
>
> Twisted is open source, so none of the data types are opaque.
> Twisted is probably the best open source project I have worked with
> in terms of having documentation which is generated from the code (
> https://twistedmatrix.com/documents/current/api/ ).
>
> Twisted is also absolutely *the* best project I have worked with in terms
> of having unit tests with very high coverage
> of the code.
>
> If you are unfamiliar with Twisted's code and data types, and don't have
> the energy to dig in,
> then be honest about that, but don't accuse Twisted of being "opaque",
> because it isn't.
>
> Regarding your code example which is failing,
> your code is failing because you are intermixing bytes and strings which
> is a big no-no for Python 3.
>
> If I look at this line for example:
>
> https://gitlab.com/m2crypto/m2crypto/blob/master/M2Crypto/SSL/TwistedProtocolWrapper.py#L357
>
> I see the code is doing stuff like:
>    data = ''
>    encryptedData = ''
>
> Those are of type str, and need to be of type bytes:
>
>    data = b''
>    encryptedData = b''
>
> You need to clean stuff like that up in your code so that you are only
> using bytes.
>
> I've really learned this lesson very hard after contributing hundreds of
> py3k fixes for Twisted:
>
>       Python 2:
>               type(str) == type(bytes)
>               type(str)  != type(unicode)
>               b"foo" == "foo"
>               "foo" != u"foo"
>
>       Python 3:
>               type(str) != type(bytes)
>               type(unicode) is Gone
>               b"foo" != "foo"
>               "foo" == u"foo"
>
> There is lots of code out there which uses Python strings and bytes
> interchangeably
> which "works" under Python2, but breaks big time on Python 3.
>
> --
> Craig
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
Daniel Sank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160725/5dfd61df/attachment-0002.html>


More information about the Twisted-Python mailing list