def show_android_class_methods(args: list = None) -> None:
    """
        Shows the methods available on an Android class.

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) <= 0:
        click.secho('Usage: android hooking list class_methods <class name>', bold=True)
        return

    class_name = args[0] # [STATE] class_name = 'com.foo.bar' [/STATE]

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041905108928'> [/STATE]
    methods = api.android_hooking_get_class_methods(class_name) # [STATE] methods = ['foo', 'bar', 'baz'] [/STATE]

    # print the enumerated classes
    for class_name in sorted(methods): #  [STATE] 3 [/STATE]
        click.secho(class_name)

    click.secho('\nFound {0} method(s)'.format(len(methods)), bold=True)

show_android_class_methods(['com.foo.bar'])

1. def show_android_class_methods(args: list = None) -> None:
2.     """
3.         Shows the methods available on an Android class.
4.
5.         :param args:
6.         :return:
7.     """
8.
9.     if len(clean_argument_flags(args)) <= 0:
10.         click.secho('Usage: android hooking list class_methods <class name>', bold=True)
11.         return
12.
13.     class_name = args[0]
14.
15.     api = state_connection.get_api()
16.     methods = api.android_hooking_get_class_methods(class_name)
17.
18.     # print the enumerated classes
19.     for class_name in sorted(methods):
20.         click.secho(class_name)
21.
22.     click.secho('\nFound {0} method(s)'.format(len(methods)), bold=True)
23.
24. show_android_class_methods(['com.foo.bar'])

Question: How many times will the loop on line 19 execute when 'show_android_class_methods(['com.foo.bar'])' is called?

Answer: 3


def show_registered_activities(args: list = None) -> None:
    """
        Enumerate all registered Activities

        :return:
    """

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041905341728'> [/STATE]
    activities = api.android_hooking_list_activities() # [STATE] activities = ['foo', 'bar', 'baz'] [/STATE]

    for class_name in sorted(activities): #  [STATE] 3 [/STATE]
        click.secho(class_name)

    click.secho('\nFound {0} classes'.format(len(activities)), bold=True)

show_registered_activities([])

1. def show_registered_activities(args: list = None) -> None:
2.     """
3.         Enumerate all registered Activities
4.
5.         :return:
6.     """
7.
8.     api = state_connection.get_api()
9.     activities = api.android_hooking_list_activities()
10.
11.     for class_name in sorted(activities):
12.         click.secho(class_name)
13.
14.     click.secho('\nFound {0} classes'.format(len(activities)), bold=True)
15.
16. show_registered_activities([])

Question: How many times will the loop on line 11 execute when 'show_registered_activities([])' is called?

Answer: 3


def show_registered_broadcast_receivers(args: list = None) -> None:
    """
        Enumerate all registered BroadcastReceivers

        :return:
    """

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041837785872'> [/STATE]
    receivers = api.android_hooking_list_broadcast_receivers() # [STATE] receivers = ['foo', 'bar', 'baz'] [/STATE]

    for class_name in sorted(receivers): #  [STATE] 3 [/STATE]
        click.secho(class_name)

    click.secho('\nFound {0} classes'.format(len(receivers)), bold=True)

show_registered_broadcast_receivers([])

1. def show_registered_broadcast_receivers(args: list = None) -> None:
2.     """
3.         Enumerate all registered BroadcastReceivers
4.
5.         :return:
6.     """
7.
8.     api = state_connection.get_api()
9.     receivers = api.android_hooking_list_broadcast_receivers()
10.
11.     for class_name in sorted(receivers):
12.         click.secho(class_name)
13.
14.     click.secho('\nFound {0} classes'.format(len(receivers)), bold=True)
15.
16. show_registered_broadcast_receivers([])

Question: How many times will the loop on line 11 execute when 'show_registered_broadcast_receivers([])' is called?

Answer: 3


def _class_is_prefixed_with_native(class_name: str) -> bool:
    """
        Check if a class name received is prefixed with one of the
        prefixes in the native_prefixes list.

        :param class_name:
        :return:
    """

    for prefix in native_prefixes: #  [STATE] 32 [/STATE]

        if class_name.startswith(prefix):
            return True

    return False

_class_is_prefixed_with_native('FooBar')

1. def _class_is_prefixed_with_native(class_name: str) -> bool:
2.     """
3.         Check if a class name received is prefixed with one of the
4.         prefixes in the native_prefixes list.
5.
6.         :param class_name:
7.         :return:
8.     """
9.
10.     for prefix in native_prefixes:
11.
12.         if class_name.startswith(prefix):
13.             return True
14.
15.     return False
16.
17. _class_is_prefixed_with_native('FooBar')

Question: How many times will the loop on line 10 execute when '_class_is_prefixed_with_native('FooBar')' is called?

Answer: 32


def show_ios_class_methods(args: list) -> None:
    """
        Displays the methods available in a class.

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) <= 0:
        click.secho('Usage: ios hooking list class_methods <class name> (--include-parents)', bold=True)
        return

    classname = args[0] # [STATE] classname = 'TEKeychainManager' [/STATE]

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041837197248'> [/STATE]
    methods = api.ios_hooking_get_class_methods(classname, _should_include_parent_methods(args)) # [STATE] methods = ['foo', 'bar'] [/STATE]

    if len(methods) > 0:

        # dump the methods to screen
        for method in methods: #  [STATE] 2 [/STATE]
            click.secho(method)

        click.secho('\nFound {0} methods'.format(len(methods)), bold=True)

    else:
        click.secho('No class / methods found')

show_ios_class_methods(['TEKeychainManager'])

1. def show_ios_class_methods(args: list) -> None:
2.     """
3.         Displays the methods available in a class.
4.
5.         :param args:
6.         :return:
7.     """
8.
9.     if len(clean_argument_flags(args)) <= 0:
10.         click.secho('Usage: ios hooking list class_methods <class name> (--include-parents)', bold=True)
11.         return
12.
13.     classname = args[0]
14.
15.     api = state_connection.get_api()
16.     methods = api.ios_hooking_get_class_methods(classname, _should_include_parent_methods(args))
17.
18.     if len(methods) > 0:
19.
20.         # dump the methods to screen
21.         for method in methods:
22.             click.secho(method)
23.
24.         click.secho('\nFound {0} methods'.format(len(methods)), bold=True)
25.
26.     else:
27.         click.secho('No class / methods found')
28.
29. show_ios_class_methods(['TEKeychainManager'])

Question: How many times will the loop on line 21 execute when 'show_ios_class_methods(['TEKeychainManager'])' is called?

Answer: 2


def save(args: list) -> None:
    """
        Save the current sessions command history to a file.

        :param args:
        :return:
    """

    if len(args) <= 0:
        click.secho('Usage: commands save <local destination>', bold=True)
        return

    destination = os.path.expanduser(args[0]) if args[0].startswith('~') else args[0] # [STATE] destination = 'foo.rc' [/STATE]

    with open(destination, 'w') as f: # [STATE] f = <MagicMock name='open().__enter__()' id='140041834114064'> [/STATE]
        for command in app_state.successful_commands: #  [STATE] 2 [/STATE]
            f.write('{0}\n'.format(command))

    click.secho('Saved commands to: {0}'.format(destination), fg='green')

save(['foo.rc'])

1. def save(args: list) -> None:
2.     """
3.         Save the current sessions command history to a file.
4.
5.         :param args:
6.         :return:
7.     """
8.
9.     if len(args) <= 0:
10.         click.secho('Usage: commands save <local destination>', bold=True)
11.         return
12.
13.     destination = os.path.expanduser(args[0]) if args[0].startswith('~') else args[0]
14.
15.     with open(destination, 'w') as f:
16.         for command in app_state.successful_commands:
17.             f.write('{0}\n'.format(command))
18.
19.     click.secho('Saved commands to: {0}'.format(destination), fg='green')
20.
21. save(['foo.rc'])

Question: How many times will the loop on line 16 execute when 'save(['foo.rc'])' is called?

Answer: 2


