remove use of unichr, basestring and unicode objects.#9724
Conversation
I find at least an occurrence of chr in handyTech.py. Having said that, you just said that you haven't touched braille display drivers in this pr, so I assume you mean that chr isn't used outside braille display drivers.
How about the cases where str is already used? I'm pretty sure we need a way to distinguish between cases where str has now been introduced instead of basestring, and cases where str was already efined. |
LeonarddeR
left a comment
There was a problem hiding this comment.
Apart from my question about whether this is the right moment to convert basestring to str without covering all the str cases first, here are some comments, particularly about very long lines that could be fixed while at it. I don't insist on doing this as part of this pr, though.
| 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: nstr |
| 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] |
There was a problem hiding this comment.
I wonder whether we should change this into locale.getpreferredencoding() while at it.
| @@ -128,7 +128,7 @@ | |||
| } | |||
|
|
|||
| def bytesToInt(bytes): | |||
There was a problem hiding this comment.
This function can be removed anyway, but that will be dealt with later.
| # Return True if the URL indicates that this is probably a web browser document. | ||
| # We do this check because we don't want to remember caret positions for email messages, etc. | ||
| return isinstance(docConstId, basestring) and docConstId.split("://", 1)[0] in ("http", "https", "ftp", "ftps", "file") | ||
| return isinstance(docConstId, str) and docConstId.split("://", 1)[0] in ("http", "https", "ftp", "ftps", "file") |
There was a problem hiding this comment.
This line is really huge. Could you split it while at it?
| if scriptHandler.getLastScriptRepeatCount()>=1: | ||
| if curObject.TextInfo!=NVDAObjectTextInfo: | ||
| textList=[] | ||
| if curObject.name and isinstance(curObject.name, basestring) and not curObject.name.isspace(): |
There was a problem hiding this comment.
Could you also split this one while at it?
| @@ -55,7 +55,7 @@ def translate(tableList, inbuf, typeform=None, cursorPos=None, mode=0): | |||
| * returns a list of integers instead of an string with cells, and | |||
There was a problem hiding this comment.
Ugh, this should be a string instead of an string.
|
|
||
| def _escapeXml(text): | ||
| text = unicode(text).translate(XML_ESCAPES) | ||
| text = str(text).translate(XML_ESCAPES) |
There was a problem hiding this comment.
Do we ever expect text to be something else than str? if not, we can safely omit wrapping this into str
| text = str(text).translate(XML_ESCAPES) | |
| text = text.translate(XML_ESCAPES) |
| for fileName in os.listdir(dir): | ||
| if os.path.isfile("%s\\%s"%(dir,fileName)): | ||
| file=codecs.open("%s\\%s"%(dir,fileName)) | ||
| file=open("%s\\%s"%(dir,fileName)) |
There was a problem hiding this comment.
Is there something that makes this change necessary?
| dialogArguements = automation.VARIANT( dialogString ) | ||
| gui.mainFrame.prePopup() | ||
| windll.mshtml.ShowHTMLDialogEx( gui.mainFrame.Handle , moniker , HTMLDLG_MODELESS , addressof( dialogArguements ) , unicode(DIALOG_OPTIONS ), None) | ||
| windll.mshtml.ShowHTMLDialogEx( gui.mainFrame.Handle , moniker , HTMLDLG_MODELESS , addressof( dialogArguements ) , DIALOG_OPTIONS, None) |
There was a problem hiding this comment.
Wow, this is long as well!
| if log.isEnabledFor(log.DEBUG): | ||
| startTime = time.time() | ||
| self.VBufHandle=NVDAHelper.localLib.VBuf_createBuffer(self.rootNVDAObject.appModule.helperLocalBindingHandle,self.rootDocHandle,self.rootID,unicode(self.backendName)) | ||
| self.VBufHandle=NVDAHelper.localLib.VBuf_createBuffer(self.rootNVDAObject.appModule.helperLocalBindingHandle,self.rootDocHandle,self.rootID,self.backendName) |
There was a problem hiding this comment.
Another pretty long line
cadf853 to
97f4380
Compare
|
I realized last night I had not pushed all my commits for this branch.
Though I have now.
However, I will address the feedback you have given me so far.
Also, re basestring to str: I checked all existing uses of str, and they
didn't look problematic to me.
|
|
may I ask how you checked for current str? Just a grep for str?
|
|
That is correct.
|
|
This modifies a few braille drivers, and other braille related files. I expect it will conflict with the work I am doing. Please see #9736. Can you revert the changes to the overlapping files: |
|
@LeonarddeR and @feerrenrut this is ready for another review again. |
Link to issue number:
None
Summary of the issue:
In Python3, strings are unicode by default. str is unicode, and unicode and basestring no longer exist.
Description of how this pull request fixes the issue:
This pr was produced by grepping for the various symbols, and handling each case specifically by looking at the code.
Testing performed:
With one or two other runtime changes to do with hashing etc (addressed in a separate pr), NVDA can now run, and all synthDrivers, including eSpeak function correctly.
Known issues with pull request:
No brailleDisplay drivers have been touched yet, nor has hwIo in any significant way. These will have to be handled carefully in regards to what should be bytes and what should be strings.
Change log entry:
None.