Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/NVDAObjects/IAccessible/MSHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def _get_name(self):
title=self.HTMLAttributes['title']
# #2121: MSHTML sometimes returns a node for the title attribute.
# This doesn't make any sense, so ignore it.
if title and isinstance(title,basestring):
if title and isinstance(title,str):
return title
return ""
return super(MSHTML,self).name
Expand Down
16 changes: 8 additions & 8 deletions source/NVDAObjects/IAccessible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _iterTextWithEmbeddedObjects(self, withFields, formatConfig=None):
items = [self.text]
offset = self._startOffset
for item in items:
if not isinstance(item, basestring):
if not isinstance(item, str):
# This is a field.
yield item
continue
Expand Down Expand Up @@ -741,14 +741,14 @@ def _get_name(self):
res=self.IAccessibleObject.accName(self.IAccessibleChildID)
except COMError:
res=None
return res if isinstance(res,basestring) and not res.isspace() else None
return res if isinstance(res,str) and not res.isspace() else None

def _get_value(self):
try:
res=self.IAccessibleObject.accValue(self.IAccessibleChildID)
except COMError:
res=None
return res if isinstance(res,basestring) and not res.isspace() else None
return res if isinstance(res,str) and not res.isspace() else None

def _get_actionCount(self):
if hasattr(self,'IAccessibleActionObject'):
Expand Down Expand Up @@ -824,7 +824,7 @@ def _get_role(self):
superRole=super(IAccessible,self).role
if superRole!=controlTypes.ROLE_WINDOW:
return superRole
if isinstance(IARole,basestring):
if isinstance(IARole,str):
IARole=IARole.split(',')[0].lower()
log.debug("IARole: %s"%IARole)
return IAccessibleHandler.IAccessibleRolesToNVDARoles.get(IARole,controlTypes.ROLE_UNKNOWN)
Expand Down Expand Up @@ -904,22 +904,22 @@ def _get_decodedAccDescription(self):
def _get_description(self):
if self.hasEncodedAccDescription:
d=self.decodedAccDescription
if isinstance(d,basestring):
if isinstance(d,str):
return d
else:
return ""
try:
res=self.IAccessibleObject.accDescription(self.IAccessibleChildID)
except COMError:
res=None
return res if isinstance(res,basestring) and not res.isspace() else None
return res if isinstance(res,str) and not res.isspace() else None

def _get_keyboardShortcut(self):
try:
res=self.IAccessibleObject.accKeyboardShortcut(self.IAccessibleChildID)
except COMError:
res=None
return res if isinstance(res,basestring) and not res.isspace() else None
return res if isinstance(res,str) and not res.isspace() else None

def _get_childCount(self):
if self.IAccessibleChildID!=0:
Expand Down Expand Up @@ -1379,7 +1379,7 @@ def _get_positionInfo(self):
pass
if self.hasEncodedAccDescription:
d=self.decodedAccDescription
if d and not isinstance(d,basestring):
if d and not isinstance(d,str):
groupdict=d.groupdict()
return {x:int(y) for x,y in groupdict.items() if y is not None}
if self.allowIAccessibleChildIDAndChildCountForPositionInfo and self.IAccessibleChildID>0:
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/IAccessible/ia2TextMozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _iterRecursiveText(self, ti, controlStack, formatConfig):
for item in ti._iterTextWithEmbeddedObjects(controlStack is not None, formatConfig=formatConfig):
if item is None:
yield u""
elif isinstance(item, basestring):
elif isinstance(item, str):
yield item
elif isinstance(item, int): # Embedded object.
embedded = _getEmbedded(ti.obj, item)
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/IAccessible/mozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Gecko1_9(Mozilla):

