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:
parent
ece31cf3cf
commit
222aeed2f3
|
@ -11,7 +11,6 @@ import base64
|
||||||
import binascii
|
import binascii
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
import locale
|
|
||||||
import logging
|
import logging
|
||||||
import numbers
|
import numbers
|
||||||
import os
|
import os
|
||||||
|
@ -1315,26 +1314,6 @@ def set_env_variable(name, value):
|
||||||
log.debug("Set Env Var '%s' to '%s' (msvcrt._putenv)", 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):
|
def run_profiled(func, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Profile a function with cProfile
|
Profile a function with cProfile
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
|
@ -57,7 +58,7 @@ class UI:
|
||||||
return self.__options
|
return self.__options
|
||||||
|
|
||||||
def start(self, parser=None):
|
def start(self, parser=None):
|
||||||
args = deluge.common.unicode_argv()[1:]
|
args = sys.argv[1:]
|
||||||
if parser is None:
|
if parser is None:
|
||||||
parser = self.parser
|
parser = self.parser
|
||||||
self.__options = self.parse_args(parser, args)
|
self.__options = self.parse_args(parser, args)
|
||||||
|
|
Loading…
Reference in New Issue