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
This commit is contained in:
Chase Sterling 2022-02-03 16:47:23 -05:00 committed by Calum Lind
parent ece31cf3cf
commit 222aeed2f3
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
2 changed files with 2 additions and 22 deletions

View File

@ -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

View File

@ -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)