def _get_description(self):
rawDescription=super(Mozilla,self).description
if isinstance(rawDescription,basestring) and rawDescription.startswith('Description: '):
if isinstance(rawDescription,str) and rawDescription.startswith('Description: '):
return rawDescription[13:]
else:
return ""
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/IAccessible/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def _get_errorText(self):
inBold=False
textList=[]
for field in fields:
if isinstance(field,basestring):
if isinstance(field,str):
if inBold: textList.append(field)
elif field.field:
inBold=field.field.get('bold',False)
Expand Down
4 changes: 2 additions & 2 deletions source/NVDAObjects/UIA/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def getTextWithFields(self,formatConfig=None):
index=0
while index<len(fields):
field=fields[index]
if index>1 and isinstance(field,basestring) and field.isspace():
if index>1 and isinstance(field,str) and field.isspace():
prevField=fields[index-2]
if isinstance(prevField,textInfos.FieldCommand) and prevField.command=="controlEnd":
del fields[index-1:index+1]
Expand All @@ -214,7 +214,7 @@ def getTextWithFields(self,formatConfig=None):
numFields=len(fields)
for index in range(numFields-1,-1,-1):
field=fields[index]
if isinstance(field,basestring):
if isinstance(field,str):
break
elif isinstance(field,textInfos.FieldCommand) and field.command=="controlStart" and not field.field.get('embedded'):
startCount+=1
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/UIA/wordDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def getTextWithFields(self,formatConfig=None):
elif isinstance(field,textInfos.FieldCommand) and field.command=="formatChange":
# This is the most recent formatField we have seen.
lastFormatField=field.field
elif listItemStarted and isinstance(field,basestring):
elif listItemStarted and isinstance(field,str):
# This is the first text string within the list.
# Remove the text up to the first space, and store it as line-prefix which NVDA will appropriately speak/braille as a bullet.
try:
Expand Down
20 changes: 10 additions & 10 deletions source/NVDAObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _get_appModule(self):

def _get_name(self):
"""The name or label of this object (example: the text of a button).
@rtype: basestring
@rtype: str
"""
return ""

Expand All @@ -408,13 +408,13 @@ def _get_roleText(self):

def _get_value(self):
"""The value of this object (example: the current percentage of a scrollbar, the selected option in a combo box).
@rtype: basestring
@rtype: str
"""
return ""

def _get_description(self):
"""The description or help text of this object.
@rtype: basestring
@rtype: str
"""
return ""

Expand All @@ -432,7 +432,7 @@ def getActionName(self,index=None):
@param index: the optional 0-based index of the wanted action.
@type index: int
@return: the action's name
@rtype: basestring
@rtype: str
"""
raise NotImplementedError

Expand All @@ -448,7 +448,7 @@ def _get_defaultActionIndex(self):

def _get_keyboardShortcut(self):
"""The shortcut key that activates this object(example: alt+t).
@rtype: basestring
@rtype: str
"""
return ""

Expand Down Expand Up @@ -1098,7 +1098,7 @@ def _get_basicText(self):
newTime=time.time()
oldTime=getattr(self,'_basicTextTime',0)
if newTime-oldTime>0.5:
self._basicText=u" ".join(x for x in (self.name, self.value, self.description) if isinstance(x, basestring) and len(x) > 0 and not x.isspace())
self._basicText=u" ".join(x for x in (self.name, self.value, self.description) if isinstance(x, str) and len(x) > 0 and not x.isspace())
if len(self._basicText)==0:
self._basicText=u""
else:
Expand All @@ -1120,13 +1120,13 @@ def _formatLongDevInfoString(string, truncateLen=250):
If the string is too long to be useful, it will be truncated.
This string should be included as returned. There is no need to call repr.
@param string: The string to format.
@type string: nbasestring
@type string: str
@param truncateLen: The length at which to truncate the string.
@type truncateLen: int
@return: The formatted string.
@rtype: basestring
@rtype: str
"""
if isinstance(string, basestring) and len(string) > truncateLen:
if isinstance(string, str) and len(string) > truncateLen:
return "%r (truncated)" % string[:truncateLen]
return repr(string)

Expand Down Expand Up @@ -1238,7 +1238,7 @@ def _get_mathMl(self):
raise NotImplementedError

#: The language/locale of this object.
#: @type: basestring
#: @type: str
language = None

def _get__hasNavigableText(self):
Expand Down
3 changes: 2 additions & 1 deletion source/NVDAObjects/window/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ def _getTextRange(self,start,end):
if self.obj.isWindowUnicode or (res>1 and (buf[res]!=0 or buf[res+1]!=0)):
text=ctypes.cast(buf,ctypes.c_wchar_p).value
else:
text=unicode(ctypes.cast(buf,ctypes.c_char_p).value, errors="replace", encoding=locale.getlocale()[1])
encoding=locale.getlocale()[1]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should change this into locale.getpreferredencoding() while at it.

