code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
182
url
stringlengths
46
251
license
stringclasses
4 values
def test_pdb_until_command_for_coroutine(): """Testing no unwindng stack for coroutines for "until" command if target breakpoing is not reached >>> import asyncio >>> async def test_coro(): ... print(0) ... await asyncio.sleep(0) ... print(1) ... await asyncio.sleep(0) ... print(2) ... await asyncio.sleep(0) ... print(3) >>> async def test_main(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... await test_coro() >>> def test_function(): ... loop = asyncio.new_event_loop() ... loop.run_until_complete(test_main()) ... loop.close() ... print("finished") >>> with PdbTestInput(['step', ... 'until 8', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main() -> await test_coro() (Pdb) step --Call-- > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro() -> async def test_coro(): (Pdb) until 8 0 1 2 > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro() -> print(3) (Pdb) continue 3 finished """
Testing no unwindng stack for coroutines for "until" command if target breakpoing is not reached >>> import asyncio >>> async def test_coro(): ... print(0) ... await asyncio.sleep(0) ... print(1) ... await asyncio.sleep(0) ... print(2) ... await asyncio.sleep(0) ... print(3) >>> async def test_main(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... await test_coro() >>> def test_function(): ... loop = asyncio.new_event_loop() ... loop.run_until_complete(test_main()) ... loop.close() ... print("finished") >>> with PdbTestInput(['step', ... 'until 8', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[2]>(3)test_main() -> await test_coro() (Pdb) step --Call-- > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(1)test_coro() -> async def test_coro(): (Pdb) until 8 0 1 2 > <doctest test.test_pdb.test_pdb_until_command_for_coroutine[1]>(8)test_coro() -> print(3) (Pdb) continue 3 finished
test_pdb_until_command_for_coroutine
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def test_pdb_next_command_in_generator_for_loop(): """The next command on returning from a generator controlled by a for loop. >>> def test_gen(): ... yield 0 ... return 1 >>> def test_function(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... for i in test_gen(): ... print('value', i) ... x = 123 >>> with PdbTestInput(['break test_gen', ... 'continue', ... 'next', ... 'next', ... 'next', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() -> for i in test_gen(): (Pdb) break test_gen Breakpoint 6 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1 (Pdb) continue > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen() -> yield 0 (Pdb) next value 0 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(3)test_gen() -> return 1 (Pdb) next Internal StopIteration: 1 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() -> for i in test_gen(): (Pdb) next > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(5)test_function() -> x = 123 (Pdb) continue """
The next command on returning from a generator controlled by a for loop. >>> def test_gen(): ... yield 0 ... return 1 >>> def test_function(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... for i in test_gen(): ... print('value', i) ... x = 123 >>> with PdbTestInput(['break test_gen', ... 'continue', ... 'next', ... 'next', ... 'next', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() -> for i in test_gen(): (Pdb) break test_gen Breakpoint 6 at <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>:1 (Pdb) continue > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(2)test_gen() -> yield 0 (Pdb) next value 0 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[0]>(3)test_gen() -> return 1 (Pdb) next Internal StopIteration: 1 > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(3)test_function() -> for i in test_gen(): (Pdb) next > <doctest test.test_pdb.test_pdb_next_command_in_generator_for_loop[1]>(5)test_function() -> x = 123 (Pdb) continue
test_pdb_next_command_in_generator_for_loop
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def test_pdb_next_command_subiterator(): """The next command in a generator with a subiterator. >>> def test_subgenerator(): ... yield 0 ... return 1 >>> def test_gen(): ... x = yield from test_subgenerator() ... return x >>> def test_function(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... for i in test_gen(): ... print('value', i) ... x = 123 >>> with PdbTestInput(['step', ... 'step', ... 'next', ... 'next', ... 'next', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() -> for i in test_gen(): (Pdb) step --Call-- > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(1)test_gen() -> def test_gen(): (Pdb) step > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(2)test_gen() -> x = yield from test_subgenerator() (Pdb) next value 0 > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(3)test_gen() -> return x (Pdb) next Internal StopIteration: 1 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() -> for i in test_gen(): (Pdb) next > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_function() -> x = 123 (Pdb) continue """
The next command in a generator with a subiterator. >>> def test_subgenerator(): ... yield 0 ... return 1 >>> def test_gen(): ... x = yield from test_subgenerator() ... return x >>> def test_function(): ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() ... for i in test_gen(): ... print('value', i) ... x = 123 >>> with PdbTestInput(['step', ... 'step', ... 'next', ... 'next', ... 'next', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() -> for i in test_gen(): (Pdb) step --Call-- > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(1)test_gen() -> def test_gen(): (Pdb) step > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(2)test_gen() -> x = yield from test_subgenerator() (Pdb) next value 0 > <doctest test.test_pdb.test_pdb_next_command_subiterator[1]>(3)test_gen() -> return x (Pdb) next Internal StopIteration: 1 > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(3)test_function() -> for i in test_gen(): (Pdb) next > <doctest test.test_pdb.test_pdb_next_command_subiterator[2]>(5)test_function() -> x = 123 (Pdb) continue
test_pdb_next_command_subiterator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def test_pdb_issue_20766(): """Test for reference leaks when the SIGINT handler is set. >>> def test_function(): ... i = 1 ... while i <= 2: ... sess = pdb.Pdb() ... sess.set_trace(sys._getframe()) ... print('pdb %d: %s' % (i, sess._previous_sigint_handler)) ... i += 1 >>> with PdbTestInput(['continue', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_issue_20766[0]>(6)test_function() -> print('pdb %d: %s' % (i, sess._previous_sigint_handler)) (Pdb) continue pdb 1: <built-in function default_int_handler> > <doctest test.test_pdb.test_pdb_issue_20766[0]>(5)test_function() -> sess.set_trace(sys._getframe()) (Pdb) continue pdb 2: <built-in function default_int_handler> """
Test for reference leaks when the SIGINT handler is set. >>> def test_function(): ... i = 1 ... while i <= 2: ... sess = pdb.Pdb() ... sess.set_trace(sys._getframe()) ... print('pdb %d: %s' % (i, sess._previous_sigint_handler)) ... i += 1 >>> with PdbTestInput(['continue', ... 'continue']): ... test_function() > <doctest test.test_pdb.test_pdb_issue_20766[0]>(6)test_function() -> print('pdb %d: %s' % (i, sess._previous_sigint_handler)) (Pdb) continue pdb 1: <built-in function default_int_handler> > <doctest test.test_pdb.test_pdb_issue_20766[0]>(5)test_function() -> sess.set_trace(sys._getframe()) (Pdb) continue pdb 2: <built-in function default_int_handler>
test_pdb_issue_20766
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def run_pdb_script(self, script, commands): """Run 'script' lines with pdb and the pdb 'commands'.""" filename = 'main.py' with open(filename, 'w') as f: f.write(textwrap.dedent(script)) self.addCleanup(support.unlink, filename) return self._run_pdb([filename], commands)
Run 'script' lines with pdb and the pdb 'commands'.
run_pdb_script
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def run_pdb_module(self, script, commands): """Runs the script code as part of a module""" self.module_name = 't_main' support.rmtree(self.module_name) main_file = self.module_name + '/__main__.py' init_file = self.module_name + '/__init__.py' os.mkdir(self.module_name) with open(init_file, 'w') as f: pass with open(main_file, 'w') as f: f.write(textwrap.dedent(script)) self.addCleanup(support.rmtree, self.module_name) return self._run_pdb(['-m', self.module_name], commands)
Runs the script code as part of a module
run_pdb_module
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def test_issue13183(self): script = """ from bar import bar def foo(): bar() def nope(): pass def foobar(): foo() nope() foobar() """ commands = """ from bar import bar break bar continue step step quit """ bar = """ def bar(): pass """ with open('bar.py', 'w') as f: f.write(textwrap.dedent(bar)) self.addCleanup(support.unlink, 'bar.py') stdout, stderr = self.run_pdb_script(script, commands) self.assertTrue( any('main.py(5)foo()->None' in l for l in stdout.splitlines()), 'Fail to step into the caller after a return')
commands =
test_issue13183
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def test_relative_imports(self): self.module_name = 't_main' support.rmtree(self.module_name) main_file = self.module_name + '/__main__.py' init_file = self.module_name + '/__init__.py' module_file = self.module_name + '/module.py' self.addCleanup(support.rmtree, self.module_name) os.mkdir(self.module_name) with open(init_file, 'w') as f: f.write(textwrap.dedent(""" top_var = "VAR from top" """)) with open(main_file, 'w') as f: f.write(textwrap.dedent(""" from . import top_var from .module import var from . import module pass # We'll stop here and print the vars """)) with open(module_file, 'w') as f: f.write(textwrap.dedent(""" var = "VAR from module" var2 = "second var" """)) commands = """ b 5 c p top_var p var p module.var2 quit """ stdout, _ = self._run_pdb(['-m', self.module_name], commands) self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) self.assertTrue(any("VAR from top" in l for l in stdout.splitlines())) self.assertTrue(any("second var" in l for l in stdout.splitlines()))
)) with open(main_file, 'w') as f: f.write(textwrap.dedent(
test_relative_imports
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pdb.py
MIT
def cmd_auth(self, line): """Set up secure control channel.""" self.push('234 AUTH TLS successful') self.secure_connection()
Set up secure control channel.
cmd_auth
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
MIT
def cmd_pbsz(self, line): """Negotiate size of buffer for secure data transfer. For TLS/SSL the only valid value for the parameter is '0'. Any other value is accepted but ignored. """ self.push('200 PBSZ=0 successful.')
Negotiate size of buffer for secure data transfer. For TLS/SSL the only valid value for the parameter is '0'. Any other value is accepted but ignored.
cmd_pbsz
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
MIT
def cmd_prot(self, line): """Setup un/secure data channel.""" arg = line.upper() if arg == 'C': self.push('200 Protection set to Clear') self.secure_data_channel = False elif arg == 'P': self.push('200 Protection set to Private') self.secure_data_channel = True else: self.push("502 Unrecognized PROT type (use C or P).")
Setup un/secure data channel.
cmd_prot
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_ftplib.py
MIT
def test_delegation_of_initial_next_to_subgenerator(self): """ Test delegation of initial next() call to subgenerator """ trace = [] def g1(): trace.append("Starting g1") yield from g2() trace.append("Finishing g1") def g2(): trace.append("Starting g2") yield 42 trace.append("Finishing g2") for x in g1(): trace.append("Yielded %s" % (x,)) self.assertEqual(trace,[ "Starting g1", "Starting g2", "Yielded 42", "Finishing g2", "Finishing g1", ])
Test delegation of initial next() call to subgenerator
test_delegation_of_initial_next_to_subgenerator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_raising_exception_in_initial_next_call(self): """ Test raising exception in initial next() call """ trace = [] def g1(): try: trace.append("Starting g1") yield from g2() finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") raise ValueError("spanish inquisition occurred") finally: trace.append("Finishing g2") try: for x in g1(): trace.append("Yielded %s" % (x,)) except ValueError as e: self.assertEqual(e.args[0], "spanish inquisition occurred") else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Starting g1", "Starting g2", "Finishing g2", "Finishing g1", ])
Test raising exception in initial next() call
test_raising_exception_in_initial_next_call
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegation_of_next_call_to_subgenerator(self): """ Test delegation of next() call to subgenerator """ trace = [] def g1(): trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" trace.append("Finishing g1") def g2(): trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" trace.append("Finishing g2") for x in g1(): trace.append("Yielded %s" % (x,)) self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Yielded g2 more spam", "Finishing g2", "Yielded g1 eggs", "Finishing g1", ])
Test delegation of next() call to subgenerator
test_delegation_of_next_call_to_subgenerator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_raising_exception_in_delegated_next_call(self): """ Test raising exception in delegated next() call """ trace = [] def g1(): try: trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") yield "g2 spam" raise ValueError("hovercraft is full of eels") yield "g2 more spam" finally: trace.append("Finishing g2") try: for x in g1(): trace.append("Yielded %s" % (x,)) except ValueError as e: self.assertEqual(e.args[0], "hovercraft is full of eels") else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Finishing g2", "Finishing g1", ])
Test raising exception in delegated next() call
test_raising_exception_in_delegated_next_call
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegation_of_send(self): """ Test delegation of send() """ trace = [] def g1(): trace.append("Starting g1") x = yield "g1 ham" trace.append("g1 received %s" % (x,)) yield from g2() x = yield "g1 eggs" trace.append("g1 received %s" % (x,)) trace.append("Finishing g1") def g2(): trace.append("Starting g2") x = yield "g2 spam" trace.append("g2 received %s" % (x,)) x = yield "g2 more spam" trace.append("g2 received %s" % (x,)) trace.append("Finishing g2") g = g1() y = next(g) x = 1 try: while 1: y = g.send(x) trace.append("Yielded %s" % (y,)) x += 1 except StopIteration: pass self.assertEqual(trace,[ "Starting g1", "g1 received 1", "Starting g2", "Yielded g2 spam", "g2 received 2", "Yielded g2 more spam", "g2 received 3", "Finishing g2", "Yielded g1 eggs", "g1 received 4", "Finishing g1", ])
Test delegation of send()
test_delegation_of_send
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_handling_exception_while_delegating_send(self): """ Test handling exception while delegating 'send' """ trace = [] def g1(): trace.append("Starting g1") x = yield "g1 ham" trace.append("g1 received %s" % (x,)) yield from g2() x = yield "g1 eggs" trace.append("g1 received %s" % (x,)) trace.append("Finishing g1") def g2(): trace.append("Starting g2") x = yield "g2 spam" trace.append("g2 received %s" % (x,)) raise ValueError("hovercraft is full of eels") x = yield "g2 more spam" trace.append("g2 received %s" % (x,)) trace.append("Finishing g2") def run(): g = g1() y = next(g) x = 1 try: while 1: y = g.send(x) trace.append("Yielded %s" % (y,)) x += 1 except StopIteration: trace.append("StopIteration") self.assertRaises(ValueError,run) self.assertEqual(trace,[ "Starting g1", "g1 received 1", "Starting g2", "Yielded g2 spam", "g2 received 2", ])
Test handling exception while delegating 'send'
test_handling_exception_while_delegating_send
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegating_close(self): """ Test delegating 'close' """ trace = [] def g1(): try: trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" finally: trace.append("Finishing g2") g = g1() for i in range(2): x = next(g) trace.append("Yielded %s" % (x,)) g.close() self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Finishing g2", "Finishing g1" ])
Test delegating 'close'
test_delegating_close
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_handing_exception_while_delegating_close(self): """ Test handling exception while delegating 'close' """ trace = [] def g1(): try: trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" finally: trace.append("Finishing g2") raise ValueError("nybbles have exploded with delight") try: g = g1() for i in range(2): x = next(g) trace.append("Yielded %s" % (x,)) g.close() except ValueError as e: self.assertEqual(e.args[0], "nybbles have exploded with delight") self.assertIsInstance(e.__context__, GeneratorExit) else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Finishing g2", "Finishing g1", ])
Test handling exception while delegating 'close'
test_handing_exception_while_delegating_close
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegating_throw(self): """ Test delegating 'throw' """ trace = [] def g1(): try: trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" finally: trace.append("Finishing g2") try: g = g1() for i in range(2): x = next(g) trace.append("Yielded %s" % (x,)) e = ValueError("tomato ejected") g.throw(e) except ValueError as e: self.assertEqual(e.args[0], "tomato ejected") else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Finishing g2", "Finishing g1", ])
Test delegating 'throw'
test_delegating_throw
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_value_attribute_of_StopIteration_exception(self): """ Test 'value' attribute of StopIteration exception """ trace = [] def pex(e): trace.append("%s: %s" % (e.__class__.__name__, e)) trace.append("value = %s" % (e.value,)) e = StopIteration() pex(e) e = StopIteration("spam") pex(e) e.value = "eggs" pex(e) self.assertEqual(trace,[ "StopIteration: ", "value = None", "StopIteration: spam", "value = spam", "StopIteration: spam", "value = eggs", ])
Test 'value' attribute of StopIteration exception
test_value_attribute_of_StopIteration_exception
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_generator_return_value(self): """ Test generator return value """ trace = [] def g1(): trace.append("Starting g1") yield "g1 ham" ret = yield from g2() trace.append("g2 returned %r" % (ret,)) for v in 1, (2,), StopIteration(3): ret = yield from g2(v) trace.append("g2 returned %r" % (ret,)) yield "g1 eggs" trace.append("Finishing g1") def g2(v = None): trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" trace.append("Finishing g2") if v: return v for x in g1(): trace.append("Yielded %s" % (x,)) self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Yielded g2 more spam", "Finishing g2", "g2 returned None", "Starting g2", "Yielded g2 spam", "Yielded g2 more spam", "Finishing g2", "g2 returned 1", "Starting g2", "Yielded g2 spam", "Yielded g2 more spam", "Finishing g2", "g2 returned (2,)", "Starting g2", "Yielded g2 spam", "Yielded g2 more spam", "Finishing g2", "g2 returned StopIteration(3)", "Yielded g1 eggs", "Finishing g1", ])
Test generator return value
test_generator_return_value
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegation_of_next_to_non_generator(self): """ Test delegation of next() to non-generator """ trace = [] def g(): yield from range(3) for x in g(): trace.append("Yielded %s" % (x,)) self.assertEqual(trace,[ "Yielded 0", "Yielded 1", "Yielded 2", ])
Test delegation of next() to non-generator
test_delegation_of_next_to_non_generator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_conversion_of_sendNone_to_next(self): """ Test conversion of send(None) to next() """ trace = [] def g(): yield from range(3) gi = g() for x in range(3): y = gi.send(None) trace.append("Yielded: %s" % (y,)) self.assertEqual(trace,[ "Yielded: 0", "Yielded: 1", "Yielded: 2", ])
Test conversion of send(None) to next()
test_conversion_of_sendNone_to_next
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegation_of_close_to_non_generator(self): """ Test delegation of close() to non-generator """ trace = [] def g(): try: trace.append("starting g") yield from range(3) trace.append("g should not be here") finally: trace.append("finishing g") gi = g() next(gi) with captured_stderr() as output: gi.close() self.assertEqual(output.getvalue(), '') self.assertEqual(trace,[ "starting g", "finishing g", ])
Test delegation of close() to non-generator
test_delegation_of_close_to_non_generator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_delegating_throw_to_non_generator(self): """ Test delegating 'throw' to non-generator """ trace = [] def g(): try: trace.append("Starting g") yield from range(10) finally: trace.append("Finishing g") try: gi = g() for i in range(5): x = next(gi) trace.append("Yielded %s" % (x,)) e = ValueError("tomato ejected") gi.throw(e) except ValueError as e: self.assertEqual(e.args[0],"tomato ejected") else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Starting g", "Yielded 0", "Yielded 1", "Yielded 2", "Yielded 3", "Yielded 4", "Finishing g", ])
Test delegating 'throw' to non-generator
test_delegating_throw_to_non_generator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_attempting_to_send_to_non_generator(self): """ Test attempting to send to non-generator """ trace = [] def g(): try: trace.append("starting g") yield from range(3) trace.append("g should not be here") finally: trace.append("finishing g") try: gi = g() next(gi) for x in range(3): y = gi.send(42) trace.append("Should not have yielded: %s" % (y,)) except AttributeError as e: self.assertIn("send", e.args[0]) else: self.fail("was able to send into non-generator") self.assertEqual(trace,[ "starting g", "finishing g", ])
Test attempting to send to non-generator
test_attempting_to_send_to_non_generator
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_broken_getattr_handling(self): """ Test subiterator with a broken getattr implementation """ class Broken: def __iter__(self): return self def __next__(self): return 1 def __getattr__(self, attr): 1/0 def g(): yield from Broken() with self.assertRaises(ZeroDivisionError): gi = g() self.assertEqual(next(gi), 1) gi.send(1) with self.assertRaises(ZeroDivisionError): gi = g() self.assertEqual(next(gi), 1) gi.throw(AttributeError) with captured_stderr() as output: gi = g() self.assertEqual(next(gi), 1) gi.close() self.assertIn('ZeroDivisionError', output.getvalue())
Test subiterator with a broken getattr implementation
test_broken_getattr_handling
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_exception_in_initial_next_call(self): """ Test exception in initial next() call """ trace = [] def g1(): trace.append("g1 about to yield from g2") yield from g2() trace.append("g1 should not be here") def g2(): yield 1/0 def run(): gi = g1() next(gi) self.assertRaises(ZeroDivisionError,run) self.assertEqual(trace,[ "g1 about to yield from g2" ])
Test exception in initial next() call
test_exception_in_initial_next_call
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_attempted_yield_from_loop(self): """ Test attempted yield-from loop """ trace = [] def g1(): trace.append("g1: starting") yield "y1" trace.append("g1: about to yield from g2") yield from g2() trace.append("g1 should not be here") def g2(): trace.append("g2: starting") yield "y2" trace.append("g2: about to yield from g1") yield from gi trace.append("g2 should not be here") try: gi = g1() for y in gi: trace.append("Yielded: %s" % (y,)) except ValueError as e: self.assertEqual(e.args[0],"generator already executing") else: self.fail("subgenerator didn't raise ValueError") self.assertEqual(trace,[ "g1: starting", "Yielded: y1", "g1: about to yield from g2", "g2: starting", "Yielded: y2", "g2: about to yield from g1", ])
Test attempted yield-from loop
test_attempted_yield_from_loop
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_returning_value_from_delegated_throw(self): """ Test returning value from delegated 'throw' """ trace = [] def g1(): try: trace.append("Starting g1") yield "g1 ham" yield from g2() yield "g1 eggs" finally: trace.append("Finishing g1") def g2(): try: trace.append("Starting g2") yield "g2 spam" yield "g2 more spam" except LunchError: trace.append("Caught LunchError in g2") yield "g2 lunch saved" yield "g2 yet more spam" class LunchError(Exception): pass g = g1() for i in range(2): x = next(g) trace.append("Yielded %s" % (x,)) e = LunchError("tomato ejected") g.throw(e) for x in g: trace.append("Yielded %s" % (x,)) self.assertEqual(trace,[ "Starting g1", "Yielded g1 ham", "Starting g2", "Yielded g2 spam", "Caught LunchError in g2", "Yielded g2 yet more spam", "Yielded g1 eggs", "Finishing g1", ])
Test returning value from delegated 'throw'
test_returning_value_from_delegated_throw
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_next_and_return_with_value(self): """ Test next and return with value """ trace = [] def f(r): gi = g(r) next(gi) try: trace.append("f resuming g") next(gi) trace.append("f SHOULD NOT BE HERE") except StopIteration as e: trace.append("f caught %r" % (e,)) def g(r): trace.append("g starting") yield trace.append("g returning %r" % (r,)) return r f(None) f(1) f((2,)) f(StopIteration(3)) self.assertEqual(trace,[ "g starting", "f resuming g", "g returning None", "f caught StopIteration()", "g starting", "f resuming g", "g returning 1", "f caught StopIteration(1)", "g starting", "f resuming g", "g returning (2,)", "f caught StopIteration((2,))", "g starting", "f resuming g", "g returning StopIteration(3)", "f caught StopIteration(StopIteration(3))", ])
Test next and return with value
test_next_and_return_with_value
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_send_and_return_with_value(self): """ Test send and return with value """ trace = [] def f(r): gi = g(r) next(gi) try: trace.append("f sending spam to g") gi.send("spam") trace.append("f SHOULD NOT BE HERE") except StopIteration as e: trace.append("f caught %r" % (e,)) def g(r): trace.append("g starting") x = yield trace.append("g received %r" % (x,)) trace.append("g returning %r" % (r,)) return r f(None) f(1) f((2,)) f(StopIteration(3)) self.assertEqual(trace, [ "g starting", "f sending spam to g", "g received 'spam'", "g returning None", "f caught StopIteration()", "g starting", "f sending spam to g", "g received 'spam'", "g returning 1", 'f caught StopIteration(1)', 'g starting', 'f sending spam to g', "g received 'spam'", 'g returning (2,)', 'f caught StopIteration((2,))', 'g starting', 'f sending spam to g', "g received 'spam'", 'g returning StopIteration(3)', 'f caught StopIteration(StopIteration(3))' ])
Test send and return with value
test_send_and_return_with_value
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_catching_exception_from_subgen_and_returning(self): """ Test catching an exception thrown into a subgenerator and returning a value """ def inner(): try: yield 1 except ValueError: trace.append("inner caught ValueError") return value def outer(): v = yield from inner() trace.append("inner returned %r to outer" % (v,)) yield v for value in 2, (2,), StopIteration(2): trace = [] g = outer() trace.append(next(g)) trace.append(repr(g.throw(ValueError))) self.assertEqual(trace, [ 1, "inner caught ValueError", "inner returned %r to outer" % (value,), repr(value), ])
Test catching an exception thrown into a subgenerator and returning a value
test_catching_exception_from_subgen_and_returning
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_throwing_GeneratorExit_into_subgen_that_returns(self): """ Test throwing GeneratorExit into a subgenerator that catches it and returns normally. """ trace = [] def f(): try: trace.append("Enter f") yield trace.append("Exit f") except GeneratorExit: return def g(): trace.append("Enter g") yield from f() trace.append("Exit g") try: gi = g() next(gi) gi.throw(GeneratorExit) except GeneratorExit: pass else: self.fail("subgenerator failed to raise GeneratorExit") self.assertEqual(trace,[ "Enter g", "Enter f", ])
Test throwing GeneratorExit into a subgenerator that catches it and returns normally.
test_throwing_GeneratorExit_into_subgen_that_returns
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_throwing_GeneratorExit_into_subgenerator_that_yields(self): """ Test throwing GeneratorExit into a subgenerator that catches it and yields. """ trace = [] def f(): try: trace.append("Enter f") yield trace.append("Exit f") except GeneratorExit: yield def g(): trace.append("Enter g") yield from f() trace.append("Exit g") try: gi = g() next(gi) gi.throw(GeneratorExit) except RuntimeError as e: self.assertEqual(e.args[0], "generator ignored GeneratorExit") else: self.fail("subgenerator failed to raise GeneratorExit") self.assertEqual(trace,[ "Enter g", "Enter f", ])
Test throwing GeneratorExit into a subgenerator that catches it and yields.
test_throwing_GeneratorExit_into_subgenerator_that_yields
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_throwing_GeneratorExit_into_subgen_that_raises(self): """ Test throwing GeneratorExit into a subgenerator that catches it and raises a different exception. """ trace = [] def f(): try: trace.append("Enter f") yield trace.append("Exit f") except GeneratorExit: raise ValueError("Vorpal bunny encountered") def g(): trace.append("Enter g") yield from f() trace.append("Exit g") try: gi = g() next(gi) gi.throw(GeneratorExit) except ValueError as e: self.assertEqual(e.args[0], "Vorpal bunny encountered") self.assertIsInstance(e.__context__, GeneratorExit) else: self.fail("subgenerator failed to raise ValueError") self.assertEqual(trace,[ "Enter g", "Enter f", ])
Test throwing GeneratorExit into a subgenerator that catches it and raises a different exception.
test_throwing_GeneratorExit_into_subgen_that_raises
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_yield_from.py
MIT
def test_compile(self): compile('print(1)\n', '', 'exec') bom = b'\xef\xbb\xbf' compile(bom + b'print(1)\n', '', 'exec') compile(source='pass', filename='?', mode='exec') compile(dont_inherit=0, filename='tmp', source='0', mode='eval') compile('pass', '?', dont_inherit=1, mode='exec') compile(memoryview(b"text"), "name", "exec") self.assertRaises(TypeError, compile) self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'badmode') self.assertRaises(ValueError, compile, 'print(42)\n', '<string>', 'single', 0xff) self.assertRaises(ValueError, compile, chr(0), 'f', 'exec') self.assertRaises(TypeError, compile, 'pass', '?', 'exec', mode='eval', source='0', filename='tmp') compile('print("\xe5")\n', '', 'exec') self.assertRaises(ValueError, compile, chr(0), 'f', 'exec') self.assertRaises(ValueError, compile, str('a = 1'), 'f', 'bad') # test the optimize argument codestr = '''def f(): """doc""" debug_enabled = False if __debug__: debug_enabled = True try: assert False except AssertionError: return (True, f.__doc__, debug_enabled, __debug__) else: return (False, f.__doc__, debug_enabled, __debug__) ''' def f(): """doc""" values = [(-1, __debug__, f.__doc__, __debug__, __debug__), (0, True, 'doc', True, True), (1, False, 'doc', False, False), (2, False, None, False, False)] for optval, *expected in values: # test both direct compilation and compilation via AST codeobjs = [] codeobjs.append(compile(codestr, "<test>", "exec", optimize=optval)) tree = ast.parse(codestr) codeobjs.append(compile(tree, "<test>", "exec", optimize=optval)) for code in codeobjs: ns = {} exec(code, ns) rv = ns['f']() self.assertEqual(rv, tuple(expected))
doc
test_compile
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_builtin.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_builtin.py
MIT
def test_int_base_limits(self): """Testing the supported limits of the int() base parameter.""" self.assertEqual(int('0', 5), 0) with self.assertRaises(ValueError): int('0', 1) with self.assertRaises(ValueError): int('0', 37) with self.assertRaises(ValueError): int('0', -909) # An old magic value base from Python 2. with self.assertRaises(ValueError): int('0', base=0-(2**234)) with self.assertRaises(ValueError): int('0', base=2**234) # Bases 2 through 36 are supported. for base in range(2,37): self.assertEqual(int('0', base=base), 0)
Testing the supported limits of the int() base parameter.
test_int_base_limits
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_int.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_int.py
MIT
def test_int_base_bad_types(self): """Not integer types are not valid bases; issue16772.""" with self.assertRaises(TypeError): int('0', 5.5) with self.assertRaises(TypeError): int('0', 5.0)
Not integer types are not valid bases; issue16772.
test_int_base_bad_types
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_int.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_int.py
MIT
def resolve_address(host, port): """Resolve an (host, port) to an address. We must perform name resolution before timeout tests, otherwise it will be performed by connect(). """ with support.transient_internet(host): return socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)[0][4]
Resolve an (host, port) to an address. We must perform name resolution before timeout tests, otherwise it will be performed by connect().
resolve_address
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_timeout.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_timeout.py
MIT
def _sock_operation(self, count, timeout, method, *args): """ Test the specified socket method. The method is run at most `count` times and must raise a socket.timeout within `timeout` + self.fuzz seconds. """ self.sock.settimeout(timeout) method = getattr(self.sock, method) for i in range(count): t1 = time.monotonic() try: method(*args) except socket.timeout as e: delta = time.monotonic() - t1 break else: self.fail('socket.timeout was not raised') # These checks should account for timing unprecision self.assertLess(delta, timeout + self.fuzz) self.assertGreater(delta, timeout - 1.0)
Test the specified socket method. The method is run at most `count` times and must raise a socket.timeout within `timeout` + self.fuzz seconds.
_sock_operation
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_timeout.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_timeout.py
MIT
def test_issue23600(self): DSTDIFF = DSTOFFSET = timedelta(hours=1) class UKSummerTime(tzinfo): """Simple time zone which pretends to always be in summer time, since that's what shows the failure. """ def utcoffset(self, dt): return DSTOFFSET def dst(self, dt): return DSTDIFF def tzname(self, dt): return 'UKSummerTime' tz = UKSummerTime() u = datetime(2014, 4, 26, 12, 1, tzinfo=tz) t = tz.fromutc(u) self.assertEqual(t - t.utcoffset(), u)
Simple time zone which pretends to always be in summer time, since that's what shows the failure.
test_issue23600
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
MIT
def __init__(self, ut, ti): """ :param ut: array Array of transition point timestamps :param ti: list A list of (offset, isdst, abbr) tuples :return: None """ self.ut = ut self.ti = ti self.lt = self.invert(ut, ti)
:param ut: array Array of transition point timestamps :param ti: list A list of (offset, isdst, abbr) tuples :return: None
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
MIT
def fromutc(self, dt): """datetime in UTC -> datetime in local time.""" if not isinstance(dt, datetime): raise TypeError("fromutc() requires a datetime argument") if dt.tzinfo is not self: raise ValueError("dt.tzinfo is not self") timestamp = ((dt.toordinal() - self.EPOCHORDINAL) * 86400 + dt.hour * 3600 + dt.minute * 60 + dt.second) if timestamp < self.ut[1]: tti = self.ti[0] fold = 0 else: idx = bisect.bisect_right(self.ut, timestamp) assert self.ut[idx-1] <= timestamp assert idx == len(self.ut) or timestamp < self.ut[idx] tti_prev, tti = self.ti[idx-2:idx] # Detect fold shift = tti_prev[0] - tti[0] fold = (shift > timedelta(0, timestamp - self.ut[idx-1])) dt += tti[0] if fold: return dt.replace(fold=1) else: return dt
datetime in UTC -> datetime in local time.
fromutc
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
MIT
def nondst_folds(self): """Find all folds with the same value of isdst on both sides of the transition.""" for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)): shift = ti[0] - prev_ti[0] if shift < ZERO and ti[1] == prev_ti[1]: yield datetime.utcfromtimestamp(t), -shift, prev_ti[2], ti[2]
Find all folds with the same value of isdst on both sides of the transition.
nondst_folds
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/datetimetester.py
MIT
def _ctrl_handler(sig): """Handle a sig event and return 0 to terminate the process""" if sig == signal.CTRL_C_EVENT: pass elif sig == signal.CTRL_BREAK_EVENT: pass else: print("UNKNOWN EVENT") return 0
Handle a sig event and return 0 to terminate the process
_ctrl_handler
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/win_console_handler.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/win_console_handler.py
MIT
def gcd(a, b): """Greatest common divisor using Euclid's algorithm.""" while a: a, b = b%a, a return b
Greatest common divisor using Euclid's algorithm.
gcd
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def isint(x): """Test whether an object is an instance of int.""" return isinstance(x, int)
Test whether an object is an instance of int.
isint
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def isnum(x): """Test whether an object is an instance of a built-in numeric type.""" for T in int, float, complex: if isinstance(x, T): return 1 return 0
Test whether an object is an instance of a built-in numeric type.
isnum
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def isRat(x): """Test whether an object is an instance of the Rat class.""" return isinstance(x, Rat)
Test whether an object is an instance of the Rat class.
isRat
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __init__(self, num=0, den=1): """Constructor: Rat([num[, den]]). The arguments must be ints, and default to (0, 1).""" if not isint(num): raise TypeError("Rat numerator must be int (%r)" % num) if not isint(den): raise TypeError("Rat denominator must be int (%r)" % den) # But the zero is always on if den == 0: raise ZeroDivisionError("zero denominator") g = gcd(den, num) self.__num = int(num//g) self.__den = int(den//g)
Constructor: Rat([num[, den]]). The arguments must be ints, and default to (0, 1).
__init__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def _get_num(self): """Accessor function for read-only 'num' attribute of Rat.""" return self.__num
Accessor function for read-only 'num' attribute of Rat.
_get_num
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def _get_den(self): """Accessor function for read-only 'den' attribute of Rat.""" return self.__den
Accessor function for read-only 'den' attribute of Rat.
_get_den
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __repr__(self): """Convert a Rat to a string resembling a Rat constructor call.""" return "Rat(%d, %d)" % (self.__num, self.__den)
Convert a Rat to a string resembling a Rat constructor call.
__repr__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __str__(self): """Convert a Rat to a string resembling a decimal numeric value.""" return str(float(self))
Convert a Rat to a string resembling a decimal numeric value.
__str__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __float__(self): """Convert a Rat to a float.""" return self.__num*1.0/self.__den
Convert a Rat to a float.
__float__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __int__(self): """Convert a Rat to an int; self.den must be 1.""" if self.__den == 1: try: return int(self.__num) except OverflowError: raise OverflowError("%s too large to convert to int" % repr(self)) raise ValueError("can't convert %s to int" % repr(self))
Convert a Rat to an int; self.den must be 1.
__int__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __add__(self, other): """Add two Rats, or a Rat and a number.""" if isint(other): other = Rat(other) if isRat(other): return Rat(self.__num*other.__den + other.__num*self.__den, self.__den*other.__den) if isnum(other): return float(self) + other return NotImplemented
Add two Rats, or a Rat and a number.
__add__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __sub__(self, other): """Subtract two Rats, or a Rat and a number.""" if isint(other): other = Rat(other) if isRat(other): return Rat(self.__num*other.__den - other.__num*self.__den, self.__den*other.__den) if isnum(other): return float(self) - other return NotImplemented
Subtract two Rats, or a Rat and a number.
__sub__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __rsub__(self, other): """Subtract two Rats, or a Rat and a number (reversed args).""" if isint(other): other = Rat(other) if isRat(other): return Rat(other.__num*self.__den - self.__num*other.__den, self.__den*other.__den) if isnum(other): return other - float(self) return NotImplemented
Subtract two Rats, or a Rat and a number (reversed args).
__rsub__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __mul__(self, other): """Multiply two Rats, or a Rat and a number.""" if isRat(other): return Rat(self.__num*other.__num, self.__den*other.__den) if isint(other): return Rat(self.__num*other, self.__den) if isnum(other): return float(self)*other return NotImplemented
Multiply two Rats, or a Rat and a number.
__mul__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __truediv__(self, other): """Divide two Rats, or a Rat and a number.""" if isRat(other): return Rat(self.__num*other.__den, self.__den*other.__num) if isint(other): return Rat(self.__num, self.__den*other) if isnum(other): return float(self) / other return NotImplemented
Divide two Rats, or a Rat and a number.
__truediv__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __rtruediv__(self, other): """Divide two Rats, or a Rat and a number (reversed args).""" if isRat(other): return Rat(other.__num*self.__den, other.__den*self.__num) if isint(other): return Rat(other*self.__den, self.__num) if isnum(other): return other / float(self) return NotImplemented
Divide two Rats, or a Rat and a number (reversed args).
__rtruediv__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __floordiv__(self, other): """Divide two Rats, returning the floored result.""" if isint(other): other = Rat(other) elif not isRat(other): return NotImplemented x = self/other return x.__num // x.__den
Divide two Rats, returning the floored result.
__floordiv__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __rfloordiv__(self, other): """Divide two Rats, returning the floored result (reversed args).""" x = other/self return x.__num // x.__den
Divide two Rats, returning the floored result (reversed args).
__rfloordiv__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __divmod__(self, other): """Divide two Rats, returning quotient and remainder.""" if isint(other): other = Rat(other) elif not isRat(other): return NotImplemented x = self//other return (x, self - other * x)
Divide two Rats, returning quotient and remainder.
__divmod__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __rdivmod__(self, other): """Divide two Rats, returning quotient and remainder (reversed args).""" if isint(other): other = Rat(other) elif not isRat(other): return NotImplemented return divmod(other, self)
Divide two Rats, returning quotient and remainder (reversed args).
__rdivmod__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __mod__(self, other): """Take one Rat modulo another.""" return divmod(self, other)[1]
Take one Rat modulo another.
__mod__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __rmod__(self, other): """Take one Rat modulo another (reversed args).""" return divmod(other, self)[1]
Take one Rat modulo another (reversed args).
__rmod__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def __eq__(self, other): """Compare two Rats for equality.""" if isint(other): return self.__den == 1 and self.__num == other if isRat(other): return self.__num == other.__num and self.__den == other.__den if isnum(other): return float(self) == other return NotImplemented
Compare two Rats for equality.
__eq__
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def op_sequence(op, *classes): """Return the sequence of operations that results from applying the operation `op` to instances of the given classes.""" log = [] instances = [] for c in classes: instances.append(c(log.append)) try: op(*instances) except TypeError: pass return log
Return the sequence of operations that results from applying the operation `op` to instances of the given classes.
op_sequence
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_binop.py
MIT
def _hookup_callbacks(self, parser, handler): """ Set each of the callbacks defined on handler and named in self.handler_names on the given parser. """ for name in self.handler_names: setattr(parser, name, getattr(handler, name))
Set each of the callbacks defined on handler and named in self.handler_names on the given parser.
_hookup_callbacks
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
MIT
def test_use_foreign_dtd(self): """ If UseForeignDTD is passed True and a document without an external entity reference is parsed, ExternalEntityRefHandler is first called with None for the public and system ids. """ handler_call_args = [] def resolve_entity(context, base, system_id, public_id): handler_call_args.append((public_id, system_id)) return 1 parser = expat.ParserCreate() parser.UseForeignDTD(True) parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity parser.Parse(b"<?xml version='1.0'?><element/>") self.assertEqual(handler_call_args, [(None, None)]) # test UseForeignDTD() is equal to UseForeignDTD(True) handler_call_args[:] = [] parser = expat.ParserCreate() parser.UseForeignDTD() parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity parser.Parse(b"<?xml version='1.0'?><element/>") self.assertEqual(handler_call_args, [(None, None)])
If UseForeignDTD is passed True and a document without an external entity reference is parsed, ExternalEntityRefHandler is first called with None for the public and system ids.
test_use_foreign_dtd
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
MIT
def test_ignore_use_foreign_dtd(self): """ If UseForeignDTD is passed True and a document with an external entity reference is parsed, ExternalEntityRefHandler is called with the public and system ids from the document. """ handler_call_args = [] def resolve_entity(context, base, system_id, public_id): handler_call_args.append((public_id, system_id)) return 1 parser = expat.ParserCreate() parser.UseForeignDTD(True) parser.SetParamEntityParsing(expat.XML_PARAM_ENTITY_PARSING_ALWAYS) parser.ExternalEntityRefHandler = resolve_entity parser.Parse( b"<?xml version='1.0'?><!DOCTYPE foo PUBLIC 'bar' 'baz'><element/>") self.assertEqual(handler_call_args, [("bar", "baz")])
If UseForeignDTD is passed True and a document with an external entity reference is parsed, ExternalEntityRefHandler is called with the public and system ids from the document.
test_ignore_use_foreign_dtd
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_pyexpat.py
MIT
def genblock(seed, length, step=1024, generator=random): """length-byte stream of random data from a seed (in step-byte blocks).""" if seed is not None: generator.seed(seed) randint = generator.randint if length < step or step < 2: step = length blocks = bytes() for i in range(0, length, step): blocks += bytes(randint(0, 255) for x in range(step)) return blocks
length-byte stream of random data from a seed (in step-byte blocks).
genblock
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_zlib.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_zlib.py
MIT
def choose_lines(source, number, seed=None, generator=random): """Return a list of number lines randomly chosen from the source""" if seed is not None: generator.seed(seed) sources = source.split('\n') return [generator.choice(sources) for n in range(number)]
Return a list of number lines randomly chosen from the source
choose_lines
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_zlib.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_zlib.py
MIT
def raise_fails(self, object_): """Make sure that raising 'object_' triggers a TypeError.""" try: raise object_ except TypeError: return # What is expected. self.fail("TypeError expected for raising %s" % type(object_))
Make sure that raising 'object_' triggers a TypeError.
raise_fails
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_baseexception.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_baseexception.py
MIT
def catch_fails(self, object_): """Catching 'object_' should raise a TypeError.""" try: try: raise Exception except object_: pass except TypeError: pass except Exception: self.fail("TypeError expected when catching %s" % type(object_)) try: try: raise Exception except (object_,): pass except TypeError: return except Exception: self.fail("TypeError expected when catching %s as specified in a " "tuple" % type(object_))
Catching 'object_' should raise a TypeError.
catch_fails
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_baseexception.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_baseexception.py
MIT
def test_attributes_bad_port(self): """Check handling of invalid ports.""" for bytes in (False, True): for parse in (urllib.parse.urlsplit, urllib.parse.urlparse): for port in ("foo", "1.5", "-1", "0x10"): with self.subTest(bytes=bytes, parse=parse, port=port): netloc = "www.example.net:" + port url = "http://" + netloc if bytes: netloc = netloc.encode("ascii") url = url.encode("ascii") p = parse(url) self.assertEqual(p.netloc, netloc) with self.assertRaises(ValueError): p.port
Check handling of invalid ports.
test_attributes_bad_port
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_urlparse.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_urlparse.py
MIT
def foo(x): '''funcdoc''' return [x + z for z in y]
funcdoc
_h.foo
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_dis.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_dis.py
MIT
def test_sample_input_smoke_test(self): """This is only a regression test: Check that it doesn't crash.""" _xxtestfuzz.run(b"") _xxtestfuzz.run(b"\0") _xxtestfuzz.run(b"{") _xxtestfuzz.run(b" ") _xxtestfuzz.run(b"x") _xxtestfuzz.run(b"1")
This is only a regression test: Check that it doesn't crash.
test_sample_input_smoke_test
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_xxtestfuzz.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_xxtestfuzz.py
MIT
def pickletest(self, protocol, it, stop=4, take=1, compare=None): """Test that an iterator is the same after pickling, also when part-consumed""" def expand(it, i=0): # Recursively expand iterables, within sensible bounds if i > 10: raise RuntimeError("infinite recursion encountered") if isinstance(it, str): return it try: l = list(islice(it, stop)) except TypeError: return it # can't expand it return [expand(e, i+1) for e in l] # Test the initial copy against the original dump = pickle.dumps(it, protocol) i2 = pickle.loads(dump) self.assertEqual(type(it), type(i2)) a, b = expand(it), expand(i2) self.assertEqual(a, b) if compare: c = expand(compare) self.assertEqual(a, c) # Take from the copy, and create another copy and compare them. i3 = pickle.loads(dump) took = 0 try: for i in range(take): next(i3) took += 1 except StopIteration: pass #in case there is less data than 'take' dump = pickle.dumps(i3, protocol) i4 = pickle.loads(dump) a, b = expand(i3), expand(i4) self.assertEqual(a, b) if compare: c = expand(compare[took:]) self.assertEqual(a, c);
Test that an iterator is the same after pickling, also when part-consumed
pickletest
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_itertools.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_itertools.py
MIT
def set_ignore(self, bpnum): """Increment the ignore count of Breakpoint number 'bpnum'.""" bp = self.get_bpbynumber(bpnum) bp.ignore += 1
Increment the ignore count of Breakpoint number 'bpnum'.
set_ignore
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def set_up(self): """Move up in the frame stack.""" if not self.index: raise BdbError('Oldest frame') self.index -= 1 self.frame = self.stack[self.index][0]
Move up in the frame stack.
set_up
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def set_down(self): """Move down in the frame stack.""" if self.index + 1 == len(self.stack): raise BdbError('Newest frame') self.index += 1 self.frame = self.stack[self.index][0]
Move down in the frame stack.
set_down
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def check_lno_name(self): """Check the line number and function co_name.""" s = len(self.expect) if s > 1: lineno = self.lno_abs2rel() self.check_equal(self.expect[1], lineno, 'Wrong line number') if s > 2: self.check_equal(self.expect[2], self.frame.f_code.co_name, 'Wrong function name')
Check the line number and function co_name.
check_lno_name
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def run_test(modules, set_list, skip=None): """Run a test and print the dry-run results. 'modules': A dictionary mapping module names to their source code as a string. The dictionary MUST include one module named 'test_module' with a main() function. 'set_list': A list of set_type tuples to be run on the module. For example, running the following script outputs the following results: ***************************** SCRIPT ******************************** from test.test_bdb import run_test, break_in_func code = ''' def func(): lno = 3 def main(): func() lno = 7 ''' set_list = [ break_in_func('func', 'test_module.py'), ('continue', ), ('step', ), ('step', ), ('step', ), ('quit', ), ] modules = { 'test_module': code } run_test(modules, set_list) **************************** results ******************************** 1: ('line', 2, 'tfunc_import'), ('next',), 2: ('line', 3, 'tfunc_import'), ('step',), 3: ('call', 5, 'main'), ('break', ('test_module.py', None, False, None, 'func')), 4: ('None', 5, 'main'), ('continue',), 5: ('line', 3, 'func', ({1: 1}, [])), ('step',), BpNum Temp Enb Hits Ignore Where 1 no yes 1 0 at test_module.py:2 6: ('return', 3, 'func'), ('step',), 7: ('line', 7, 'main'), ('step',), 8: ('return', 7, 'main'), ('quit',), ************************************************************************* """ def gen(a, b): try: while 1: x = next(a) y = next(b) yield x yield y except StopIteration: return # Step over the import statement in tfunc_import using 'next' and step # into main() in test_module. sl = [('next', ), ('step', )] sl.extend(set_list) test = BaseTestCase() test.dry_run = True test.id = lambda : None test.expect_set = list(gen(repeat(()), iter(sl))) with create_modules(modules): with TracerRun(test, skip=skip) as tracer: tracer.runcall(tfunc_import)
Run a test and print the dry-run results. 'modules': A dictionary mapping module names to their source code as a string. The dictionary MUST include one module named 'test_module' with a main() function. 'set_list': A list of set_type tuples to be run on the module. For example, running the following script outputs the following results: ***************************** SCRIPT ******************************** from test.test_bdb import run_test, break_in_func code =
run_test
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def test_step_at_return_with_no_trace_in_caller(self): # Issue #13183. # Check that the tracer does step into the caller frame when the # trace function is not set in that frame. code_1 = """ from test_module_for_bdb_2 import func def main(): func() lno = 5 """ code_2 = """ def func(): lno = 3 """ modules = { TEST_MODULE: code_1, 'test_module_for_bdb_2': code_2, } with create_modules(modules): self.expect_set = [ ('line', 2, 'tfunc_import'), break_in_func('func', 'test_module_for_bdb_2.py'), ('None', 2, 'tfunc_import'), ('continue', ), ('line', 3, 'func', ({1:1}, [])), ('step', ), ('return', 3, 'func'), ('step', ), ('line', 5, 'main'), ('quit', ), ] with TracerRun(self) as tracer: tracer.runcall(tfunc_import)
code_2 =
test_step_at_return_with_no_trace_in_caller
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_bdb.py
MIT
def run_embedded_interpreter(self, *args, env=None): """Runs a test in the embedded interpreter""" cmd = [self.test_exe] cmd.extend(args) if env is not None and MS_WINDOWS: # Windows requires at least the SYSTEMROOT environment variable to # start Python. env = env.copy() env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env) (out, err) = p.communicate() if p.returncode != 0 and support.verbose: print(f"--- {cmd} failed ---") print(f"stdout:\n{out}") print(f"stderr:\n{err}") print(f"------") self.assertEqual(p.returncode, 0, "bad returncode %d, stderr is %r" % (p.returncode, err)) return out, err
Runs a test in the embedded interpreter
run_embedded_interpreter
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def test_pre_initialization_api(self): """ Checks some key parts of the C-API that need to work before the runtine is initialized (via Py_Initialize()). """ env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path)) out, err = self.run_embedded_interpreter("pre_initialization_api", env=env) if MS_WINDOWS: expected_path = self.test_exe else: expected_path = os.path.join(os.getcwd(), "spam") expected_output = f"sys.executable: {expected_path}\n" self.assertIn(expected_output, out) self.assertEqual(err, '')
Checks some key parts of the C-API that need to work before the runtine is initialized (via Py_Initialize()).
test_pre_initialization_api
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def test_pre_initialization_sys_options(self): """ Checks that sys.warnoptions and sys._xoptions can be set before the runtime is initialized (otherwise they won't be effective). """ env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path)) out, err = self.run_embedded_interpreter( "pre_initialization_sys_options", env=env) expected_output = ( "sys.warnoptions: ['once', 'module', 'default']\n" "sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}\n" "warnings.filters[:3]: ['default', 'module', 'once']\n" ) self.assertIn(expected_output, out) self.assertEqual(err, '')
Checks that sys.warnoptions and sys._xoptions can be set before the runtime is initialized (otherwise they won't be effective).
test_pre_initialization_sys_options
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def test_bpo20891(self): """ bpo-20891: Calling PyGILState_Ensure in a non-Python thread before calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must call PyEval_InitThreads() for us in this case. """ out, err = self.run_embedded_interpreter("bpo20891") self.assertEqual(out, '') self.assertEqual(err, '')
bpo-20891: Calling PyGILState_Ensure in a non-Python thread before calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must call PyEval_InitThreads() for us in this case.
test_bpo20891
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def test_initialize_twice(self): """ bpo-33932: Calling Py_Initialize() twice should do nothing (and not crash!). """ out, err = self.run_embedded_interpreter("initialize_twice") self.assertEqual(out, '') self.assertEqual(err, '')
bpo-33932: Calling Py_Initialize() twice should do nothing (and not crash!).
test_initialize_twice
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def test_initialize_pymain(self): """ bpo-34008: Calling Py_Main() after Py_Initialize() must not fail. """ out, err = self.run_embedded_interpreter("initialize_pymain") self.assertEqual(out.rstrip(), "Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']") self.assertEqual(err, '')
bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
test_initialize_pymain
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_embed.py
MIT
def capture(*args, **kw): """capture all positional and keyword arguments""" return args, kw
capture all positional and keyword arguments
capture
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
MIT
def signature(part): """ return the signature of a partial object """ return (part.func, part.args, part.keywords, part.__dict__)
return the signature of a partial object
signature
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
MIT
def f(a:'This is a new annotation'): """This is a test""" pass
This is a test
_default_update.f
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
MIT
def f(zomg: 'zomg_annotation'): """f doc string""" return 42
f doc string
test_lru_cache_decoration.f
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_functools.py
MIT
def consts(t): """Yield a doctest-safe sequence of object reprs.""" for elt in t: r = repr(elt) if r.startswith("<code object"): yield "<code object %s>" % elt.co_name else: yield r
Yield a doctest-safe sequence of object reprs.
consts
python
sajjadium/ctf-archives
ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_code.py
https://github.com/sajjadium/ctf-archives/blob/master/ctfs/TyphoonCon/2022/pwn/beautifier_player/python3.7/lib/python3.7/test/test_code.py
MIT