From 222aeed2f3bfc058739835afb4007955a92dde05 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Thu, 3 Feb 2022 16:47:23 -0500 Subject: [PATCH] Remove legacy PY2 sys.argv unicode handling Fixed crash when sys.stdout was None When using pythonw on windows, sys.stdout and stdin are None. We had a legacy unicode_argv handler that was crashing in this instance. Just removed that, since sys.argv is always unicode on python 3 to fix the crash. Closes: https://github.com/deluge-torrent/deluge/pull/361 --- deluge/common.py | 21 --------------------- deluge/ui/ui.py | 3 ++- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/deluge/common.py b/deluge/common.py index 82adb0715..ad71e3bf5 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -11,7 +11,6 @@ import base64 import binascii import functools import glob -import locale import logging import numbers import os @@ -1315,26 +1314,6 @@ def set_env_variable(name, value): log.debug("Set Env Var '%s' to '%s' (msvcrt._putenv)", name, value) -def unicode_argv(): - """ Gets sys.argv as list of unicode objects on any platform.""" - # On platforms other than Windows, we have to find the likely encoding of the args and decode - # First check if sys.stdout or stdin have encoding set - encoding = getattr(sys.stdout, 'encoding') or getattr(sys.stdin, 'encoding') - # If that fails, check what the locale is set to - encoding = encoding or locale.getpreferredencoding() - # As a last resort, just default to utf-8 - encoding = encoding or 'utf-8' - - arg_list = [] - for arg in sys.argv: - try: - arg_list.append(arg.decode(encoding)) - except AttributeError: - arg_list.append(arg) - - return arg_list - - def run_profiled(func, *args, **kwargs): """ Profile a function with cProfile diff --git a/deluge/ui/ui.py b/deluge/ui/ui.py index cb92d1e07..338f8a8e0 100644 --- a/deluge/ui/ui.py +++ b/deluge/ui/ui.py @@ -7,6 +7,7 @@ # import logging +import sys import deluge.common import deluge.configmanager @@ -57,7 +58,7 @@ class UI: return self.__options def start(self, parser=None): - args = deluge.common.unicode_argv()[1:] + args = sys.argv[1:] if parser is None: parser = self.parser self.__options = self.parse_args(parser, args)