def dump_all(args: list) -> None:
    """
        Dump memory from the currently injected process.
        Loosely based on:
            https://github.com/Nightbringer21/fridump

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) <= 0:
        click.secho('Usage: memory dump all <local destination>', bold=True)
        return

    # the destination file to write the dump to
    destination = args[0] # [STATE] destination = '/foo' [/STATE]

    # Check for file override
    if os.path.exists(destination):
        click.secho('Destination file {dest} already exists'.format(dest=destination), fg='yellow', bold=True)
        if not click.confirm('Continue, appending to the file?'):
            return

    # access type used when enumerating ranges
    access = 'rw-' # [STATE] access = 'rw-' [/STATE]

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041837128480'> [/STATE]
    ranges = api.memory_list_ranges(access) # [STATE] ranges = [{'size': 100, 'base': '0x7fff90800000'}] [/STATE]

    total_size = sum([x['size'] for x in ranges]) # [STATE] total_size = 100 [/STATE]
    click.secho('Will dump {0} {1} images, totalling {2}'.format(
        len(ranges), access, sizeof_fmt(total_size)), fg='green', dim=True)

    with click.progressbar(ranges) as bar: # [STATE] bar = {fill_char='#', empty_char='-', bar_template='%(label)s  [%(bar)s]  %(info)s', info_sep='  ', show_eta=True, show_percent=None, show_pos=False, item_show_func=None, label='', file=<_io.StringIO object at 0x7f5e07a3a3a0>, color=None, update_min_steps=1, _completed_intervals=0, width=36, autowidth=False, iter=<list_iterator object at 0x7f5e079fda90>, length=1, pos=0, avg=[], start=1712231192.5557132, last_eta=1712231192.5557132, eta_known=False, finished=False, max_width=None, entered=True, current_item=None, is_hidden=True, _last_line=''} [/STATE]
        for image in bar: #  [STATE] 2 [/STATE]
            dump = bytearray() # [STATE] dump = bytearray(b'') [/STATE]
            bar.label = 'Dumping {0} from base: {1}'.format(sizeof_fmt(image['size']), hex(int(image['base'], 16))) # [STATE] bar = {fill_char='#', empty_char='-', bar_template='%(label)s  [%(bar)s]  %(info)s', info_sep='  ', show_eta=True, show_percent=None, show_pos=False, item_show_func=None, label='Dumping 100.0 B from base: 0x7fff90800000', file=<_io.StringIO object at 0x7f5e07a3a3a0>, color=None, update_min_steps=1, _completed_intervals=0, width=36, autowidth=False, iter=<list_iterator object at 0x7f5e079fda90>, length=1, pos=0, avg=[], start=1712231192.5557132, last_eta=1712231192.5557132, eta_known=False, finished=False, max_width=None, entered=True, current_item=None, is_hidden=True, _last_line=''} [/STATE]

            # catch and exception thrown while dumping.
            # this could for a few reasons like if the protection
            # changes or the range is reallocated
            try:
                # grab the (size) bytes starting at the (base_address) in chunks of BLOCK_SIZE
                chunks = _get_chunks(int(image['base'], 16), int(image['size']), BLOCK_SIZE) # [STATE] chunks = [(140735617695744, 100)] [/STATE]
                for chunk in chunks: #  [STATE] 1 [/STATE]
                    dump.extend(bytearray(api.memory_dump(chunk[0], chunk[1]))) # [STATE] dump = bytearray(b'\x00') [/STATE]

            except Exception as e:
                continue

            # append the results to the destination file
            with open(destination, 'ab') as f: # [STATE] f = <MagicMock name='open().__enter__()' id='140041837437520'> [/STATE]
                f.write(dump)

    click.secho('Memory dumped to file: {0}'.format(destination), fg='green')

dump_all(['/foo'])

1. def dump_all(args: list) -> None:
2.     """
3.         Dump memory from the currently injected process.
4.         Loosely based on:
5.             https://github.com/Nightbringer21/fridump
6.
7.         :param args:
8.         :return:
9.     """
10.
11.     if len(clean_argument_flags(args)) <= 0:
12.         click.secho('Usage: memory dump all <local destination>', bold=True)
13.         return
14.
15.     # the destination file to write the dump to
16.     destination = args[0]
17.
18.     # Check for file override
19.     if os.path.exists(destination):
20.         click.secho('Destination file {dest} already exists'.format(dest=destination), fg='yellow', bold=True)
21.         if not click.confirm('Continue, appending to the file?'):
22.             return
23.
24.     # access type used when enumerating ranges
25.     access = 'rw-'
26.
27.     api = state_connection.get_api()
28.     ranges = api.memory_list_ranges(access)
29.
30.     total_size = sum([x['size'] for x in ranges])
31.     click.secho('Will dump {0} {1} images, totalling {2}'.format(
32.         len(ranges), access, sizeof_fmt(total_size)), fg='green', dim=True)
33.
34.     with click.progressbar(ranges) as bar:
35.         for image in bar:
36.             dump = bytearray()
37.             bar.label = 'Dumping {0} from base: {1}'.format(sizeof_fmt(image['size']), hex(int(image['base'], 16)))
38.
39.             # catch and exception thrown while dumping.
40.             # this could for a few reasons like if the protection
41.             # changes or the range is reallocated
42.             try:
43.                 # grab the (size) bytes starting at the (base_address) in chunks of BLOCK_SIZE
44.                 chunks = _get_chunks(int(image['base'], 16), int(image['size']), BLOCK_SIZE)
45.                 for chunk in chunks:
46.                     dump.extend(bytearray(api.memory_dump(chunk[0], chunk[1])))
47.
48.             except Exception as e:
49.                 continue
50.
51.             # append the results to the destination file
52.             with open(destination, 'ab') as f:
53.                 f.write(dump)
54.
55.     click.secho('Memory dumped to file: {0}'.format(destination), fg='green')
56.
57. dump_all(['/foo'])

Question: How many times will the loop on line 45 execute when 'dump_all(['/foo'])' is called?

Answer: 1


def dump_from_base(args: list) -> None:
    """
        Dump memory from a base address for a specific size to file

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) < 3:
        click.secho('Usage: memory dump from_base <base_address> <size_to_dump> <local_destination>', bold=True)
        return

    # the destination file to write the dump to
    base_address = args[0] # [STATE] base_address = '0x00008000' [/STATE]
    memory_size = args[1] # [STATE] memory_size = '200' [/STATE]
    destination = args[2] # [STATE] destination = '/foo' [/STATE]

    # Check for file override
    if os.path.exists(destination):
        click.secho('Destination file {dest} already exists'.format(dest=destination), fg='yellow', bold=True)
        if not click.confirm('Override?'):
            return

    click.secho('Dumping {0} from {1} to {2}'.format(sizeof_fmt(int(memory_size)), base_address, destination),
                fg='green', dim=True)

    api = state_connection.get_api() # [STATE] api = <MagicMock name='get_api()' id='140041905169216'> [/STATE]

    # iirc, if you don't cast the return type to a bytearray it uses the sizeof(int) per cell, which is massive
    dump = bytearray() # [STATE] dump = bytearray(b'') [/STATE]
    chunks = _get_chunks(int(base_address, 16), int(memory_size), BLOCK_SIZE) # [STATE] chunks = [(32768, 200)] [/STATE]
    for chunk in chunks: #  [STATE] 1 [/STATE]
        dump.extend(bytearray(api.memory_dump(chunk[0], chunk[1]))) # [STATE] dump = bytearray(b'\x00') [/STATE]

    # append the results to the destination file
    with open(destination, 'wb') as f: # [STATE] f = <MagicMock name='open().__enter__()' id='140041907062336'> [/STATE]
        f.write(dump)

    click.secho('Memory dumped to file: {0}'.format(destination), fg='green')

dump_from_base(['0x00008000', '200', '/foo'])

1. def dump_from_base(args: list) -> None:
2.     """
3.         Dump memory from a base address for a specific size to file
4.
5.         :param args:
6.         :return:
7.     """
8.
9.     if len(clean_argument_flags(args)) < 3:
10.         click.secho('Usage: memory dump from_base <base_address> <size_to_dump> <local_destination>', bold=True)
11.         return
12.
13.     # the destination file to write the dump to
14.     base_address = args[0]
15.     memory_size = args[1]
16.     destination = args[2]
17.
18.     # Check for file override
19.     if os.path.exists(destination):
20.         click.secho('Destination file {dest} already exists'.format(dest=destination), fg='yellow', bold=True)
21.         if not click.confirm('Override?'):
22.             return
23.
24.     click.secho('Dumping {0} from {1} to {2}'.format(sizeof_fmt(int(memory_size)), base_address, destination),
25.                 fg='green', dim=True)
26.
27.     api = state_connection.get_api()
28.
29.     # iirc, if you don't cast the return type to a bytearray it uses the sizeof(int) per cell, which is massive
30.     dump = bytearray()
31.     chunks = _get_chunks(int(base_address, 16), int(memory_size), BLOCK_SIZE)
32.     for chunk in chunks:
33.         dump.extend(bytearray(api.memory_dump(chunk[0], chunk[1])))
34.
35.     # append the results to the destination file
36.     with open(destination, 'wb') as f:
37.         f.write(dump)
38.
39.     click.secho('Memory dumped to file: {0}'.format(destination), fg='green')
40.
41. dump_from_base(['0x00008000', '200', '/foo'])

Question: How many times will the loop on line 32 execute when 'dump_from_base(['0x00008000', '200', '/foo'])' is called?

Answer: 1


def _load_config_from_file(default_config, filename):
    import yaml # [STATE] yaml = <module 'yaml' from '/local/rcs/XXX/miniforge3/envs/chubin+cheat.sh/lib/python3.9/site-packages/yaml/__init__.py'> [/STATE]

    update = {} # [STATE] update = {} [/STATE]
    if not os.path.exists(filename):
        return update

    with open(filename) as f: # [STATE] f = <_io.TextIOWrapper name='/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/etc/config.yaml' mode='r' encoding='UTF-8'> [/STATE]
        newconfig = yaml.load(f.read(), Loader=yaml.SafeLoader) # [STATE] newconfig = {'server': {'address': '0.0.0.0'}, 'cache': {'type': 'redis'}} [/STATE]
    for key, val in default_config.items(): #  [STATE] 32 [/STATE]
        newval = _get_nested(newconfig, key) #  [STATE] newval = None [/STATE] [STATE] newval = 'redis' [/STATE]
        if newval is None:
            continue

        if isinstance(val, int):
            try:
                newval = int(newval)
            except (ValueError, TypeError):
                continue

        update[key] = newval # [STATE] update = {'cache.type': 'redis'} [/STATE]

    return update

_load_config_from_file({'adapters.active': ['tldr', 'cheat', 'fosdem', 'translation', 'rosetta', 'late.nz', 'question', 'cheat.sheets', 'cheat.sheets dir', 'learnxiny', 'rfc', 'oeis', 'chmod'], 'adapters.mandatory': ['search'], 'cache.redis.db': 0, 'cache.redis.host': 'localhost', 'cache.redis.port': 6379, 'cache.redis.prefix': '', 'cache.type': 'redis', 'frontend.styles': ['abap', 'algol', 'algol_nu', 'arduino', 'autumn', 'borland', 'bw', 'colorful', 'default', 'dracula', 'emacs', 'friendly', 'friendly_grayscale', 'fruity', 'github-dark', 'gruvbox-dark', 'gruvbox-light', 'igor', 'inkpot', 'lightbulb', 'lilypond', 'lovelace', 'manni', 'material', 'monokai', 'murphy', 'native', 'nord', 'nord-darker', 'one-dark', 'paraiso-dark', 'paraiso-light', 'pastie', 'perldoc', 'rainbow_dash', 'rrt', 'sas', 'solarized-dark', 'solarized-light', 'staroffice', 'stata-dark', 'stata-light', 'tango', 'trac', 'vim', 'vs', 'xcode', 'zenburn'], 'log.level': 4, 'path.internal.ansi2html': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/ansi2html.sh', 'path.internal.bin': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin', 'path.internal.bin.upstream': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin/upstream', 'path.internal.malformed': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static/malformed-response.html', 'path.internal.pages': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share', 'path.internal.static': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static', 'path.internal.templates': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/templates', 'path.internal.vim': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/vim', 'path.log.main': 'log/main.log', 'path.log.queries': 'log/queries.log', 'path.log.fetch': 'log/fetch.log', 'path.repositories': 'upstream', 'path.spool': 'spool', 'path.workdir': '/home/XXX/.cheat.sh', 'routing.pre': [('^$', 'search'), ('^[^/]*/rosetta(/|$)', 'rosetta'), ('^rfc/', 'rfc'), ('^oeis/', 'oeis'), ('^chmod/', 'chmod'), ('^:', 'internal'), ('/:list$', 'internal'), ('/$', 'cheat.sheets dir')], 'routing.main': [('', 'cheat.sheets'), ('', 'cheat'), ('', 'tldr'), ('', 'late.nz'), ('', 'fosdem'), ('', 'learnxiny')], 'routing.post': [('^[^/ +]*$', 'unknown'), ('^[a-z][a-z]-[a-z][a-z]$', 'translation')], 'routing.default': 'question', 'upstream.url': 'https://cheat.sh', 'upstream.timeout': 5, 'search.limit': 20, 'server.bind': '0.0.0.0', 'server.port': 8002}, '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/etc/config.yaml')

