ftp_deploy.utils.curl: 26 total statements, 100.0% covered

Generated: Sun 2014-03-16 19:26 GMT

Source file: /var/www/service.dev/service/ftp_deploy/utils/curl.py

Stats: 23 executed, 0 missed, 3 excluded, 15 ignored

  1. import pycurl
  2. import certifi
  3. import StringIO
  4. class curl_connection(object):
  5. """Helper for curl connections"""
  6. def __init__(self, username, password):
  7. self.username = username
  8. self.password = password
  9. def authenticate(self):
  10. """Authenticate curl connection"""
  11. self.curl = pycurl.Curl()
  12. self.curl.setopt(pycurl.CAINFO, certifi.where())
  13. self.curl.setopt(self.curl.USERPWD, '%s:%s' % (self.username, self.password))
  14. def perform(self, url):
  15. """Perform get request and return respond value"""
  16. b = StringIO.StringIO()
  17. self.curl.setopt(self.curl.URL, str(url))
  18. self.curl.setopt(self.curl.WRITEFUNCTION, b.write)
  19. self.curl.perform()
  20. return b.getvalue()
  21. def perform_post(self, url, post):
  22. """Perform post request"""
  23. self.curl.setopt(self.curl.URL, str(url))
  24. self.curl.setopt(self.curl.POST, 1)
  25. self.curl.setopt(self.curl.POSTFIELDS, post)
  26. self.curl.perform()
  27. def get_http_code(self):
  28. """Return curl HTTP Code"""
  29. return self.curl.getinfo(pycurl.HTTP_CODE)
  30. def close(self):
  31. """Close curl connection"""
  32. self.curl.close()