def blankLineAfterLiteral(self, oldLines): ''' Guarantee a blank line after literal blocks. ''' lines = [oldLines[0]] # start with first line... for first, second in windowed(oldLines, 2): if (first.strip() and first[0].isspace() and second.strip() and not second[0].isspace()): lines.append('') lines.append(second) if '.. parsed-literal::' in second: lines.append(' :class: ipython-result') return lines
def run(self): if 'StreamIterator' in self.streamSearch.classes: thisStreamIterator = self.streamSearch else: if self.recurse: thisStreamIterator = self.streamSearch.recurse() else: thisStreamIterator = self.searchStream.iter if self.filterNotesAndRests: thisStreamIterator.addFilter( filters.ClassFilter('GeneralNote')) elif self.filterNotes: thisStreamIterator.addFilter( filters.ClassFilter(['Note', 'Chord'])) self.activeIterator = thisStreamIterator streamIteratorEls = list(thisStreamIterator) streamLength = len(streamIteratorEls) searchLength = len(self.searchList) if searchLength == 0: raise SearchException('the search Stream or list cannot be empty') foundEls = [] if searchLength > streamLength: return foundEls for startPosition, streamEls in enumerate( windowed(streamIteratorEls, searchLength)): result = None for j in range(searchLength): streamEl = streamEls[j] searchEl = self.searchList[j] for thisAlgorithm in self.algorithms: result = thisAlgorithm(self, streamEl, searchEl) if result is not None: # break on True or False break if result is False: break if result is True: result = None if result is not False: sm = SearchMatch(streamEls[0], streamEls, startPosition, self.activeIterator) foundEls.append(sm) return foundEls
def blankLineAfterLiteral(self, oldLines): ''' Guarantee a blank line after literal blocks. ''' lines = [oldLines[0]] # start with first line... for first, second in windowed(oldLines, 2): if (first.strip() and first[0].isspace() and second.strip() and not second[0].isspace()): lines.append('') lines.append(second) if '.. parsed-literal::' in second: lines.append(' :class: ipython-result') return lines
def run(self): if 'StreamIterator' in self.streamSearch.classes: thisStreamIterator = self.streamSearch else: if self.recurse: thisStreamIterator = self.streamSearch.recurse() else: thisStreamIterator = self.searchStream.iter if self.filterNotesAndRests: thisStreamIterator.addFilter(filters.ClassFilter('GeneralNote')) elif self.filterNotes: thisStreamIterator.addFilter(filters.ClassFilter(['Note', 'Chord'])) self.activeIterator = thisStreamIterator streamIteratorEls = list(thisStreamIterator) streamLength = len(streamIteratorEls) searchLength = len(self.searchList) if searchLength == 0: raise SearchException('the search Stream or list cannot be empty') foundEls = [] if searchLength > streamLength: return foundEls for startPosition, streamEls in enumerate(windowed(streamIteratorEls, searchLength)): result = None for j in range(searchLength): streamEl = streamEls[j] searchEl = self.searchList[j] for thisAlgorithm in self.algorithms: result = thisAlgorithm(self, streamEl, searchEl) if result is not None: # break on True or False break if result is False: break if result is True: result = None if result is not False: sm = SearchMatch(streamEls[0], streamEls, startPosition, self.activeIterator) foundEls.append(sm) return foundEls
def streamSearchBase(thisStreamOrIterator, searchList, algorithm=None): ''' A basic search function that is used by other search mechanisms, which takes in a stream or StreamIterator and a searchList or stream and an algorithm to run on each pair of elements to determine if they match. ''' if algorithm is None: raise SearchException('algorithm must be a function not None') result = None if 'StreamIterator' in thisStreamOrIterator.classes: thisStreamIterator = thisStreamOrIterator else: thisStreamIterator = thisStreamOrIterator.recurse() streamIteratorEls = list(thisStreamIterator) streamLength = len(streamIteratorEls) searchLength = len(searchList) if searchLength == 0: raise SearchException('the search Stream or list cannot be empty') foundEls = [] if searchLength > streamLength: return foundEls for startPosition, streamEls in enumerate( windowed(streamIteratorEls, searchLength)): for j in range(searchLength): streamEl = streamEls[j] searchEl = searchList[j] result = algorithm(streamEl, searchEl) if not result: break if result: foundEls.append(startPosition) return foundEls
def streamSearchBase(thisStreamOrIterator, searchList, algorithm=None): ''' A basic search function that is used by other search mechanisms, which takes in a stream or StreamIterator and a searchList or stream and an algorithm to run on each pair of elements to determine if they match. ''' if algorithm is None: raise SearchException('algorithm must be a function not None') if 'StreamIterator' in thisStreamOrIterator.classes: thisStreamIterator = thisStreamOrIterator else: thisStreamIterator = thisStreamOrIterator.recurse() streamIteratorEls = list(thisStreamIterator) streamLength = len(streamIteratorEls) searchLength = len(searchList) if searchLength == 0: raise SearchException('the search Stream or list cannot be empty') foundEls = [] if searchLength > streamLength: return foundEls for startPosition, streamEls in enumerate(windowed(streamIteratorEls, searchLength)): for j in range(searchLength): streamEl = streamEls[j] searchEl = searchList[j] result = algorithm(streamEl, searchEl) if not result: break if result: foundEls.append(startPosition) return foundEls