bpo-15999: Clean up of handling boolean arguments. (GH-15610)
* Use the 'p' format unit instead of manually called PyObject_IsTrue(). * Pass boolean value instead 0/1 integers to functions that needs boolean. * Convert some arguments to boolean only once.
This commit is contained in:
parent
5eca7f3f38
commit
1f21eaa15e
|
@ -2295,7 +2295,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
return not eof
|
return not eof
|
||||||
|
|
||||||
def _pack_cookie(self, position, dec_flags=0,
|
def _pack_cookie(self, position, dec_flags=0,
|
||||||
bytes_to_feed=0, need_eof=0, chars_to_skip=0):
|
bytes_to_feed=0, need_eof=False, chars_to_skip=0):
|
||||||
# The meaning of a tell() cookie is: seek to position, set the
|
# The meaning of a tell() cookie is: seek to position, set the
|
||||||
# decoder flags to dec_flags, read bytes_to_feed bytes, feed them
|
# decoder flags to dec_flags, read bytes_to_feed bytes, feed them
|
||||||
# into the decoder with need_eof as the EOF flag, then skip
|
# into the decoder with need_eof as the EOF flag, then skip
|
||||||
|
@ -2309,7 +2309,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
rest, dec_flags = divmod(rest, 1<<64)
|
rest, dec_flags = divmod(rest, 1<<64)
|
||||||
rest, bytes_to_feed = divmod(rest, 1<<64)
|
rest, bytes_to_feed = divmod(rest, 1<<64)
|
||||||
need_eof, chars_to_skip = divmod(rest, 1<<64)
|
need_eof, chars_to_skip = divmod(rest, 1<<64)
|
||||||
return position, dec_flags, bytes_to_feed, need_eof, chars_to_skip
|
return position, dec_flags, bytes_to_feed, bool(need_eof), chars_to_skip
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
if not self._seekable:
|
if not self._seekable:
|
||||||
|
@ -2383,7 +2383,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
# (a point where the decoder has nothing buffered, so seek()
|
# (a point where the decoder has nothing buffered, so seek()
|
||||||
# can safely start from there and advance to this location).
|
# can safely start from there and advance to this location).
|
||||||
bytes_fed = 0
|
bytes_fed = 0
|
||||||
need_eof = 0
|
need_eof = False
|
||||||
# Chars decoded since `start_pos`
|
# Chars decoded since `start_pos`
|
||||||
chars_decoded = 0
|
chars_decoded = 0
|
||||||
for i in range(skip_bytes, len(next_input)):
|
for i in range(skip_bytes, len(next_input)):
|
||||||
|
@ -2400,7 +2400,7 @@ class TextIOWrapper(TextIOBase):
|
||||||
else:
|
else:
|
||||||
# We didn't get enough decoded data; signal EOF to get more.
|
# We didn't get enough decoded data; signal EOF to get more.
|
||||||
chars_decoded += len(decoder.decode(b'', final=True))
|
chars_decoded += len(decoder.decode(b'', final=True))
|
||||||
need_eof = 1
|
need_eof = True
|
||||||
if chars_decoded < chars_to_skip:
|
if chars_decoded < chars_to_skip:
|
||||||
raise OSError("can't reconstruct logical file position")
|
raise OSError("can't reconstruct logical file position")
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ class Compile:
|
||||||
self.flags = PyCF_DONT_IMPLY_DEDENT
|
self.flags = PyCF_DONT_IMPLY_DEDENT
|
||||||
|
|
||||||
def __call__(self, source, filename, symbol):
|
def __call__(self, source, filename, symbol):
|
||||||
codeob = compile(source, filename, symbol, self.flags, 1)
|
codeob = compile(source, filename, symbol, self.flags, True)
|
||||||
for feature in _features:
|
for feature in _features:
|
||||||
if codeob.co_flags & feature.compiler_flag:
|
if codeob.co_flags & feature.compiler_flag:
|
||||||
self.flags |= feature.compiler_flag
|
self.flags |= feature.compiler_flag
|
||||||
|
|
|
@ -1326,7 +1326,7 @@ class DocTestRunner:
|
||||||
try:
|
try:
|
||||||
# Don't blink! This is where the user's code gets run.
|
# Don't blink! This is where the user's code gets run.
|
||||||
exec(compile(example.source, filename, "single",
|
exec(compile(example.source, filename, "single",
|
||||||
compileflags, 1), test.globs)
|
compileflags, True), test.globs)
|
||||||
self.debugger.set_continue() # ==== Example Finished ====
|
self.debugger.set_continue() # ==== Example Finished ====
|
||||||
exception = None
|
exception = None
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
@ -204,11 +204,11 @@ def main():
|
||||||
print("-t: quote tabs")
|
print("-t: quote tabs")
|
||||||
print("-d: decode; default encode")
|
print("-d: decode; default encode")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
deco = 0
|
deco = False
|
||||||
tabs = 0
|
tabs = False
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-t': tabs = 1
|
if o == '-t': tabs = True
|
||||||
if o == '-d': deco = 1
|
if o == '-d': deco = True
|
||||||
if tabs and deco:
|
if tabs and deco:
|
||||||
sys.stdout = sys.stderr
|
sys.stdout = sys.stderr
|
||||||
print("-t and -d are mutually exclusive")
|
print("-t and -d are mutually exclusive")
|
||||||
|
|
|
@ -6160,7 +6160,7 @@ class CapiTest(unittest.TestCase):
|
||||||
def test_date_from_date(self):
|
def test_date_from_date(self):
|
||||||
exp_date = date(1993, 8, 26)
|
exp_date = date(1993, 8, 26)
|
||||||
|
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro):
|
with self.subTest(macro=macro):
|
||||||
c_api_date = _testcapi.get_date_fromdate(
|
c_api_date = _testcapi.get_date_fromdate(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6173,7 +6173,7 @@ class CapiTest(unittest.TestCase):
|
||||||
def test_datetime_from_dateandtime(self):
|
def test_datetime_from_dateandtime(self):
|
||||||
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)
|
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)
|
||||||
|
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro):
|
with self.subTest(macro=macro):
|
||||||
c_api_date = _testcapi.get_datetime_fromdateandtime(
|
c_api_date = _testcapi.get_datetime_fromdateandtime(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6191,7 +6191,7 @@ class CapiTest(unittest.TestCase):
|
||||||
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)
|
exp_date = datetime(1993, 8, 26, 22, 12, 55, 99999)
|
||||||
|
|
||||||
for fold in [0, 1]:
|
for fold in [0, 1]:
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro, fold=fold):
|
with self.subTest(macro=macro, fold=fold):
|
||||||
c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(
|
c_api_date = _testcapi.get_datetime_fromdateandtimeandfold(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6210,7 +6210,7 @@ class CapiTest(unittest.TestCase):
|
||||||
def test_time_from_time(self):
|
def test_time_from_time(self):
|
||||||
exp_time = time(22, 12, 55, 99999)
|
exp_time = time(22, 12, 55, 99999)
|
||||||
|
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro):
|
with self.subTest(macro=macro):
|
||||||
c_api_time = _testcapi.get_time_fromtime(
|
c_api_time = _testcapi.get_time_fromtime(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6225,7 +6225,7 @@ class CapiTest(unittest.TestCase):
|
||||||
exp_time = time(22, 12, 55, 99999)
|
exp_time = time(22, 12, 55, 99999)
|
||||||
|
|
||||||
for fold in [0, 1]:
|
for fold in [0, 1]:
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro, fold=fold):
|
with self.subTest(macro=macro, fold=fold):
|
||||||
c_api_time = _testcapi.get_time_fromtimeandfold(
|
c_api_time = _testcapi.get_time_fromtimeandfold(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6241,7 +6241,7 @@ class CapiTest(unittest.TestCase):
|
||||||
def test_delta_from_dsu(self):
|
def test_delta_from_dsu(self):
|
||||||
exp_delta = timedelta(26, 55, 99999)
|
exp_delta = timedelta(26, 55, 99999)
|
||||||
|
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro):
|
with self.subTest(macro=macro):
|
||||||
c_api_delta = _testcapi.get_delta_fromdsu(
|
c_api_delta = _testcapi.get_delta_fromdsu(
|
||||||
macro,
|
macro,
|
||||||
|
@ -6254,7 +6254,7 @@ class CapiTest(unittest.TestCase):
|
||||||
def test_date_from_timestamp(self):
|
def test_date_from_timestamp(self):
|
||||||
ts = datetime(1995, 4, 12).timestamp()
|
ts = datetime(1995, 4, 12).timestamp()
|
||||||
|
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(macro=macro):
|
with self.subTest(macro=macro):
|
||||||
d = _testcapi.get_date_fromtimestamp(int(ts), macro)
|
d = _testcapi.get_date_fromtimestamp(int(ts), macro)
|
||||||
|
|
||||||
|
@ -6272,7 +6272,7 @@ class CapiTest(unittest.TestCase):
|
||||||
|
|
||||||
from_timestamp = _testcapi.get_datetime_fromtimestamp
|
from_timestamp = _testcapi.get_datetime_fromtimestamp
|
||||||
for case in cases:
|
for case in cases:
|
||||||
for macro in [0, 1]:
|
for macro in False, True:
|
||||||
with self.subTest(case=case, macro=macro):
|
with self.subTest(case=case, macro=macro):
|
||||||
dtup, tzinfo, usetz = case
|
dtup, tzinfo, usetz = case
|
||||||
dt_orig = datetime(*dtup, tzinfo=tzinfo)
|
dt_orig = datetime(*dtup, tzinfo=tzinfo)
|
||||||
|
|
|
@ -182,7 +182,7 @@ class BaseLockTests(BaseTestCase):
|
||||||
def test_timeout(self):
|
def test_timeout(self):
|
||||||
lock = self.locktype()
|
lock = self.locktype()
|
||||||
# Can't set timeout if not blocking
|
# Can't set timeout if not blocking
|
||||||
self.assertRaises(ValueError, lock.acquire, 0, 1)
|
self.assertRaises(ValueError, lock.acquire, False, 1)
|
||||||
# Invalid timeout values
|
# Invalid timeout values
|
||||||
self.assertRaises(ValueError, lock.acquire, timeout=-100)
|
self.assertRaises(ValueError, lock.acquire, timeout=-100)
|
||||||
self.assertRaises(OverflowError, lock.acquire, timeout=1e100)
|
self.assertRaises(OverflowError, lock.acquire, timeout=1e100)
|
||||||
|
|
|
@ -320,8 +320,8 @@ class BuiltinTest(unittest.TestCase):
|
||||||
bom = b'\xef\xbb\xbf'
|
bom = b'\xef\xbb\xbf'
|
||||||
compile(bom + b'print(1)\n', '', 'exec')
|
compile(bom + b'print(1)\n', '', 'exec')
|
||||||
compile(source='pass', filename='?', mode='exec')
|
compile(source='pass', filename='?', mode='exec')
|
||||||
compile(dont_inherit=0, filename='tmp', source='0', mode='eval')
|
compile(dont_inherit=False, filename='tmp', source='0', mode='eval')
|
||||||
compile('pass', '?', dont_inherit=1, mode='exec')
|
compile('pass', '?', dont_inherit=True, mode='exec')
|
||||||
compile(memoryview(b"text"), "name", "exec")
|
compile(memoryview(b"text"), "name", "exec")
|
||||||
self.assertRaises(TypeError, compile)
|
self.assertRaises(TypeError, compile)
|
||||||
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
|
self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode')
|
||||||
|
@ -1853,7 +1853,7 @@ class TestSorted(unittest.TestCase):
|
||||||
self.assertEqual(data, sorted(copy, key=lambda x: -x))
|
self.assertEqual(data, sorted(copy, key=lambda x: -x))
|
||||||
self.assertNotEqual(data, copy)
|
self.assertNotEqual(data, copy)
|
||||||
random.shuffle(copy)
|
random.shuffle(copy)
|
||||||
self.assertEqual(data, sorted(copy, reverse=1))
|
self.assertEqual(data, sorted(copy, reverse=True))
|
||||||
self.assertNotEqual(data, copy)
|
self.assertNotEqual(data, copy)
|
||||||
|
|
||||||
def test_bad_arguments(self):
|
def test_bad_arguments(self):
|
||||||
|
|
|
@ -48,7 +48,7 @@ class IoctlTests(unittest.TestCase):
|
||||||
else:
|
else:
|
||||||
buf.append(fill)
|
buf.append(fill)
|
||||||
with open("/dev/tty", "rb") as tty:
|
with open("/dev/tty", "rb") as tty:
|
||||||
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1)
|
r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, True)
|
||||||
rpgrp = buf[0]
|
rpgrp = buf[0]
|
||||||
self.assertEqual(r, 0)
|
self.assertEqual(r, 0)
|
||||||
self.assertIn(rpgrp, ids)
|
self.assertIn(rpgrp, ids)
|
||||||
|
|
|
@ -407,9 +407,9 @@ class OrderedDictTests:
|
||||||
self.assertEqual(list(od), list('abcde'))
|
self.assertEqual(list(od), list('abcde'))
|
||||||
od.move_to_end('c')
|
od.move_to_end('c')
|
||||||
self.assertEqual(list(od), list('abdec'))
|
self.assertEqual(list(od), list('abdec'))
|
||||||
od.move_to_end('c', 0)
|
od.move_to_end('c', False)
|
||||||
self.assertEqual(list(od), list('cabde'))
|
self.assertEqual(list(od), list('cabde'))
|
||||||
od.move_to_end('c', 0)
|
od.move_to_end('c', False)
|
||||||
self.assertEqual(list(od), list('cabde'))
|
self.assertEqual(list(od), list('cabde'))
|
||||||
od.move_to_end('e')
|
od.move_to_end('e')
|
||||||
self.assertEqual(list(od), list('cabde'))
|
self.assertEqual(list(od), list('cabde'))
|
||||||
|
@ -418,7 +418,7 @@ class OrderedDictTests:
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
od.move_to_end('x')
|
od.move_to_end('x')
|
||||||
with self.assertRaises(KeyError):
|
with self.assertRaises(KeyError):
|
||||||
od.move_to_end('x', 0)
|
od.move_to_end('x', False)
|
||||||
|
|
||||||
def test_move_to_end_issue25406(self):
|
def test_move_to_end_issue25406(self):
|
||||||
OrderedDict = self.OrderedDict
|
OrderedDict = self.OrderedDict
|
||||||
|
|
|
@ -2820,15 +2820,15 @@ class CAPITest(unittest.TestCase):
|
||||||
for s in ['abc', '\xa1\xa2', '\u4f60\u597d', 'a\U0001f600',
|
for s in ['abc', '\xa1\xa2', '\u4f60\u597d', 'a\U0001f600',
|
||||||
'a\ud800b\udfffc', '\ud834\udd1e']:
|
'a\ud800b\udfffc', '\ud834\udd1e']:
|
||||||
l = len(s)
|
l = len(s)
|
||||||
self.assertEqual(unicode_asucs4(s, l, 1), s+'\0')
|
self.assertEqual(unicode_asucs4(s, l, True), s+'\0')
|
||||||
self.assertEqual(unicode_asucs4(s, l, 0), s+'\uffff')
|
self.assertEqual(unicode_asucs4(s, l, False), s+'\uffff')
|
||||||
self.assertEqual(unicode_asucs4(s, l+1, 1), s+'\0\uffff')
|
self.assertEqual(unicode_asucs4(s, l+1, True), s+'\0\uffff')
|
||||||
self.assertEqual(unicode_asucs4(s, l+1, 0), s+'\0\uffff')
|
self.assertEqual(unicode_asucs4(s, l+1, False), s+'\0\uffff')
|
||||||
self.assertRaises(SystemError, unicode_asucs4, s, l-1, 1)
|
self.assertRaises(SystemError, unicode_asucs4, s, l-1, True)
|
||||||
self.assertRaises(SystemError, unicode_asucs4, s, l-2, 0)
|
self.assertRaises(SystemError, unicode_asucs4, s, l-2, False)
|
||||||
s = '\0'.join([s, s])
|
s = '\0'.join([s, s])
|
||||||
self.assertEqual(unicode_asucs4(s, len(s), 1), s+'\0')
|
self.assertEqual(unicode_asucs4(s, len(s), True), s+'\0')
|
||||||
self.assertEqual(unicode_asucs4(s, len(s), 0), s+'\uffff')
|
self.assertEqual(unicode_asucs4(s, len(s), False), s+'\uffff')
|
||||||
|
|
||||||
# Test PyUnicode_AsUTF8()
|
# Test PyUnicode_AsUTF8()
|
||||||
@support.cpython_only
|
@support.cpython_only
|
||||||
|
|
|
@ -262,7 +262,7 @@ class Condition:
|
||||||
def _is_owned(self):
|
def _is_owned(self):
|
||||||
# Return True if lock is owned by current_thread.
|
# Return True if lock is owned by current_thread.
|
||||||
# This method is called only if _lock doesn't have _is_owned().
|
# This method is called only if _lock doesn't have _is_owned().
|
||||||
if self._lock.acquire(0):
|
if self._lock.acquire(False):
|
||||||
self._lock.release()
|
self._lock.release()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -2241,7 +2241,7 @@ class Tk(Misc, Wm):
|
||||||
_w = '.'
|
_w = '.'
|
||||||
|
|
||||||
def __init__(self, screenName=None, baseName=None, className='Tk',
|
def __init__(self, screenName=None, baseName=None, className='Tk',
|
||||||
useTk=1, sync=0, use=None):
|
useTk=True, sync=False, use=None):
|
||||||
"""Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
|
"""Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
|
||||||
be created. BASENAME will be used for the identification of the profile file (see
|
be created. BASENAME will be used for the identification of the profile file (see
|
||||||
readprofile).
|
readprofile).
|
||||||
|
@ -2259,7 +2259,7 @@ class Tk(Misc, Wm):
|
||||||
baseName, ext = os.path.splitext(baseName)
|
baseName, ext = os.path.splitext(baseName)
|
||||||
if ext not in ('.py', '.pyc'):
|
if ext not in ('.py', '.pyc'):
|
||||||
baseName = baseName + ext
|
baseName = baseName + ext
|
||||||
interactive = 0
|
interactive = False
|
||||||
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
|
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
|
||||||
if useTk:
|
if useTk:
|
||||||
self._loadtk()
|
self._loadtk()
|
||||||
|
@ -2361,7 +2361,7 @@ class Tk(Misc, Wm):
|
||||||
# copied into the Pack, Place or Grid class.
|
# copied into the Pack, Place or Grid class.
|
||||||
|
|
||||||
|
|
||||||
def Tcl(screenName=None, baseName=None, className='Tk', useTk=0):
|
def Tcl(screenName=None, baseName=None, className='Tk', useTk=False):
|
||||||
return Tk(screenName, baseName, className, useTk)
|
return Tk(screenName, baseName, className, useTk)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -383,8 +383,10 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
|
||||||
encoding = "utf-8";
|
encoding = "utf-8";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
raw = PyObject_CallFunction(RawIO_class,
|
raw = PyObject_CallFunction(RawIO_class, "OsOO",
|
||||||
"OsiO", path_or_fd, rawmode, closefd, opener);
|
path_or_fd, rawmode,
|
||||||
|
closefd ? Py_True : Py_False,
|
||||||
|
opener);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw == NULL)
|
if (raw == NULL)
|
||||||
|
@ -476,10 +478,10 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
|
||||||
|
|
||||||
/* wraps into a TextIOWrapper */
|
/* wraps into a TextIOWrapper */
|
||||||
wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type,
|
wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type,
|
||||||
"Osssi",
|
"OsssO",
|
||||||
buffer,
|
buffer,
|
||||||
encoding, errors, newline,
|
encoding, errors, newline,
|
||||||
line_buffering);
|
line_buffering ? Py_True : Py_False);
|
||||||
if (wrapper == NULL)
|
if (wrapper == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
result = wrapper;
|
result = wrapper;
|
||||||
|
|
|
@ -714,9 +714,9 @@ _io_StringIO___init___impl(stringio *self, PyObject *value,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->readuniversal) {
|
if (self->readuniversal) {
|
||||||
self->decoder = PyObject_CallFunction(
|
self->decoder = PyObject_CallFunctionObjArgs(
|
||||||
(PyObject *)&PyIncrementalNewlineDecoder_Type,
|
(PyObject *)&PyIncrementalNewlineDecoder_Type,
|
||||||
"Oi", Py_None, (int) self->readtranslate);
|
Py_None, self->readtranslate ? Py_True : Py_False, NULL);
|
||||||
if (self->decoder == NULL)
|
if (self->decoder == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -880,9 +880,9 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (self->readuniversal) {
|
if (self->readuniversal) {
|
||||||
PyObject *incrementalDecoder = PyObject_CallFunction(
|
PyObject *incrementalDecoder = PyObject_CallFunctionObjArgs(
|
||||||
(PyObject *)&PyIncrementalNewlineDecoder_Type,
|
(PyObject *)&PyIncrementalNewlineDecoder_Type,
|
||||||
"Oi", self->decoder, (int)self->readtranslate);
|
self->decoder, self->readtranslate ? Py_True : Py_False, NULL);
|
||||||
if (incrementalDecoder == NULL)
|
if (incrementalDecoder == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
Py_CLEAR(self->decoder);
|
Py_CLEAR(self->decoder);
|
||||||
|
@ -2591,8 +2591,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
||||||
}
|
}
|
||||||
Py_XSETREF(self->snapshot, snapshot);
|
Py_XSETREF(self->snapshot, snapshot);
|
||||||
|
|
||||||
decoded = _PyObject_CallMethodId(self->decoder, &PyId_decode,
|
decoded = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_decode,
|
||||||
"Oi", input_chunk, (int)cookie.need_eof);
|
input_chunk, cookie.need_eof ? Py_True : Py_False, NULL);
|
||||||
|
|
||||||
if (check_decoded(decoded) < 0)
|
if (check_decoded(decoded) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -2819,7 +2819,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
|
||||||
if (input == input_end) {
|
if (input == input_end) {
|
||||||
/* We didn't get enough decoded data; signal EOF to get more. */
|
/* We didn't get enough decoded data; signal EOF to get more. */
|
||||||
PyObject *decoded = _PyObject_CallMethodId(
|
PyObject *decoded = _PyObject_CallMethodId(
|
||||||
self->decoder, &PyId_decode, "yi", "", /* final = */ 1);
|
self->decoder, &PyId_decode, "yO", "", /* final = */ Py_True);
|
||||||
if (check_decoded(decoded) < 0)
|
if (check_decoded(decoded) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
chars_decoded += PyUnicode_GET_LENGTH(decoded);
|
chars_decoded += PyUnicode_GET_LENGTH(decoded);
|
||||||
|
|
|
@ -1059,10 +1059,10 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored))
|
||||||
}
|
}
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
}
|
}
|
||||||
return Py_BuildValue("O(N)(Oi)", Py_TYPE(lz), it, lz->saved, 1);
|
return Py_BuildValue("O(N)(OO)", Py_TYPE(lz), it, lz->saved, Py_True);
|
||||||
}
|
}
|
||||||
return Py_BuildValue("O(O)(Oi)", Py_TYPE(lz), lz->it, lz->saved,
|
return Py_BuildValue("O(O)(OO)", Py_TYPE(lz), lz->it, lz->saved,
|
||||||
lz->firstpass);
|
lz->firstpass ? Py_True : Py_False);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -292,7 +292,7 @@ pymain_run_module(const wchar_t *modname, int set_argv0)
|
||||||
Py_DECREF(runmodule);
|
Py_DECREF(runmodule);
|
||||||
return pymain_exit_err_print();
|
return pymain_exit_err_print();
|
||||||
}
|
}
|
||||||
runargs = Py_BuildValue("(Oi)", module, set_argv0);
|
runargs = PyTuple_Pack(2, module, set_argv0 ? Py_True : Py_False);
|
||||||
if (runargs == NULL) {
|
if (runargs == NULL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Could not create arguments for runpy._run_module_as_main\n");
|
"Could not create arguments for runpy._run_module_as_main\n");
|
||||||
|
|
|
@ -1080,25 +1080,20 @@ parser__pickler(PyObject *self, PyObject *args)
|
||||||
NOTE(ARGUNUSED(self))
|
NOTE(ARGUNUSED(self))
|
||||||
PyObject *result = NULL;
|
PyObject *result = NULL;
|
||||||
PyObject *st = NULL;
|
PyObject *st = NULL;
|
||||||
PyObject *empty_dict = NULL;
|
|
||||||
|
|
||||||
if (PyArg_ParseTuple(args, "O!:_pickler", &PyST_Type, &st)) {
|
if (PyArg_ParseTuple(args, "O!:_pickler", &PyST_Type, &st)) {
|
||||||
PyObject *newargs;
|
PyObject *newargs;
|
||||||
PyObject *tuple;
|
PyObject *tuple;
|
||||||
|
|
||||||
if ((empty_dict = PyDict_New()) == NULL)
|
if ((newargs = PyTuple_Pack(2, st, Py_True)) == NULL)
|
||||||
goto finally;
|
return NULL;
|
||||||
if ((newargs = Py_BuildValue("Oi", st, 1)) == NULL)
|
tuple = parser_st2tuple((PyST_Object*)NULL, newargs, NULL);
|
||||||
goto finally;
|
|
||||||
tuple = parser_st2tuple((PyST_Object*)NULL, newargs, empty_dict);
|
|
||||||
if (tuple != NULL) {
|
if (tuple != NULL) {
|
||||||
result = Py_BuildValue("O(O)", pickle_constructor, tuple);
|
result = Py_BuildValue("O(O)", pickle_constructor, tuple);
|
||||||
Py_DECREF(tuple);
|
Py_DECREF(tuple);
|
||||||
}
|
}
|
||||||
Py_DECREF(newargs);
|
Py_DECREF(newargs);
|
||||||
}
|
}
|
||||||
finally:
|
|
||||||
Py_XDECREF(empty_dict);
|
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c
|
||||||
io = PyImport_ImportModule("_io");
|
io = PyImport_ImportModule("_io");
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
stream = _PyObject_CallMethodId(io, &PyId_open, "isisssi", fd, mode,
|
stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode,
|
||||||
buffering, encoding, errors,
|
buffering, encoding, errors,
|
||||||
newline, closefd);
|
newline, closefd ? Py_True : Py_False);
|
||||||
Py_DECREF(io);
|
Py_DECREF(io);
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1820,8 +1820,9 @@ static PyObject *
|
||||||
builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
static const char * const _keywords[] = {"sep", "end", "file", "flush", 0};
|
static const char * const _keywords[] = {"sep", "end", "file", "flush", 0};
|
||||||
static struct _PyArg_Parser _parser = {"|OOOO:print", _keywords, 0};
|
static struct _PyArg_Parser _parser = {"|OOOp:print", _keywords, 0};
|
||||||
PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
|
PyObject *sep = NULL, *end = NULL, *file = NULL;
|
||||||
|
int flush = 0;
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
if (kwnames != NULL &&
|
if (kwnames != NULL &&
|
||||||
|
@ -1883,19 +1884,12 @@ builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
|
||||||
if (err)
|
if (err)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (flush != NULL) {
|
if (flush) {
|
||||||
PyObject *tmp;
|
PyObject *tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
|
||||||
int do_flush = PyObject_IsTrue(flush);
|
|
||||||
if (do_flush == -1)
|
|
||||||
return NULL;
|
|
||||||
else if (do_flush) {
|
|
||||||
tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
|
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
else
|
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1735,10 +1735,10 @@ create_stdio(const PyConfig *config, PyObject* io,
|
||||||
mode = "wb";
|
mode = "wb";
|
||||||
else
|
else
|
||||||
mode = "rb";
|
mode = "rb";
|
||||||
buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOi",
|
buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOO",
|
||||||
fd, mode, buffering,
|
fd, mode, buffering,
|
||||||
Py_None, Py_None, /* encoding, errors */
|
Py_None, Py_None, /* encoding, errors */
|
||||||
Py_None, 0); /* newline, closefd */
|
Py_None, Py_False); /* newline, closefd */
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue