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.

40 lines
1.1 KiB

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