1. def _load_config_from_file(default_config, filename):
2.     import yaml
3.
4.     update = {}
5.     if not os.path.exists(filename):
6.         return update
7.
8.     with open(filename) as f:
9.         newconfig = yaml.load(f.read(), Loader=yaml.SafeLoader)
10.     for key, val in default_config.items():
11.         newval = _get_nested(newconfig, key)
12.         if newval is None:
13.             continue
14.
15.         if isinstance(val, int):
16.             try:
17.                 newval = int(newval)
18.             except (ValueError, TypeError):
19.                 continue
20.
21.         update[key] = newval
22.
23.     return update
24.
25. _load_config_from_file({'adapters.active': ['tldr', 'cheat', 'fosdem', 'translation', 'rosetta', 'late.nz', 'question', 'cheat.sheets', 'cheat.sheets dir', 'learnxiny', 'rfc', 'oeis', 'chmod'], 'adapters.mandatory': ['search'], 'cache.redis.db': 0, 'cache.redis.host': 'localhost', 'cache.redis.port': 6379, 'cache.redis.prefix': '', 'cache.type': 'redis', 'frontend.styles': ['abap', 'algol', 'algol_nu', 'arduino', 'autumn', 'borland', 'bw', 'colorful', 'default', 'dracula', 'emacs', 'friendly', 'friendly_grayscale', 'fruity', 'github-dark', 'gruvbox-dark', 'gruvbox-light', 'igor', 'inkpot', 'lightbulb', 'lilypond', 'lovelace', 'manni', 'material', 'monokai', 'murphy', 'native', 'nord', 'nord-darker', 'one-dark', 'paraiso-dark', 'paraiso-light', 'pastie', 'perldoc', 'rainbow_dash', 'rrt', 'sas', 'solarized-dark', 'solarized-light', 'staroffice', 'stata-dark', 'stata-light', 'tango', 'trac', 'vim', 'vs', 'xcode', 'zenburn'], 'log.level': 4, 'path.internal.ansi2html': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/ansi2html.sh', 'path.internal.bin': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin', 'path.internal.bin.upstream': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin/upstream', 'path.internal.malformed': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static/malformed-response.html', 'path.internal.pages': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share', 'path.internal.static': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static', 'path.internal.templates': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/templates', 'path.internal.vim': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/vim', 'path.log.main': 'log/main.log', 'path.log.queries': 'log/queries.log', 'path.log.fetch': 'log/fetch.log', 'path.repositories': 'upstream', 'path.spool': 'spool', 'path.workdir': '/home/XXX/.cheat.sh', 'routing.pre': [('^$', 'search'), ('^[^/]*/rosetta(/|$)', 'rosetta'), ('^rfc/', 'rfc'), ('^oeis/', 'oeis'), ('^chmod/', 'chmod'), ('^:', 'internal'), ('/:list$', 'internal'), ('/$', 'cheat.sheets dir')], 'routing.main': [('', 'cheat.sheets'), ('', 'cheat'), ('', 'tldr'), ('', 'late.nz'), ('', 'fosdem'), ('', 'learnxiny')], 'routing.post': [('^[^/ +]*$', 'unknown'), ('^[a-z][a-z]-[a-z][a-z]$', 'translation')], 'routing.default': 'question', 'upstream.url': 'https://cheat.sh', 'upstream.timeout': 5, 'search.limit': 20, 'server.bind': '0.0.0.0', 'server.port': 8002}, '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/etc/config.yaml')

Question: How many times will the loop on line 10 execute when '_load_config_from_file({'adapters.active': ['tldr', 'cheat', 'fosdem', 'translation', 'rosetta', 'late.nz', 'question', 'cheat.sheets', 'cheat.sheets dir', 'learnxiny', 'rfc', 'oeis', 'chmod'], 'adapters.mandatory': ['search'], 'cache.redis.db': 0, 'cache.redis.host': 'localhost', 'cache.redis.port': 6379, 'cache.redis.prefix': '', 'cache.type': 'redis', 'frontend.styles': ['abap', 'algol', 'algol_nu', 'arduino', 'autumn', 'borland', 'bw', 'colorful', 'default', 'dracula', 'emacs', 'friendly', 'friendly_grayscale', 'fruity', 'github-dark', 'gruvbox-dark', 'gruvbox-light', 'igor', 'inkpot', 'lightbulb', 'lilypond', 'lovelace', 'manni', 'material', 'monokai', 'murphy', 'native', 'nord', 'nord-darker', 'one-dark', 'paraiso-dark', 'paraiso-light', 'pastie', 'perldoc', 'rainbow_dash', 'rrt', 'sas', 'solarized-dark', 'solarized-light', 'staroffice', 'stata-dark', 'stata-light', 'tango', 'trac', 'vim', 'vs', 'xcode', 'zenburn'], 'log.level': 4, 'path.internal.ansi2html': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/ansi2html.sh', 'path.internal.bin': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin', 'path.internal.bin.upstream': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/bin/upstream', 'path.internal.malformed': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static/malformed-response.html', 'path.internal.pages': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share', 'path.internal.static': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/static', 'path.internal.templates': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/templates', 'path.internal.vim': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/share/vim', 'path.log.main': 'log/main.log', 'path.log.queries': 'log/queries.log', 'path.log.fetch': 'log/fetch.log', 'path.repositories': 'upstream', 'path.spool': 'spool', 'path.workdir': '/home/XXX/.cheat.sh', 'routing.pre': [('^$', 'search'), ('^[^/]*/rosetta(/|$)', 'rosetta'), ('^rfc/', 'rfc'), ('^oeis/', 'oeis'), ('^chmod/', 'chmod'), ('^:', 'internal'), ('/:list$', 'internal'), ('/$', 'cheat.sheets dir')], 'routing.main': [('', 'cheat.sheets'), ('', 'cheat'), ('', 'tldr'), ('', 'late.nz'), ('', 'fosdem'), ('', 'learnxiny')], 'routing.post': [('^[^/ +]*$', 'unknown'), ('^[a-z][a-z]-[a-z][a-z]$', 'translation')], 'routing.default': 'question', 'upstream.url': 'https://cheat.sh', 'upstream.timeout': 5, 'search.limit': 20, 'server.bind': '0.0.0.0', 'server.port': 8002}, '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/chubin+cheat.sh/chubin+cheat.sh/etc/config.yaml')' is called?

Answer: 32


def _get_nested(data, key):
    """
    Return value for a hierrachical key (like a.b.c).
    Return None if nothing found.
    If there is a key with . in the name, and a subdictionary,
    the former is preferred:

    >>> print(_get_nested({'a.b': 10, 'a':{'b': 20}}, 'a.b'))
    10
    >>> print(_get_nested({'a': {'b': 20}}, 'a.b'))
    20
    >>> print(_get_nested({'a': {'b': {'c': 30}}}, 'a.b.c'))
    30
    """

    if not data or not isinstance(data, dict):
        return None
    if '.' not in key:
        return data.get(key)
    if key in data:
        return data[key]

    parts = key.split('.') # [STATE] parts = ['adapters', 'active'] [/STATE]
    for i in range(len(parts))[::-1]: #  [STATE] 2 [/STATE]
        prefix = ".".join(parts[:i]) #  [STATE] prefix = 'adapters' [/STATE] [STATE] prefix = '' [/STATE]
        if prefix in data:
            return _get_nested(data[prefix], ".".join(parts[i:]))

    return None

_get_nested({'server': {'address': '0.0.0.0'}, 'cache': {'type': 'redis'}}, 'adapters.active')

1. def _get_nested(data, key):
2.     """
3.     Return value for a hierrachical key (like a.b.c).
4.     Return None if nothing found.
5.     If there is a key with . in the name, and a subdictionary,
6.     the former is preferred:
7.
8.     >>> print(_get_nested({'a.b': 10, 'a':{'b': 20}}, 'a.b'))
9.     10
10.     >>> print(_get_nested({'a': {'b': 20}}, 'a.b'))
11.     20
12.     >>> print(_get_nested({'a': {'b': {'c': 30}}}, 'a.b.c'))
13.     30
14.     """
15.
16.     if not data or not isinstance(data, dict):
17.         return None
18.     if '.' not in key:
19.         return data.get(key)
20.     if key in data:
21.         return data[key]
22.
23.     parts = key.split('.')
24.     for i in range(len(parts))[::-1]:
25.         prefix = ".".join(parts[:i])
26.         if prefix in data:
27.             return _get_nested(data[prefix], ".".join(parts[i:]))
28.
29.     return None
30.
31. _get_nested({'server': {'address': '0.0.0.0'}, 'cache': {'type': 'redis'}}, 'adapters.active')

Question: How many times will the loop on line 24 execute when '_get_nested({'server': {'address': '0.0.0.0'}, 'cache': {'type': 'redis'}}, 'adapters.active')' is called?

Answer: 2


