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.

33 lines
980 B

  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. import SOAPpy
  6. class errorCode(Exception):
  7. def __init__(self, status):
  8. self.status = status
  9. class UPnPPublisher(soap.SOAPPublisher):
  10. """UPnP requires OUT parameters to be returned in a slightly
  11. different way than the SOAPPublisher class does."""
  12. def _gotResult(self, result, request, methodName):
  13. response = SOAPpy.buildSOAP(kw=result, encoding=self.encoding)
  14. self._sendResponse(request, response)
  15. def _gotError(self, failure, request, methodName):
  16. e = failure.value
  17. status = 500
  18. if isinstance(e, SOAPpy.faultType):
  19. fault = e
  20. else:
  21. if isinstance(e, errorCode):
  22. status = e.status
  23. fault = SOAPpy.faultType("%s:Server" % SOAPpy.NS.ENV_T, "Method %s failed." % methodName)
  24. response = SOAPpy.buildSOAP(fault, encoding=self.encoding)
  25. self._sendResponse(request, response, status=status)