curl-and-python

Conversion of Curl object factory functions to real constructors

From: Oleg Pudeyev <oleg+pycurl_at_bsdpower.com>
Date: Wed, 11 Jun 2014 11:37:09 -0400

Hi folks,

While working on creating better documentation for PycURL, a big
problem was the fact that Curl/CurlMulti/CurlShare objects did not have
constructors, but instead global factory functions with identical names:

>>> import pycurl
>>> pycurl.Curl
<built-in function Curl>
>>> pycurl.Curl.setopt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute
'setopt'
>>> dir(pycurl.Curl)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__',
'__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__le__', '__lt__', '__module__', '__name__',
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

I was able to convert these factory functions to real constructors,
such that pycurl.Curl etc. are now types:

>>> import pycurl
>>> pycurl.Curl
<type 'pycurl.Curl'>
>>> pycurl.Curl.setopt
<method 'setopt' of 'pycurl.Curl' objects>
>>> dir(pycurl.Curl)
['__class__', '__delattr__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'close', 'errstr', 'getinfo', 'pause', 'perform',
'reset', 'setopt', 'unsetopt']

While my changes pass the test suite, I am not 100% confident that they
are correct in theory. Python documentation is a little thinner than I
would have liked in this area.

As such I have a pull request open with these changes and I would
appreciate their review:

https://github.com/pycurl/pycurl/pull/194

If you are not registered on github please feel free to reply via email.

Also, I don't see any problems for PycURL clients with changing the
type of pycurl.Curl et al from function to type, but this is
another area where I would like a confirmation.

Thanks!
Oleg
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2014-06-11