示例#1
0
            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']
示例#2
0
    def __init__(self, type, params):
        self.type = type
        self.params = params
    def __repr__(self):
        return "%s, params=%s" % (self.type,self.params)

def _parseContentDisposition(header):
    """
    Parses a Content-Disposition header.
    """
    type,args = http_headers.parseArgs(header)
    type = type[0].lower()
    if not type == "form-data" and not type == "file":
        raise ValueError("Content-Disposition type is not 'form-data' or 'file'")
    return ContentDisposition(type, dict(args))
DefaultHTTPHandler.addParser("content-disposition", (tokenize, _parseContentDisposition))

class PostableResource(resource.Resource, CoreLogger):

    def acceptFile(self, headers):
        """
        The default function which is called before reading a file sent via an HTTP POST.
        If the return value is a string, then the stream data will be appended to the
        file at the path referenced by the string, otherwise the stream data is discarded.

        Note that if for some reason open() fails (part of the path doesn't exists, you
        don't have permission, ...) we will silently fail and move on.  It is the
        responsibility of the implementor of acceptFile to do these checks.
        """
        return None
示例#3
0
                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))
示例#4
0
        try:
            if not request.headers.hasHeader('sid'):
                return Response(412)
            sid = request.headers.getHeader('sid')
            self.service._unsubscribe(sid)
            return Response(200)
        except KeyError:
            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))