def __init__(self, service, event_host, callback, cargo): """ Constructor for the RenewSubscribeRequest class. @param service: service that is renewing the subscribe @param event_host: 2-tuple (host, port) of the event listener server @param callback: callback @param cargo: callback parameters @type service: Service @type event_host: tuple @type callback: callable """ log.debug("renew subscribe") if not service.event_sid or service.event_sid == "": return self.callback = callback self.cargo = cargo self.service = service addr = "%s%s" % (service.url_base, service.event_sub_url) Paddr = parse_url(addr) headers = {} headers["HOST"] = '%s:%d' % (Paddr.hostname, Paddr.port) headers["SID"] = self.service.event_sid headers["TIMEOUT"] = 'Second-300' run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=0, method='SUBSCRIBE', url=addr, headers=headers)
def __init__(self, service, event_host, callback, cargo): """ Constructor for the SubscribeRequest class. @param service: service that is subscribing @param event_host: 2-tuple (host, port) of the event listener server @param callback: callback @param cargo: callback parameters @type service: Service @type event_host: tuple @type callback: callable """ log.debug("subscribe") self.callback = callback self.cargo = cargo self.service = service addr = "%s%s" % (service.url_base, service.event_sub_url) Paddr = parse_url(addr) headers = {} headers["User-agent"] = 'BRisa UPnP Framework' headers["TIMEOUT"] = 'Second-300' headers["NT"] = 'upnp:event' headers["CALLBACK"] = "<http://%s:%d/eventSub>" % event_host headers["HOST"] = '%s:%d' % (Paddr.hostname, Paddr.port) run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=0, method='SUBSCRIBE', url=addr, headers=headers)
def __init__(self, service, event_host, callback, cargo): """ Constructor for the UnsubscribeRequest class. @param service: service that is unsubscribing @param event_host: 2-tuple (host, port) of the event listener server @param callback: callback @param cargo: callback parameters @type service: Service @type event_host: tuple @type callback: callable """ self.old_sid = service.event_sid service.event_sid = "" service.event_timeout = 0 self.callback = callback self.cargo = cargo self.service = service addr = "%s%s" % (service.url_base, service.event_sub_url) Paddr = parse_url(addr) headers = {} headers["User-agent"] = 'BRISA-CP' headers["HOST"] = '%s:%d' % (Paddr.hostname, Paddr.port) headers["SID"] = self.old_sid run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=0, method='UNSUBSCRIBE', url=addr, headers=headers)
def _build_async(self, cb): """ Builds the service asynchronously. Forwards True to the specified callback 'cb' if the service was successfully built (otherwise, forwards False). """ # print "_build_async: " + str(self.scpd_url) # print "_build_async url_base: " + str(self.url_base) # TODO: test file processing below! if is_file(self.scpd_url): # fd = open(self.scpd_url[8:], 'r') run_async_call(open, success_callback=self._fetch_scpd_async_done, error_callback=self._fetch_scpd_async_error, delay=0, file=self.scpd_url[8:], mode='r', success_callback_cargo=cb, error_callback_cargo=cb) else: if is_relative(self.scpd_url, self.url_base): path = '%s%s' % (self.url_base, self.scpd_url) else: path = self.scpd_url # print "_build_async path: " + str(path) run_async_call(url_fetch, success_callback=self._fetch_scpd_async_done, error_callback=self._fetch_scpd_async_error, delay=0, url=path, success_callback_cargo=cb, error_callback_cargo=cb)
def __init__(self, service, event_host, callback, cargo): """ Constructor for the SubscribeRequest class. @param service: service that is subscribing @param event_host: 2-tuple (host, port) of the event listener server @param callback: callback @param cargo: callback parameters @type service: Service @type event_host: tuple @type callback: callable """ log.debug("subscribe") self.callback = callback self.cargo = cargo self.service = service addr = "%s%s" % (service.url_base, service.event_sub_url) Paddr = parse_url(addr) headers = {} # headers["Host"] = Paddr.hostname headers["User-agent"] = 'BRisa UPnP Framework' headers["TIMEOUT"] = 'Second-1800' headers["NT"] = 'upnp:event' headers["CALLBACK"] = "<http://%s:%d/eventSub>" % event_host headers["HOST"] = '%s:%d' % (Paddr.hostname, Paddr.port) run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=0, method='SUBSCRIBE', url=addr, headers=headers)
def _build_async(self, cb): """ Builds the service asynchronously. Forwards True to the specified callback 'cb' if the service was successfully built (otherwise, forwards False). """ # TODO: test file processing below! if is_file(self.scpd_url): # fd = open(self.scpd_url[8:], 'r') run_async_call( open, success_callback=self._fetch_scpd_async_done, error_callback=self._fetch_scpd_async_error, delay=0, file=self.scpd_url[8:], mode="r", success_callback_cargo=cb, error_callback_cargo=cb, ) else: if is_relative(self.scpd_url, self.url_base): path = "%s%s" % (self.url_base, self.scpd_url) else: path = self.scpd_url run_async_call( url_fetch, success_callback=self._fetch_scpd_async_done, error_callback=self._fetch_scpd_async_error, delay=0, url=path, success_callback_cargo=cb, error_callback_cargo=cb, )
def mount_device_async(self, callback, cargo): self.callback = callback self.cargo = cargo log.debug('self.location is %s' % self.location) if self.filename is None: run_async_call(url_fetch, success_callback=self.mount_device_async_gotdata, error_callback=self.mount_device_async_error, delay=0, url=self.location) else: self.mount_device_async_gotdata(self, open(self.filename))
def _build_async(self, cb): """ Builds the service asynchronously. Forwards True to the specified callback 'cb' if the service was successfully built (otherwise, forwards False). """ if is_relative(self.scpd_url, self.url_base): path = '%s%s' % (self.url_base, self.scpd_url) else: path = self.scpd_url run_async_call(url_fetch, success_callback=self._fetch_scpd_async_done, error_callback=self._fetch_scpd_async_error, delay=0, url=path, success_callback_cargo=cb, error_callback_cargo=cb)
def mount_device_async(self, callback, cargo): self.callback = callback self.cargo = cargo log.debug('self.location is %s' % self.location) # if '0.0.0.0' in self.location: # import traceback # traceback.print_stack() if self.filename is None: run_async_call(url_fetch, success_callback=self.mount_device_async_gotdata, error_callback=self.mount_device_async_error, delay=0, url=self.location) else: self.mount_device_async_gotdata(self, open(self.filename))
def __init__(self, subscriber, variables, event_delay, cargo): """ Constructor for the EventMessage class. @param subscriber: subscriber that will receive the message @param variables: variables of the event @param event_delay: delay to wait before sending the event @param cargo: callback parameters @type subscriber: Subscriber @type variables: dict @type event_delay: float """ log.debug("event message") if not variables: log.error("There are no variables to send") return self.cargo = cargo headers = {} headers["HOST"] = subscriber.delivery_url headers["CONTENT-TYPE"] = 'text/xml' headers["NT"] = 'upnp:event' headers["NTS"] = 'upnp:propchange' headers["SID"] = "uuid:" + str(subscriber.subscription_id) headers["SEQ"] = str(subscriber.event_key) subscriber.event_key_increment() event_body = self._build_message_body(variables) headers["CONTENT-LENGTH"] = str(len(event_body)) log.debug("Running http call") run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=event_delay, method='NOTIFY', url=subscriber.delivery_url, body=event_body, headers=headers)
def __init__(self, subscriber, variables, event_delay, cargo): """ Constructor for the EventMessage class. @param subscriber: subscriber that will receive the message @param variables: variables of the event @param event_delay: delay to wait before sending the event @param cargo: callback parameters @type subscriber: Subscriber @type variables: dict @type event_delay: float """ log.debug("event message") if not variables: log.error("There are no variables to send") return self.cargo = cargo headers = {} # headers["HOST"] = subscriber.delivery_url headers["HOST"] = subscriber.host headers["CONTENT-TYPE"] = 'text/xml' headers["NT"] = 'upnp:event' headers["NTS"] = 'upnp:propchange' headers["SID"] = "uuid:" + str(subscriber.subscription_id) headers["SEQ"] = str(subscriber.event_key) subscriber.event_key_increment() event_body = self._build_message_body(variables) headers["CONTENT-LENGTH"] = str(len(event_body)) log.debug("Running http call") run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=event_delay, method='NOTIFY', url=subscriber.delivery_url, body=event_body, headers=headers)
def __init__(self, service, event_host, callback, cargo): """ Constructor for the RenewSubscribeRequest class. @param service: service that is renewing the subscribe @param event_host: 2-tuple (host, port) of the event listener server @param callback: callback @param cargo: callback parameters @type service: Service @type event_host: tuple @type callback: callable """ log.debug("renew subscribe") if not service.event_sid or service.event_sid == "": return self.callback = callback self.cargo = cargo self.service = service addr = "%s%s" % (service.url_base, service.event_sub_url) Paddr = parse_url(addr) headers = {} headers["HOST"] = '%s:%d' % (Paddr.hostname, Paddr.port) headers["SID"] = self.service.event_sid headers["TIMEOUT"] = 'Second-1800' run_async_call(http_call, success_callback=self.response, error_callback=self.error, delay=0, method='SUBSCRIBE', url=addr, headers=headers)