Example #1
0
    def __init__(self, input):

        if isinstance(input, dict):
            input_to_file = input
            conservative_update(self, input_to_file)
            # self.__dict__.update(input_to_file)

        elif hasattr(input,'__iter__'):
            input_to_file = input

        else: # Modules, objects, etc.
            input_to_file = input.__dict__
            conservative_update(self, input_to_file)
            # self.__dict__.update(input_to_file)
        
        dictpop = copy(self.__dict__)
        if dictpop.has_key('self'):
            dictpop.pop('self')
        
        self._dict_container = DictContainer(dictpop)
        file_items(self, input_to_file)

        self._value = copy(self)
        ContainerBase.__init__(self, input)
        self.OCValue = OCValue(self)
Example #2
0
    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)
Example #3
0
    def __init__(self, iterable):
        dict.__init__(self, iterable)
        ContainerBase.__init__(self, iterable)
        self._value = copy(iterable)
        file_items(self, iterable)

        self.val_keys = []
        self.val_obj = []
        self.nonval_keys = []
        self.nonval_obj = []
        self._value = {}
        for key, obj in self.iteritems():
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                self.val_keys.append(key)
                self.val_obj.append(obj)
            else:
                self.nonval_keys.append(key)
                self.nonval_obj.append(obj)
        # In case val_obj is only a single array, avert confusion.
        # Leave this even though it's confusing!
        self.val_obj.append(None)
        self.nonval_obj.append(None)

        self.n_val = len(self.val_keys)
        self.val_keys = array(self.val_keys, dtype=object)
        # self.val_obj = array(self.val_obj, dtype=object)
        self.n_nonval = len(self.nonval_keys)
        self.nonval_keys = array(self.nonval_keys, dtype=object)
        self.nonval_obj = array(self.nonval_obj, dtype=object)
        self.DCValue = DCValue(self)
Example #4
0
    def __init__(self, input):

        if isinstance(input, dict):
            input_to_file = input
            conservative_update(self, input_to_file)
            # self.__dict__.update(input_to_file)

        elif hasattr(input, '__iter__'):
            input_to_file = input

        else:  # Modules, objects, etc.
            input_to_file = input.__dict__
            conservative_update(self, input_to_file)
            # self.__dict__.update(input_to_file)

        dictpop = copy(self.__dict__)
        if dictpop.has_key('self'):
            dictpop.pop('self')

        self._dict_container = DictContainer(dictpop)
        file_items(self, input_to_file)

        self._value = copy(self)
        ContainerBase.__init__(self, input)
        self.OCValue = OCValue(self)
Example #5
0
    def __init__(self, iterable):
        new_tup = file_items(self, iterable)
        if len(self.containers)>0:
            raise NotImplementedError, """We have not figured out how to satisfactorily implement nested TupleContainers.
The reason is there is no way to change an element of a tuple after it has been created.
Even the Python-C API makes this impossible by checking that a tuple is new
before allowing you to change one of its elements."""
        ContainerBase.__init__(self, iterable)
        file_items(self, iterable)
        self._value = list(self)
        sort_list(self, self._value)
Example #6
0
    def __init__(self, iterable):
        new_tup = file_items(self, iterable)
        if len(self.containers) > 0:
            raise NotImplementedError, """We have not figured out how to satisfactorily implement nested TupleContainers.
The reason is there is no way to change an element of a tuple after it has been created.
Even the Python-C API makes this impossible by checking that a tuple is new
before allowing you to change one of its elements."""
        ContainerBase.__init__(self, iterable)
        file_items(self, iterable)
        self._value = list(self)
        sort_list(self, self._value)
Example #7
0
    def __init__(self, input):

        if isinstance(input, dict):
            input_to_file = input
            self.__dict__.update(input_to_file)

        elif hasattr(input, '__iter__'):
            input_to_file = input

        else:  # Modules, objects, etc.
            input_to_file = input.__dict__
            self.__dict__.update(input_to_file)

        self._dict_container = DictContainer(self.__dict__)
        file_items(self, input_to_file)

        self._value = copy(self)
        ContainerBase.__init__(self, input)
        self.OCValue = OCValue(self)
Example #8
0
    def __new__(subtype, array_in):
        if not array_in.dtype == dtype('object'):
            raise ValueError, 'Cannot create container from array whose dtype is not object.'

        C = array(array_in, copy=True).view(subtype)
        C_ravel = C.ravel()
        ContainerBase.__init__(C, array_in)

        # Sort out contents and wrap internal containers.
        file_items(C, C_ravel)
        C._value = C.copy()
        C._ravelledvalue = C._value.ravel()

        # An array range to keep around.
        C.iterrange = arange(len(C_ravel))

        val_ind = []
        val_obj = []
        nonval_ind = []
        nonval_obj = []
        for i in xrange(len(C_ravel)):
            obj = C_ravel[i]
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                val_ind.append(i)
                val_obj.append(obj)
            else:
                nonval_ind.append(i)
                nonval_obj.append(obj)
        val_obj.append(None)
        C.val_ind = array(val_ind, dtype='int32')
        C.val_obj = val_obj
        C.n_val = len(val_ind)
        nonval_obj.append(None)
        C.nonval_ind = array(nonval_ind, dtype='int32')
        C.nonval_obj = array(nonval_obj, dtype=object)
        C.n_nonval = len(nonval_ind)


        C.flags['W'] = False
        C.ACValue = ACValue(C)

        return C
Example #9
0
    def __new__(subtype, array_in):
        if not array_in.dtype == dtype('object'):
            raise ValueError, 'Cannot create container from array whose dtype is not object.'

        C = array(array_in, copy=True).view(subtype)
        C_ravel = C.ravel()
        ContainerBase.__init__(C, array_in)

        # Sort out contents and wrap internal containers.
        file_items(C, C_ravel)
        C._value = C.copy()
        C._ravelledvalue = C._value.ravel()

        # An array range to keep around.
        C.iterrange = arange(len(C_ravel))

        val_ind = []
        val_obj = []
        nonval_ind = []
        nonval_obj = []
        for i in xrange(len(C_ravel)):
            obj = C_ravel[i]
            if isinstance(obj, Variable) or isinstance(obj, ContainerBase):
                val_ind.append(i)
                val_obj.append(obj)
            else:
                nonval_ind.append(i)
                nonval_obj.append(obj)
        val_obj.append(None)
        C.val_ind = array(val_ind, dtype=int)
        C.val_obj = array(val_obj, dtype=object)
        C.n_val = len(val_ind)
        nonval_obj.append(None)
        C.nonval_ind = array(nonval_ind, dtype=int)
        C.nonval_obj = array(nonval_obj, dtype=object)
        C.n_nonval = len(nonval_ind)

        C.flags['W'] = False
        C.ACValue = ACValue(C)

        return C
Example #10
0
 def __init__(self, iterable):
     list.__init__(self, iterable)
     ContainerBase.__init__(self, iterable)
     file_items(self, iterable)
     self._value = list(self)
     sort_list(self, self._value)
Example #11
0
 def __init__(self, iterable):
     list.__init__(self, iterable)
     ContainerBase.__init__(self, iterable)
     file_items(self, iterable)
     self._value = list(self)
     sort_list(self, self._value)