text=ctypes.cast(buf,ctypes.c_char_p).value.decode(encoding,errors="replace")
# #4095: Some protected richEdit controls do not hide their password characters.
# We do this specifically.
# Note that protected standard edit controls get characters hidden in _getStoryText.
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ def _get_children(self):
background=item.field.get('background-color',None)
if (background,foreground)==self._highlightColors:
states.add(controlTypes.STATE_SELECTED)
if isinstance(item,basestring):
if isinstance(item,str):
obj=ExcelDropdownItem(parent=self,name=item,states=states,index=index)
children.append(obj)
index+=1
Expand Down
5 changes: 3 additions & 2 deletions source/NVDAObjects/window/scintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ def _getTextRange(self,start,end):
winKernel.virtualFreeEx(processHandle,internalBuf,0,winKernel.MEM_RELEASE)
cp=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_GETCODEPAGE,0,0)
if cp==SC_CP_UTF8:
return unicode(buf.value, errors="replace", encoding="utf-8")
encoding="utf-8"
else:
return unicode(buf.value, errors="replace", encoding=locale.getlocale()[1])
encoding=locale.getlocale()[1]
return buf.value.decode(encoding,errors="replace")

def _getWordOffsets(self,offset):
start=watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_WORDSTARTPOSITION,offset,0)
Expand Down
2 changes: 1 addition & 1 deletion source/NVDAObjects/window/winword.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ def getTextWithFields(self,formatConfig=None):
item.field=self._normalizeControlField(field)
elif isinstance(field,textInfos.FormatField):
item.field=self._normalizeFormatField(field,extraDetail=extraDetail)
elif index>0 and isinstance(item,basestring) and item.isspace():
elif index>0 and isinstance(item,str) and item.isspace():
#2047: don't expose language for whitespace as its incorrect for east-asian languages
lastItem=commandList[index-1]
if isinstance(lastItem,textInfos.FieldCommand) and isinstance(lastItem.field,textInfos.FormatField):
Expand Down
4 changes: 2 additions & 2 deletions source/XMLFormatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _startElementHandler(self,tagName,attrs):
data=attrs.get('value',None)
if data is not None:
try:
data=unichr(int(data))
data=chr(int(data))
except ValueError:
data=u'\ufffd'
self._CharacterDataHandler(data)
Expand Down Expand Up @@ -50,7 +50,7 @@ def _EndElementHandler(self,tagName):

