Example #1
0
    def copy(self,invalid_listener,peered,multi_threaded):
        '''
        Returns a deep copy of the object.
        '''
        # will be used as initial_val when constructing copied
        # InternalMap that we return.
        new_internal_val = {}

        val_to_copy = self.val
            
        for key in val_to_copy:
            to_copy = val_to_copy[key]

            if is_reference_container(to_copy):
                to_copy = to_copy.copy(invalid_listener,peered,multi_threaded)
            elif isinstance(to_copy,WaldoObj):

                if to_copy.is_value_type():
                    to_copy = to_copy.get_val(invalid_listener)
                else:
                    to_copy = to_copy.copy(
                        invalid_listener,peered,multi_threaded)
                
            new_internal_val[key] = to_copy

        if multi_threaded:
            return InternalMap(
                self.host_uuid,peered,new_internal_val)
        else:
            return SingleThreadInternalMap(
                self.host_uuid,peered,new_internal_val)
    def assign_on_key(self,lhs,key,rhs,active_event):
        '''
        For bracket statements + struct statements
        '''
        if not isinstance(lhs,WaldoObj):
            return False

        raw_key = self.get_val_if_waldo(key,active_event)

        if wVariables.is_non_ext_text_var(lhs):
            raw_rhs = self.get_val_if_waldo(rhs,active_event)            
            to_overwrite_string = lhs.get_val(active_event)
            to_overwrite_string[raw_key] = raw_rhs
            lhs.write_val(active_event,to_overwrite_string)
        elif isinstance(lhs,wVariables.WaldoExtTextVariable):
            raw_rhs = self.get_val_if_waldo(rhs,active_event)            
            to_overwrite_string = lhs.get_val(active_event).get_val(active_event)
            to_overwrite_string[raw_key] = raw_rhs
            lhs.get_val(active_event).write_val(active_event,to_overwrite_string)
        elif waldoReferenceContainerBase.is_reference_container(lhs):
            # just write the value explicitly for now.  Later, will
            # need to check if we need to wrap it first.
            lhs.write_val_on_key(active_event,raw_key,rhs)
        else:
            # just write the value explicitly for now.  Later, will
            # need to check if we need to wrap it first.
            lhs.get_val(active_event).write_val_on_key(active_event,raw_key,rhs)

        return True
Example #3
0
    def append_val(self,invalid_listener,new_val):
        '''
        When we append, we insert at the end of the list.
        Changes contains, len, keys.
        '''
        # adding key at end.
        self.version_obj.add_key(len(self.val))

        # if we are peered, then we want to assign into ourselves a
        # copy of the object, not the object itself.  This will only
        # be a problem for container types.  Non-container types
        # already have the semantics that they will be copied on read.
        # (And we throw an error if a peered variable has a container
        # with externals inside of it.)
        if self.peered:

            if is_reference_container(new_val):
                new_val = new_val.copy(invalid_listener,True,True)

            elif isinstance(new_val,WaldoObj):
                
                if new_val.is_value_type():
                    new_val = new_val.get_val(invalid_listener)
                else:
                    new_val = new_val.copy(invalid_listener,True,True)
                    
        self.val.append(new_val)
Example #4
0
    def append_val(self,new_val,invalid_listener,peered):
        # adding key at end.
        self.version_obj.add_key(len(self.val))

        # if we are peered, then we want to assign into ourselves a
        # copy of the object, not the object itself.  This will only
        # be a problem for container types.  Non-container types
        # already have the semantics that they will be copied on read.
        # (And we throw an error if a peered variable has a container
        # with externals inside of it.)
        if peered:
            if is_reference_container(new_val):
                new_val = new_val.copy(invalid_listener,True,True)

            elif isinstance(new_val, WaldoObj):
                if new_val.is_value_type():
                    new_val = new_val.get_val(invalid_listener)
                else:
                    new_val = new_val.copy(invalid_listener,True,True)

        if not self.written_at_least_once:
            self.written_at_least_once = True
            self.val = self.waldo_reference._non_waldo_copy()

        self.val.append(new_val)
