mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-23 19:35:19 +01:00
[compat] Do not compare None <= 0
The result is meaningless (and it emits a warning in cpython2 when called with -3), so handle None before making integer comparisons.
This commit is contained in:
parent
c4af7684d8
commit
4810c48d6d
|
@ -417,18 +417,18 @@ else:
|
||||||
_terminal_size = collections.namedtuple('terminal_size', ['columns', 'lines'])
|
_terminal_size = collections.namedtuple('terminal_size', ['columns', 'lines'])
|
||||||
|
|
||||||
def compat_get_terminal_size(fallback=(80, 24)):
|
def compat_get_terminal_size(fallback=(80, 24)):
|
||||||
columns = compat_getenv('COLUMNS', None)
|
columns = compat_getenv('COLUMNS')
|
||||||
if columns:
|
if columns:
|
||||||
columns = int(columns)
|
columns = int(columns)
|
||||||
else:
|
else:
|
||||||
columns = None
|
columns = None
|
||||||
lines = compat_getenv('LINES', None)
|
lines = compat_getenv('LINES')
|
||||||
if lines:
|
if lines:
|
||||||
lines = int(lines)
|
lines = int(lines)
|
||||||
else:
|
else:
|
||||||
lines = None
|
lines = None
|
||||||
|
|
||||||
if columns <= 0 or lines <= 0:
|
if columns is None or lines is None or columns <= 0 or lines <= 0:
|
||||||
try:
|
try:
|
||||||
sp = subprocess.Popen(
|
sp = subprocess.Popen(
|
||||||
['stty', 'size'],
|
['stty', 'size'],
|
||||||
|
@ -438,9 +438,9 @@ else:
|
||||||
except Exception:
|
except Exception:
|
||||||
_columns, _lines = _terminal_size(*fallback)
|
_columns, _lines = _terminal_size(*fallback)
|
||||||
|
|
||||||
if columns <= 0:
|
if columns is None or columns <= 0:
|
||||||
columns = _columns
|
columns = _columns
|
||||||
if lines <= 0:
|
if lines is None or lines <= 0:
|
||||||
lines = _lines
|
lines = _lines
|
||||||
return _terminal_size(columns, lines)
|
return _terminal_size(columns, lines)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user