def saveUserConfig(filename, config): if config is not None: makeSettingsDir() path = userConfigFilePath(filename) try: f = open(path, 'w+') except IOError: print 'Could not open user config file \'%s\' for writing' % path return IsolationPickle.dump(config, f) f.close()
def save(self): data = IsolationPickle.dumps(self._contents) f = open(self._filename, 'w') f.write(data) f.close() if self._bHasUnsavedData: self._bHasUnsavedData = False self._saveTime = datetime.now()
def readFile(world, filename): if os.path.exists(filename): try: f = open(filename, 'rU') documentRoot = IsolationPickle.load(f) f.close() document = Document(world, documentRoot) document._setFilename(filename) document._saveTime = datetime.now() return document except IOError: return None
def loadUserConfig(filename): config = None path = userConfigFilePath(filename) if os.path.exists(path): try: f = open(path, 'r') except IOError: print 'Could not open config file \'%s\' for reading' % path return try: config = IsolationPickle.load(f) except EOFError: print 'Could not read config file \'%s\' - EOF' % path finally: f.close() return config
def reload(self): # Shut down self.shutdown() # Reload if self._filename is None: raise ValueError, 'Cannot reload document - no filename' f = open(self._filename, 'rU') documentRoot = IsolationPickle.load(f) f.close() # New contents self._contents = documentRoot self._changeHistory.removeChangeHistoryListener(self) # New change history self._changeHistory = ChangeHistory() self._changeHistory.track(self._contents) self._changeHistory.addChangeHistoryListener(self)
def readFromInputStream(world, stream, documentName): documentRoot = IsolationPickle.loadFromInputStream(stream) document = Document(world, documentRoot) document._docName = documentName return document
def readFromBytes(world, buf, documentName): documentRoot = IsolationPickle.loadFromBytes(buf) document = Document(world, documentRoot) document._docName = documentName return document
def writeToOutputStream(self, stream): IsolationPickle.dumpToOutputStream(self._contents, stream)
def writeAsBytes(self): return IsolationPickle.dumpToBytes(self._contents)
def _check(self, dataFn, testFn): data = dataFn() s = IsolationPickle.dumps(data) pickled = IsolationPickle.loads(s) testFn(pickled)