Ejemplo n.º 1
0
 def get_action_results(self, result, action, instance):
     """ check for out arguments
         if yes: check if there are related ones to StateVariables with
                 non A_ARG_TYPE_ prefix
                 if yes: check if there is a call plugin method for this action
                         if yes: update StateVariable values with call result
                         if no:  get StateVariable values and
                                 add them to result dict
     """
     self.debug('get_action_results', result)
     #print 'get_action_results', action, instance
     r = result
     notify = []
     for argument in action.get_out_arguments():
         #print 'get_state_variable_contents', argument.name
         if argument.name[0:11] != 'A_ARG_TYPE_':
             if action.get_callback() != None:
                 variable = self.variables[instance][argument.get_state_variable()]
                 variable.update(r[argument.name])
                 #print 'update state variable contents', variable.name, variable.value, variable.send_events
                 if(variable.send_events == 'yes' and variable.moderated == False):
                     notify.append(variable)
             else:
                 variable = self.variables[instance][argument.get_state_variable()]
                 #print 'get state variable contents', variable.name, variable.value
                 r[argument.name] = variable.value
                 #print "r", r
         self.service.propagate_notification(notify)
     #r= { '%sResponse'%action.name: r}
     self.info( 'action_results', action.name, r)
     return r
Ejemplo n.º 2
0
    def get_action_results(self, result, action, instance):
        """ check for out arguments
            if yes: check if there are related ones to StateVariables with
                    non A_ARG_TYPE_ prefix
                    if yes: check if there is a call plugin method for this action
                            if yes: update StateVariable values with call result
                            if no:  get StateVariable values and
                                    add them to result dict
        """
        self.debug('get_action_results %s', result)
        # print 'get_action_results', action, instance
        r = result
        notify = []
        for argument in action.get_out_arguments():
          # print 'get_state_variable_contents', argument.name
          if argument.name[0:11] != 'A_ARG_TYPE_':
            if action.get_callback() is not None:
              variable = self.variables[instance][argument.get_state_variable()]
              variable.update(r[argument.name])
              if variable.send_events == 'yes' and not variable.moderated:
                  notify.append(variable)
            else:
              variable = self.variables[instance][argument.get_state_variable()]
              r[argument.name] = variable.value
          self.service.propagate_notification(notify)

        self.info('action_results unsorted %s %s', action.name, r)
        if len(r) == 0:
            return r

        ordered_result = OrderedDict()
        for argument in action.get_out_arguments():
          ordered_result[argument.name] = r[argument.name]
        self.info('action_results sorted %s %s', action.name, ordered_result)
        return ordered_result
Ejemplo n.º 3
0
 def process_value(result):
     variable.update(result)
     if default == True:
         variable.default_value = variable.value
     if(variable.send_events == True and
         variable.moderated == False and
         len(self._subscribers) > 0):
         xml = self.build_single_notification(instance, variable_name, variable.value)
         for s in self._subscribers.values():
             event.send_notification(s, xml)
Ejemplo n.º 4
0
 def process_value(result):
     variable.update(result)
     if default:
         variable.default_value = variable.value
     if variable.send_events and not variable.moderated and len(self._subscribers) > 0:
         xml = self.build_single_notification(instance, variable_name, variable.value)
         for s in self._subscribers.values():
             d, p = event.send_notification(s, xml)
             self._pending_notifications[d] = p
             d.addBoth(self.rm_notification, d)
Ejemplo n.º 5
0
 def process_value(result):
     variable.update(result)
     if default == True:
         variable.default_value = variable.value
     if (variable.send_events == True and variable.moderated == False
             and len(self._subscribers) > 0):
         xml = self.build_single_notification(instance, variable_name,
                                              variable.value)
         for s in self._subscribers.values():
             d, p = event.send_notification(s, xml)
             self._pending_notifications[d] = p
             d.addBoth(self.rm_notification, d)
Ejemplo n.º 6
0
 def process_value(result):
     variable.update(result)
     if default:
         variable.default_value = variable.value
     if variable.send_events and not variable.moderated and len(
             self._subscribers) > 0:
         xml = self.build_single_notification(instance, variable_name,
                                              variable.value)
         for s in list(self._subscribers.values()):
             d, p = event.send_notification(s, xml)
             self._pending_notifications[d] = p
             d.addBoth(self.rm_notification, d)
