pycurl Module Functionality¶
- pycurl.global_init(option) None¶
Initialize curl environment.
option is one of the constants pycurl.GLOBAL_SSL, pycurl.GLOBAL_WIN32, pycurl.GLOBAL_ALL, pycurl.GLOBAL_NOTHING, pycurl.GLOBAL_DEFAULT.
Corresponds to curl_global_init in libcurl.
- pycurl.global_cleanup() None¶
Cleanup curl environment.
Corresponds to curl_global_cleanup in libcurl.
- pycurl.version¶
This is a string with version information on libcurl, corresponding to curl_version in libcurl.
Example usage:
>>> import pycurl >>> pycurl.version 'PycURL/7.19.3 libcurl/7.33.0 OpenSSL/0.9.8x zlib/1.2.7'
- pycurl.version_info() tuple¶
Returns a 12-tuple with the version info.
Corresponds to curl_version_info in libcurl. Returns a tuple of information which is similar to the
curl_version_info_datastruct returned bycurl_version_info()in libcurl.Example usage:
>>> import pycurl >>> pycurl.version_info() (3, '7.33.0', 467200, 'amd64-portbld-freebsd9.1', 33436, 'OpenSSL/0.9.8x', 0, '1.2.7', ('dict', 'file', 'ftp', 'ftps', 'gopher', 'http', 'https', 'imap', 'imaps', 'pop3', 'pop3s', 'rtsp', 'smtp', 'smtps', 'telnet', 'tftp'), None, 0, None)
- class pycurl.Curl New Curl object
Creates a new Curl Object which corresponds to a
CURLhandle in libcurl. Curl objects automatically set CURLOPT_VERBOSE to 0, CURLOPT_NOPROGRESS to 1, provide a default CURLOPT_USERAGENT and setup CURLOPT_ERRORBUFFER to point to a private error buffer.Implicitly calls
pycurl.global_init()if the latter has not yet been called.The
Curlobject can be used as a context manager. Exiting the context callsclose().Example:
with pycurl.Curl() as c: # perform operations
- class pycurl.CurlMulti(close_handles=False) New CurlMulti object
Creates a new CurlMulti Object which corresponds to a
CURLMhandle in libcurl.The
CurlMultiobject can be used as a context manager. Exiting the context callsclose().Example:
with pycurl.CurlMulti(close_handles=True) as m: m.add_handle(curl) # perform multi operations # easy handles have been removed and closed
- Parameters:
close_handles (bool) –
If
False(default), easy handles added to the multi handle are removed from the multi handle whenclose()is called or when exiting the context manager, but remain open and must be managed by the caller.If
True, easy handles are removed from the multi handle whenclose()is called or when exiting the context manager, and are then automatically closed.In all cases, easy handles are not closed when they are removed individually from the multi handle.
- class pycurl.CurlShare(detach_on_close=True) New CurlShare object
Creates a new CurlShare Object which corresponds to a
CURLSHhandle in libcurl. CurlShare objects is what you pass as an argument to the SHARE option on Curl objects.The
CurlShareobject can be used as a context manager. Exiting the context callsclose().When a
CurlShareis closed, its behavior depends on the value ofdetach_on_close.Example:
with pycurl.CurlShare(detach_on_close=True) as s: curl.setopt(pycurl.SHARE, s) # perform operations # the CurlShare is closed and the Curl object has been detached
- Parameters:
detach_on_close (bool) –
Controls how associated Curl objects are handled when the
CurlShareis closed.If
True(default), all liveCurlobjects associated with the share are automatically detached whenclose()is called or when exiting the context manager. Detaching clears theSHAREoption on eachCurlobject, but does not close them. The caller remains responsible for managing the lifetime of theCurlobjects.If
False, callingclose()(or exiting the context manager) while there are stillCurlobjects associated with the share raises an exception. In this mode, the caller must explicitly remove or close all associatedCurlobjects before closing theCurlShare.
Warning
Detaching
Curlobjects from aCurlShareis not thread-safe with respect to thoseCurlobjects.The caller is responsible for ensuring proper synchronization when using
CurlShareandCurlobjects across multiple threads.
- class pycurl.CurlMime
Python wrapper for libcurl MIME API.
- class pycurl.CurlMimePart
A MIME part belonging to a CurlMime object.