stream="""<?xml version="1.0"?> <u:Envelope xmlns:u="http://schemas.xmlsoap.org/soap/envelope" u:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" <u:Body> <u:Fault> <faultcode>u:Client</faultcode> <faultstring>UPnPError</faultstring> <detail> <UPnPError xmlns="urn:schemas-upnp-org:control-1-0"> <errorCode>%i</errorCode> <errorDescription>%s</errorDescription> </UPnPError> </detail> </u:Fault> </u:Body> </u:Envelope>""" % (e.code, e.reason) ) def http_POST(self, request): request.buffered_stream = BufferedStream(request.stream) request.soap_data = '' request.soap_ns,request.soap_action = request.headers.getHeader('soapaction') return self._readSoapData(request).addCallbacks(lambda l: self._dispatchSoapRequest(request)) def _parseSoapAction(header): return ''.join(header.split('"')).split('#', 1) DefaultHTTPHandler.addParser("soapaction", (last, _parseSoapAction)) DefaultHTTPHandler.addGenerators("EXT", (str, singleHeader))
s.handle.reset(timeout) logger.log_debug("service %s renewed subscription %s for %i seconds" % (self.serviceID, sid, timeout)) except Exception, e: logger.log_debug("service %s failed to renew %s: %s" % (self.serviceID, sid, str(e))) def _unsubscribe(self, sid): try: s = self._subscribers[sid] s.handle.cancel() del self._subscribers[sid] logger.log_debug("service %s unsubscribed %s" % (self.serviceID, sid)) except Exception, e: logger.log_debug("service %s failed to unsubscribe %s: %s" % (self.serviceID, sid, str(e))) def _notify(self, statevars): for s in self._subscribers.values(): s._notify(statevars) def __str__(self): return self.serviceID def _generateNTS(nts): return str(nts) DefaultHTTPHandler.addGenerators("NTS", (_generateNTS, singleHeader)) def _generateSEQ(seq): return str(seq) DefaultHTTPHandler.addGenerators("SEQ", (_generateSEQ, singleHeader)) # Define the public API __all__ = ['UPNPDeviceService', 'Subscription']
return Response(412) except Exception, e: logger.log_fatal("UNSUBSCRIBE failed: %s" % e) return Response(500) def _parseCallback(header): """Returns a list of one or more callback URLs""" return [cb[1:] for cb in header.split('>') if not cb == ''] DefaultHTTPHandler.addParser("Callback", (last, _parseCallback)) def _parseNT(header): """Returns the notification type header""" return header DefaultHTTPHandler.addParser("NT", (last, _parseNT)) DefaultHTTPHandler.addGenerators("NT", (str, singleHeader)) def _parseSID(header): """Returns the subscription id header""" return header DefaultHTTPHandler.addParser("SID", (last, _parseNT)) DefaultHTTPHandler.addGenerators("SID", (str, singleHeader)) def _parseTimeout(header): """Returns the event timeout""" try: unused,timeout = header.split('-') if timeout.lower() == 'infinite': return -1 timeout = int(timeout)