Skip to content

Commit

Permalink
Speech/refactor results: xrnage -> range. RE nvaccess#7105.
Browse files Browse the repository at this point in the history
Because various calls to xrange are used by generators, change them by calling range function (in Python 3, range returns generators).
  • Loading branch information
josephsl committed May 23, 2019
1 parent b9489a2 commit 1c663cd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions source/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def speak(speechSequence, symbolLevel=None, priority=None):
symbolLevel=config.conf["speech"]["symbolLevel"]
curLanguage=defaultLanguage
inCharacterMode=False
for index in xrange(len(speechSequence)):
for index in range(len(speechSequence)):
item=speechSequence[index]
if isinstance(item,CharacterModeCommand):
inCharacterMode=item.state
Expand Down Expand Up @@ -820,7 +820,7 @@ def speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=cont
raise ValueError("unknown field: %s"%field)
#Calculate how many fields in the old and new controlFieldStacks are the same
commonFieldCount=0
for count in xrange(min(len(newControlFieldStack),len(controlFieldStackCache))):
for count in range(min(len(newControlFieldStack),len(controlFieldStackCache))):
# #2199: When comparing controlFields try using uniqueID if it exists before resorting to compairing the entire dictionary
oldUniqueID=controlFieldStackCache[count].get('uniqueID')
newUniqueID=newControlFieldStack[count].get('uniqueID')
Expand All @@ -833,7 +833,7 @@ def speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=cont
# We don't do this for focus because hearing "out of list", etc. isn't useful when tabbing or using quick navigation and makes navigation less efficient.
if reason!=controlTypes.REASON_FOCUS:
endingBlock=False
for count in reversed(xrange(commonFieldCount,len(controlFieldStackCache))):
for count in reversed(range(commonFieldCount,len(controlFieldStackCache))):
text=info.getControlFieldSpeech(controlFieldStackCache[count],controlFieldStackCache[0:count],"end_removedFromControlFieldStack",formatConfig,extraDetail,reason=reason)
if text:
speechSequence.append(text)
Expand All @@ -849,7 +849,7 @@ def speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=cont

#Get speech text for any fields that are in both controlFieldStacks, if extra detail is not requested
if not extraDetail:
for count in xrange(commonFieldCount):
for count in range(commonFieldCount):
field=newControlFieldStack[count]
text=info.getControlFieldSpeech(field,newControlFieldStack[0:count],"start_inControlFieldStack",formatConfig,extraDetail,reason=reason)
if text:
Expand All @@ -862,7 +862,7 @@ def speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=cont
# When true, we are inside a clickable field, and should therefore not announce any more new clickable fields
inClickable=False
#Get speech text for any fields in the new controlFieldStack that are not in the old controlFieldStack
for count in xrange(commonFieldCount,len(newControlFieldStack)):
for count in range(commonFieldCount,len(newControlFieldStack)):
field=newControlFieldStack[count]
if not inClickable and formatConfig['reportClickable']:
states=field.get('states')
Expand Down Expand Up @@ -1006,7 +1006,7 @@ def speakTextInfo(info, useCache=True, formatConfig=None, unit=None, reason=cont
speechSequence.append(LangChangeCommand(None))
lastLanguage=None
if not extraDetail:
for count in reversed(xrange(min(len(newControlFieldStack),commonFieldCount))):
for count in reversed(range(min(len(newControlFieldStack),commonFieldCount))):
text=info.getControlFieldSpeech(newControlFieldStack[count],newControlFieldStack[0:count],"end_inControlFieldStack",formatConfig,extraDetail,reason=reason)
if text:
speechSequence.append(text)
Expand Down Expand Up @@ -1758,7 +1758,7 @@ def speakWithoutPauses(speechSequence,detectBreaks=True):
if detectBreaks and speechSequence:
sequenceLen=len(speechSequence)
spoke = False
for index in xrange(sequenceLen):
for index in range(sequenceLen):
if isinstance(speechSequence[index],EndUtteranceCommand):
if index>0 and lastStartIndex<index:
speakWithoutPauses(speechSequence[lastStartIndex:index],detectBreaks=False)
Expand All @@ -1778,7 +1778,7 @@ def speakWithoutPauses(speechSequence,detectBreaks=True):
else: #Handling normal speech
#Scan the given speech and place all completed phrases in finalSpeechSequence to be spoken,
#And place the final incomplete phrase in pendingSpeechSequence
for index in xrange(len(speechSequence)-1,-1,-1):
for index in range(len(speechSequence)-1,-1,-1):
item=speechSequence[index]
if isinstance(item,basestring):
m=re_last_pause.match(item)
Expand All @@ -1793,7 +1793,7 @@ def speakWithoutPauses(speechSequence,detectBreaks=True):
finalSpeechSequence.append(before)
# Apply the last language change to the pending sequence.
# This will need to be done for any other speech change commands introduced in future.
for changeIndex in xrange(index-1,-1,-1):
for changeIndex in range(index-1,-1,-1):
change=speechSequence[changeIndex]
if not isinstance(change,LangChangeCommand):
continue
Expand Down Expand Up @@ -2235,7 +2235,7 @@ def _generateIndexes(self):
in the same or previous utterance.
"""
while True:
for index in xrange(1, self.MAX_INDEX + 1):
for index in range(1, self.MAX_INDEX + 1):
yield index

def _reset(self):
Expand Down Expand Up @@ -2451,7 +2451,7 @@ def _removeCompletedFromQueue(self, index):
else:
# Keep track of parameters changed so far.
# This is necessary in case this utterance is preempted by higher priority speech.
for seqIndex in xrange(seqIndex + 1):
for seqIndex in range(seqIndex + 1):
seq = self._curPriQueue.pendingSequences[seqIndex]
for command in seq:
if isinstance(command, SynthParamCommand):
Expand Down

0 comments on commit 1c663cd

Please sign in to comment.