示例#1
0
文件: raStanza.py 项目: bowhan/kent
    def readLine(self, line):
        '''
        Reads a single line from the stanza, extracting the key-value pair
        '''

        if line.startswith('#') or line == '':
            OrderedDict.append(self, line)
        else:
            raKey = line.split(' ', 1)[0].strip()
            raVal = ''
            if (len(line.split(' ', 1)) == 2):
                raVal = line.split(' ', 1)[1].strip()
            #if raKey in self:
                #raise KeyError(raKey + ' already exists')
            self[raKey] = raVal
示例#2
0
    def readLine(self, line):
        '''
        Reads a single line from the stanza, extracting the key-value pair
        '''

        if line.startswith('#') or line == '':
            OrderedDict.append(self, line)
        else:
            raKey = line.split(' ', 1)[0]
            raVal = ''
            if (len(line.split(' ', 1)) == 2):
                raVal = line.split(' ', 1)[1]
            #if raKey in self:
                #raise KeyError(raKey + ' already exists')
            self[raKey] = raVal
示例#3
0
文件: raFile.py 项目: yuzhenpeng/kent
    def read(self, filePath, key=None):
        '''
        Reads an rafile stanza by stanza, and internalizes it. Don't override
        this for derived types, instead override readStanza.
        '''
        self._filename = filePath
        file = open(filePath, 'r')
        scopes = list()

        #entry = None
        stanza = list()
        keyValue = ''

        reading = 1

        while reading:
            line = file.readline()  # get the line
            if line == '':
                reading = 0

            # if its a comment or whitespace we append it to the list representation and ignore in dict
            #line = line.strip()
            if len(stanza) == 0 and (line.strip().startswith('#') or
                                     (line.strip() == '' and reading)):
                OrderedDict.append(self, line)
                continue

            if line.strip() != '':
                stanza.append(line)
            elif len(stanza) > 0:
                if keyValue == '':
                    keyValue, name, entry = self.readStanza(stanza, key)
                else:
                    testKey, name, entry = self.readStanza(stanza, key)
                    if entry != None and keyValue != testKey:
                        raise KeyError('Inconsistent Key ' + testKey)

                if entry != None:
                    if name != None or key == None:
                        if name in self:
                            print KeyError('Duplicate Key ' + name)
                        self[name] = entry

                stanza = list()

        file.close()
示例#4
0
文件: raFile.py 项目: bowhan/kent
    def read(self, filePath, key=None):
        '''
        Reads an rafile stanza by stanza, and internalizes it. Don't override
        this for derived types, instead override readStanza.
        '''
        self._filename = filePath
        file = open(filePath, 'r')
        scopes = list()

        #entry = None
        stanza = list()
        keyValue = ''

        reading = 1
        
        while reading:
            line = file.readline() # get the line
            if line == '':
                reading = 0
        
            # if its a comment or whitespace we append it to the list representation and ignore in dict
            #line = line.strip()
            if len(stanza) == 0 and (line.strip().startswith('#') or (line.strip() == '' and reading)):
                OrderedDict.append(self, line)
                continue

            if line.strip() != '':
                stanza.append(line)
            elif len(stanza) > 0:
                if keyValue == '':
                    keyValue, name, entry = self.readStanza(stanza, key)
                else:
                    testKey, name, entry = self.readStanza(stanza, key)
                    if entry != None and keyValue != testKey:
                        raise KeyError('Inconsistent Key ' + testKey)

                if entry != None:
                    if name != None or key == None:
                        if name in self:
                            print KeyError('Duplicate Key ' + name)
                        self[name] = entry

                stanza = list()

        file.close()
示例#5
0
 def append(self, item):
     OrderedDict.append(self, item)
示例#6
0
文件: raFile.py 项目: bowhan/kent
 def append(self, item):
     OrderedDict.append(self, item)