def add_context(ref_set: set[str], count: int = 0, chapter: bool = False) -> set[str]: """Add count number of verses before and after each reference.""" if count == 0 and not chapter: return ref_set # Make a copy to work on. clone_set = set(ref_set) if count > 0: for ref in ref_set: start = Sword.VerseKey(ref) end = Sword.VerseKey(ref) # Pass the beginning of the book. start.decrement() start.decrement(count - 1) # Pass the end of the book. end.increment() end.increment(count - 1) clone_set.update(VerseIter(start.getText(), end.getText())) if chapter: for i in ref_set: ref = Sword.VerseKey(i) chap_ref = f'{ref.getBookName()} {ref.getChapter()}' clone_set.update(parse_verse_range(chap_ref)) return clone_set
def parse_verse_range(verse_ref_list): """ Uses VerseKey ParseVerseList to parse the reference list. """ # Make the argument a parseable string. if isinstance(verse_ref_list, str): verse_ref_str = verse_ref_list else: verse_ref_str = ' '.join(verse_ref_list) verse_key = Sword.VerseKey() # Parse the list. # args: verse_list, default_key, expand_range, chapter_as_verse? verse_list = verse_key.parseVerseList(verse_ref_str, 'Genesis 1:1', True, False) verse_set = set() for i in range(verse_list.getCount()): key = Sword.VerseKey(verse_list.getElement(i)) if key: upper = key.getUpperBound().getText() lower = key.getLowerBound().getText() if upper != lower: verse_set.update(VerseIter(lower, upper)) else: verse_set.add(key.getText()) return verse_set
def __init__(self, book='Genesis', chapter=1): """ Setup iterator. """ start = Sword.VerseKey('%s %s:1' % (book, chapter)) end = Sword.VerseKey(start.clone()) end.setVerse(end.getVerseMax()) super(ChapterIter, self).__init__(start.getText(), end.getText())
def __init__(self, book='Genesis'): """ Setup iterator. """ start = Sword.VerseKey('%s 1:1' % book) end = Sword.VerseKey(start.clone()) end.setChapter(end.getChapterMax()) end.setVerse(end.getVerseMax()) super(BookIter, self).__init__(start.getText(), end.getText())
def display_verse(key,moduleName,outputType=Sword.FMT_PLAIN): vk=Sword.VerseKey(key) markup=Sword.MarkupFilterMgr(outputType) #markup=Sword.MarkupFilterMgr(Sword.FMT_HTML) markup.thisown=False mgr = Sword.SWMgr(markup) mgr.prefixPath = swordDir mgr.configPath = "%s/mods.d" % swordDir mod=mgr.getModule(moduleName) mod.setKey(vk) #Look in bindings/objc/src/SwordManager.h for the correct mapping between C++ define and python string. #you may also have to look into specific module code though such as src/modules/filters/osisxlit.cpp: static const char oName[] = "Transliterated Forms"; mgr.setGlobalOption("Strong's Numbers","Off") mgr.setGlobalOption("Cross-references","Off") mgr.setGlobalOption("Morpheme Segmentation","Off") mgr.setGlobalOption("Morphological Tags","Off") mgr.setGlobalOption("Lemmas","Off") mgr.setGlobalOption("Words of Christ in Red","Off") mgr.setGlobalOption("Textual Variants","Off") mgr.setGlobalOption("Word Javascript","Off") mgr.setGlobalOption("Transliterated Forms","Off") if not mod: print "No module" sys.exit() return mod.renderText()
def get_verse(bookStr, chapterInt, verseNbr, moduleName, outputType=Sword.FMT_PLAIN): markup = Sword.MarkupFilterMgr(outputType) markup.thisown = False mgr = Sword.SWMgr(markup) mod = mgr.getModule(moduleName) versification = mod.getConfigEntry("Versification") vk = Sword.VerseKey() vk.setVersificationSystem(versification) #vk.setTestament() ?? vk.setBookName(bookStr) vk.setChapter(chapterInt) vk.setVerse(verseNbr) mod.setKey(vk) mgr.setGlobalOption("Hebrew Vowel Points", "On") if not mod: print("No module") sys.exit() return mod.renderText()
def Find( attribute ): """ Search for methods and attributes """ print( "\nSearching for attribute '{}'...".format( attribute ) ) found = False AA = attribute.upper() for thing in dir(Sword): BB = thing.upper() if BB.startswith(AA): print( " Have {} in Sword".format( thing ) ); found = True for thing in dir(Sword.SWVersion()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWVersion".format( thing ) ); found = True for thing in dir(Sword.SWMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWMgr".format( thing ) ); found = True module = library.getModule( "KJV" ) for thing in dir(module): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWModule".format( thing ) ); found = True for thing in dir(Sword.SWKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWKey".format( thing ) ); found = True for thing in dir(Sword.VerseKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in VerseKey".format( thing ) ); found = True #for thing in dir(Sword.InstallMgr()): #BB = thing.upper() #if BB.startswith(AA): print( " Have {} in InstallMgr".format( thing ) ); found = True for thing in dir(Sword.LocaleMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in LocaleMgr".format( thing ) ); found = True for thing in dir(Sword.SWFilterMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWFilterMgr".format( thing ) ); found = True if not found: print( " Sorry, '{}' not found.".format( attribute ) )
def book_gen() -> Generator[str, None, None]: """Create a Generator that yields book names in order.""" # Yield a list of all the book names in the bible. verse_key = Sword.VerseKey('Genesis 1:1') for testament in [1, 2]: for book in range(1, verse_key.bookCount(testament) + 1): yield (verse_key.bookName(testament, book))
def getBCV( BCV, moduleAbbreviation='KJV' ): # Very slow -- for testing only if Globals.debugFlag: print( "SwordResources.getBCV({},{})".format( BCV, moduleAbbreviation ) ) library = Sword.SWMgr() module = library.getModule( moduleAbbreviation ) refString = "{} {}:{}".format( BCV[0][:3], BCV[1], BCV[2] ) #print( 'refString', refString ) return module.stripText( Sword.VerseKey( refString ) )
def getVerseMax(moduleName, bookName, chapterNbr, mgr): mod = mgr.getModule(moduleName) versification = mod.getConfigEntry("Versification") vk = Sword.VerseKey() vk.setVersificationSystem(versification) vk.setBookName(bookName) vk.setChapter(chapterNbr) return vk.getVerseMax()
def __init__(self, reference: str = "Genesis 1:1"): """ Get the book, chapter, and verse of the reference so it can be incremented and decremented. """ self._verse_ref = Sword.VerseKey(reference) self._book = self._verse_ref.getBookCount() self._chapter = self._verse_ref.getChapter() self._verse = self._verse_ref.getVerse()
def _book_gen(self): """ A Generator function that yields book names in order. """ # Yield a list of all the book names in the bible. verse_key = Sword.VerseKey('Genesis 1:1') for testament in [1, 2]: for book in range(1, verse_key.bookCount(testament) + 1): yield (verse_key.bookName(testament, book))
def __init__(self, start, end='Revelation of John 22:21'): """ Setup the start and end references of the range. """ # Make sure the range is in order. start, end = sorted([start, end], key=sort_key) self._verse = Sword.VerseKey(start, end) self._end_ref = self._verse.getUpperBound().getText() self._verse_ref = ''
def getNbrChapter(moduleName, bookAbbr, mgr): mod = mgr.getModule(moduleName) versification = mod.getConfigEntry("Versification") vk = Sword.VerseKey() vk.setVersificationSystem(versification) targetBook = 0 for curBook in getAllBooks(versification): if curBook["abbr"] == bookAbbr: targetBook = curBook nbrChapter = vk.chapterCount(targetBook['testament'], targetBook['bookCount']) return nbrChapter
def add_context(ref_set, count=0): """ Add count number of verses before and after each reference. """ if count == 0: return ref_set # Make a copy to work on. clone_set = set(ref_set) for ref in ref_set: start = Sword.VerseKey(ref) end = Sword.VerseKey(ref) # Pass the beginning of the book. start.decrement() start.decrement(count - 1) # Pass the end of the book. end.increment() end.increment(count - 1) clone_set.update(VerseIter(start.getText(), end.getText())) return clone_set
def makeKey( self, BBB, C, V ): #if Globals.debugFlag: print( "SwordResources.makeKey({})".format( BCV ) ) #if BCV in self.keyCache: #print( "Cached", BCV ) #return self.keyCache[BCV] if SwordType == "CrosswireLibrary": B = Globals.BibleBooksCodes.getOSISAbbreviation( BBB ) refString = "{} {}:{}".format( B, C, V ) #print( 'refString', refString ) verseKey = Sword.VerseKey( refString ) #self.keyCache[BCV] = verseKey return verseKey else: return SwordKey( BBB, C, V )
def index_sword_biblical_book_names(self) -> None: """Index sword biblical book names. Sword use some names to designate biblibal books. Index them once for all. """ if self.index.get_from_header('are_sword_biblical_books_indexed', "no") == "yes": logger.debug( "ThekeIndexBuilder − Index sword biblical book names [skip]") return logger.debug("ThekeIndexBuilder − Index sword biblical book names") # Index names used by sword for biblical books vk = Sword.VerseKey() for itestament in [theke.BIBLE_OT, theke.BIBLE_NT]: vk.setTestament(itestament) for ibook in range(1, vk.getBookMax() + 1): vk.setBook(ibook) # Create a new biblical book entry documentId = self.index.execute_returning_id( """INSERT INTO documents (type) VALUES(?);""", (theke.TYPE_BIBLE, )) # Index the biblical book name self.index_biblical_book_name(documentId, vk.getBookName(), "en", "sword", doCommit=False) # Index the number of chapters and the testament self.index.execute( """INSERT OR IGNORE INTO biblicalBookData (id_document, nbOfChapters, testament) VALUES(?, ?, ?);""", (documentId, vk.getChapterMax(), itestament)) self.index.execute("""INSERT INTO header (key, value) VALUES(?, ?);""", ("are_sword_biblical_books_indexed", "yes")) self.index.commit()
def getAllBooks(): """ Return an array: [{'testament': 1, 'bookCount': 1, 'name': 'Genesis', 'abbr': 'Gen'}, {'testament': 1, 'bookCount': 2, 'name': 'Exodus', 'abbr': 'Exod'}, """ vk=Sword.VerseKey() out=[] for i in range(1,3): vk.setTestament(i) for j in range(1,vk.bookCount(i)+1): vk.setBook(j) tmp={} tmp['name']=vk.bookName(i,j) tmp['abbr']=vk.getBookAbbrev() tmp['testament']=i tmp['bookCount']=j out.append(tmp) return out
def modcompare(arglist=sys.argv): # pylint: disable=dangerous-default-value """ Compares two modules, verse by verse, and reports verses that differ between the two. """ parser = argparse.ArgumentParser( description="Compares two SWORD modules, verse by" " verse, to certify that the contents of each are identical") parser.add_argument("original", help="First module") parser.add_argument("test", help="Second module to compare against the first") args = parser.parse_args(arglist) original = utils.get_mod(args.original) test = utils.get_mod(args.test) if original is None or test is None: print( "Please double check that both modules are installed and accessible", file=sys.stderr, ) sys.exit(1) key = Sword.VerseKey(original.createKey()) test.setKey(key) book = key.getBook() while key.popError() == "\x00": if book != key.getBook(): print("Checked up through ", key.getText()) book = key.getBook() original_text = original.renderText().c_str() test_text = test.renderText().c_str() if original_text != test_text: print(f"Mismatch in {key.getText()}") print(f"Original text is*********:\n{original_text}") print(f"New text is*********:\n{test_text}") key.increment() original.setKey(key) test.setKey(key) print("Comparison ended at ", key.getText())
def get_verse(bookStr, chapterInt, verseNbr, moduleName, mgr): mod = mgr.getModule(moduleName) versification = mod.getConfigEntry("Versification") vk = Sword.VerseKey() vk.setVersificationSystem(versification) vk.setBookName(bookStr) vk.setChapter(chapterInt) vk.setVerse(verseNbr) mod.setKey(vk) mgr.setGlobalOption("Hebrew Vowel Points", "On") mgr.setGlobalOption("Hebrew Cantillation", "On") mgr.setGlobalOption("Strong's Numbers", "Off") mgr.setGlobalOption("Headings", "Off") mgr.setGlobalOption("Footnotes", "Off") mgr.setGlobalOption("Textual Variants", "Off") mgr.setGlobalOption("Morphological Tags", "Off") mgr.setGlobalOption("Lemmas", "Off") mgr.setGlobalOption("Greek Accents", "On") if not mod: print("No module") sys.exit() return mod.renderText()
def index_sword_biblical_module(self, sourceId, mod) -> None: """Index a sword biblical module """ logger.debug("ThekeIndexBuilder - Index %s as a Bible (id: %s)", mod.get_name(), sourceId) # Index each of the biblical books of this module # TODO: Y a-t-il une façon plus propre de faire la même chose ? vk = Sword.VerseKey() for itestament in [1, 2]: vk.setTestament(itestament) for ibook in range(1, vk.getBookMax() + 1): vk.setBook(ibook) if mod.has_entry(vk): bookId = self.index.get_document_id(vk.getBookName()) self.link_biblical_book(vk.getBookName(), bookId, sourceId, doCommit=False) self.index.commit()
import sys """ from corediatheke.cpp if ((optionfilters & OP_VARIANTS) && variants) { if (variants == -1) manager.setGlobalOption("Textual Variants", "All Readings"); else if (variants == 1) manager.setGlobalOption("Textual Variants", "Secondary Reading"); } else manager.setGlobalOption("Textual Variants", "Primary Reading"); """ key="Josh 15:21" moduleName="LXX" vk=Sword.VerseKey(key) markup=Sword.MarkupFilterMgr(Sword.FMT_PLAIN) markup.thisown=False mgr = Sword.SWMgr(markup) mod=mgr.getModule(moduleName) if not mod: print( "No module found") sys.exit() mod.setKey(vk) #Look in bindings/objc/src/SwordManager.h for the correct mapping between C++ define and python string. #you may also have to look into specific module code though such as src/modules/filters/osisxlit.cpp: static const char oName[] = "Transliterated Forms"; mgr.setGlobalOption("Strong's Numbers","Off") mgr.setGlobalOption("Cross-references","Off") mgr.setGlobalOption("Morpheme Segmentation","Off") mgr.setGlobalOption("Morphological Tags","Off") mgr.setGlobalOption("Lemmas","Off")
sys.exit(-1) # Warn if we have too many if len(sys.argv) > 3: print('Usage: {0} <First Module> <Second Module>'.format(sys.argv[0])) print('WARNING: Only accepts two arguments, treating first two arguments ' 'as module names, ignoring the rest.') # Grab the base SWORD manager mgr = Sword.SWMgr() # Get the two modules, provided they both exist - this is an advanced user # tool, if these throw errors, too bad original = mgr.getModule(sys.argv[1]) test = mgr.getModule(sys.argv[2]) # Create the keys we will need so we can track - if original is not a Bible or # Commentary, this will probably cause errors key = Sword.VerseKey(original.CreateKey()) test.SetKey(key) book = key.Book() # Loop until one of the two modules throws an error, then exit while original.Error() == '\x00' and test.Error() == '\x00': # Get the texts of each module and compare them oText = original.RenderText() tText = test.RenderText() if oText != tText: print('Mismatch in {0}\nOriginal text is**********:\n{1}\n' 'New Text is*********:\n{2}\n'.format(key.getText(), oText, tText)) # Increment the keys to the next verse, and provide feedback if we have # finished comparing an entire canonical book original.increment()
def demo(): """ Sword """ if Globals.verbosityLevel > 0: print( ProgNameVersion ) #print( "\ndir Sword", dir(Sword) ) if SwordType == "CrosswireLibrary": print( "\ndir Sword.SWVersion()", dir(Sword.SWVersion()) ) print( "Version", Sword.SWVersion().getText() ) print( "Versions", Sword.SWVersion().major, Sword.SWVersion().minor, Sword.SWVersion().minor2, Sword.SWVersion().minor3 ) # ints library = Sword.SWMgr() #print( "\ndir library", dir(library) ) #print( "\nlibrary getHomeDir", library.getHomeDir().getRawData() ) def Find( attribute ): """ Search for methods and attributes """ print( "\nSearching for attribute '{}'...".format( attribute ) ) found = False AA = attribute.upper() for thing in dir(Sword): BB = thing.upper() if BB.startswith(AA): print( " Have {} in Sword".format( thing ) ); found = True for thing in dir(Sword.SWVersion()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWVersion".format( thing ) ); found = True for thing in dir(Sword.SWMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWMgr".format( thing ) ); found = True module = library.getModule( "KJV" ) for thing in dir(module): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWModule".format( thing ) ); found = True for thing in dir(Sword.SWKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWKey".format( thing ) ); found = True for thing in dir(Sword.VerseKey()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in VerseKey".format( thing ) ); found = True #for thing in dir(Sword.InstallMgr()): #BB = thing.upper() #if BB.startswith(AA): print( " Have {} in InstallMgr".format( thing ) ); found = True for thing in dir(Sword.LocaleMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in LocaleMgr".format( thing ) ); found = True for thing in dir(Sword.SWFilterMgr()): BB = thing.upper() if BB.startswith(AA): print( " Have {} in SWFilterMgr".format( thing ) ); found = True if not found: print( " Sorry, '{}' not found.".format( attribute ) ) # end of Find if 0: # Install manager print( "\nINSTALL MANAGER" ) im = Sword.InstallMgr() # FAILS print( "\ndir im", im, dir(im) ) if 0: # Locale manager print( "\nLOCALE MANAGER" ) lm = Sword.LocaleMgr() print( "dir lm", lm, dir(lm) ) print( "default {}".format( lm.getDefaultLocaleName() ) ) print( "available {}".format( lm.getAvailableLocales() ) ) # Gives weird result: "available ()" print( "locale {}".format( lm.getLocale( "en" ) ) ) # Needs a string parameter but why does it return None? if 0: # try filters print( "\nFILTER MANAGER" ) fm = Sword.SWFilterMgr() print( "\ndir filters", dir(fm) ) if SwordType == "CrosswireLibrary": # Get a list of available module names and types print( "\n{} modules are installed.".format( len(library.getModules()) ) ) for j,moduleBuffer in enumerate(library.getModules()): moduleID = moduleBuffer.getRawData() module = library.getModule( moduleID ) if 0: print( "{} {} ({}) {} '{}'".format( j, module.getName(), module.getType(), module.getLanguage(), module.getEncoding() ) ) try: print( " {} '{}' {} {}".format( module.getDescription(), module.getMarkup(), module.getDirection(), "" ) ) except UnicodeDecodeError: print( " Description is not Unicode!" ) #print( "\n", j, "dir module", dir(module) ) # Try some modules mod1 = library.getModule( "KJV" ) print( "\nmod1 {} ({}) '{}'".format( mod1.getName(), mod1.getType(), mod1.getDescription() ) ) mod2 = library.getModule( "ASV" ) print( "\nmod2 {} ({}) '{}'".format( mod2.getName(), mod2.getType(), mod2.getDescription() ) ) mod3 = library.getModule( "WEB" ) print( "\nmod3 {} ({}) '{}'".format( mod3.getName(), mod3.getType(), mod3.getDescription() ) ) strongsGreek = library.getModule( "StrongsGreek" ) print( "\nSG {} ({}) '{}'\n".format( strongsGreek.getName(), strongsGreek.getType(), strongsGreek.getDescription() ) ) strongsHebrew = library.getModule( "StrongsHebrew" ) print( "\nSH {} ({}) '{}'\n".format( strongsHebrew.getName(), strongsHebrew.getType(), strongsHebrew.getDescription() ) ) print() # Try a sword key sk = Sword.SWKey( "H0430" ) #print( "\ndir sk", dir(sk) ) # Try a verse key vk = Sword.VerseKey( "Jn 3:16" ) #print( "\ndir vk", dir(vk) ) #print( "val", vk.validateCurrentLocale() ) # gives None print( "getInfo", vk.getLocale(), vk.getBookCount(), vk.getBookMax(), vk.getIndex(), vk.getVersificationSystem() ) print( "getBCV {}({}/{}) {}/{}:{} in '{}'({})/{}".format( vk.getBookName(), vk.getBookAbbrev(), vk.getOSISBookName(), vk.getChapter(), vk.getChapterMax(), vk.getVerse(), repr(vk.getTestament()), vk.getTestamentIndex(), vk.getTestamentMax() ) ) print( "getText {} {} {} {} '{}'".format( vk.getOSISRef(), vk.getText(), vk.getRangeText(), vk.getShortText(), vk.getSuffix() ) ) #print( "bounds {} {}".format( vk.getLowerBound(), vk.getUpperBound() ) ) if 0: # Set a filter HOW DO WE DO THIS??? rFs = mod1.getRenderFilters() print( mod1.getRenderFilters() ) mod1.setRenderFilter() print( "\n{} {}: {}".format( mod1.getName(), "Jonny 1:1", mod1.renderText( Sword.VerseKey("Jn 1:1") ) ) ) mod1.increment() print( "\n{} {}: {}".format( mod1.getName(), mod1.getKey().getText(), mod1.stripText( ) ) ) mod1.increment() print( "\n{} {}: {}".format( mod1.getName(), mod1.getKey().getText(), mod1.renderText( ) ) ) print( "\n{} {}: {}".format( mod2.getName(), vk.getText(), mod2.renderText( vk ) ) ) print( "\n{} {}: {}".format( mod3.getName(), vk.getText(), mod3.renderText( vk ) ) ) print( "\n{} {}: {}".format( mod3.getName(), vk.getText(), mod3.renderText( vk ) ) ) print( "\n{} {}: {}".format( strongsGreek.getName(), sk.getText(), strongsGreek.renderText( Sword.SWKey("G746") ) ) ) print( "\n{} {}: {}".format( strongsHebrew.getName(), sk.getText(), strongsHebrew.renderText( sk ) ) ) if 0: # Get all vernacular booknames # VerseKey vk; while (!vk.Error()) { cout << vk.getBookName(); vk.setBook(vk.getBook()+1); } vk = Sword.VerseKey() while vk.popError()=='\x00': print( "bookname", vk.getBookName() ) booknumber = int( bytes( vk.getBook(),'utf-8' )[0] ) vk.setBook( booknumber + 1 ) if 0: # Get booknames by testament (from http://www.crosswire.org/wiki/DevTools:Code_Examples) vk = Sword.VerseKey() for t in range( 1, 2+1 ): vk.setTestament( t ) for i in range( 1, vk.getBookMax()+1 ): vk.setBook( i ) print( t, i, vk.getBookName() ) # Try a tree key on a GenBook module = library.getModule( "Westminster" ) print( "\nmodule {} ({}) '{}'".format( module.getName(), module.getType(), module.getDescription() ) ) def getGenBookTOC( tk, parent ): if tk is None: # obtain one from the module tk = Sword.TreeKey_castTo( module.getKey() ) # Only works for gen books if tk and tk.firstChild(): while True: print( " ", tk.getText() ) # Keep track of the information for custom implementation #Class *item = storeItemInfoForLaterUse(parent, text); item = (parent) # temp .................... if tk.hasChildren(): print( " Getting children..." ) getGenBookTOC( tk, item ) if not tk.nextSibling(): break # end of getGenBookTOC getGenBookTOC( None, None )
d = pq(filename=sys.argv[1]) # Get the list of versifications if debug: print 'Fetching a list of versifications' vmgr = Sword.VersificationMgr.getSystemVersificationMgr() av11ns = vmgr.getVersificationSystems() # Get the list of all osisIDs if debug: print 'Fetching a list of OSIS IDs' ids = d("*[osisID]") # Iterate each versification scheme for v11n in av11ns: print 'Checking %s' % (v11n.c_str(), ) # Construct a list of the IDs in this versification key = Sword.VerseKey() key.setVersificationSystem(v11n.c_str()) otkeyList = [ ] # Anything left in this afterwards is missing from the OSIS ot ntkeyList = [ ] # Anything left in this afterwards is missing from the OSIS nt otextraKeys = [ ] # Anything that gets placed in here is extraneous OT material (we think) ntextraKeys = [ ] # Anything that gets placed in here is extraneous NT material (we think) inNT = False while key.popError() == '\x00': skey = key.getOSISRef() if not inNT and re.match( '^Matt', skey): # Assume we enter the NT when we hit Matthew