1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 12:41:29 +00:00

Fix encoding issues related to Python 3 upgrade.

Python 3 str() is a unicode already, so can't be decoded.
subprocess.Popen needs to be in text mode (universal_newlines is the
oldest compatible kwarg for this) in order to do line-based buffering.
In general, all the filesystem encoding stuff we were doing is done by
Python itself now.
This commit is contained in:
dmiller
2022-12-07 20:34:07 +00:00
parent 12d41ec2cd
commit 9e4d6f5f5c
14 changed files with 35 additions and 125 deletions

View File

@@ -65,7 +65,6 @@ gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
import os
import sys
import tempfile
# Prevent loading PyXML
@@ -134,8 +133,7 @@ class ScriptHelpXMLContentHandler (xml.sax.handler.ContentHandler):
if "path" not in attrs:
raise ValueError(
'"directory" element did not have "path" attribute')
path = attrs["path"].encode("raw_unicode_escape").decode(
sys.getfilesystemencoding())
path = attrs["path"]
if dirname == "scripts":
self.scripts_dir = path
elif dirname == "nselib":
@@ -229,7 +227,7 @@ class ScriptInterface:
# Separate stderr to avoid breaking XML parsing with "Warning: File
# ./nse_main.lua exists, but Nmap is using...".
stderr = tempfile.TemporaryFile(
mode="rb", prefix=APP_NAME + "-script-help-stderr-")
mode="r", prefix=APP_NAME + "-script-help-stderr-")
log.debug("Script interface: running %s" % repr(command_string))
nmap_process = NmapCommand(command_string)
try: