def load(self, sectionNameOrID): wantedID = _getSectionID(sectionNameOrID) # TODO alias section = self.existence(wantedID) if False == section: return Exception('section-not-exists') self._loadID = section[0] self.name = section[1].decode('hex') return True
def create(self, sectionName): if _isSectionID(sectionName): # a sectionName, which looks like a sectionID, is forbidden. return Exception('not-section-name') # use HEX encode, making it able to search sectionNameEncoded = _regulateSectionName(sectionName).encode('hex') sectionID = _getSectionID(sectionName) if False != self.existence(sectionID): return Exception('section-already-exists') self._sqldb.insert('sections', { 'sid': sectionID, 'name': sectionNameEncoded, }) self.load(sectionID) return True
def create(self, sectionName): if _isSectionID(sectionName): # a sectionName, which looks like a sectionID, is forbidden. return Exception('not-section-name') # use HEX encode, making it able to search sectionNameEncoded = _regulateSectionName(sectionName).encode('hex') sectionID = _getSectionID(sectionName) if False != self.existence(sectionID): return Exception('section-already-exists') self._sqldb.insert( 'sections', { 'sid': sectionID, 'name': sectionNameEncoded, } ) self.load(sectionID) return True