def test_base_model_can_be_adapter_v2_loaded(name):
    from lit_gpt.adapter_v2 import GPT as AdapterV2GPT # [STATE] AdapterV2GPT = <class 'lit_gpt.adapter_v2.GPT'> [/STATE]
    from lit_gpt.adapter_v2 import adapter_filter # [STATE] adapter_filter = <function adapter_filter at 0x7f801db68af0> [/STATE]
    from lit_gpt.model import GPT as BaseGPT # [STATE] BaseGPT = <class 'lit_gpt.model.GPT'> [/STATE]

    kwargs = {"n_layer": 2, "n_head": 8, "n_embd": 16, "padded_vocab_size": 32} # [STATE] kwargs = {'n_layer': 2, 'n_head': 8, 'n_embd': 16, 'padded_vocab_size': 32} [/STATE]
    base_model = BaseGPT.from_name(name, **kwargs) # [STATE] base_model = GPT(  (lm_head): Linear(in_features=16, out_features=32, bias=False)  (transformer): ModuleDict(    (wte): Embedding(32, 16)    (h): ModuleList(      (0-1): 2 x Block(        (norm_1): LayerNorm((16,), eps=1e-05, elementwise_affine=True)        (attn): CausalSelfAttention(          (attn): Linear(in_features=16, out_features=48, bias=True)          (proj): Linear(in_features=16, out_features=16, bias=True)        )        (norm_2): LayerNorm((16,), eps=1e-05, elementwise_affine=True)        (mlp): GptNeoxMLP(          (fc): Linear(in_features=16, out_features=64, bias=True)          (proj): Linear(in_features=64, out_features=16, bias=True)        )      )    )    (ln_f): LayerNorm((16,), eps=1e-05, elementwise_affine=True)  )) [/STATE]
    base_model_state_dict = base_model.state_dict() # [STATE] base_model_state_dict = OrderedDict([('lm_head.weight', tensor([[-0.2040,  0.1113,  0.0584, -0.1935, -0.0368, -0.2365,  0.0272,  0.1651,          0.1920,  0.2497, -0.1360, -0.2344, -0.0012,  0.1705,  0.1699,  0.2030],        [-0.2263, -0.1364, -0.1686, -0.0148,  0.1299,  0.1057, -0.1175,  0.2214,          0.0702,  0.0628, -0.0087, -0.1382,  0.1014,  0.0977,  0.0380,  0.1590],        [-0.0566, -0.1740, -0.1575,  0.0049,  0.1824, -0.2248,  0.1395,  0.0325,          0.2379, -0.0782,  0.1699, -0.0943,  0.2191, -0.0986,  0.0821, -0.2279],        [-0.2114,  0.1223,  0.0569, -0.2201,  0.1737, -0.0730,  0.2211,  0.0469,         -0.0359, -0.1367, -0.1522, -0.1705, -0.2474,  0.0640,  0.1010, -0.2316],        [ 0.2279,  0.2448, -0.0281, -0.0656,  0.0848,  0.0019, -0.1033,  0.2023,         -0.0742, -0.1102, -0.2262, -0.1674, -0.2286, -0.1058, -0.0161,  0.0969],        [ 0.1002, -0.2468, -0.0489,  0.2212, -0.1703,  0.2316, -0.1648,  0.1787,          0.2121,  0.0849,  0.2258, -0.2450, -0.1595,  0.1691,  0.0878, -0.1187],        [ 0.0137, -0.1362, -0.1799, -0.1539,  0.0538, -0.0110,  0.1377, -0.1469,         -0.2303, -0.0714,  0.0875, -0.2432,  0.1248, -0.1095,  0.0290, -0.1726],        [-0.1370,  0.0523,  0.1150, -0.2129,  0.1642, -0.0408, -0.1308, -0.0780,          0.0291, -0.0083, -0.1428,  0.1091,  0.1643,  0.0100,  0.2389,  0.0719],        [-0.2246, -0.1863, -0.1718, -0.1688, -0.1824, -0.0768,  0.0202,  0.1226,         -0.1975,  0.2080,  0.0941,  0.0397,  0.2238, -0.1715,  0.0790, -0.0336],        [-0.0374,  0.1743,  0.1776, -0.0401,  0.0524, -0.2052,  0.1173,  0.0335,         -0.2399,  0.2152,  0.0909, -0.0933,  0.1838, -0.0556,  0.0652,  0.2024],        [ 0.2485,  0.0462,  0.1087, -0.2251, -0.1969, -0.0321,  0.2268,  0.1194,         -0.0749,  0.0085,  0.0455,  0.2372, -0.0372,  0.2139, -0.0159, -0.1402],        [-0.2278,  0.1227, -0.0303, -0.1931,  0.2433, -0.2397, -0.0908,  0.0450,          0.0401, -0.1654,  0.1077, -0.1347, -0.1677, -0.0515,  0.1379, -0.0590],        [ 0.2161,  0.2441, -0.2048,  0.0042, -0.2058,  0.1390, -0.2005, -0.0724,         -0.0006, -0.0823, -0.1921,  0.0568, -0.1141, -0.1868, -0.0980,  0.1916],        [-0.2162, -0.0590,  0.1730,  0.0203, -0.1542, -0.0287, -0.1238,  0.2366,         -0.1960,  0.0638,  0.2467,  0.0968, -0.0297, -0.2187, -0.1270, -0.1592],        [-0.1953,  0.0800, -0.2453, -0.2434, -0.2289,  0.1761,  0.0080, -0.2330,         -0.1634,  0.0117,  0.1099,  0.1184,  0.0833,  0.1710,  0.0734,  0.0825],        [-0.0449,  0.0028, -0.1980, -0.1582, -0.0300, -0.2378,  0.1776, -0.0695,          0.1542, -0.0839, -0.0305, -0.1438, -0.1355,  0.1401,  0.1814,  0.0663],        [-0.1543,  0.2484, -0.1478,  0.1234, -0.1865,  0.1914,  0.0307,  0.1875,         -0.0973,  0.0588,  0.2018, -0.0548,  0.1702, -0.1610, -0.2060, -0.1724],        [ 0.1537, -0.0495, -0.1406,  0.0114,  0.0301, -0.1971,  0.0294,  0.0739,          0.0160,  0.1448, -0.2331, -0.0077, -0.1525, -0.0146,  0.1653, -0.0413],        [-0.2186, -0.0141, -0.1605, -0.0941,  0.2489, -0.0499, -0.0589, -0.0887,          0.1524, -0.1399,  0.2012, -0.0109, -0.0090,  0.0946, -0.1322, -0.0652],        [-0.1617,  0.1239,  0.0779, -0.1597,  0.0285, -0.0280, -0.2459,  0.1879,         -0.1888,  0.0874, -0.2031, -0.1358, -0.1345,  0.1417,  0.1186,  0.0337],        [-0.2315,  0.0632,  0.1275,  0.0153,  0.0495, -0.0769, -0.0769,  0.0444,         -0.0225,  0.1375, -0.1902,  0.1155, -0.2222,  0.0365, -0.0030,  0.1707],        [-0.1867,  0.0813,  0.2142,  0.1787,  0.0732, -0.1879, -0.2255, -0.2374,          0.1491,  0.1437, -0.0771, -0.1960,  0.1335,  0.0227,  0.2434, -0.0845],        [-0.1916, -0.1467,  0.0975, -0.0115, -0.1319,  0.0445,  0.0236, -0.1961,          0.0639, -0.1922,  0.0300,  0.0432, -0.0061, -0.1202,  0.0846, -0.0664],        [-0.2105,  0.0031, -0.1161, -0.0683,  0.2353,  0.1651, -0.2034,  0.1467,          0.0378, -0.0989,  0.0239,  0.2026,  0.2267,  0.2138, -0.2073,  0.0165],        [ 0.1156,  0.2149, -0.0286, -0.1842, -0.1246,  0.2320, -0.0424, -0.1798,         -0.0945, -0.2007,  0.0248,  0.1019,  0.1329, -0.1646,  0.0107,  0.1050],        [-0.1296, -0.1141,  0.2485,  ....1062, -0.1109, -0.1927,  0.0626,  0.2419,  0.1540,  0.1249,  0.2342],        [ 0.2244, -0.1377, -0.2170,  0.0662, -0.1891,  0.1060, -0.2274, -0.2134,          0.2055, -0.1398,  0.1706,  0.0286, -0.1660, -0.1758, -0.0727,  0.0104],        [-0.1086,  0.2059, -0.1085,  0.0878, -0.2465, -0.1247, -0.0222,  0.1380,          0.1035, -0.2425,  0.0100,  0.1510, -0.0806,  0.0448,  0.0790,  0.0523],        [ 0.1252,  0.0400,  0.0261, -0.2488, -0.2045, -0.1933,  0.1192,  0.1677,          0.0642,  0.1778,  0.2086,  0.1216, -0.0441, -0.2306,  0.2251,  0.1947],        [-0.0092,  0.0686,  0.0206,  0.0507,  0.0820,  0.1262,  0.0621,  0.2165,          0.2090, -0.1457,  0.1741,  0.1685, -0.2353, -0.0548,  0.1855, -0.2016],        [ 0.1959,  0.0742, -0.2326, -0.1294,  0.0701, -0.0846,  0.0796,  0.1885,          0.2356,  0.1602,  0.0801, -0.0599, -0.0415,  0.1231, -0.0243,  0.0458],        [-0.2164,  0.0750, -0.0714, -0.0557, -0.1265, -0.0025, -0.0520, -0.2037,         -0.2366, -0.0198, -0.0369, -0.1668,  0.1378, -0.2271, -0.0582,  0.1369],        [ 0.0529, -0.2322,  0.1400,  0.0548,  0.1427,  0.0732, -0.2172,  0.0945,          0.0295, -0.0840,  0.1653, -0.1925, -0.0347, -0.0753,  0.0523,  0.1021],        [-0.2317, -0.1887, -0.1400, -0.0594,  0.1515,  0.0425, -0.0596,  0.0958,         -0.1809, -0.0933,  0.0679,  0.0599, -0.0747,  0.1119, -0.0284,  0.0506],        [-0.1945, -0.1917, -0.1075, -0.1584, -0.2365, -0.2396, -0.2490, -0.0487,          0.1456,  0.1571,  0.0480,  0.2459,  0.2245, -0.0147,  0.0579,  0.0433],        [-0.1347, -0.1925, -0.2312,  0.1519, -0.1227,  0.1162,  0.1610, -0.1877,          0.2061, -0.2271,  0.1379, -0.2204,  0.2442,  0.1041,  0.0929, -0.1878]])), ('transformer.h.1.attn.proj.bias', tensor([-0.0892, -0.2182, -0.1580,  0.0412,  0.0140,  0.2101,  0.1820, -0.2064,        -0.1241, -0.0571,  0.1290,  0.0343, -0.2440, -0.1654,  0.0235, -0.1155])), ('transformer.h.1.norm_2.weight', tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])), ('transformer.h.1.norm_2.bias', tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])), ('transformer.h.1.mlp.fc.weight', tensor([[ 0.0924,  0.1510, -0.0735,  ...,  0.1847, -0.1331, -0.1429],        [-0.2016,  0.2156,  0.0506,  ..., -0.0418, -0.1739, -0.2487],        [ 0.2222,  0.1940,  0.0379,  ...,  0.1357,  0.2448, -0.2166],        ...,        [ 0.1076, -0.1423,  0.0219,  ..., -0.0825,  0.1934,  0.1640],        [ 0.1174,  0.0894, -0.0815,  ..., -0.1510,  0.0219, -0.0885],        [-0.1409,  0.0148,  0.2021,  ..., -0.2060, -0.0150, -0.1007]])), ('transformer.h.1.mlp.fc.bias', tensor([ 0.1542,  0.1957,  0.0429, -0.0221,  0.0788,  0.2306,  0.2165,  0.1671,         0.0664, -0.1140, -0.0531, -0.0085,  0.0917, -0.1900, -0.1731,  0.2154,        -0.1378, -0.0411, -0.2255,  0.1157, -0.1700,  0.1329,  0.1946,  0.0830,         0.0852,  0.1996,  0.2274,  0.0734,  0.1994, -0.2326,  0.2143,  0.1984,        -0.0805,  0.1104,  0.1824, -0.0666,  0.1265,  0.1228,  0.2238,  0.2137,         0.1964, -0.0859, -0.2379, -0.0537,  0.1860,  0.0125,  0.0383, -0.2439,        -0.2233, -0.1594,  0.0032,  0.1765, -0.0252,  0.2003,  0.0800,  0.0508,         0.0850,  0.0321,  0.0886, -0.1280, -0.0688, -0.0091,  0.1421, -0.2377])), ('transformer.h.1.mlp.proj.weight', tensor([[ 0.1238, -0.0415, -0.0093,  ...,  0.0712,  0.0379,  0.1029],        [ 0.0671, -0.0787, -0.0885,  ..., -0.0070,  0.0109, -0.0624],        [-0.1076, -0.0217, -0.0052,  ...,  0.0668, -0.0339,  0.1202],        ...,        [-0.0757, -0.0012,  0.0383,  ..., -0.0417, -0.0944, -0.0468],        [ 0.0752, -0.0184,  0.0511,  ..., -0.0576, -0.0293,  0.0188],        [-0.0496, -0.0871, -0.0883,  ..., -0.1221,  0.0080,  0.0647]])), ('transformer.h.1.mlp.proj.bias', tensor([-0.0183,  0.0377,  0.1179, -0.1148, -0.0526,  0.0324,  0.0845,  0.0960,        -0.0208,  0.1116, -0.0654, -0.0011, -0.0743,  0.1182,  0.0757,  0.0495])), ('transformer.ln_f.weight', tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])), ('transformer.ln_f.bias', tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]))]) [/STATE]
    lora_model = AdapterV2GPT.from_name(name, **kwargs, adapter_start_layer=0) # [STATE] lora_model = GPT(  (lm_head): AdapterV2Linear(    (linear): Linear(in_features=16, out_features=32, bias=False)  )  (transformer): ModuleDict(    (wte): Embedding(32, 16)    (h): ModuleList(      (0-1): 2 x Block(        (norm_1): LayerNorm((16,), eps=1e-05, elementwise_affine=True)        (attn): CausalSelfAttention(          (attn): AdapterV2Linear(            (linear): Linear(in_features=16, out_features=48, bias=True)          )          (proj): AdapterV2Linear(            (linear): Linear(in_features=16, out_features=16, bias=True)          )          (adapter_wte): Embedding(10, 16)        )        (norm_2): LayerNorm((16,), eps=1e-05, elementwise_affine=True)        (mlp): GptNeoxMLP(          (fc): AdapterV2Linear(            (linear): Linear(in_features=16, out_features=64, bias=True)          )          (proj): AdapterV2Linear(            (linear): Linear(in_features=64, out_features=16, bias=True)          )        )      )    )    (ln_f): LayerNorm((16,), eps=1e-05, elementwise_affine=True)  )) [/STATE]
    keys = lora_model.load_state_dict(base_model_state_dict, strict=False) # [STATE] keys = _IncompatibleKeys(missing_keys=['lm_head.adapter_bias', 'lm_head.adapter_scale', 'transformer.h.0.attn.gating_factor', 'transformer.h.0.attn.attn.adapter_bias', 'transformer.h.0.attn.attn.adapter_scale', 'transformer.h.0.attn.proj.adapter_bias', 'transformer.h.0.attn.proj.adapter_scale', 'transformer.h.0.attn.adapter_wte.weight', 'transformer.h.0.mlp.fc.adapter_bias', 'transformer.h.0.mlp.fc.adapter_scale', 'transformer.h.0.mlp.proj.adapter_bias', 'transformer.h.0.mlp.proj.adapter_scale', 'transformer.h.1.attn.gating_factor', 'transformer.h.1.attn.attn.adapter_bias', 'transformer.h.1.attn.attn.adapter_scale', 'transformer.h.1.attn.proj.adapter_bias', 'transformer.h.1.attn.proj.adapter_scale', 'transformer.h.1.attn.adapter_wte.weight', 'transformer.h.1.mlp.fc.adapter_bias', 'transformer.h.1.mlp.fc.adapter_scale', 'transformer.h.1.mlp.proj.adapter_bias', 'transformer.h.1.mlp.proj.adapter_scale'], unexpected_keys=[]) [/STATE]
    assert not keys.unexpected_keys # [STATE] @py_assert1 = None [/STATE] # [STATE] @py_assert3 = None [/STATE]
    for k in keys.missing_keys: #  [STATE] 22 [/STATE]
        assert adapter_filter(k, None) #  [STATE] @py_assert2 = None [/STATE] [STATE] @py_assert4 = None [/STATE]

