old_contents: #! /usr/bin/env python
  # -*- coding: utf-8 -*-
  # vi:ts=4:et
  
  import socket
  import pycurl
  import unittest
  
  from . import appmanager
  from . import util
  
  setup_module, teardown_module = appmanager.setup(('app', 8380))
  
  socket_open_called = False
  socket_open_address = None
  
  def socket_open(purpose, curl_address):
      family, socktype, protocol, address = curl_address
      global socket_open_called
      global socket_open_address
      socket_open_called = True
      socket_open_address = address
  
      #print(family, socktype, protocol, address)
      s = socket.socket(family, socktype, protocol)
      s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
      return s
  
  class OpenSocketCbTest(unittest.TestCase):
      def setUp(self):
          self.curl = pycurl.Curl()
  
      def tearDown(self):
          self.curl.close()
  
      def test_socket_open(self):
          self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open)
          self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
          sio = util.BytesIO()
          self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
          self.curl.perform()
  
          assert socket_open_called
          self.assertEqual(("127.0.0.1", 8380), socket_open_address)
          self.assertEqual('success', sio.getvalue().decode())
  
      def test_socket_open_none(self):
          self.curl.setopt(pycurl.OPENSOCKETFUNCTION, None)
  
      def test_unset_socket_open(self):
          self.curl.unsetopt(pycurl.OPENSOCKETFUNCTION)
  
new_contents: #! /usr/bin/env python
  # -*- coding: utf-8 -*-
  # vi:ts=4:et
  
  import socket
  import pycurl
  import unittest
  
  from . import appmanager
  from . import util
  
  setup_module, teardown_module = appmanager.setup(('app', 8380))
  
  socket_open_called = False
  socket_open_address = None
  
  def socket_open(purpose, curl_address):
      family, socktype, protocol, address = curl_address
      global socket_open_called
      global socket_open_address
      socket_open_called = True
      socket_open_address = address
  
      assert len(address) == 2
      assert address[0] == '127.0.0.1'
      assert address[1] == 8380
  
      #print(family, socktype, protocol, address)
      s = socket.socket(family, socktype, protocol)
      s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
      return s
  
  class OpenSocketCbTest(unittest.TestCase):
      def setUp(self):
          self.curl = pycurl.Curl()
  
      def tearDown(self):
          self.curl.close()
  
      def test_socket_open(self):
          self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open)
          self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
          sio = util.BytesIO()
          self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
          self.curl.perform()
  
          assert socket_open_called
          self.assertEqual(("127.0.0.1", 8380), socket_open_address)
          self.assertEqual('success', sio.getvalue().decode())
  
      def test_socket_open_none(self):
          self.curl.setopt(pycurl.OPENSOCKETFUNCTION, None)
  
      def test_unset_socket_open(self):
          self.curl.unsetopt(pycurl.OPENSOCKETFUNCTION)
  
subject: Test ipv4 address spec