Example #5
0
    def copy(self,invalid_listener,peered,multi_threaded):
        '''
        @param {} invalid_listener

        @param {bool} peered --- Should the returned copy be peered or
        un-peered

        @param {bool} multi_threaded --- Do we need to use locking on
        the object.  Ie., can the object be accessed from multiple
        threads simultaneously?  (True if yes, False if no.)

        Returns a deep copy of the object.
        '''

        # will be used as initial_val when constructing copied
        # InternalMap that we return.
        new_internal_val = []

        # a peered internal map may point to values or it may point to
        # _ReferenceContainers.  (It may not point to non
        # _ReferenceContainer _WaldoObjects because we disallow
        # externals as value types for maps and lists.)
        self._lock()
        val_to_copy = self.val
        self_to_copy = True
        if invalid_listener.uuid in self._dirty_map:
            self_to_copy = False
            val_to_copy = self._dirty_map[invalid_listener.uuid].val

        # if copying from internal: stay within the lock so that
        # nothing else can write to internal while we are.
        if not self_to_copy:
            self._unlock()

        for to_copy in val_to_copy:
            # if it's not a _ReferenceContainer, then it must just
            # have a value type.  (See comment after
            # new_internal_val.)
            if is_reference_container(to_copy):
                to_copy = to_copy.copy(invalid_listener,peered,multi_threaded)

            elif isinstance(to_copy, WaldoObj):

                if to_copy.is_value_type():
                    to_copy = to_copy.get_val(invalid_listener)
                else:
                    to_copy = to_copy.copy(invalid_listener,peered,multi_threaded)

            new_internal_val.append(to_copy)

        if self_to_copy:
            self._unlock()

        if multi_threaded:
            return InternalList(
                self.host_uuid,peered,new_internal_val)
        else:
            return SingleThreadInternalList(
                self.host_uuid,peered,new_internal_val)            
Example #6
0
    def copy(self,invalid_listener,peered,multi_threaded):
        '''
        @param {} invalid_listener

        @param {bool} peered --- Should the returned copy be peered or
        un-peered

        @param {bool} multi_threaded --- Do we need to use locking on
        the object.  Ie., can the object be accessed from multiple
        threads simultaneously?  (True if yes, False if no.)
        
        Returns a deep copy of the object.
        '''
        # will be used as initial_val when constructing copied
        # InternalMap that we return.
        new_internal_val = {}
        
        self._lock()
        val_to_copy = self.val
        self_to_copy = True
        if invalid_listener.uuid in self._dirty_map:
            self_to_copy = False
            val_to_copy = self._dirty_map[invalid_listener.uuid].val
            
        # if copying from internal: stay within the lock so that
        # nothing else can write to internal while we are.
        if not self_to_copy:
            self._unlock()

        for key in val_to_copy:
            to_copy = val_to_copy[key]

            if is_reference_container(to_copy):
                to_copy = to_copy.copy(invalid_listener,peered,multi_threaded)
            elif isinstance(to_copy,WaldoObj):

                if to_copy.is_value_type():
                    to_copy = to_copy.get_val(invalid_listener)
                else:
                    to_copy = to_copy.copy(invalid_listener,peered,multi_threaded)
                
            new_internal_val[key] = to_copy
            
        if self_to_copy:
            self._unlock()

        if multi_threaded:
            return InternalMap(self.host_uuid,peered,new_internal_val)
        else:
            return SingleThreadInternalMap(
                self.host_uuid,peered,new_internal_val)
    def get_val_on_key(self,to_get_from,key,active_event):
        raw_key = self.get_val_if_waldo(key,active_event)
        
        if not isinstance(to_get_from,WaldoObj):
            return to_get_from[raw_key]

        # handle text + ext text
        if wVariables.is_non_ext_text_var(lhs):
            return to_get_from.get_val(active_event)[raw_key]

        if isinstance(lhs,wVariables.WaldoExtTextVariable):
            return to_get_from.get_val(active_event).get_val(active_event)[raw_key]

        # handle internals containers
        if waldoReferenceContainerBase.is_reference_container(lhs):
            return to_get_from.get_val_on_key(active_event,raw_key)

        # handle map, list, struct
        return to_get_from.get_val(active_event).get_val_on_key(active_event,raw_key)
Example #8
0
    def copy(self,invalid_listener,peered,multi_threaded):
        # will be used as initial_val when constructing copied
        # InternalMap that we return.
        new_internal_val = []
        
        # a peered internal map may point to values or it may point to
        # _ReferenceContainers.  (It may not point to non
        # _ReferenceContainer _WaldoObjects because we disallow
        # externals as value types for maps and lists.)
        val_to_copy = self.val
            

        for to_copy in val_to_copy:
            # if it's not a _ReferenceContainer, then it must just
            # have a value type.  (See comment after
            # new_internal_val.)
            if is_reference_container(to_copy):

                to_copy = to_copy.copy(
                    invalid_listener,peered,multi_threaded)

            elif isinstance(to_copy,WaldoObj):

                if to_copy.is_value_type():
                    to_copy = to_copy.get_val(invalid_listener)
                else:
                    to_copy = to_copy.copy(
                        invalid_listener,peered,multi_threaded)
                
            new_internal_val.append(to_copy)


        if multi_threaded:
            return InternalList(
                self.host_uuid,peered,new_internal_val)
        else:
            return SingleThreadInternalList(
                self.host_uuid,peered,new_internal_val)