prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Memset provider: TypeError: string indices must be integers
  Hi,
  
  When using the Memset provider with the default table formatting I get this error:
  
  ```bash
  $ lexicon memset create example.com TXT --name _acme-challenge.example.com --content BLAH --ttl 300
  Traceback (most recent call last):
    File "/usr/local/bin/lexicon", line 11, in <module>
      sys.exit(main())
    File "/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py", line 133, in main
      handle_output(results, parsed_args.output)
    File "/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py", line 109, in handle_output
      table = generate_table_result(logger, results, output_type == 'TABLE-NO-HEADER')
    File "/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py", line 75, in generate_table_result
      array = [[row['id'], row['type'], row['name'], row['content'], row['ttl']] for row in output]
  TypeError: string indices must be integers
  ```
  
  I think this is because `output` is a string not an array - when I added `print output` I got a string like `969f9caabe19859c11249333dd80aa15`.
  
  When I use `--output JSON` I get the same ID plus quotes:
  
  ```bash
  $ lexicon memset create example.com TXT --name _acme-challenge.example.com --content BLAH --ttl 300 --output JSON
  "969f9caabe19859c11249333dd80aa15"
  ```
  
  I know Memset's not public so if you need any help to test it just let me know. For now I'll work around it with `--output QUIET` since I don't really care about the output here.
  
  Thanks!
  Dave
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `lexicon/cli.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 """Module for Lexicon command-line interface"""
  3 from __future__ import absolute_import, print_function
  4 import json
  5 import logging
  6 import os
  7 import sys
  8 
  9 from lexicon.client import Client
  10 from lexicon.config import ConfigResolver
  11 from lexicon.parser import generate_cli_main_parser
  12 
  13 
  14 logger = logging.getLogger(__name__)  # pylint: disable=C0103
  15 
  16 
  17 def generate_table_result(lexicon_logger, output=None, without_header=None):
  18     """Convert returned JSON into a nice table for command line usage"""
  19     try:
  20         _ = (entry for entry in output)
  21     except TypeError:
  22         lexicon_logger.debug('Command output is not iterable, and then cannot '
  23                              'be printed with --quiet parameter not enabled.')
  24         return None
  25 
  26     array = [[
  27         row.get('id', ''),
  28         row.get('type', ''),
  29         row.get('name', ''),
  30         row.get('content', ''),
  31         row.get('ttl', '')] for row in output]
  32 
  33     # Insert header (insert before calculating the max width of each column
  34     # to take headers size into account)
  35     if not without_header:
  36         headers = ['ID', 'TYPE', 'NAME', 'CONTENT', 'TTL']
  37         array.insert(0, headers)
  38 
  39     column_widths = [0, 0, 0, 0, 0]
  40     # Find max width for each column
  41     for row in array:
  42         for idx, col in enumerate(row):
  43             width = len(str(col))
  44             if width > column_widths[idx]:
  45                 column_widths[idx] = width
  46 
  47     # Add a 'nice' separator
  48     if not without_header:
  49         array.insert(1, ['-' * column_widths[idx]
  50                          for idx in range(len(column_widths))])
  51 
  52     # Construct table to be printed
  53     table = []
  54     for row in array:
  55         row_list = []
  56         for idx, col in enumerate(row):
  57             row_list.append(str(col).ljust(column_widths[idx]))
  58         table.append(' '.join(row_list))
  59 
  60     # Return table
  61     return '\n'.join(table)
  62 
  63 
  64 def handle_output(results, output_type):
  65     """Print the relevant output for given output_type"""
  66     if not output_type == 'QUIET':
  67         if not output_type == 'JSON':
  68             table = generate_table_result(
  69                 logger, results, output_type == 'TABLE-NO-HEADER')
  70             if table:
  71                 print(table)
  72         else:
  73             try:
  74                 _ = (entry for entry in results)
  75                 json_str = json.dumps(results)
  76                 if json_str:
  77                     print(json_str)
  78             except TypeError:
  79                 logger.debug('Output is not a JSON, and then cannot '
  80                              'be printed with --output=JSON parameter.')
  81 
  82 
  83 def main():
  84     """Main function of Lexicon."""
  85     # Dynamically determine all the providers available and gather command line arguments.
  86     parsed_args = generate_cli_main_parser().parse_args()
  87 
  88     log_level = logging.getLevelName(parsed_args.log_level)
  89     logging.basicConfig(stream=sys.stdout, level=log_level,
  90                         format='%(message)s')
  91     logger.debug('Arguments: %s', parsed_args)
  92 
  93     # In the CLI context, will get configuration interactively:
  94     #   * from the command line
  95     #   * from the environment variables
  96     #   * from lexicon configuration files in working directory
  97     config = ConfigResolver()
  98     config.with_args(parsed_args).with_env().with_config_dir(os.getcwd())
  99 
  100     client = Client(config)
  101 
  102     results = client.execute()
  103 
  104     handle_output(results, parsed_args.output)
  105 
  106 
  107 if __name__ == '__main__':
  108     main()
  109
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/lexicon/cli.py b/lexicon/cli.py
  --- a/lexicon/cli.py
  +++ b/lexicon/cli.py
  @@ -14,12 +14,10 @@
   logger = logging.getLogger(__name__)  # pylint: disable=C0103
   
   
  -def generate_table_result(lexicon_logger, output=None, without_header=None):
  -    """Convert returned JSON into a nice table for command line usage"""
  -    try:
  -        _ = (entry for entry in output)
  -    except TypeError:
  -        lexicon_logger.debug('Command output is not iterable, and then cannot '
  +def generate_list_table_result(lexicon_logger, output=None, without_header=None):
  +    """Convert returned data from list actions into a nice table for command line usage"""
  +    if not isinstance(output, list):
  +        lexicon_logger.debug('Command output is not a list, and then cannot '
                                'be printed with --quiet parameter not enabled.')
           return None
   
  @@ -58,26 +56,43 @@
           table.append(' '.join(row_list))
   
       # Return table
  -    return '\n'.join(table)
  +    return os.linesep.join(table)
   
   
  -def handle_output(results, output_type):
  +def generate_table_results(output=None, without_header=None):
  +    """Convert returned data from non-list actions into a nice table for command line usage"""
  +    array = []
  +    str_output = str(output)
  +
  +    if not without_header:
  +        array.append('RESULT')
  +        array.append('-' * max(6, len(str_output)))
  +
  +    array.append(str_output)
  +    return os.linesep.join(array)
  +
  +
  +def handle_output(results, output_type, action):
       """Print the relevant output for given output_type"""
  -    if not output_type == 'QUIET':
  -        if not output_type == 'JSON':
  -            table = generate_table_result(
  +    if output_type == 'QUIET':
  +        return
  +
  +    if not output_type == 'JSON':
  +        if action == 'list':
  +            table = generate_list_table_result(
                   logger, results, output_type == 'TABLE-NO-HEADER')
  -            if table:
  -                print(table)
           else:
  -            try:
  -                _ = (entry for entry in results)
  -                json_str = json.dumps(results)
  -                if json_str:
  -                    print(json_str)
  -            except TypeError:
  -                logger.debug('Output is not a JSON, and then cannot '
  -                             'be printed with --output=JSON parameter.')
  +            table = generate_table_results(results, output_type == 'TABLE-NO-HEADER')
  +        if table:
  +            print(table)
  +    else:
  +        try:
  +            json_str = json.dumps(results)
  +            if json_str:
  +                print(json_str)
  +        except TypeError:
  +            logger.debug('Output is not JSON serializable, and then cannot '
  +                         'be printed with --output=JSON parameter.')
   
   
   def main():
  @@ -101,7 +116,7 @@
   
       results = client.execute()
   
  -    handle_output(results, parsed_args.output)
  +    handle_output(results, parsed_args.output, config.resolve('lexicon:action'))
   
   
   if __name__ == '__main__':
  
verification_info: {"golden_diff": "diff --git a/lexicon/cli.py b/lexicon/cli.py\n--- a/lexicon/cli.py\n+++ b/lexicon/cli.py\n@@ -14,12 +14,10 @@\n logger = logging.getLogger(__name__)  # pylint: disable=C0103\n \n \n-def generate_table_result(lexicon_logger, output=None, without_header=None):\n-    \"\"\"Convert returned JSON into a nice table for command line usage\"\"\"\n-    try:\n-        _ = (entry for entry in output)\n-    except TypeError:\n-        lexicon_logger.debug('Command output is not iterable, and then cannot '\n+def generate_list_table_result(lexicon_logger, output=None, without_header=None):\n+    \"\"\"Convert returned data from list actions into a nice table for command line usage\"\"\"\n+    if not isinstance(output, list):\n+        lexicon_logger.debug('Command output is not a list, and then cannot '\n                              'be printed with --quiet parameter not enabled.')\n         return None\n \n@@ -58,26 +56,43 @@\n         table.append(' '.join(row_list))\n \n     # Return table\n-    return '\\n'.join(table)\n+    return os.linesep.join(table)\n \n \n-def handle_output(results, output_type):\n+def generate_table_results(output=None, without_header=None):\n+    \"\"\"Convert returned data from non-list actions into a nice table for command line usage\"\"\"\n+    array = []\n+    str_output = str(output)\n+\n+    if not without_header:\n+        array.append('RESULT')\n+        array.append('-' * max(6, len(str_output)))\n+\n+    array.append(str_output)\n+    return os.linesep.join(array)\n+\n+\n+def handle_output(results, output_type, action):\n     \"\"\"Print the relevant output for given output_type\"\"\"\n-    if not output_type == 'QUIET':\n-        if not output_type == 'JSON':\n-            table = generate_table_result(\n+    if output_type == 'QUIET':\n+        return\n+\n+    if not output_type == 'JSON':\n+        if action == 'list':\n+            table = generate_list_table_result(\n                 logger, results, output_type == 'TABLE-NO-HEADER')\n-            if table:\n-                print(table)\n         else:\n-            try:\n-                _ = (entry for entry in results)\n-                json_str = json.dumps(results)\n-                if json_str:\n-                    print(json_str)\n-            except TypeError:\n-                logger.debug('Output is not a JSON, and then cannot '\n-                             'be printed with --output=JSON parameter.')\n+            table = generate_table_results(results, output_type == 'TABLE-NO-HEADER')\n+        if table:\n+            print(table)\n+    else:\n+        try:\n+            json_str = json.dumps(results)\n+            if json_str:\n+                print(json_str)\n+        except TypeError:\n+            logger.debug('Output is not JSON serializable, and then cannot '\n+                         'be printed with --output=JSON parameter.')\n \n \n def main():\n@@ -101,7 +116,7 @@\n \n     results = client.execute()\n \n-    handle_output(results, parsed_args.output)\n+    handle_output(results, parsed_args.output, config.resolve('lexicon:action'))\n \n \n if __name__ == '__main__':\n", "issue": "Memset provider: TypeError: string indices must be integers\nHi,\r\n\r\nWhen using the Memset provider with the default table formatting I get this error:\r\n\r\n```bash\r\n$ lexicon memset create example.com TXT --name _acme-challenge.example.com --content BLAH --ttl 300\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/lexicon\", line 11, in <module>\r\n    sys.exit(main())\r\n  File \"/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py\", line 133, in main\r\n    handle_output(results, parsed_args.output)\r\n  File \"/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py\", line 109, in handle_output\r\n    table = generate_table_result(logger, results, output_type == 'TABLE-NO-HEADER')\r\n  File \"/usr/local/lib/python2.7/dist-packages/lexicon/__main__.py\", line 75, in generate_table_result\r\n    array = [[row['id'], row['type'], row['name'], row['content'], row['ttl']] for row in output]\r\nTypeError: string indices must be integers\r\n```\r\n\r\nI think this is because `output` is a string not an array - when I added `print output` I got a string like `969f9caabe19859c11249333dd80aa15`.\r\n\r\nWhen I use `--output JSON` I get the same ID plus quotes:\r\n\r\n```bash\r\n$ lexicon memset create example.com TXT --name _acme-challenge.example.com --content BLAH --ttl 300 --output JSON\r\n\"969f9caabe19859c11249333dd80aa15\"\r\n```\r\n\r\nI know Memset's not public so if you need any help to test it just let me know. For now I'll work around it with `--output QUIET` since I don't really care about the output here.\r\n\r\nThanks!\r\nDave\n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"Module for Lexicon command-line interface\"\"\"\nfrom __future__ import absolute_import, print_function\nimport json\nimport logging\nimport os\nimport sys\n\nfrom lexicon.client import Client\nfrom lexicon.config import ConfigResolver\nfrom lexicon.parser import generate_cli_main_parser\n\n\nlogger = logging.getLogger(__name__)  # pylint: disable=C0103\n\n\ndef generate_table_result(lexicon_logger, output=None, without_header=None):\n    \"\"\"Convert returned JSON into a nice table for command line usage\"\"\"\n    try:\n        _ = (entry for entry in output)\n    except TypeError:\n        lexicon_logger.debug('Command output is not iterable, and then cannot '\n                             'be printed with --quiet parameter not enabled.')\n        return None\n\n    array = [[\n        row.get('id', ''),\n        row.get('type', ''),\n        row.get('name', ''),\n        row.get('content', ''),\n        row.get('ttl', '')] for row in output]\n\n    # Insert header (insert before calculating the max width of each column\n    # to take headers size into account)\n    if not without_header:\n        headers = ['ID', 'TYPE', 'NAME', 'CONTENT', 'TTL']\n        array.insert(0, headers)\n\n    column_widths = [0, 0, 0, 0, 0]\n    # Find max width for each column\n    for row in array:\n        for idx, col in enumerate(row):\n            width = len(str(col))\n            if width > column_widths[idx]:\n                column_widths[idx] = width\n\n    # Add a 'nice' separator\n    if not without_header:\n        array.insert(1, ['-' * column_widths[idx]\n                         for idx in range(len(column_widths))])\n\n    # Construct table to be printed\n    table = []\n    for row in array:\n        row_list = []\n        for idx, col in enumerate(row):\n            row_list.append(str(col).ljust(column_widths[idx]))\n        table.append(' '.join(row_list))\n\n    # Return table\n    return '\\n'.join(table)\n\n\ndef handle_output(results, output_type):\n    \"\"\"Print the relevant output for given output_type\"\"\"\n    if not output_type == 'QUIET':\n        if not output_type == 'JSON':\n            table = generate_table_result(\n                logger, results, output_type == 'TABLE-NO-HEADER')\n            if table:\n                print(table)\n        else:\n            try:\n                _ = (entry for entry in results)\n                json_str = json.dumps(results)\n                if json_str:\n                    print(json_str)\n            except TypeError:\n                logger.debug('Output is not a JSON, and then cannot '\n                             'be printed with --output=JSON parameter.')\n\n\ndef main():\n    \"\"\"Main function of Lexicon.\"\"\"\n    # Dynamically determine all the providers available and gather command line arguments.\n    parsed_args = generate_cli_main_parser().parse_args()\n\n    log_level = logging.getLevelName(parsed_args.log_level)\n    logging.basicConfig(stream=sys.stdout, level=log_level,\n                        format='%(message)s')\n    logger.debug('Arguments: %s', parsed_args)\n\n    # In the CLI context, will get configuration interactively:\n    #   * from the command line\n    #   * from the environment variables\n    #   * from lexicon configuration files in working directory\n    config = ConfigResolver()\n    config.with_args(parsed_args).with_env().with_config_dir(os.getcwd())\n\n    client = Client(config)\n\n    results = client.execute()\n\n    handle_output(results, parsed_args.output)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lexicon/cli.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"Module for Lexicon command-line interface\"\"\"\nfrom __future__ import absolute_import, print_function\nimport json\nimport logging\nimport os\nimport sys\n\nfrom lexicon.client import Client\nfrom lexicon.config import ConfigResolver\nfrom lexicon.parser import generate_cli_main_parser\n\n\nlogger = logging.getLogger(__name__)  # pylint: disable=C0103\n\n\ndef generate_list_table_result(lexicon_logger, output=None, without_header=None):\n    \"\"\"Convert returned data from list actions into a nice table for command line usage\"\"\"\n    if not isinstance(output, list):\n        lexicon_logger.debug('Command output is not a list, and then cannot '\n                             'be printed with --quiet parameter not enabled.')\n        return None\n\n    array = [[\n        row.get('id', ''),\n        row.get('type', ''),\n        row.get('name', ''),\n        row.get('content', ''),\n        row.get('ttl', '')] for row in output]\n\n    # Insert header (insert before calculating the max width of each column\n    # to take headers size into account)\n    if not without_header:\n        headers = ['ID', 'TYPE', 'NAME', 'CONTENT', 'TTL']\n        array.insert(0, headers)\n\n    column_widths = [0, 0, 0, 0, 0]\n    # Find max width for each column\n    for row in array:\n        for idx, col in enumerate(row):\n            width = len(str(col))\n            if width > column_widths[idx]:\n                column_widths[idx] = width\n\n    # Add a 'nice' separator\n    if not without_header:\n        array.insert(1, ['-' * column_widths[idx]\n                         for idx in range(len(column_widths))])\n\n    # Construct table to be printed\n    table = []\n    for row in array:\n        row_list = []\n        for idx, col in enumerate(row):\n            row_list.append(str(col).ljust(column_widths[idx]))\n        table.append(' '.join(row_list))\n\n    # Return table\n    return os.linesep.join(table)\n\n\ndef generate_table_results(output=None, without_header=None):\n    \"\"\"Convert returned data from non-list actions into a nice table for command line usage\"\"\"\n    array = []\n    str_output = str(output)\n\n    if not without_header:\n        array.append('RESULT')\n        array.append('-' * max(6, len(str_output)))\n\n    array.append(str_output)\n    return os.linesep.join(array)\n\n\ndef handle_output(results, output_type, action):\n    \"\"\"Print the relevant output for given output_type\"\"\"\n    if output_type == 'QUIET':\n        return\n\n    if not output_type == 'JSON':\n        if action == 'list':\n            table = generate_list_table_result(\n                logger, results, output_type == 'TABLE-NO-HEADER')\n        else:\n            table = generate_table_results(results, output_type == 'TABLE-NO-HEADER')\n        if table:\n            print(table)\n    else:\n        try:\n            json_str = json.dumps(results)\n            if json_str:\n                print(json_str)\n        except TypeError:\n            logger.debug('Output is not JSON serializable, and then cannot '\n                         'be printed with --output=JSON parameter.')\n\n\ndef main():\n    \"\"\"Main function of Lexicon.\"\"\"\n    # Dynamically determine all the providers available and gather command line arguments.\n    parsed_args = generate_cli_main_parser().parse_args()\n\n    log_level = logging.getLevelName(parsed_args.log_level)\n    logging.basicConfig(stream=sys.stdout, level=log_level,\n                        format='%(message)s')\n    logger.debug('Arguments: %s', parsed_args)\n\n    # In the CLI context, will get configuration interactively:\n    #   * from the command line\n    #   * from the environment variables\n    #   * from lexicon configuration files in working directory\n    config = ConfigResolver()\n    config.with_args(parsed_args).with_env().with_config_dir(os.getcwd())\n\n    client = Client(config)\n\n    results = client.execute()\n\n    handle_output(results, parsed_args.output, config.resolve('lexicon:action'))\n\n\nif __name__ == '__main__':\n    main()\n", "path": "lexicon/cli.py"}]}