示例#1
0
 def __init__(self, location, max_age, usn):
     super(UPnPRootDevice, self).__init__(channel=usn)
     self._location = location
     self._usn = usn
     self._ready = False
     self._comm_chan = "client." + usn
     self._client = Client(location, channel=self._comm_chan).register(self)
     @handler("response", channel=self._comm_chan)
     def _on_response(self, response):
         if response.status == http_client.OK:
             self._initialize(response.read())
     self.addHandler(_on_response)
     @handler("error", channel=self._comm_chan)
     def _on_error(self, *args, **kwargs):
         self._client.close()
         self.unregister()
     self.addHandler(_on_error)
     self.fire(Request("GET", self._location), self._client)
     self._expiry_timer \
         = Timer(max_age, UPnPDeviceByeBye(usn)).register(self)
示例#2
0
 def __init__(self, location, max_age, usn):
     super(UPnPRootDevice, self).__init__(channel=usn)
     self._location = location
     self._usn = usn
     self._ready = False
     self._comm_chan = "client." + usn
     self._client = Client(location, channel=self._comm_chan).register(self)
     @handler("response", channel=self._comm_chan)
     def _on_response(self, response):
         if response.status == httplib.OK:
             self._initialize(response.read())
     self.addHandler(_on_response)
     @handler("error", channel=self._comm_chan)
     def _on_error(self, *args, **kwargs):
         self._client.close()
         self.unregister()
     self.addHandler(_on_error)
     self.fire(Request("GET", self._location), self._client)
     self._expiry_timer \
         = Timer(max_age, UPnPDeviceByeBye(usn)).register(self)
示例#3
0
class UPnPRootDevice(BaseComponent):

    def __init__(self, location, max_age, usn):
        super(UPnPRootDevice, self).__init__(channel=usn)
        self._location = location
        self._usn = usn
        self._ready = False
        self._comm_chan = "client." + usn
        self._client = Client(location, channel=self._comm_chan).register(self)
        @handler("response", channel=self._comm_chan)
        def _on_response(self, response):
            if response.status == http_client.OK:
                self._initialize(response.read())
        self.addHandler(_on_response)
        @handler("error", channel=self._comm_chan)
        def _on_error(self, *args, **kwargs):
            self._client.close()
            self.unregister()
        self.addHandler(_on_error)
        self.fire(Request("GET", self._location), self._client)
        self._expiry_timer \
            = Timer(max_age, UPnPDeviceByeBye(usn)).register(self)

    def _initialize(self, xml_src):
        data = XML(xml_src)
        self._friendly_name = data.findtext \
            ("{%s}device/{%s}friendlyName" \
             % (SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA))
        icons = data.findall \
            ("{%s}device/{%s}iconList/{%s}icon" \
             % (SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA))
        self._icons = []
        for icon in icons:
            width = int(icon.findtext("{%s}width" % SSDP_DEVICE_SCHEMA))
            height = int(icon.findtext("{%s}height" % SSDP_DEVICE_SCHEMA))
            url = urljoin(self._location,
                          icon.findtext("{%s}url" % SSDP_DEVICE_SCHEMA))
            self._icons.append(IconInfo(width, height, url))
        self._ready = True

    @handler("upnp_device_alive")
    def _on_device_alive \
        (self, location, notification_type, max_age, server, usn):
        self._expiry_timer.interval = max_age
        self._expiry_timer.reset()

    @handler("upnp_device_bye_bye")
    def _on_device_bye_bye (self, usn):
        self._client.close()
        self.unregister()

    @property
    def usn(self):
        return getattr(self, "_usn", None)
        
    @property
    def location(self):
        return getattr(self, "_location", None)

    @property
    def ready(self):
        return getattr(self, "_ready", None)

    @property
    def friendly_name(self):
        return getattr(self, "_friendly_name", None)

    @property
    def icons(self):
        return copy(getattr(self, "_icons", None))
    
    @property
    def valid_until(self):
        return self._expiry_timer._eTime \
            if hasattr(self, "_expiry_timer") else None
        
示例#4
0
class UPnPRootDevice(BaseComponent):

    def __init__(self, location, max_age, usn):
        super(UPnPRootDevice, self).__init__(channel=usn)
        self._location = location
        self._usn = usn
        self._ready = False
        self._comm_chan = "client." + usn
        self._client = Client(location, channel=self._comm_chan).register(self)
        @handler("response", channel=self._comm_chan)
        def _on_response(self, response):
            if response.status == httplib.OK:
                self._initialize(response.read())
        self.addHandler(_on_response)
        @handler("error", channel=self._comm_chan)
        def _on_error(self, *args, **kwargs):
            self._client.close()
            self.unregister()
        self.addHandler(_on_error)
        self.fire(Request("GET", self._location), self._client)
        self._expiry_timer \
            = Timer(max_age, UPnPDeviceByeBye(usn)).register(self)

    def _initialize(self, xml_src):
        data = XML(xml_src)
        self._friendly_name = data.findtext \
            ("{%s}device/{%s}friendlyName" \
             % (SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA))
        icons = data.findall \
            ("{%s}device/{%s}iconList/{%s}icon" \
             % (SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA, SSDP_DEVICE_SCHEMA))
        self._icons = []
        for icon in icons:
            width = int(icon.findtext("{%s}width" % SSDP_DEVICE_SCHEMA))
            height = int(icon.findtext("{%s}height" % SSDP_DEVICE_SCHEMA))
            url = urljoin(self._location,
                          icon.findtext("{%s}url" % SSDP_DEVICE_SCHEMA))
            self._icons.append(IconInfo(width, height, url))
        self._ready = True

    @handler("upnp_device_alive")
    def _on_device_alive \
        (self, location, notification_type, max_age, server, usn):
        self._expiry_timer.interval = max_age
        self._expiry_timer.reset()

    @handler("upnp_device_bye_bye")
    def _on_device_bye_bye (self, usn):
        self._client.close()
        self.unregister()

    @property
    def usn(self):
        return getattr(self, "_usn", None)
        
    @property
    def location(self):
        return getattr(self, "_location", None)

    @property
    def ready(self):
        return getattr(self, "_ready", None)

    @property
    def friendly_name(self):
        return getattr(self, "_friendly_name", None)

    @property
    def icons(self):
        return copy(getattr(self, "_icons", None))
    
    @property
    def valid_until(self):
        return self._expiry_timer._eTime \
            if hasattr(self, "_expiry_timer") else None