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