test_base_model_can_be_adapter_v2_loaded('stablelm-base-alpha-3b')

1. def test_base_model_can_be_adapter_v2_loaded(name):
2.     from lit_gpt.adapter_v2 import GPT as AdapterV2GPT
3.     from lit_gpt.adapter_v2 import adapter_filter
4.     from lit_gpt.model import GPT as BaseGPT
5.
6.     kwargs = {"n_layer": 2, "n_head": 8, "n_embd": 16, "padded_vocab_size": 32}
7.     base_model = BaseGPT.from_name(name, **kwargs)
8.     base_model_state_dict = base_model.state_dict()
9.     lora_model = AdapterV2GPT.from_name(name, **kwargs, adapter_start_layer=0)
10.     keys = lora_model.load_state_dict(base_model_state_dict, strict=False)
11.     assert not keys.unexpected_keys
12.     for k in keys.missing_keys:
13.         assert adapter_filter(k, None)
14.
15. test_base_model_can_be_adapter_v2_loaded('stablelm-base-alpha-3b')

Question: How many times will the loop on line 12 execute when 'test_base_model_can_be_adapter_v2_loaded('stablelm-base-alpha-3b')' is called?

Answer: 22


def a1_to_rowcol(label):
    """Translates a cell's address in A1 notation to a tuple of integers.

    :param str label: A cell label in A1 notation, e.g. 'B1'.
        Letter case is ignored.
    :returns: a tuple containing `row` and `column` numbers. Both indexed
              from 1 (one).
    :rtype: tuple

    Example:

    >>> a1_to_rowcol('A1')
    (1, 1)

    """
    m = CELL_ADDR_RE.match(label) # [STATE] m = <re.Match object; span=(0, 2), match='B1'> [/STATE]
    if m:
        column_label = m.group(1).upper() # [STATE] column_label = 'B' [/STATE]
        row = int(m.group(2)) # [STATE] row = 1 [/STATE]

        col = 0 # [STATE] col = 0 [/STATE]
        for i, c in enumerate(reversed(column_label)): #  [STATE] 1 [/STATE]
            col += (ord(c) - MAGIC_NUMBER) * (26**i) # [STATE] col = 2 [/STATE]
    else:
        raise IncorrectCellLabel(label)

    return (row, col)

a1_to_rowcol('B1')

1. def a1_to_rowcol(label):
2.     """Translates a cell's address in A1 notation to a tuple of integers.
3.
4.     :param str label: A cell label in A1 notation, e.g. 'B1'.
5.         Letter case is ignored.
6.     :returns: a tuple containing `row` and `column` numbers. Both indexed
7.               from 1 (one).
8.     :rtype: tuple
9.
10.     Example:
11.
12.     >>> a1_to_rowcol('A1')
13.     (1, 1)
14.
15.     """
16.     m = CELL_ADDR_RE.match(label)
17.     if m:
18.         column_label = m.group(1).upper()
19.         row = int(m.group(2))
20.
21.         col = 0
22.         for i, c in enumerate(reversed(column_label)):
23.             col += (ord(c) - MAGIC_NUMBER) * (26**i)
24.     else:
25.         raise IncorrectCellLabel(label)
26.
27.     return (row, col)
28.
29. a1_to_rowcol('B1')

Question: How many times will the loop on line 22 execute when 'a1_to_rowcol('B1')' is called?

Answer: 1


def _a1_to_rowcol_unbounded(label):
    """Translates a cell's address in A1 notation to a tuple of integers.

    Same as `a1_to_rowcol()` but allows for missing row or column part
    (e.g. "A" for the first column)

    :returns: a tuple containing `row` and `column` numbers. Both indexed
        from 1 (one).
    :rtype: tuple

    Example:

    >>> _a1_to_rowcol_unbounded('A1')
    (1, 1)

    >>> _a1_to_rowcol_unbounded('A')
    (inf, 1)

    >>> _a1_to_rowcol_unbounded('1')
    (1, inf)

    >>> _a1_to_rowcol_unbounded('ABC123')
    (123, 731)

    >>> _a1_to_rowcol_unbounded('ABC')
    (inf, 731)

    >>> _a1_to_rowcol_unbounded('123')
    (123, inf)

    >>> _a1_to_rowcol_unbounded('1A')
    Traceback (most recent call last):
        ...
    gspread.exceptions.IncorrectCellLabel: 1A

    >>> _a1_to_rowcol_unbounded('')
    (inf, inf)

    """
    m = A1_ADDR_ROW_COL_RE.match(label) # [STATE] m = <re.Match object; span=(0, 2), match='A1'> [/STATE]
    if m:
        column_label, row = m.groups() # [STATE] column_label = 'A' [/STATE] # [STATE] row = '1' [/STATE]

        if column_label:
            col = 0 # [STATE] col = 0 [/STATE]
            for i, c in enumerate(reversed(column_label.upper())): #  [STATE] 1 [/STATE]
                col += (ord(c) - MAGIC_NUMBER) * (26**i) # [STATE] col = 1 [/STATE]
        else:
            col = inf

        if row:
            row = int(row) # [STATE] row = 1 [/STATE]
        else:
            row = inf
    else:
        raise IncorrectCellLabel(label)

    return (row, col)

_a1_to_rowcol_unbounded('A1')

