mirror of
https://github.com/python/cpython.git
synced 2025-01-06 00:25:19 +08:00
bpo-40275: Remove test.support.TESTFN_ENCODING (GH-20482)
Replace test.support.TESTFN_ENCODING with sys.getfilesystemencoding().
This commit is contained in:
parent
84ee7e1573
commit
24bddc1b3b
@ -263,11 +263,6 @@ The :mod:`test.support` module defines the following constants:
|
|||||||
Set to a non-ASCII name for a temporary file.
|
Set to a non-ASCII name for a temporary file.
|
||||||
|
|
||||||
|
|
||||||
.. data:: TESTFN_ENCODING
|
|
||||||
|
|
||||||
Set to :func:`sys.getfilesystemencoding`.
|
|
||||||
|
|
||||||
|
|
||||||
.. data:: TESTFN_UNENCODABLE
|
.. data:: TESTFN_UNENCODABLE
|
||||||
|
|
||||||
Set to a filename (str type) that should not be able to be encoded by file
|
Set to a filename (str type) that should not be able to be encoded by file
|
||||||
|
@ -785,7 +785,6 @@ if sys.platform == 'darwin':
|
|||||||
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
|
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
|
||||||
import unicodedata
|
import unicodedata
|
||||||
TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE)
|
TESTFN_UNICODE = unicodedata.normalize('NFD', TESTFN_UNICODE)
|
||||||
TESTFN_ENCODING = sys.getfilesystemencoding()
|
|
||||||
|
|
||||||
# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be
|
# TESTFN_UNENCODABLE is a filename (str type) that should *not* be able to be
|
||||||
# encoded by the filesystem encoding (in strict mode). It can be None if we
|
# encoded by the filesystem encoding (in strict mode). It can be None if we
|
||||||
@ -798,23 +797,23 @@ if os.name == 'nt':
|
|||||||
# probability that the whole name is encodable to MBCS (issue #9819)
|
# probability that the whole name is encodable to MBCS (issue #9819)
|
||||||
TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80"
|
TESTFN_UNENCODABLE = TESTFN + "-\u5171\u0141\u2661\u0363\uDC80"
|
||||||
try:
|
try:
|
||||||
TESTFN_UNENCODABLE.encode(TESTFN_ENCODING)
|
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
|
print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
|
||||||
'Unicode filename tests may not be effective'
|
'Unicode filename tests may not be effective'
|
||||||
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
|
% (TESTFN_UNENCODABLE, sys.getfilesystemencoding()))
|
||||||
TESTFN_UNENCODABLE = None
|
TESTFN_UNENCODABLE = None
|
||||||
# Mac OS X denies unencodable filenames (invalid utf-8)
|
# Mac OS X denies unencodable filenames (invalid utf-8)
|
||||||
elif sys.platform != 'darwin':
|
elif sys.platform != 'darwin':
|
||||||
try:
|
try:
|
||||||
# ascii and utf-8 cannot encode the byte 0xff
|
# ascii and utf-8 cannot encode the byte 0xff
|
||||||
b'\xff'.decode(TESTFN_ENCODING)
|
b'\xff'.decode(sys.getfilesystemencoding())
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# 0xff will be encoded using the surrogate character u+DCFF
|
# 0xff will be encoded using the surrogate character u+DCFF
|
||||||
TESTFN_UNENCODABLE = TESTFN \
|
TESTFN_UNENCODABLE = TESTFN \
|
||||||
+ b'-\xff'.decode(TESTFN_ENCODING, 'surrogateescape')
|
+ b'-\xff'.decode(sys.getfilesystemencoding(), 'surrogateescape')
|
||||||
else:
|
else:
|
||||||
# File system encoding (eg. ISO-8859-* encodings) can encode
|
# File system encoding (eg. ISO-8859-* encodings) can encode
|
||||||
# the byte 0xff. Skip some unicode filename tests.
|
# the byte 0xff. Skip some unicode filename tests.
|
||||||
@ -845,7 +844,7 @@ for name in (
|
|||||||
b'\x81\x98',
|
b'\x81\x98',
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
name.decode(TESTFN_ENCODING)
|
name.decode(sys.getfilesystemencoding())
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
|
TESTFN_UNDECODABLE = os.fsencode(TESTFN) + name
|
||||||
break
|
break
|
||||||
|
@ -19,6 +19,7 @@ from io import BytesIO, StringIO
|
|||||||
import codecs
|
import codecs
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from test import support
|
from test import support
|
||||||
@ -35,7 +36,7 @@ except UnicodeEncodeError:
|
|||||||
supports_nonascii_filenames = True
|
supports_nonascii_filenames = True
|
||||||
if not os.path.supports_unicode_filenames:
|
if not os.path.supports_unicode_filenames:
|
||||||
try:
|
try:
|
||||||
support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING)
|
support.TESTFN_UNICODE.encode(sys.getfilesystemencoding())
|
||||||
except (UnicodeError, TypeError):
|
except (UnicodeError, TypeError):
|
||||||
# Either the file system encoding is None, or the file name
|
# Either the file system encoding is None, or the file name
|
||||||
# cannot be encoded in the file system encoding.
|
# cannot be encoded in the file system encoding.
|
||||||
|
@ -2,15 +2,16 @@
|
|||||||
# We don't test many operations on files other than
|
# We don't test many operations on files other than
|
||||||
# that their names can be used with Unicode characters.
|
# that their names can be used with Unicode characters.
|
||||||
import os, glob, time, shutil
|
import os, glob, time, shutil
|
||||||
|
import sys
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from test.support import (run_unittest, rmtree, change_cwd,
|
from test.support import (run_unittest, rmtree, change_cwd,
|
||||||
TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)
|
TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file)
|
||||||
|
|
||||||
if not os.path.supports_unicode_filenames:
|
if not os.path.supports_unicode_filenames:
|
||||||
try:
|
try:
|
||||||
TESTFN_UNICODE.encode(TESTFN_ENCODING)
|
TESTFN_UNICODE.encode(sys.getfilesystemencoding())
|
||||||
except (UnicodeError, TypeError):
|
except (UnicodeError, TypeError):
|
||||||
# Either the file system encoding is None, or the file name
|
# Either the file system encoding is None, or the file name
|
||||||
# cannot be encoded in the file system encoding.
|
# cannot be encoded in the file system encoding.
|
||||||
|
Loading…
Reference in New Issue
Block a user