コード例 #1
0
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()
コード例 #2
0
 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()
コード例 #3
0
    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
コード例 #4
0
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
コード例 #5
0
    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)
コード例 #6
0
    def readFromInputStream(world, stream, documentName):
        documentRoot = IsolationPickle.loadFromInputStream(stream)

        document = Document(world, documentRoot)
        document._docName = documentName
        return document
コード例 #7
0
    def readFromBytes(world, buf, documentName):
        documentRoot = IsolationPickle.loadFromBytes(buf)

        document = Document(world, documentRoot)
        document._docName = documentName
        return document
コード例 #8
0
 def writeToOutputStream(self, stream):
     IsolationPickle.dumpToOutputStream(self._contents, stream)
コード例 #9
0
 def writeAsBytes(self):
     return IsolationPickle.dumpToBytes(self._contents)
コード例 #10
0
 def _check(self, dataFn, testFn):
     data = dataFn()
     s = IsolationPickle.dumps(data)
     pickled = IsolationPickle.loads(s)
     testFn(pickled)