Ejemplo n.º 7
0
    def get_action_results(self, result, action, instance):
        """ check for out arguments
            if yes: check if there are related ones to StateVariables with
                    non A_ARG_TYPE_ prefix
                    if yes: check if there is a call plugin method for this action
                            if yes: update StateVariable values with call result
                            if no:  get StateVariable values and
                                    add them to result dict
        """
        self.debug('get_action_results %s', result)
        #print 'get_action_results', action, instance
        notify = []
        for argument in action.get_out_arguments():
            #print 'get_state_variable_contents', argument.name
            if argument.name[0:11] != 'A_ARG_TYPE_':
                variable = self.variables[instance][argument.get_state_variable()]
                variable.update(result[argument.name].decode('utf-8').encode('utf-8'))
                #print 'update state variable contents', variable.name, variable.value, variable.send_events
                if(variable.send_events == 'yes' and variable.moderated == False):
                    notify.append(variable)

            self.service.propagate_notification(notify)
        self.info('action_results unsorted %s %s', action.name, result)
        if len(result) == 0:
            return result
        ordered_result = OrderedDict()
        for argument in action.get_out_arguments():
            if action.name == 'XXXBrowse' and argument.name == 'Result':
                didl = DIDLLite.DIDLElement.fromString(result['Result'].decode('utf-8'))
                changed = False
                for item in didl.getItems():
                    new_res = DIDLLite.Resources()
                    for res in item.res:
                        remote_protocol, remote_network, remote_content_format, _ = res.protocolInfo.split(':')
                        if remote_protocol == 'http-get' and remote_network == '*':
                            quoted_url = urllib.quote_plus(res.data)
                            print "modifying", res.data
                            res.data = urlparse.urlunsplit(('http', self.service.device.external_address, 'mirabeau', quoted_url, ""))
                            print "--->", res.data
                            new_res.append(res)
                            changed = True
                    item.res = new_res
                if changed == True:
                    didl.rebuild()
                    ordered_result[argument.name] = didl.toString()  # .replace('<ns0:','<')
                else:
                    ordered_result[argument.name] = result[argument.name].decode('utf-8')
            else:
                ordered_result[argument.name] = result[argument.name].decode('utf-8').encode('utf-8')
        self.info('action_results sorted %s %s', action.name, ordered_result)
        return ordered_result
Ejemplo n.º 8
0
    def get_action_results(self, result, action, instance):
        """ check for out arguments
            if yes: check if there are related ones to StateVariables with
                    non A_ARG_TYPE_ prefix
                    if yes: check if there is a call plugin method for this action
                            if yes: update StateVariable values with call result
                            if no:  get StateVariable values and
                                    add them to result dict
        """
        self.debug('get_action_results', result)
        #print 'get_action_results', action, instance
        notify = []
        for argument in action.get_out_arguments():
            #print 'get_state_variable_contents', argument.name
            if argument.name[0:11] != 'A_ARG_TYPE_':
                variable = self.variables[instance][argument.get_state_variable()]
                variable.update(result[argument.name].decode('utf-8').encode('utf-8'))
                #print 'update state variable contents', variable.name, variable.value, variable.send_events
                if(variable.send_events == 'yes' and variable.moderated == False):
                    notify.append(variable)

            self.service.propagate_notification(notify)
        self.info( 'action_results unsorted', action.name, result)
        if len(result) == 0:
            return result
        ordered_result = OrderedDict()
        for argument in action.get_out_arguments():
            if action.name  == 'XXXBrowse' and argument.name == 'Result':
                didl = DIDLLite.DIDLElement.fromString(result['Result'].decode('utf-8'))
                changed = False
                for item in didl.getItems():
                    new_res = DIDLLite.Resources()
                    for res in item.res:
                        remote_protocol,remote_network,remote_content_format,_ = res.protocolInfo.split(':')
                        if remote_protocol == 'http-get' and remote_network == '*':
                            quoted_url = urllib.quote_plus(res.data)
                            #print "modifying", res.data
                            res.data = urlparse.urlunsplit(('http', self.service.device.external_address,'mirabeau',quoted_url,""))
                            #print "--->", res.data
                            new_res.append(res)
                            changed = True
                    item.res = new_res
                if changed == True:
                    didl.rebuild()
                    ordered_result[argument.name] = didl.toString().replace('<ns0:','<')
                else:
                    ordered_result[argument.name] = result[argument.name].decode('utf-8')
            else:
                ordered_result[argument.name] = result[argument.name].decode('utf-8').encode('utf-8')
        self.info( 'action_results sorted', action.name, ordered_result)
        return ordered_result