def _CharacterDataHandler(self,data):
cmdList=self._commandList
if cmdList and isinstance(cmdList[-1],basestring):
if cmdList and isinstance(cmdList[-1],str):
cmdList[-1]+=data
else:
cmdList.append(data)
Expand Down
11 changes: 5 additions & 6 deletions source/addonHandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ def addToPackagePath(self, package):
if not os.path.isdir(extension_path):
# This addon does not have extension points for this package
return
# Python 2.x doesn't properly handle unicode import paths, so convert them before adding.
converted_path = self._getPathForInclusionInPackage(package)
package.__path__.insert(0, converted_path)
self._extendedPackages.add(package)
Expand Down Expand Up @@ -474,9 +473,9 @@ def getDocFilePath(self, fileName=None):
An add-on can specify a default documentation file name
via the docFileName parameter in its manifest.
@param fileName: The requested file name or C{None} for the add-on's default.
@type fileName: basestring
@type fileName: str
@return: The path to the requested file or C{None} if it wasn't found.
@rtype: basestring
@rtype: str
"""
if not fileName:
fileName = self.manifest["docFileName"]
Expand Down Expand Up @@ -507,7 +506,7 @@ def getCodeAddon(obj=None, frameDist=1):
if obj is None:
obj = sys._getframe(frameDist)
fileName = inspect.getfile(obj)
dir= unicode(os.path.abspath(os.path.dirname(fileName)), "mbcs")
dir= os.path.abspath(os.path.dirname(fileName))
# if fileName is not a subdir of one of the addon paths
# It does not belong to an addon.
for p in _getDefaultAddonPaths():
Expand Down Expand Up @@ -558,7 +557,7 @@ def __init__(self, bundlePath):
""" Constructs an L{AddonBundle} from a filename.
@param bundlePath: The path for the bundle file.
"""
self._path = bundlePath if isinstance(bundlePath, unicode) else unicode(bundlePath, "mbcs")
self._path = bundlePath
# Read manifest:
translatedInput=None
with zipfile.ZipFile(self._path, 'r') as z:
Expand All @@ -581,7 +580,7 @@ def extract(self, addonPath):
"""
with zipfile.ZipFile(self._path, 'r') as z:
for info in z.infolist():
if isinstance(info.filename, str):
if isinstance(info.filename, bytes):
# #2505: Handle non-Unicode file names.
# Most archivers seem to use the local OEM code page, even though the spec says only cp437.
# HACK: Overriding info.filename is a bit ugly, but it avoids a lot of code duplication.
Expand Down
4 changes: 2 additions & 2 deletions source/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def copyToClip(text):
@param text: the text which will be copied to the clipboard
@type text: string
"""
if not isinstance(text,basestring) or len(text)==0:
if not isinstance(text,str) or len(text)==0:
return False
import gui
with winUser.openClipboard(gui.mainFrame.Handle):
Expand Down Expand Up @@ -335,7 +335,7 @@ def getStatusBarText(obj):
text = obj.name or ""
if text:
text += " "
return text + " ".join(chunk for child in obj.children for chunk in (child.name, child.value) if chunk and isinstance(chunk, basestring) and not chunk.isspace())
return text + " ".join(chunk for child in obj.children for chunk in (child.name, child.value) if chunk and isinstance(chunk, str) and not chunk.isspace())

def filterFileName(name):
"""Replaces invalid characters in a given string to make a windows compatible file name.
Expand Down
14 changes: 5 additions & 9 deletions source/appModuleHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ def getAppNameFromProcessID(processID,includeExt=False):
@param includeExt: C{True} to include the extension of the application's executable filename, C{False} to exclude it.
@type window: bool
@returns: application name
@rtype: unicode or str
@rtype: str
"""
if processID==NVDAProcessID:
return "nvda.exe" if includeExt else "nvda"
FSnapshotHandle = winKernel.kernel32.CreateToolhelp32Snapshot (2,0)
FProcessEntry32 = processEntry32W()
FProcessEntry32.dwSize = ctypes.sizeof(processEntry32W)
ContinueLoop = winKernel.kernel32.Process32FirstW(FSnapshotHandle, ctypes.byref(FProcessEntry32))
appName = unicode()
appName = str()
while ContinueLoop:
if FProcessEntry32.th32ProcessID == processID:
appName = FProcessEntry32.szExeFile
Expand All @@ -93,8 +93,6 @@ def getAppNameFromProcessID(processID,includeExt=False):
# This might be an executable which hosts multiple apps.
# Try querying the app module for the name of the app being hosted.
try:
# Python 2.x can't properly handle unicode module names, so convert them.
# #8768 (Py3 review required): no longer the case in Python 3.
mod = importlib.import_module("appModules.%s" % appName, package="appModules")
return mod.getAppNameFromHost(processID)
except (ImportError, AttributeError, LookupError):
Expand Down Expand Up @@ -162,23 +160,21 @@ def fetchAppModule(processID,appName):
@param processID: process ID for it to be associated with
@type processID: integer
@param appName: the application name for which an appModule should be found.
@type appName: unicode or str
@type appName: str
@returns: the appModule, or None if not found
@rtype: AppModule
"""
# First, check whether the module exists.
# We need to do this separately because even though an ImportError is raised when a module can't be found, it might also be raised for other reasons.
# Python 2.x can't properly handle unicode module names, so convert them.
modName = appName.encode("mbcs")
modName = appName

if doesAppModuleExist(modName):
try:
return importlib.import_module("appModules.%s" % modName, package="appModules").AppModule(processID, appName)
except:
log.error("error in appModule %r"%modName, exc_info=True)
# We can't present a message which isn't unicode, so use appName, not modName.
# Translators: This is presented when errors are found in an appModule (example output: error in appModule explorer).
ui.message(_("Error in appModule %s")%appName)
ui.message(_("Error in appModule %s")%modName)

# Use the base AppModule.
return AppModule(processID, appName)
Expand Down
2 changes: 1 addition & 1 deletion source/appModules/msnmsgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _get_basicText(self):

def _get_value(self):
value=super(OldMSNHistory,self).value
if not isinstance(value,basestring):
if not isinstance(value,str):
value=""
return value

Expand Down
Loading