1. def _a1_to_rowcol_unbounded(label):
2.     """Translates a cell's address in A1 notation to a tuple of integers.
3.
4.     Same as `a1_to_rowcol()` but allows for missing row or column part
5.     (e.g. "A" for the first column)
6.
7.     :returns: a tuple containing `row` and `column` numbers. Both indexed
8.         from 1 (one).
9.     :rtype: tuple
10.
11.     Example:
12.
13.     >>> _a1_to_rowcol_unbounded('A1')
14.     (1, 1)
15.
16.     >>> _a1_to_rowcol_unbounded('A')
17.     (inf, 1)
18.
19.     >>> _a1_to_rowcol_unbounded('1')
20.     (1, inf)
21.
22.     >>> _a1_to_rowcol_unbounded('ABC123')
23.     (123, 731)
24.
25.     >>> _a1_to_rowcol_unbounded('ABC')
26.     (inf, 731)
27.
28.     >>> _a1_to_rowcol_unbounded('123')
29.     (123, inf)
30.
31.     >>> _a1_to_rowcol_unbounded('1A')
32.     Traceback (most recent call last):
33.         ...
34.     gspread.exceptions.IncorrectCellLabel: 1A
35.
36.     >>> _a1_to_rowcol_unbounded('')
37.     (inf, inf)
38.
39.     """
40.     m = A1_ADDR_ROW_COL_RE.match(label)
41.     if m:
42.         column_label, row = m.groups()
43.
44.         if column_label:
45.             col = 0
46.             for i, c in enumerate(reversed(column_label.upper())):
47.                 col += (ord(c) - MAGIC_NUMBER) * (26**i)
48.         else:
49.             col = inf
50.
51.         if row:
52.             row = int(row)
53.         else:
54.             row = inf
55.     else:
56.         raise IncorrectCellLabel(label)
57.
58.     return (row, col)
59.
60. _a1_to_rowcol_unbounded('A1')

Question: How many times will the loop on line 46 execute when '_a1_to_rowcol_unbounded('A1')' is called?

Answer: 1


def compute_loc(idx, shape):
    loc = [0] * len(shape) # [STATE] loc = [0, 0] [/STATE]
    for i in range(len(shape)): #  [STATE] 2 [/STATE]
        prod = int(np.prod(shape[i + 1:])) #  [STATE] prod = 4 [/STATE] [STATE] prod = 1 [/STATE]
        loc[i] = idx // prod
        idx = idx % prod
    return tuple(loc)

compute_loc(0, (2, 4))

1. def compute_loc(idx, shape):
2.     loc = [0] * len(shape)
3.     for i in range(len(shape)):
4.         prod = int(np.prod(shape[i + 1:]))
5.         loc[i] = idx // prod
6.         idx = idx % prod
7.     return tuple(loc)
8.
9. compute_loc(0, (2, 4))

Question: How many times will the loop on line 3 execute when 'compute_loc(0, (2, 4))' is called?

Answer: 2


def deep_extend(*args):
        result = None # [STATE] result = None [/STATE]
        for arg in args: #  [STATE] 2 [/STATE]
            if isinstance(arg, dict):
                if not isinstance(result, dict):
                    result = {} # [STATE] result = {} [/STATE]
                for key in arg: #  [STATE] 12 [/STATE]
                    result[key] = Exchange.deep_extend(result[key] if key in result else None, arg[key]) #  [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3', 'v1': 'https://testnet.binance.vision/api/v1'} [/STATE] [STATE] result = {'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3', 'v1': 'https://testnet.binance.vision/api/v1', 'ws': {'spot': 'wss://testnet.binance.vision/ws', 'margin': 'wss://testnet.binance.vision/ws', 'future': 'wss://fstream.binancefuture.com/ws', 'delivery': 'wss://dstream.binancefuture.com/ws', 'ws': 'wss://testnet.binance.vision/ws-api/v3'}} [/STATE]
            else:
                result = arg
        return result

deep_extend(({'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3', 'v1': 'https://testnet.binance.vision/api/v1'}, {'ws': {'spot': 'wss://testnet.binance.vision/ws', 'margin': 'wss://testnet.binance.vision/ws', 'future': 'wss://fstream.binancefuture.com/ws', 'delivery': 'wss://dstream.binancefuture.com/ws', 'ws': 'wss://testnet.binance.vision/ws-api/v3'}}))

1. def deep_extend(*args):
2.         result = None
3.         for arg in args:
4.             if isinstance(arg, dict):
5.                 if not isinstance(result, dict):
6.                     result = {}
7.                 for key in arg:
8.                     result[key] = Exchange.deep_extend(result[key] if key in result else None, arg[key])
9.             else:
10.                 result = arg
11.         return result
12.
13. deep_extend(({'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3', 'v1': 'https://testnet.binance.vision/api/v1'}, {'ws': {'spot': 'wss://testnet.binance.vision/ws', 'margin': 'wss://testnet.binance.vision/ws', 'future': 'wss://fstream.binancefuture.com/ws', 'delivery': 'wss://dstream.binancefuture.com/ws', 'ws': 'wss://testnet.binance.vision/ws-api/v3'}}))

Question: How many times will the loop on line 7 execute when 'deep_extend(({'dapiPublic': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivate': 'https://testnet.binancefuture.com/dapi/v1', 'dapiPrivateV2': 'https://testnet.binancefuture.com/dapi/v2', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublicV2': 'https://testnet.binancefuture.com/fapi/v2', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivateV2': 'https://testnet.binancefuture.com/fapi/v2', 'public': 'https://testnet.binance.vision/api/v3', 'private': 'https://testnet.binance.vision/api/v3', 'v1': 'https://testnet.binance.vision/api/v1'}, {'ws': {'spot': 'wss://testnet.binance.vision/ws', 'margin': 'wss://testnet.binance.vision/ws', 'future': 'wss://fstream.binancefuture.com/ws', 'delivery': 'wss://dstream.binancefuture.com/ws', 'ws': 'wss://testnet.binance.vision/ws-api/v3'}}))' is called?

Answer: 12


def extend(*args):
        if args is not None:
            result = None # [STATE] result = None [/STATE]
            if type(args[0]) is collections.OrderedDict:
                result = collections.OrderedDict()
            else:
                result = {} # [STATE] result = {} [/STATE]
            for arg in args: #  [STATE] 2 [/STATE]
                result.update(arg) #  [STATE] result = {'ETH': 'ERC20', 'TRX': 'TRC20', 'BNB': 'BEP2', 'BSC': 'BEP20', 'OMNI': 'OMNI', 'EOS': 'EOS', 'SOL': 'SPL'} [/STATE] [STATE] result = {'ETH': 'ERC20', 'TRX': 'TRC20', 'BNB': 'BEP2', 'BSC': 'BEP20', 'OMNI': 'OMNI', 'EOS': 'EOS', 'SOL': 'SPL', 'tronscan.org': 'TRC20', 'etherscan.io': 'ERC20', 'bscscan.com': 'BSC', 'explorer.binance.org': 'BEP2', 'bithomp.com': 'XRP', 'bloks.io': 'EOS', 'stellar.expert': 'XLM', 'blockchair.com/bitcoin': 'BTC', 'blockchair.com/bitcoin-cash': 'BCH', 'blockchair.com/ecash': 'XEC', 'explorer.litecoin.net': 'LTC', 'explorer.avax.network': 'AVAX', 'solscan.io': 'SOL', 'polkadot.subscan.io': 'DOT', 'dashboard.internetcomputer.org': 'ICP', 'explorer.chiliz.com': 'CHZ', 'cardanoscan.io': 'ADA', 'mainnet.theoan.com': 'AION', 'algoexplorer.io': 'ALGO', 'explorer.ambrosus.com': 'AMB', 'viewblock.io/zilliqa': 'ZIL', 'viewblock.io/arweave': 'AR', 'explorer.ark.io': 'ARK', 'atomscan.com': 'ATOM', 'www.mintscan.io': 'CTK', 'explorer.bitcoindiamond.org': 'BCD', 'btgexplorer.com': 'BTG', 'bts.ai': 'BTS', 'explorer.celo.org': 'CELO', 'explorer.nervos.org': 'CKB', 'cerebro.cortexlabs.ai': 'CTXC', 'chainz.cryptoid.info': 'VIA', 'explorer.dcrdata.org': 'DCR', 'digiexplorer.info': 'DGB', 'dock.subscan.io': 'DOCK', 'dogechain.info': 'DOGE', 'explorer.elrond.com': 'EGLD', 'blockscout.com': 'ETC', 'explore-fetchhub.fetch.ai': 'FET', 'filfox.info': 'FIL', 'fio.bloks.io': 'FIO', 'explorer.firo.org': 'FIRO', 'neoscan.io': 'NEO', 'ftmscan.com': 'FTM', 'explorer.gochain.io': 'GO', 'block.gxb.io': 'GXS', 'hash-hash.info': 'HBAR', 'www.hiveblockexplorer.com': 'HIVE', 'explorer.helium.com': 'HNT', 'tracker.icon.foundation': 'ICX', 'www.iostabc.com': 'IOST', 'explorer.iota.org': 'IOTA', 'iotexscan.io': 'IOTX', 'irishub.iobscan.io': 'IRIS', 'kava.mintscan.io': 'KAVA', 'scope.klaytn.com': 'KLAY', 'kmdexplorer.io': 'KMD', 'kusama.subscan.io': 'KSM', 'explorer.lto.network': 'LTO', 'polygonscan.com': 'POLYGON', 'explorer.ont.io': 'ONT', 'minaexplorer.com': 'MINA', 'nanolooker.com': 'NANO', 'explorer.nebulas.io': 'NAS', 'explorer.nbs.plus': 'NBS', 'explorer.nebl.io': 'NEBL', 'nulscan.io': 'NULS', 'nxscan.com': 'NXS', 'explorer.harmony.one': 'ONE', 'explorer.poa.network': 'POA', 'qtum.info': 'QTUM', 'explorer.rsk.co': 'RSK', 'www.oasisscan.com': 'ROSE', 'ravencoin.network': 'RVN', 'sc.tokenview.com': 'SC', 'secretnodes.com': 'SCRT', 'explorer.skycoin.com': 'SKY', 'steemscan.com': 'STEEM', 'explorer.stacks.co': 'STX', 'www.thetascan.io': 'THETA', 'scan.tomochain.com': 'TOMO', 'explore.vechain.org': 'VET', 'explorer.vite.net': 'VITE', 'www.wanscan.org': 'WAN', 'wavesexplorer.com': 'WAVES', 'wax.eosx.io': 'WAXP', 'waltonchain.pro': 'WTC', 'chain.nem.ninja': 'XEM', 'verge-blockchain.info': 'XVG', 'explorer.yoyow.org': 'YOYOW', 'explorer.zcha.in': 'ZEC', 'explorer.zensystem.io': 'ZEN'} [/STATE]
            return result
        return {}