Ejemplo n.º 9
0
 def get_action_results(self, result, action, instance):
     """ check for out arguments
         if yes: check if there are related ones to StateVariables with
                 non A_ARG_TYPE_ prefix
                 if yes: check if there is a call plugin method for this action
                         if yes: update StateVariable values with call result
                         if no:  get StateVariable values and
                                 add them to result dict
     """
     self.debug('get_action_results', result)
     #print 'get_action_results', action, instance
     r = result
     notify = []
     for argument in action.get_out_arguments():
         #print 'get_state_variable_contents', argument.name
         if argument.name[0:11] != 'A_ARG_TYPE_':
             if action.get_callback() != None:
                 variable = self.variables[instance][
                     argument.get_state_variable()]
                 variable.update(r[argument.name])
                 #print 'update state variable contents', variable.name, variable.value, variable.send_events
                 if (variable.send_events == 'yes'
                         and variable.moderated == False):
                     notify.append(variable)
             else:
                 variable = self.variables[instance][
                     argument.get_state_variable()]
                 #print 'get state variable contents', variable.name, variable.value
                 r[argument.name] = variable.value
                 #print "r", r
         self.service.propagate_notification(notify)
     #r= { '%sResponse'%action.name: r}
     self.info('action_results unsorted', action.name, r)
     if len(r) == 0:
         return r
     ordered_result = OrderedDict()
     for argument in action.get_out_arguments():
         ordered_result[argument.name] = r[argument.name]
     self.info('action_results sorted', action.name, ordered_result)
     return ordered_result
Ejemplo n.º 10
0
    def get_action_results(self, result, action, instance):
        '''
        Check for out arguments, if yes:

            - check if there are related ones to StateVariables with
              non `A_ARG_TYPE_ prefix`, if yes:

                - check if there is a call plugin method for this action:

                    - if yes => update StateVariable values with call result.
                    - if no  => get StateVariable values and add them to
                      the result dict.

        '''
        self.debug(f'get_action_results {result}')
        # print 'get_action_results', action, instance
        notify = []
        for argument in action.get_out_arguments():
            # print 'get_state_variable_contents', argument.name
            if argument.name[0:11] != 'A_ARG_TYPE_':
                variable = self.variables[instance][
                    argument.get_state_variable()]
                variable.update(
                    result[argument.name].decode('utf-8').encode('utf-8'))
                # print('update state variable contents',
                #       variable.name, variable.value, variable.send_events)
                if (variable.send_events == 'yes'
                        and variable.moderated is False):
                    notify.append(variable)

            self.service.propagate_notification(notify)
        self.info(f'action_results unsorted {action.name} {result}')
        if len(result) == 0:
            return result
        ordered_result = OrderedDict()
        for argument in action.get_out_arguments():
            if action.name == 'XXXBrowse' and argument.name == 'Result':
                didl = DIDLLite.DIDLElement.fromString(
                    result['Result'].decode('utf-8'))
                changed = False
                for item in didl.getItems():
                    new_res = DIDLLite.Resources()
                    for res in item.res:
                        (
                            remote_protocol,
                            remote_network,
                            remote_content_format,
                            _,
                        ) = res.protocolInfo.split(':')
                        if (remote_protocol == 'http-get'
                                and remote_network == '*'):
                            quoted_url = urllib.parse.quote_plus(res.data)
                            res.data = urllib.parse.urlunsplit((
                                'http',
                                self.service.device.external_address,
                                'mirabeau',
                                quoted_url,
                                '',
                            ))
                            new_res.append(res)
                            changed = True
                    item.res = new_res
                if changed:
                    didl.rebuild()
                    ordered_result[argument.name] = didl.toString()
                else:
                    ordered_result[argument.name] = result[
                        argument.name].decode('utf-8')
            else:
                ordered_result[argument.name] = (
                    result[argument.name].decode('utf-8').encode('utf-8'))
        self.info(f'action_results sorted {action.name} {ordered_result}')
        return ordered_result