Minor clean-up (#1112)

* Remove Python 2 clean-up misses

* Remove unused `Environment.devnull` setter

* Simplifies `get_filename_max_length()`
This commit is contained in:
Mickaël Schoentgen 2021-07-26 23:56:38 +02:00 committed by GitHub
parent 2f8d7f77bd
commit 04d05a8abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 18 deletions

View File

@ -119,10 +119,6 @@ class Environment:
self._devnull = open(os.devnull, 'w+') self._devnull = open(os.devnull, 'w+')
return self._devnull return self._devnull
@devnull.setter
def devnull(self, value):
self._devnull = value
def log_error(self, msg, level='error'): def log_error(self, msg, level='error'):
assert level in ['error', 'warning'] assert level in ['error', 'warning']
self._orig_stderr.write(f'\n{self.program_name}: {level}: {msg}\n\n') self._orig_stderr.write(f'\n{self.program_name}: {level}: {msg}\n\n')

View File

@ -2,7 +2,6 @@
Download mode implementation. Download mode implementation.
""" """
import errno
import mimetypes import mimetypes
import os import os
import re import re
@ -150,16 +149,8 @@ def trim_filename(filename: str, max_len: int) -> str:
def get_filename_max_length(directory: str) -> int: def get_filename_max_length(directory: str) -> int:
max_len = 255 max_len = 255
try: if hasattr(os, 'pathconf') and 'PC_NAME_MAX' in os.pathconf_names:
pathconf = os.pathconf max_len = os.pathconf(directory, 'PC_NAME_MAX')
except AttributeError:
pass # non-posix
else:
try:
max_len = pathconf(directory, 'PC_NAME_MAX')
except OSError as e:
if e.errno != errno.EINVAL:
raise
return max_len return max_len

View File

@ -39,7 +39,7 @@ def write_message(
} }
try: try:
if env.is_windows and 'colors' in args.prettify: if env.is_windows and 'colors' in args.prettify:
write_stream_with_colors_win_py3(**write_stream_kwargs) write_stream_with_colors_win(**write_stream_kwargs)
else: else:
write_stream(**write_stream_kwargs) write_stream(**write_stream_kwargs)
except OSError as e: except OSError as e:
@ -69,7 +69,7 @@ def write_stream(
outfile.flush() outfile.flush()
def write_stream_with_colors_win_py3( def write_stream_with_colors_win(
stream: 'BaseStream', stream: 'BaseStream',
outfile: TextIO, outfile: TextIO,
flush: bool flush: bool

View File

@ -189,7 +189,7 @@ class TestSession(SessionTestBase):
httpbin.url + '/get', env=self.env()) httpbin.url + '/get', env=self.env())
assert HTTP_OK in r2 assert HTTP_OK in r2
# FIXME: Authorization *sometimes* is not present on Python3 # FIXME: Authorization *sometimes* is not present
assert (r2.json['headers']['Authorization'] assert (r2.json['headers']['Authorization']
== HTTPBasicAuth.make_header('test', UNICODE)) == HTTPBasicAuth.make_header('test', UNICODE))
# httpbin doesn't interpret utf8 headers # httpbin doesn't interpret utf8 headers