A Python UPnP Media Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

  1. # Licensed under the MIT license
  2. # http://opensource.org/licenses/mit-license.php
  3. # Copyright 2005, Tim Potter <tpot@samba.org>
  4. from twisted.web import soap
  5. from twisted.python import log
  6. import SOAPpy
  7. class errorCode(Exception):
  8. def __init__(self, status):
  9. self.status = status
  10. class UPnPPublisher(soap.SOAPPublisher):
  11. """UPnP requires OUT parameters to be returned in a slightly
  12. different way than the SOAPPublisher class does."""
  13. def _gotResult(self, result, request, methodName):
  14. response = SOAPpy.buildSOAP(kw=result, encoding=self.encoding)
  15. self._sendResponse(request, response)
  16. def _gotError(self, failure, request, methodName):
  17. e = failure.value
  18. status = 500
  19. if isinstance(e, SOAPpy.faultType):
  20. fault = e
  21. else:
  22. if isinstance(e, errorCode):
  23. status = e.status
  24. else:
  25. failure.printTraceback(file = log.logfile)
  26. fault = SOAPpy.faultType("%s:Server" % SOAPpy.NS.ENV_T, "Method %s failed." % methodName)
  27. response = SOAPpy.buildSOAP(fault, encoding=self.encoding)
  28. self._sendResponse(request, response, status=status)