def getNextBookCode( self, BBB ): """ Returns the book (if any) after the given one. """ while True: nextCode = BibleBookOrderSystem.getNextBookCode( self, BBB ) if nextCode is None: return None if self.containsBook( nextCode ): return nextCode BBB = nextCode
def getNextBookCode(self, BBB): """ Returns the book (if any) after the given one. """ while True: nextCode = BibleBookOrderSystem.getNextBookCode(self, BBB) if nextCode is None: return None if self.containsBook(nextCode): return nextCode BBB = nextCode
def getPreviousBookCode( self, BBB ): """ Returns the book (if any) before the given one. """ while True: previousCode = BibleBookOrderSystem.getPreviousBookCode( self, BBB ) if previousCode is None: return None if self.containsBook( previousCode ): return previousCode BBB = previousCode
def isValidBCVRef( self, referenceTuple, referenceString, wantErrorMessages=False ): """ Returns True/False indicating if the given reference is valid in this system. """ BBB, C, V, S = referenceTuple if BibleBookOrderSystem.containsBook( self, BBB ): return BibleVersificationSystem.isValidBCVRef( self, referenceTuple, referenceString, wantErrorMessages ) elif wantErrorMessages: logging.error( _("{} {}:{} is invalid book for reference '{}' in {} versification system for {}").format(BBB,C,V,referenceString, self.getBookOrderSystemName(),self.getOrganizationalSystemName()) ) return False
def isValidBCVRef(self, referenceTuple, referenceString, extended=False): """ Returns True/False indicating if the given reference is valid in this system. Extended flag allows chapter and verse numbers of zero. """ #print( "BibleOrganizationalSystem.isValidBCVRef( {}, {}, {}, {} )".format( referenceTuple, referenceString, extended ) ) BBB, C, V, S = referenceTuple if BBB is None or not BBB: return False assert (len(BBB) == 3) if C and not C.isdigit( ): # Should be no suffix on C (although it can be blank if the reference is for a whole book) print( "BibleOrganizationalSystem.isValidBCVRef( {}, {}, {} ) expected C to be digits" .format(referenceTuple, referenceString, extended)) assert ( not V or V.isdigit() ) # Should be no suffix on V (although it can be blank if the reference is for a whole chapter) assert (not S or len(S) == 1 and S.isalpha() ) # Suffix should be only one lower-case letter if anything if BBB and BibleBookOrderSystem.containsBook(self, BBB): return BibleVersificationSystem.isValidBCVRef(self, referenceTuple, referenceString, extended=extended) logging.error( _("{} {}:{} is invalid book for reference '{}' in {} versification system for {}" ).format(BBB, C, V, referenceString, self.getBookOrderSystemName(), self.getOrganizationalSystemName())) return False
def getFirstBookCode( self ): """ Return the BBB code for the first book otherwise returns None. """ if 1: return BibleBookOrderSystem.getBookAtOrderPosition( self, 1 ) else: # I think this is wrong! Should use BookOrderSystem -- see next function bookList = self.getOrganizationalSystemValue( "includesBooks" ) if bookList is None: return None return bookList[0]
def getFirstBookCode(self): """ Return the BBB code for the first book otherwise returns None. """ if 1: return BibleBookOrderSystem.getBookAtOrderPosition(self, 1) else: # I think this is wrong! Should use BookOrderSystem -- see next function bookList = self.getOrganizationalSystemValue('includesBooks') if bookList is None: return None return bookList[0]
def __init__( self, systemName ): """ Constructor: """ self.__boss = BibleOrganizationalSystems().loadData() # Doesn't reload the XML unnecessarily :) result = self.__boss.getOrganizationalSystem( systemName ) if result is None: self.__dataDict = self.__systemName = None return # else: self.__dataDict = result self.__systemName = systemName #print( self.__dataDict ) # Now initialize the inherited classes value1 = self.getOrganizationalSystemValue( 'bookOrderSystem' ) if value1: BibleBookOrderSystem.__init__( self, value1 ) value2 = self.getOrganizationalSystemValue( 'versificationSystem' ) if value2: BibleVersificationSystem.__init__( self, value2 ) value3 = self.getOrganizationalSystemValue( 'punctuationSystem' ) if value3: BiblePunctuationSystem.__init__( self, value3 ) value4 = self.getOrganizationalSystemValue( 'booksNamesSystem' ) if value4: BibleBooksNamesSystem.__init__( self, value4, BibleBookOrderSystem.getBookList(self) ) # Does one extra step To create the input abbreviations
def isValidBCVRef( self, referenceTuple, referenceString, extended=False ): """ Returns True/False indicating if the given reference is valid in this system. Extended flag allows chapter and verse numbers of zero. """ #print( "BibleOrganizationalSystem.isValidBCVRef( {}, {}, {}, {} )".format( referenceTuple, referenceString, extended ) ) BBB, C, V, S = referenceTuple if BBB is None or not BBB: return False assert( len(BBB) == 3 ) if C and not C.isdigit(): # Should be no suffix on C (although it can be blank if the reference is for a whole book) print( "BibleOrganizationalSystem.isValidBCVRef( {}, {}, {} ) expected C to be digits".format( referenceTuple, referenceString, extended ) ) assert( not V or V.isdigit() ) # Should be no suffix on V (although it can be blank if the reference is for a whole chapter) assert( not S or len(S)==1 and S.isalpha() ) # Suffix should be only one lower-case letter if anything if BBB and BibleBookOrderSystem.containsBook( self, BBB ): return BibleVersificationSystem.isValidBCVRef( self, referenceTuple, referenceString, extended=extended ) logging.error( _("{} {}:{} is invalid book for reference '{}' in {} versification system for {}").format(BBB,C,V,referenceString, self.getBookOrderSystemName(),self.getOrganizationalSystemName()) ) return False
def __init__( self, systemName ): """ Constructor: """ def getOrganizationalSystemValue( valueName ): """ Gets a value for the system. """ def getMoreBasicTypes(): """ Returns a list of more basic (original) types. """ ix = allowedTypes.index( self.__dataDict["type"] ) return allowedTypes[ix+1:] # end of getMoreBasicTypes #print( "q0", valueName ) if valueName in self.__dataDict: return self.__dataDict[valueName] # else maybe we can find the value in a derived text #print( "q1", self.getOrganizationalSystemName() ) for tryType in getMoreBasicTypes(): if 'usesText' in self.__dataDict: for trySystemName in self.__dataDict['usesText']: #print( "q2", "{} is trying usesText of {}".format(self.__systemName,trySystemName) ) result = self.__boss.getOrganizationalSystemValue( trySystemName, valueName ) #print( " result is", result ) if result is not None: return result if 'derivedFrom' in self.__dataDict: trySystemName = self.__dataDict['derivedFrom'] if isinstance( trySystemName, str ): if BibleOrgSysGlobals.debugFlag: print( "trySystemName for 'derivedFrom' is a string: {!r}".format( trySystemName ) ) elif isinstance( trySystemName, list ): #print( "trySystemName for 'derivedFrom' is a list: {!r}".format( trySystemName ) ) trySystemName = trySystemName[0] # Take the first string from the list #print( "q3", "{} is trying derivedFrom of {}".format(self.__systemName,trySystemName) ) result = self.__boss.getOrganizationalSystemValue( trySystemName, valueName ) #print( " result is", result ) if result is not None: return result # else we couldn't find it anywhere logging.error( _("{} Bible Organizational System has no {} specified (b)").format(self.__systemName,valueName) ) # end of getOrganizationalSystemValue if BibleOrgSysGlobals.verbosityLevel > 2: print( "Loading {!r} system".format( systemName ) ) assert( systemName and isinstance( systemName, str ) ) self.__boss = BibleOrganizationalSystems().loadData() # Doesn't reload the XML unnecessarily :) result = self.__boss.getOrganizationalSystem( systemName ) if result is None: self.__dataDict = self.__systemName = None del self return # else: self.__dataDict = result self.__systemName = systemName #print( self.__dataDict ) # Now initialize the inherited classes bookOrderSystemName = self.getOrganizationalSystemValue( 'bookOrderSystem' ) versificationSystemName = self.getOrganizationalSystemValue( 'versificationSystem' ) punctuationSystemName = self.getOrganizationalSystemValue( 'punctuationSystem' ) booksNamesSystemName = self.getOrganizationalSystemValue( 'booksNamesSystem' ) if BibleOrgSysGlobals.debugFlag: print( "Got organisation bits: BOS={}, VS={}, PS={}, BNS={}".format( bookOrderSystemName, versificationSystemName, punctuationSystemName, booksNamesSystemName ) ) if bookOrderSystemName and bookOrderSystemName!='None' and bookOrderSystemName!='Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} book order system".format( bookOrderSystemName ) ) BibleBookOrderSystem.__init__( self, bookOrderSystemName ) if versificationSystemName and versificationSystemName!='None' and versificationSystemName!='Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} versification system".format( versificationSystemName ) ) BibleVersificationSystem.__init__( self, versificationSystemName ) if punctuationSystemName and punctuationSystemName!='None' and punctuationSystemName!='Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} punctuation system".format( punctuationSystemName ) ) BiblePunctuationSystem.__init__( self, punctuationSystemName ) if booksNamesSystemName and booksNamesSystemName!='None' and booksNamesSystemName!='Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} books name system".format( booksNamesSystemName ) ) BibleBooksNamesSystem.__init__( self, booksNamesSystemName, getOrganizationalSystemValue( "includesBooks" ) ) # Does one extra step To create the input abbreviations # Do some cross-checking myBooks = getOrganizationalSystemValue( "includesBooks" ) if myBooks is not None: for BBB in myBooks: if not BibleBookOrderSystem.containsBook( self, BBB ): logging.error( _("Book {!r} is included in {} system but missing from {} book order system").format( BBB, self.__systemName, BibleBookOrderSystem.getBookOrderSystemName( self ) ) )
def __init__(self, systemName): """ Constructor: """ def getOrganizationalSystemValue(valueName): """ Gets a value for the system. """ def getMoreBasicTypes(): """ Returns a list of more basic (original) types. """ ix = allowedTypes.index(self.__dataDict["type"]) return allowedTypes[ix + 1:] # end of getMoreBasicTypes #print( "q0", valueName ) if valueName in self.__dataDict: return self.__dataDict[valueName] # else maybe we can find the value in a derived text #print( "q1", self.getOrganizationalSystemName() ) for tryType in getMoreBasicTypes(): if 'usesText' in self.__dataDict: for trySystemName in self.__dataDict['usesText']: #print( "q2", "{} is trying usesText of {}".format(self.__systemName,trySystemName) ) result = self.__boss.getOrganizationalSystemValue( trySystemName, valueName) #print( " result is", result ) if result is not None: return result if 'derivedFrom' in self.__dataDict: trySystemName = self.__dataDict['derivedFrom'] if isinstance(trySystemName, str): if BibleOrgSysGlobals.debugFlag: print( "trySystemName for 'derivedFrom' is a string: {!r}" .format(trySystemName)) elif isinstance(trySystemName, list): #print( "trySystemName for 'derivedFrom' is a list: {!r}".format( trySystemName ) ) trySystemName = trySystemName[ 0] # Take the first string from the list #print( "q3", "{} is trying derivedFrom of {}".format(self.__systemName,trySystemName) ) result = self.__boss.getOrganizationalSystemValue( trySystemName, valueName) #print( " result is", result ) if result is not None: return result # else we couldn't find it anywhere logging.error( _("{} Bible Organizational System has no {} specified (b)"). format(self.__systemName, valueName)) # end of getOrganizationalSystemValue if BibleOrgSysGlobals.verbosityLevel > 2: print("Loading {!r} system".format(systemName)) assert systemName and isinstance(systemName, str) self.__boss = BibleOrganizationalSystems().loadData( ) # Doesn't reload the XML unnecessarily :) result = self.__boss.getOrganizationalSystem(systemName) if result is None: self.__dataDict = self.__systemName = None del self return # else: self.__dataDict = result self.__systemName = systemName #print( self.__dataDict ) # Now initialize the inherited classes bookOrderSystemName = self.getOrganizationalSystemValue( 'bookOrderSystem') versificationSystemName = self.getOrganizationalSystemValue( 'versificationSystem') punctuationSystemName = self.getOrganizationalSystemValue( 'punctuationSystem') booksNamesSystemName = self.getOrganizationalSystemValue( 'booksNamesSystem') if BibleOrgSysGlobals.debugFlag: print("Got organisation bits: BOS={}, VS={}, PS={}, BNS={}".format( bookOrderSystemName, versificationSystemName, punctuationSystemName, booksNamesSystemName)) if bookOrderSystemName and bookOrderSystemName != 'None' and bookOrderSystemName != 'Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} book order system".format(bookOrderSystemName)) BibleBookOrderSystem.__init__(self, bookOrderSystemName) if versificationSystemName and versificationSystemName != 'None' and versificationSystemName != 'Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print("Uses {!r} versification system".format( versificationSystemName)) BibleVersificationSystem.__init__(self, versificationSystemName) if punctuationSystemName and punctuationSystemName != 'None' and punctuationSystemName != 'Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print("Uses {!r} punctuation system".format( punctuationSystemName)) BiblePunctuationSystem.__init__(self, punctuationSystemName) if booksNamesSystemName and booksNamesSystemName != 'None' and booksNamesSystemName != 'Unknown': if BibleOrgSysGlobals.verbosityLevel > 2: print( "Uses {!r} books name system".format(booksNamesSystemName)) BibleBooksNamesSystem.__init__( self, booksNamesSystemName, getOrganizationalSystemValue('includesBooks') ) # Does one extra step To create the input abbreviations # Do some cross-checking myBooks = getOrganizationalSystemValue('includesBooks') if myBooks is not None: for BBB in myBooks: if not BibleBookOrderSystem.containsBook(self, BBB): logging.error( _("Book {!r} is included in {} system but missing from {} book order system" ).format( BBB, self.__systemName, BibleBookOrderSystem.getBookOrderSystemName( self)))