Пример #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
        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
Пример #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', 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