/usr/share/doc/python3-pycurl/tests
NameSizeModeActions
certs/-0755rm
ext/-0755rm
fake-curl/-0755rm
fixtures/-0755rm
matrix/-0755rm
tmp/-0755rm
__pycache__/-0755rm
app.py40880644editdlrm
appmanager.py13800644editdlrm
cadata_test.py14520644editdlrm
certinfo_test.py34680644editdlrm
close_socket_cb_test.py21680644editdlrm
curl_object_test.py48830644editdlrm
debug_test.py22750644editdlrm
default_write_cb_test.py30390644editdlrm
error_constants_test.py6620644editdlrm
error_test.py29010644editdlrm
failonerror_test.py35090644editdlrm
ftp_test.py15370644editdlrm
global_init_test.py10630644editdlrm
header_cb_test.py15600644editdlrm
header_test.py18480644editdlrm
high_level_curl_test.py6320644editdlrm
info_constants_test.py3870644editdlrm
internals_test.py66740644editdlrm
matrix.py68160644editdlrm
multi_option_constants_test.py25030644editdlrm
multi_socket_test.py30490644editdlrm
multi_test.py123130644editdlrm
multi_timer_test.py26950644editdlrm
open_socket_cb_test.py47610644editdlrm
option_constants_test.py163710644editdlrm
perform_test.py21790644editdlrm
procmgr.py27310644editdlrm
protocol_constants_test.py16790644editdlrm
readdata_test.py96230644editdlrm
read_cb_test.py43400644editdlrm
relative_url_test.py5510644editdlrm
reload_test.py4300644editdlrm
reset_test.py26990644editdlrm
resolve_test.py7800644editdlrm
run-quickstart.sh7680755editdlrm
run.sh6900755editdlrm
runwsgi.py37330644editdlrm
seek_cb_constants_test.py8330644editdlrm
setopt_lifecycle_test.py17970644editdlrm
setopt_string_test.py8160644editdlrm
setopt_test.py37730644editdlrm
setopt_unicode_test.py10920644editdlrm
setup_test.py100350644editdlrm
share_test.py17260644editdlrm
sockopt_cb_test.py24530644editdlrm
unset_range_test.py14820644editdlrm
user_agent_string_test.py8200644editdlrm
util.py82910644editdlrm
version_comparison_test.py5140644editdlrm
version_constants_test.py20560644editdlrm
version_test.py3130644editdlrm
vsftpd.conf2940644editdlrm
weakref_test.py4430644editdlrm
write_abort_test.py11940644editdlrm
write_cb_bogus_test.py13810644editdlrm
write_test.py100480644editdlrm
write_to_stringio_test.py12280644editdlrm
xferinfo_cb_test.py21470644editdlrm
__init__.py5350644editdlrm
Edit: /usr/share/doc/python3-pycurl/tests/open_socket_cb_test.py (4761B)
#! /usr/bin/env python # -*- coding: utf-8 -*- # vi:ts=4:et from . import localhost import socket import pycurl import unittest from . import appmanager from . import util setup_module, teardown_module = appmanager.setup(('app', 8380)) socket_open_called_ipv4 = False socket_open_called_ipv6 = False socket_open_called_unix = False socket_open_address = None def socket_open_ipv4(purpose, curl_address): family, socktype, protocol, address = curl_address global socket_open_called_ipv4 global socket_open_address socket_open_called_ipv4 = True socket_open_address = address s = socket.socket(family, socktype, protocol) s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) return s def socket_open_ipv6(purpose, curl_address): family, socktype, protocol, address = curl_address global socket_open_called_ipv6 global socket_open_address socket_open_called_ipv6 = True socket_open_address = address s = socket.socket(family, socktype, protocol) s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) return s def socket_open_unix(purpose, curl_address): family, socktype, protocol, address = curl_address global socket_open_called_unix global socket_open_address socket_open_called_unix = True socket_open_address = address sockets = socket.socketpair() sockets[0].close() return sockets[1] def socket_open_bad(purpose, curl_address): return pycurl.SOCKET_BAD class OpenSocketCbTest(unittest.TestCase): def setUp(self): self.curl = util.DefaultCurl() def tearDown(self): self.curl.close() # This is failing too much on appveyor @util.only_unix def test_socket_open(self): self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_ipv4) self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost) sio = util.BytesIO() self.curl.setopt(pycurl.WRITEFUNCTION, sio.write) self.curl.perform() assert socket_open_called_ipv4 self.assertEqual(("127.0.0.1", 8380), socket_open_address) self.assertEqual('success', sio.getvalue().decode()) @util.only_ipv6 def test_socket_open_ipv6(self): self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_ipv6) self.curl.setopt(self.curl.URL, 'http://[::1]:8380/success') sio = util.BytesIO() self.curl.setopt(pycurl.WRITEFUNCTION, sio.write) try: # perform fails because we do not listen on ::1 self.curl.perform() except pycurl.error: pass assert socket_open_called_ipv6 assert len(socket_open_address) == 4 assert socket_open_address[0] == '::1' assert socket_open_address[1] == 8380 assert type(socket_open_address[2]) == int assert type(socket_open_address[3]) == int @util.min_libcurl(7, 40, 0) @util.only_unix def test_socket_open_unix(self): self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_unix) self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost) self.curl.setopt(self.curl.UNIX_SOCKET_PATH, '/tmp/pycurl-test-path.sock') sio = util.BytesIO() self.curl.setopt(pycurl.WRITEFUNCTION, sio.write) try: # perform fails because we return a socket that is # not attached to anything self.curl.perform() except pycurl.error: pass assert socket_open_called_unix if util.py3: assert isinstance(socket_open_address, bytes) self.assertEqual(b'/tmp/pycurl-test-path.sock', socket_open_address) else: assert isinstance(socket_open_address, str) self.assertEqual('/tmp/pycurl-test-path.sock', socket_open_address) def test_socket_open_none(self): self.curl.setopt(pycurl.OPENSOCKETFUNCTION, None) def test_unset_socket_open(self): self.curl.unsetopt(pycurl.OPENSOCKETFUNCTION) def test_socket_bad(self): self.assertEqual(-1, pycurl.SOCKET_BAD) def test_socket_open_bad(self): self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_bad) self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost) try: self.curl.perform() except pycurl.error as e: # libcurl 7.38.0 for some reason fails with a timeout # (and spends 5 minutes on this test) if pycurl.version_info()[1].split('.') == ['7', '38', '0']: self.assertEqual(pycurl.E_OPERATION_TIMEDOUT, e.args[0]) else: self.assertEqual(pycurl.E_COULDNT_CONNECT, e.args[0]) else: self.fail('Should have raised')