コード例 #1
0
ファイル: treedoc.py プロジェクト: BackupTheBerlios/treeline
 def readTabbed(self, fileRef, errors='strict'):
     """Import tabbed data into a flat tree - raise exception on failure"""
     try:
         f = self.getEncodedFileObj(fileRef, globalref.localTextEncoding,
                                    errors)
         filePath = unicode(f.name, sys.getfilesystemencoding())
         textList = f.readlines()
     except UnicodeError:
         print 'Warning - bad unicode characters were replaced'
         if errors == 'strict':
             self.readTabbed(fileRef, 'replace')
         else:
             f.close()
         return
     f.close()
     bufList = [(text.count('\t', 0, len(text) - len(text.lstrip())),
                 text.strip()) for text in textList if text.strip()]
     if bufList:
         buf = bufList.pop(0)
         if buf[0] == 0:
             # set default formats ROOT & DEFAULT
             self.treeFormats = TreeFormats({}, True)
             newRoot = TreeItem(None, TreeFormats.rootFormatDefault)
             newRoot.setTitle(buf[1])
             if newRoot.loadTabbedChildren(bufList):
                 self.root = newRoot
                 self.fileName = filePath
                 return
     raise ReadFileError(_('Error in tabbed list'))
コード例 #2
0
ファイル: treedoc.py プロジェクト: rodolfoap/treeline141
 def readTabbed(self, fileRef, errors='strict'):
     """Import tabbed data into a flat tree - raise exception on failure"""
     try:
         f = self.getEncodedFileObj(fileRef, globalref.localTextEncoding,
                                    errors)
         filePath = unicode(f.name, sys.getfilesystemencoding())
         textList = f.readlines()
     except UnicodeError:
         print 'Warning - bad unicode characters were replaced'
         if errors == 'strict':
             self.readTabbed(fileRef, 'replace')
         else:
             f.close()
         return
     f.close()
     bufList = [(text.count('\t', 0,
                            len(text) - len(text.lstrip())), text.strip())
                for text in textList if text.strip()]
     if bufList:
         buf = bufList.pop(0)
         if buf[0] == 0:
             # set default formats ROOT & DEFAULT
             self.treeFormats = TreeFormats({}, True)
             newRoot = TreeItem(None, TreeFormats.rootFormatDefault)
             newRoot.setTitle(buf[1])
             if newRoot.loadTabbedChildren(bufList):
                 self.root = newRoot
                 self.fileName = filePath
                 return
     raise ReadFileError(_('Error in tabbed list'))