mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Improve pycompat urepr_encode for non-tty stdout + fix some tests
This commit is contained in:
@@ -142,8 +142,8 @@ def randomkeypair(keysize=1024):
|
||||
def test_certificate(rawcert):
|
||||
cert = windows.crypto.Certificate.from_buffer(rawcert)
|
||||
assert cert.serial == '1b 8e 94 cb 0b 3e eb b6 41 39 f3 c9 09 b1 6b 46'
|
||||
assert cert.name == b'PythonForWindowsTest'
|
||||
assert cert.issuer == b'PythonForWindowsTest'
|
||||
assert cert.name == u'PythonForWindowsTest'
|
||||
assert cert.issuer == u'PythonForWindowsTest'
|
||||
assert cert.thumbprint == 'EF 0C A8 C9 F9 E0 96 AF 74 18 56 8B C1 C9 57 27 A0 89 29 6A'
|
||||
assert cert.encoded == rawcert
|
||||
assert cert.version == 2
|
||||
|
||||
@@ -526,10 +526,4 @@ class TestProcessWithCheckGarbage(object):
|
||||
p.exit()
|
||||
p.wait()
|
||||
time.sleep(0.5) # Fail on Azure CI of no sleep
|
||||
os.unlink(target_programe)
|
||||
|
||||
|
||||
def test_testouille():
|
||||
import locale
|
||||
print(sys.stdout.isatty(), sys.stdout.encoding, locale.getpreferredencoding(), sys.getdefaultencoding(), sys.getfilesystemencoding())
|
||||
assert sys.stdout.encoding == "BADVALUE"
|
||||
os.unlink(target_programe)
|
||||
@@ -34,10 +34,11 @@ def test_security_descriptor_from_binary(binsd):
|
||||
|
||||
def test_security_descriptor_from_unicode_file(tmpdir):
|
||||
TARGET_FILENAME = u"내 한국은 최고의 한국.txt"
|
||||
TARGET_PATH = os.path.join(unicode(tmpdir), TARGET_FILENAME)
|
||||
import pdb;pdb.set_trace()
|
||||
TARGET_PATH = os.path.join(tmpdir, TARGET_FILENAME)
|
||||
with open(TARGET_PATH, "w") as f:
|
||||
f.write("Hello Test")
|
||||
SecurityDescriptor.from_filename(TARGET_PATH)
|
||||
assert SecurityDescriptor.from_filename(TARGET_PATH)
|
||||
|
||||
|
||||
def test_empty_security_descriptor():
|
||||
|
||||
+12
-4
@@ -26,10 +26,17 @@ if is_py3:
|
||||
return s.decode("latin1")
|
||||
return s
|
||||
|
||||
# No encoding of unicode repr
|
||||
# No encoding of unicode repr if we target a TTY
|
||||
# Python3 handle unicode natively in string and console output
|
||||
def urepr_encode(s):
|
||||
return s
|
||||
|
||||
if sys.stdout.isatty():
|
||||
def urepr_encode(s):
|
||||
return s
|
||||
else: # Not a TTY (seen in github CI) : if no explict encoding on stdout : use the locale to encode it the best we can to prevent print error
|
||||
repr_encoding = sys.stdout.encoding or locale.getpreferredencoding()
|
||||
|
||||
def urepr_encode_notty(s):
|
||||
return ustr.encode(repr_encoding, "backslashreplace")
|
||||
|
||||
else: # py2.7
|
||||
def str_from_ascii_function(s):
|
||||
@@ -49,8 +56,9 @@ else: # py2.7
|
||||
return s
|
||||
|
||||
# sys.stdout.encoding may be None if not a tty
|
||||
# Use sys.stdout.isatty() ?
|
||||
# Use sys.stdout.isatty() ? in py2 we will never return unicode in anycase
|
||||
repr_encoding = sys.stdout.encoding or locale.getpreferredencoding()
|
||||
repr_encoding = "cp1252"
|
||||
|
||||
def urepr_encode(ustr):
|
||||
# assert isinstance(s, unicode) # Make the check explicitly ?
|
||||
|
||||
Reference in New Issue
Block a user