# Buggy code
def get_files_completion(self):
    """Returns a list of filename, progress tuples indicating the progress
    for every file selected using set_selected_files. Progress is a float
    between 0 and 1
    """
    completion = []

    if self.lt_status:
        try:
            files = self.download.handle.get_torrent_info().files()
        except RuntimeError:
            # If we don't have the torrent file yet, we'll get a runtime error
            # stating that we used an invalid handle
            files = []

        for index, byte_progress in enumerate(
            self.download.handle.file_progress(flags=1)
        ):
            current_file = files[index]
            completion.append(
                (current_file.path, float(byte_progress) / current_file.size)
            )

    return completion


# Traceback (TypeError)
ERROR   1521650112.17    rest_manager:53    [Failure instance: Traceback: <type 'exceptions.TypeError'>: 'file_storage' object does not support indexing
/Library/Python/2.7/site-packages/twisted/protocols/basic.py:571:dataReceived
/Library/Python/2.7/site-packages/twisted/web/http.py:1752:lineReceived
/Library/Python/2.7/site-packages/twisted/web/http.py:1845:allContentReceived
/Library/Python/2.7/site-packages/twisted/web/http.py:766:requestReceived
--- <exception caught here> ---
/Library/Python/2.7/site-packages/twisted/web/server.py:190:process
/Library/Python/2.7/site-packages/twisted/web/server.py:241:render
/Library/Python/2.7/site-packages/twisted/web/resource.py:250:render
/Users/martijndevos/Documents/tribler/Tribler/Core/Modules/restapi/downloads_endpoint.py:236:render_GET
/Users/martijndevos/Documents/tribler/Tribler/Core/DownloadState.py:154:get_files_completion
]
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/twisted/web/server.py", line 190, in process
self.render(resrc)
File "/Library/Python/2.7/site-packages/twisted/web/server.py", line 241, in render
body = resrc.render(self)
File "/Library/Python/2.7/site-packages/twisted/web/resource.py", line 250, in render
return m(request)
File "/Users/martijndevos/Documents/tribler/Tribler/Core/Modules/restapi/downloads_endpoint.py", line 236, in render_GET
files_completion = dict((name, progress) for name, progress in state.get_files_completion())
File "/Users/martijndevos/Documents/tribler/Tribler/Core/DownloadState.py", line 154, in get_files_completion
current_file = files[index]
TypeError: 'file_storage' object does not support indexing

# Fixed code
def get_files_completion(self):
    """Returns a list of filename, progress tuples indicating the progress
    for every file selected using set_selected_files. Progress is a float
    between 0 and 1
    """
    completion = []

    if self.lt_status:
        try:
            files = self.download.handle.get_torrent_info().files()
        except RuntimeError:
            # If we don't have the torrent file yet, we'll get a runtime error
            # stating that we used an invalid handle
            files = []

        for index, byte_progress in enumerate(
            self.download.handle.file_progress(flags=1)
        ):
            current_file = files[index] if isinstance(files, list) else files.at(index)
            completion.append(
                (current_file.path, float(byte_progress) / current_file.size)
            )

    return completion