Browse Source

support returning other error codes as per UPnP spec..

[git-p4: depot-paths = "//depot/": change = 765]
replace/4e84fdb41ea781c7a8f872baa423e8b3be4045a7
John-Mark Gurney 19 years ago
parent
commit
dc2cd57ffd
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      upnp.py

+ 16
- 0
upnp.py View File

@@ -7,6 +7,10 @@ from twisted.web import soap


import SOAPpy import SOAPpy


class errorCode(Exception):
def __init__(self, status):
self.status = status

class UPnPPublisher(soap.SOAPPublisher): class UPnPPublisher(soap.SOAPPublisher):
"""UPnP requires OUT parameters to be returned in a slightly """UPnP requires OUT parameters to be returned in a slightly
different way than the SOAPPublisher class does.""" different way than the SOAPPublisher class does."""
@@ -14,3 +18,15 @@ class UPnPPublisher(soap.SOAPPublisher):
def _gotResult(self, result, request, methodName): def _gotResult(self, result, request, methodName):
response = SOAPpy.buildSOAP(kw=result, encoding=self.encoding) response = SOAPpy.buildSOAP(kw=result, encoding=self.encoding)
self._sendResponse(request, response) self._sendResponse(request, response)

def _gotError(self, failure, request, methodName):
e = failure.value
status = 500
if isinstance(e, SOAPpy.faultType):
fault = e
else:
if isinstance(e, errorCode):
status = e.status
fault = SOAPpy.faultType("%s:Server" % SOAPpy.NS.ENV_T, "Method %s failed." % methodName)
response = SOAPpy.buildSOAP(fault, encoding=self.encoding)
self._sendResponse(request, response, status=status)

Loading…
Cancel
Save