old_contents: #! /usr/bin/env python
  # vi:ts=4:et
  # $Id: xmlrpc_curl.py,v 1.2 2002/08/29 14:36:52 mfx Exp $
  
  import xmlrpclib, pycurl
  try:  import cStringIO as StringIO
  except:  import StringIO
  
  
  class CURLTransport(xmlrpclib.Transport):
      """Handles a cURL HTTP transaction to an XML-RPC server."""
  
      xmlrpc_h = [ "User-Agent: PycURL XML-RPC", "Content-Type: text/xml" ]
  
      def __init__(self, username=None, password=None):
          self.c = pycurl.Curl()
          self.c.setopt(pycurl.POST, 1)
          self.c.setopt(pycurl.HTTPHEADER, self.xmlrpc_h)
          if username != None and password != None:
              self.c.setopt(pycurl.USERPWD, '%s:%s' % (username, password))
  
      def request(self, host, handler, request_body, verbose=0):
          b = StringIO.StringIO()
          self.c.setopt(pycurl.URL, 'http://%s%s' % (host, handler))
          self.c.setopt(pycurl.POSTFIELDS, request_body)
          self.c.setopt(pycurl.WRITEFUNCTION, b.write)
          self.c.setopt(pycurl.VERBOSE, verbose)
          self.verbose = verbose
          try:
             self.c.perform()
          except pycurl.error, v:
              raise xmlrpclib.ProtocolError(
                  host + handler,
                  v[0], v[1], None
                  )
          b.seek(0)
          return self.parse_response(b)
  
  
  if __name__ == "__main__":
      ## Test
      server = xmlrpclib.ServerProxy("http://betty.userland.com",
                                     transport=CURLTransport())
      print server
      try:
          print server.examples.getStateName(41)
      except xmlrpclib.Error, v:
          print "ERROR", v
  
new_contents: #! /usr/bin/env python
  # vi:ts=4:et
  # $Id: xmlrpc_curl.py,v 1.3 2002/12/09 14:35:29 kjetilja Exp $
  
  # We should ignore SIGPIPE when using pycurl.NOSIGNAL - see the libcurl
  # documentation `libcurl-the-guide' for more info.
  try:
      import signal
      from signal import SIGPIPE, SIG_IGN
      signal.signal(signal.SIGPIPE, signal.SIG_IGN)
  except ImportError:  pass
  
  import xmlrpclib, pycurl
  try:  import cStringIO as StringIO
  except:  import StringIO
  
  
  class CURLTransport(xmlrpclib.Transport):
      """Handles a cURL HTTP transaction to an XML-RPC server."""
  
      xmlrpc_h = [ "User-Agent: PycURL XML-RPC", "Content-Type: text/xml" ]
  
      def __init__(self, username=None, password=None):
          self.c = pycurl.Curl()
          self.c.setopt(pycurl.POST, 1)
          self.c.setopt(pycurl.NOSIGNAL, 1)
          self.c.setopt(pycurl.HTTPHEADER, self.xmlrpc_h)
          if username != None and password != None:
              self.c.setopt(pycurl.USERPWD, '%s:%s' % (username, password))
  
      def request(self, host, handler, request_body, verbose=0):
          b = StringIO.StringIO()
          self.c.setopt(pycurl.URL, 'http://%s%s' % (host, handler))
          self.c.setopt(pycurl.POSTFIELDS, request_body)
          self.c.setopt(pycurl.WRITEFUNCTION, b.write)
          self.c.setopt(pycurl.VERBOSE, verbose)
          self.verbose = verbose
          try:
             self.c.perform()
          except pycurl.error, v:
              raise xmlrpclib.ProtocolError(
                  host + handler,
                  v[0], v[1], None
                  )
          b.seek(0)
          return self.parse_response(b)
  
  
  if __name__ == "__main__":
      ## Test
      server = xmlrpclib.ServerProxy("http://betty.userland.com",
                                     transport=CURLTransport())
      print server
      try:
          print server.examples.getStateName(41)
      except xmlrpclib.Error, v:
          print "ERROR", v
  
subject: set nosignal here and disable sigio