60 FILENAME_DEFAULT =
"webiopimem.pkl"
67 if not slots
in range(1, self.MAXSLOT_VALUE + 1):
68 raise ValueError(
"slots value [%d] out of range [%d..%d]" % (slots, 1, self.MAXSLOT_VALUE))
70 self._outputfile =
None
73 self.filename = filename
75 self.filename = self.FILENAME_DEFAULT
77 Memory.__init__(self, slots)
78 self.BYTES = [0
for i
in range(slots)]
80 if os.path.exists(self.filename):
87 return "PICKLEFILE (%s)" % self.filename
90 if self._outputfile
is not None:
91 self._outputfile.close()
96 return self.BYTES[address]
99 self.BYTES[address] = value
101 return self.__readMemoryByte__(address)
108 self.checkByteAddress(start)
109 stop = start + len(byteValues)
110 self.checkStopByteAddress(stop)
112 for byte
in byteValues:
114 self.BYTES[position] = byte
122 with open(self.filename,
"rb")
as f:
123 filebytes = pickle.load(f)
125 byteCountFile = len(filebytes)
126 if (byteCountFile > self.byteCount()):
127 slots = self.byteCount()
129 slots = byteCountFile
130 for i
in range(slots):
131 self.BYTES[i] = filebytes[i]
134 if self._outputfile
is None:
135 self._outputfile = open(self.filename,
"wb")
136 pickle.dump(self.BYTES, self._outputfile)