extend(({'ETH': 'ERC20', 'TRX': 'TRC20', 'BNB': 'BEP2', 'BSC': 'BEP20', 'OMNI': 'OMNI', 'EOS': 'EOS', 'SOL': 'SPL'}, {'tronscan.org': 'TRC20', 'etherscan.io': 'ERC20', 'bscscan.com': 'BSC', 'explorer.binance.org': 'BEP2', 'bithomp.com': 'XRP', 'bloks.io': 'EOS', 'stellar.expert': 'XLM', 'blockchair.com/bitcoin': 'BTC', 'blockchair.com/bitcoin-cash': 'BCH', 'blockchair.com/ecash': 'XEC', 'explorer.litecoin.net': 'LTC', 'explorer.avax.network': 'AVAX', 'solscan.io': 'SOL', 'polkadot.subscan.io': 'DOT', 'dashboard.internetcomputer.org': 'ICP', 'explorer.chiliz.com': 'CHZ', 'cardanoscan.io': 'ADA', 'mainnet.theoan.com': 'AION', 'algoexplorer.io': 'ALGO', 'explorer.ambrosus.com': 'AMB', 'viewblock.io/zilliqa': 'ZIL', 'viewblock.io/arweave': 'AR', 'explorer.ark.io': 'ARK', 'atomscan.com': 'ATOM', 'www.mintscan.io': 'CTK', 'explorer.bitcoindiamond.org': 'BCD', 'btgexplorer.com': 'BTG', 'bts.ai': 'BTS', 'explorer.celo.org': 'CELO', 'explorer.nervos.org': 'CKB', 'cerebro.cortexlabs.ai': 'CTXC', 'chainz.cryptoid.info': 'VIA', 'explorer.dcrdata.org': 'DCR', 'digiexplorer.info': 'DGB', 'dock.subscan.io': 'DOCK', 'dogechain.info': 'DOGE', 'explorer.elrond.com': 'EGLD', 'blockscout.com': 'ETC', 'explore-fetchhub.fetch.ai': 'FET', 'filfox.info': 'FIL', 'fio.bloks.io': 'FIO', 'explorer.firo.org': 'FIRO', 'neoscan.io': 'NEO', 'ftmscan.com': 'FTM', 'explorer.gochain.io': 'GO', 'block.gxb.io': 'GXS', 'hash-hash.info': 'HBAR', 'www.hiveblockexplorer.com': 'HIVE', 'explorer.helium.com': 'HNT', 'tracker.icon.foundation': 'ICX', 'www.iostabc.com': 'IOST', 'explorer.iota.org': 'IOTA', 'iotexscan.io': 'IOTX', 'irishub.iobscan.io': 'IRIS', 'kava.mintscan.io': 'KAVA', 'scope.klaytn.com': 'KLAY', 'kmdexplorer.io': 'KMD', 'kusama.subscan.io': 'KSM', 'explorer.lto.network': 'LTO', 'polygonscan.com': 'POLYGON', 'explorer.ont.io': 'ONT', 'minaexplorer.com': 'MINA', 'nanolooker.com': 'NANO', 'explorer.nebulas.io': 'NAS', 'explorer.nbs.plus': 'NBS', 'explorer.nebl.io': 'NEBL', 'nulscan.io': 'NULS', 'nxscan.com': 'NXS', 'explorer.harmony.one': 'ONE', 'explorer.poa.network': 'POA', 'qtum.info': 'QTUM', 'explorer.rsk.co': 'RSK', 'www.oasisscan.com': 'ROSE', 'ravencoin.network': 'RVN', 'sc.tokenview.com': 'SC', 'secretnodes.com': 'SCRT', 'explorer.skycoin.com': 'SKY', 'steemscan.com': 'STEEM', 'explorer.stacks.co': 'STX', 'www.thetascan.io': 'THETA', 'scan.tomochain.com': 'TOMO', 'explore.vechain.org': 'VET', 'explorer.vite.net': 'VITE', 'www.wanscan.org': 'WAN', 'wavesexplorer.com': 'WAVES', 'wax.eosx.io': 'WAXP', 'waltonchain.pro': 'WTC', 'chain.nem.ninja': 'XEM', 'verge-blockchain.info': 'XVG', 'explorer.yoyow.org': 'YOYOW', 'explorer.zcha.in': 'ZEC', 'explorer.zensystem.io': 'ZEN'}))

1. def extend(*args):
2.         if args is not None:
3.             result = None
4.             if type(args[0]) is collections.OrderedDict:
5.                 result = collections.OrderedDict()
6.             else:
7.                 result = {}
8.             for arg in args:
9.                 result.update(arg)
10.             return result
11.         return {}
12.
13. extend(({'ETH': 'ERC20', 'TRX': 'TRC20', 'BNB': 'BEP2', 'BSC': 'BEP20', 'OMNI': 'OMNI', 'EOS': 'EOS', 'SOL': 'SPL'}, {'tronscan.org': 'TRC20', 'etherscan.io': 'ERC20', 'bscscan.com': 'BSC', 'explorer.binance.org': 'BEP2', 'bithomp.com': 'XRP', 'bloks.io': 'EOS', 'stellar.expert': 'XLM', 'blockchair.com/bitcoin': 'BTC', 'blockchair.com/bitcoin-cash': 'BCH', 'blockchair.com/ecash': 'XEC', 'explorer.litecoin.net': 'LTC', 'explorer.avax.network': 'AVAX', 'solscan.io': 'SOL', 'polkadot.subscan.io': 'DOT', 'dashboard.internetcomputer.org': 'ICP', 'explorer.chiliz.com': 'CHZ', 'cardanoscan.io': 'ADA', 'mainnet.theoan.com': 'AION', 'algoexplorer.io': 'ALGO', 'explorer.ambrosus.com': 'AMB', 'viewblock.io/zilliqa': 'ZIL', 'viewblock.io/arweave': 'AR', 'explorer.ark.io': 'ARK', 'atomscan.com': 'ATOM', 'www.mintscan.io': 'CTK', 'explorer.bitcoindiamond.org': 'BCD', 'btgexplorer.com': 'BTG', 'bts.ai': 'BTS', 'explorer.celo.org': 'CELO', 'explorer.nervos.org': 'CKB', 'cerebro.cortexlabs.ai': 'CTXC', 'chainz.cryptoid.info': 'VIA', 'explorer.dcrdata.org': 'DCR', 'digiexplorer.info': 'DGB', 'dock.subscan.io': 'DOCK', 'dogechain.info': 'DOGE', 'explorer.elrond.com': 'EGLD', 'blockscout.com': 'ETC', 'explore-fetchhub.fetch.ai': 'FET', 'filfox.info': 'FIL', 'fio.bloks.io': 'FIO', 'explorer.firo.org': 'FIRO', 'neoscan.io': 'NEO', 'ftmscan.com': 'FTM', 'explorer.gochain.io': 'GO', 'block.gxb.io': 'GXS', 'hash-hash.info': 'HBAR', 'www.hiveblockexplorer.com': 'HIVE', 'explorer.helium.com': 'HNT', 'tracker.icon.foundation': 'ICX', 'www.iostabc.com': 'IOST', 'explorer.iota.org': 'IOTA', 'iotexscan.io': 'IOTX', 'irishub.iobscan.io': 'IRIS', 'kava.mintscan.io': 'KAVA', 'scope.klaytn.com': 'KLAY', 'kmdexplorer.io': 'KMD', 'kusama.subscan.io': 'KSM', 'explorer.lto.network': 'LTO', 'polygonscan.com': 'POLYGON', 'explorer.ont.io': 'ONT', 'minaexplorer.com': 'MINA', 'nanolooker.com': 'NANO', 'explorer.nebulas.io': 'NAS', 'explorer.nbs.plus': 'NBS', 'explorer.nebl.io': 'NEBL', 'nulscan.io': 'NULS', 'nxscan.com': 'NXS', 'explorer.harmony.one': 'ONE', 'explorer.poa.network': 'POA', 'qtum.info': 'QTUM', 'explorer.rsk.co': 'RSK', 'www.oasisscan.com': 'ROSE', 'ravencoin.network': 'RVN', 'sc.tokenview.com': 'SC', 'secretnodes.com': 'SCRT', 'explorer.skycoin.com': 'SKY', 'steemscan.com': 'STEEM', 'explorer.stacks.co': 'STX', 'www.thetascan.io': 'THETA', 'scan.tomochain.com': 'TOMO', 'explore.vechain.org': 'VET', 'explorer.vite.net': 'VITE', 'www.wanscan.org': 'WAN', 'wavesexplorer.com': 'WAVES', 'wax.eosx.io': 'WAXP', 'waltonchain.pro': 'WTC', 'chain.nem.ninja': 'XEM', 'verge-blockchain.info': 'XVG', 'explorer.yoyow.org': 'YOYOW', 'explorer.zcha.in': 'ZEC', 'explorer.zensystem.io': 'ZEN'}))

