[MERGE][bug 147530] pycurl http implementation peeks under the covers

John Arbash Meinel john at arbash-meinel.com
Mon Oct 1 16:13:57 BST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Vincent Ladeuil wrote:
> Old versions of pycurl didn't define symbols for error codes. Our
> pycurl http implementation worked around it by defining error
> codes copied from curl.h
> 
> New error codes have been added in recent version of curl and
> pycurl.
> 
> The associated patch provides a better way to define the error
> codes we care about while retaining compatibility with older
> versions.
> 
>         Vincent
> 
> 
> 

...

> +
> +def _get_pycurl_errcode(symbol, default):
> +    """
> +    Returns the numerical error code for a symbol defined by pycurl.
> +
> +    Different pycurl implementations define different symbols for error
> +    codes. Old versions never define some symbols (wether they can return the
> +    corresponding error code or not). The following addresses the problem by
> +    defining the symbols we care about.  Note: this allows to define symbols
> +    for errors that older versions will never return, which is fine.
> +    """
> +    return pycurl.__dict__.get(symbol, default)
> +
> +CURLE_SSL_CACERT_BADFILE = _get_pycurl_errcode('E_SSL_CACERT_BADFILE', 77)
> +CURLE_COULDNT_CONNECT = _get_pycurl_errcode('E_COULDNT_CONNECT', 7)
> +CURLE_COULDNT_RESOLVE_HOST = _get_pycurl_errcode('E_COULDNT_RESOLVE_HOST', 6)
> +CURLE_COULDNT_RESOLVE_PROXY = _get_pycurl_errcode('E_COULDNT_RESOLVE_PROXY', 5)
> +CURLE_GOT_NOTHING = _get_pycurl_errcode('E_GOT_NOTHING', 52)
> +CURLE_PARTIAL_FILE = _get_pycurl_errcode('E_PARTIAL_FILE', 18)
> +
> +
>  register_urlparse_netloc_protocol('http+pycurl')
>  

I'm fine with using the _get_pycurl_errcode as you have done here. But I
would rather see it done in a separate file.

I would also think that error codes aren't something that you can change
much. So having them hardcoded isn't a terrible thing.

Anyway, you could probably put all of this into _pycurl_errors.py, and
just use a simple regex substitution to turn them all into _get_* functions.

Something like:

s/CURL(E_.*) = (\d+)/CURL\1 = _get_pycurl_errcode('\1', \2)/

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHAQ61JdeBCYSNAAMRAsaUAJ47EZ359UBWzmPr6Dqm706kLt5lBQCeMjVK
YfYeas9CYGM8Y7+WEo5ble0=
=IgT+
-----END PGP SIGNATURE-----



More information about the bazaar mailing list