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.

46 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-2007 John-Mark Gurney <jmg@funkthat.com>
  5. __version__ = '$Change$'
  6. # $Id$
  7. from twisted.web import soap
  8. from twisted.python import log
  9. from types import *
  10. import soap_lite
  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. namespace = None
  18. def _gotResult(self, result, request, methodName):
  19. ns = self.namespace
  20. if ns:
  21. meth = "{%s}%s" % (ns, methodName)
  22. else:
  23. meth = methodName
  24. response = soap_lite.build_soap_call(meth, result,
  25. is_response=True, encoding=None)
  26. self._sendResponse(request, response)
  27. def _gotError(self, failure, request, methodName):
  28. e = failure.value
  29. status = 500
  30. if isinstance(e, errorCode):
  31. status = e.status
  32. else:
  33. failure.printTraceback(file = log.logfile)
  34. response = soap_lite.build_soap_error(status)
  35. self._sendResponse(request, response, status=status)