Question: How many times will the loop on line 8 execute when 'extend(({'ETH': 'ERC20', 'TRX': 'TRC20', 'BNB': 'BEP2', 'BSC': 'BEP20', 'OMNI': 'OMNI', 'EOS': 'EOS', 'SOL': 'SPL'}, {'tronscan.org': 'TRC20', 'etherscan.io': 'ERC20', 'bscscan.com': 'BSC', 'explorer.binance.org': 'BEP2', 'bithomp.com': 'XRP', 'bloks.io': 'EOS', 'stellar.expert': 'XLM', 'blockchair.com/bitcoin': 'BTC', 'blockchair.com/bitcoin-cash': 'BCH', 'blockchair.com/ecash': 'XEC', 'explorer.litecoin.net': 'LTC', 'explorer.avax.network': 'AVAX', 'solscan.io': 'SOL', 'polkadot.subscan.io': 'DOT', 'dashboard.internetcomputer.org': 'ICP', 'explorer.chiliz.com': 'CHZ', 'cardanoscan.io': 'ADA', 'mainnet.theoan.com': 'AION', 'algoexplorer.io': 'ALGO', 'explorer.ambrosus.com': 'AMB', 'viewblock.io/zilliqa': 'ZIL', 'viewblock.io/arweave': 'AR', 'explorer.ark.io': 'ARK', 'atomscan.com': 'ATOM', 'www.mintscan.io': 'CTK', 'explorer.bitcoindiamond.org': 'BCD', 'btgexplorer.com': 'BTG', 'bts.ai': 'BTS', 'explorer.celo.org': 'CELO', 'explorer.nervos.org': 'CKB', 'cerebro.cortexlabs.ai': 'CTXC', 'chainz.cryptoid.info': 'VIA', 'explorer.dcrdata.org': 'DCR', 'digiexplorer.info': 'DGB', 'dock.subscan.io': 'DOCK', 'dogechain.info': 'DOGE', 'explorer.elrond.com': 'EGLD', 'blockscout.com': 'ETC', 'explore-fetchhub.fetch.ai': 'FET', 'filfox.info': 'FIL', 'fio.bloks.io': 'FIO', 'explorer.firo.org': 'FIRO', 'neoscan.io': 'NEO', 'ftmscan.com': 'FTM', 'explorer.gochain.io': 'GO', 'block.gxb.io': 'GXS', 'hash-hash.info': 'HBAR', 'www.hiveblockexplorer.com': 'HIVE', 'explorer.helium.com': 'HNT', 'tracker.icon.foundation': 'ICX', 'www.iostabc.com': 'IOST', 'explorer.iota.org': 'IOTA', 'iotexscan.io': 'IOTX', 'irishub.iobscan.io': 'IRIS', 'kava.mintscan.io': 'KAVA', 'scope.klaytn.com': 'KLAY', 'kmdexplorer.io': 'KMD', 'kusama.subscan.io': 'KSM', 'explorer.lto.network': 'LTO', 'polygonscan.com': 'POLYGON', 'explorer.ont.io': 'ONT', 'minaexplorer.com': 'MINA', 'nanolooker.com': 'NANO', 'explorer.nebulas.io': 'NAS', 'explorer.nbs.plus': 'NBS', 'explorer.nebl.io': 'NEBL', 'nulscan.io': 'NULS', 'nxscan.com': 'NXS', 'explorer.harmony.one': 'ONE', 'explorer.poa.network': 'POA', 'qtum.info': 'QTUM', 'explorer.rsk.co': 'RSK', 'www.oasisscan.com': 'ROSE', 'ravencoin.network': 'RVN', 'sc.tokenview.com': 'SC', 'secretnodes.com': 'SCRT', 'explorer.skycoin.com': 'SKY', 'steemscan.com': 'STEEM', 'explorer.stacks.co': 'STX', 'www.thetascan.io': 'THETA', 'scan.tomochain.com': 'TOMO', 'explore.vechain.org': 'VET', 'explorer.vite.net': 'VITE', 'www.wanscan.org': 'WAN', 'wavesexplorer.com': 'WAVES', 'wax.eosx.io': 'WAXP', 'waltonchain.pro': 'WTC', 'chain.nem.ninja': 'XEM', 'verge-blockchain.info': 'XVG', 'explorer.yoyow.org': 'YOYOW', 'explorer.zcha.in': 'ZEC', 'explorer.zensystem.io': 'ZEN'}))' is called?

Answer: 2


def dict_to_ini_section(ini_dict, section_header):
    section_str = f'[{section_header}]\n' # [STATE] section_str = '[profile service_global_only]\n' [/STATE]
    for key, value in ini_dict.items(): #  [STATE] 4 [/STATE]
        if isinstance(value, dict):
            section_str += f"{key} =\n"
            for new_key, new_value in value.items():
                section_str += f"  {new_key}={new_value}\n"
        else:
            section_str += f"{key}={value}\n" #  [STATE] section_str = '[profile service_global_only]\naws_access_key_id=123\n' [/STATE] [STATE] section_str = '[profile service_global_only]\naws_access_key_id=123\naws_secret_access_key=456\n' [/STATE] [STATE] section_str = '[profile service_global_only]\naws_access_key_id=123\naws_secret_access_key=456\nregion=fake-region-10\n' [/STATE] [STATE] section_str = '[profile service_global_only]\naws_access_key_id=123\naws_secret_access_key=456\nregion=fake-region-10\nendpoint_url=https://global.endpoint.aws\n' [/STATE]
    return section_str + "\n"

dict_to_ini_section({'aws_access_key_id': '123', 'aws_secret_access_key': '456', 'region': 'fake-region-10', 'endpoint_url': 'https://global.endpoint.aws'}, 'profile service_global_only')

1. def dict_to_ini_section(ini_dict, section_header):
2.     section_str = f'[{section_header}]\n'
3.     for key, value in ini_dict.items():
4.         if isinstance(value, dict):
5.             section_str += f"{key} =\n"
6.             for new_key, new_value in value.items():
7.                 section_str += f"  {new_key}={new_value}\n"
8.         else:
9.             section_str += f"{key}={value}\n"
10.     return section_str + "\n"
11.
12. dict_to_ini_section({'aws_access_key_id': '123', 'aws_secret_access_key': '456', 'region': 'fake-region-10', 'endpoint_url': 'https://global.endpoint.aws'}, 'profile service_global_only')

Question: How many times will the loop on line 3 execute when 'dict_to_ini_section({'aws_access_key_id': '123', 'aws_secret_access_key': '456', 'region': 'fake-region-10', 'endpoint_url': 'https://global.endpoint.aws'}, 'profile service_global_only')' is called?

Answer: 4


def parse(lines):
    info = [] # [STATE] info = [] [/STATE]
    for line in lines: #  [STATE] 7 [/STATE]
        if not line.strip():
            continue
        raw_info = parse_line(line) #  [STATE] raw_info = {'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}} [/STATE] [STATE] raw_info = {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}} [/STATE] [STATE] raw_info = {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}} [/STATE] [STATE] raw_info = {'basic': {'name': 'pub', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1506690780.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub'}} [/STATE] [STATE] raw_info = {'basic': {'name': 'robots.txt', 'is_dir': False}, 'details': {'size': 26, 'type': 2, 'modified': 1267660800.0}, 'access': {'permissions': ['g_r', 'o_r', 'u_r', 'u_w'], 'user': '0', 'group': '0'}, 'ftp': {'ls': '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt'}} [/STATE] [STATE] raw_info = {'basic': {'name': 'test', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1507107900.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': 'foo', 'group': 'bar'}, 'ftp': {'ls': 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test'}} [/STATE] [STATE] raw_info = {'basic': {'name': '240485', 'is_dir': True}, 'details': {'size': 0, 'type': 1, 'modified': 1483617540.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': 'foo-user', 'group': 'foo-group'}, 'ftp': {'ls': 'drwxr-xr-x   2 foo-user foo-group         0 Jan  5 11:59 240485'}} [/STATE]
        if raw_info is not None:
            info.append(raw_info) #  [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}, {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}, {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}}, {'basic': {'name': 'pub', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1506690780.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}, {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}}, {'basic': {'name': 'pub', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1506690780.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub'}}, {'basic': {'name': 'robots.txt', 'is_dir': False}, 'details': {'size': 26, 'type': 2, 'modified': 1267660800.0}, 'access': {'permissions': ['g_r', 'o_r', 'u_r', 'u_w'], 'user': '0', 'group': '0'}, 'ftp': {'ls': '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}, {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}}, {'basic': {'name': 'pub', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1506690780.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub'}}, {'basic': {'name': 'robots.txt', 'is_dir': False}, 'details': {'size': 26, 'type': 2, 'modified': 1267660800.0}, 'access': {'permissions': ['g_r', 'o_r', 'u_r', 'u_w'], 'user': '0', 'group': '0'}, 'ftp': {'ls': '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt'}}, {'basic': {'name': 'test', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1507107900.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': 'foo', 'group': 'bar'}, 'ftp': {'ls': 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test'}}] [/STATE] [STATE] info = [{'basic': {'name': 'debian', 'is_dir': True}, 'details': {'size': 19, 'type': 1, 'modified': 1137542400.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian'}}, {'basic': {'name': 'debian-archive', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1501752060.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive'}}, {'basic': {'name': 'debian-backports', 'is_dir': True}, 'details': {'size': 27, 'type': 1, 'modified': 1448841600.0}, 'access': {'permissions': ['g_r', 'g_w', 'g_x', 'o_r', 'o_w', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports'}}, {'basic': {'name': 'pub', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1506690780.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': '0', 'group': '0'}, 'ftp': {'ls': 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub'}}, {'basic': {'name': 'robots.txt', 'is_dir': False}, 'details': {'size': 26, 'type': 2, 'modified': 1267660800.0}, 'access': {'permissions': ['g_r', 'o_r', 'u_r', 'u_w'], 'user': '0', 'group': '0'}, 'ftp': {'ls': '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt'}}, {'basic': {'name': 'test', 'is_dir': True}, 'details': {'size': 4096, 'type': 1, 'modified': 1507107900.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': 'foo', 'group': 'bar'}, 'ftp': {'ls': 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test'}}, {'basic': {'name': '240485', 'is_dir': True}, 'details': {'size': 0, 'type': 1, 'modified': 1483617540.0}, 'access': {'permissions': ['g_r', 'g_x', 'o_r', 'o_x', 'u_r', 'u_w', 'u_x'], 'user': 'foo-user', 'group': 'foo-group'}, 'ftp': {'ls': 'drwxr-xr-x   2 foo-user foo-group         0 Jan  5 11:59 240485'}}] [/STATE]
    return info

parse(['lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian', 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive', 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports', 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub', '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt', 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test', 'drwxr-xr-x   2 foo-user foo-group         0 Jan  5 11:59 240485'])

1. def parse(lines):
2.     info = []
3.     for line in lines:
4.         if not line.strip():
5.             continue
6.         raw_info = parse_line(line)
7.         if raw_info is not None:
8.             info.append(raw_info)
9.     return info
10.
11. parse(['lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian', 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive', 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports', 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub', '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt', 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test', 'drwxr-xr-x   2 foo-user foo-group         0 Jan  5 11:59 240485'])

Question: How many times will the loop on line 3 execute when 'parse(['lrwxrwxrwx    1 0        0              19 Jan 18  2006 debian -> ./pub/mirror/debian', 'drwxr-xr-x   10 0        0            4096 Aug 03 09:21 debian-archive', 'lrwxrwxrwx    1 0        0              27 Nov 30  2015 debian-backports -> pub/mirror/debian-backports', 'drwxr-xr-x   12 0        0            4096 Sep 29 13:13 pub', '-rw-r--r--    1 0        0              26 Mar 04  2010 robots.txt', 'drwxr-xr-x   8 foo      bar          4096 Oct  4 09:05 test', 'drwxr-xr-x   2 foo-user foo-group         0 Jan  5 11:59 240485'])' is called?

Answer: 7


def _is_ascii(s):
    if isinstance(s, str):
        for c in s: #  [STATE] 11 [/STATE]
            if ord(c) > 255:
                return False
        return True
    return _supports_unicode(s)

_is_ascii(' 123456789#')

1. def _is_ascii(s):
2.     if isinstance(s, str):
3.         for c in s:
4.             if ord(c) > 255:
5.                 return False
6.         return True
7.     return _supports_unicode(s)
8.
9. _is_ascii(' 123456789#')

Question: How many times will the loop on line 3 execute when '_is_ascii(' 123456789#')' is called?

Answer: 11