prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  "'dict_keys' object does not support indexing" in Python 3 using sourcecode directive
  When I include a code-block with an option, like this:
  
  ```
  .. sourcecode:: python
     :linenos:
  
     ...
  ```
  
  a WARNING appears and the corresponding file is not processed:
  
  ```
  WARNING: Could not process /home/juanlu/Development/Python/pelican_test/myproject/content/2013-07-14_hello-world.rst
  'dict_keys' object does not support indexing
  ```
  
  The problem is here:
  
  https://github.com/getpelican/pelican/blob/master/pelican/rstdirectives.py#L35
  
  and the solution is detailed here:
  
  http://stackoverflow.com/questions/8953627/python-dictionary-keys-error
  
  I have read the guidelines but, even being a trivial fix:
  
  ```
  --- rstdirectives.py    2013-07-14 12:41:00.188687997 +0200
  +++ rstdirectives.py.new    2013-07-14 12:36:25.982005000 +0200
  @@ -32,7 +32,7 @@
               # no lexer found - use the text one instead of an exception
               lexer = TextLexer()
           # take an arbitrary option if more than one is given
  -        formatter = self.options and VARIANTS[self.options.keys()[0]] \
  +        formatter = self.options and VARIANTS[list(self.options.keys())[0]] \
                       or DEFAULT
           parsed = highlight('\n'.join(self.content), lexer, formatter)
           return [nodes.raw('', parsed, format='html')]
  ```
  
  I don't have time to add docs, tests, run the test suite and, summing up, doing it properly. Hence the issue without pull request.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pelican/rstdirectives.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 from __future__ import unicode_literals, print_function
  3 
  4 from docutils import nodes, utils
  5 from docutils.parsers.rst import directives, roles, Directive
  6 from pygments.formatters import HtmlFormatter
  7 from pygments import highlight
  8 from pygments.lexers import get_lexer_by_name, TextLexer
  9 import re
  10 
  11 INLINESTYLES = False
  12 DEFAULT = HtmlFormatter(noclasses=INLINESTYLES)
  13 VARIANTS = {
  14     'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),
  15 }
  16 
  17 
  18 class Pygments(Directive):
  19     """ Source code syntax hightlighting.
  20     """
  21     required_arguments = 1
  22     optional_arguments = 0
  23     final_argument_whitespace = True
  24     option_spec = dict([(key, directives.flag) for key in VARIANTS])
  25     has_content = True
  26 
  27     def run(self):
  28         self.assert_has_content()
  29         try:
  30             lexer = get_lexer_by_name(self.arguments[0])
  31         except ValueError:
  32             # no lexer found - use the text one instead of an exception
  33             lexer = TextLexer()
  34         # take an arbitrary option if more than one is given
  35         formatter = self.options and VARIANTS[self.options.keys()[0]] \
  36                     or DEFAULT
  37         parsed = highlight('\n'.join(self.content), lexer, formatter)
  38         return [nodes.raw('', parsed, format='html')]
  39 
  40 directives.register_directive('code-block', Pygments)
  41 directives.register_directive('sourcecode', Pygments)
  42 
  43 
  44 class YouTube(Directive):
  45     """ Embed YouTube video in posts.
  46 
  47     Courtesy of Brian Hsu: https://gist.github.com/1422773
  48 
  49     VIDEO_ID is required, with / height are optional integer,
  50     and align could be left / center / right.
  51 
  52     Usage:
  53     .. youtube:: VIDEO_ID
  54         :width: 640
  55         :height: 480
  56         :align: center
  57     """
  58 
  59     def align(argument):
  60         """Conversion function for the "align" option."""
  61         return directives.choice(argument, ('left', 'center', 'right'))
  62 
  63     required_arguments = 1
  64     optional_arguments = 2
  65     option_spec = {
  66         'width': directives.positive_int,
  67         'height': directives.positive_int,
  68         'align': align
  69     }
  70 
  71     final_argument_whitespace = False
  72     has_content = False
  73 
  74     def run(self):
  75         videoID = self.arguments[0].strip()
  76         width = 420
  77         height = 315
  78         align = 'left'
  79 
  80         if 'width' in self.options:
  81             width = self.options['width']
  82 
  83         if 'height' in self.options:
  84             height = self.options['height']
  85 
  86         if 'align' in self.options:
  87             align = self.options['align']
  88 
  89         url = 'http://www.youtube.com/embed/%s' % videoID
  90         div_block = '<div class="youtube" align="%s">' % align
  91         embed_block = '<iframe width="%s" height="%s" src="%s" '\
  92                       'frameborder="0"></iframe>' % (width, height, url)
  93 
  94         return [
  95             nodes.raw('', div_block, format='html'),
  96             nodes.raw('', embed_block, format='html'),
  97             nodes.raw('', '</div>', format='html')]
  98 
  99 directives.register_directive('youtube', YouTube)
  100 
  101 _abbr_re = re.compile('\((.*)\)$')
  102 
  103 
  104 class abbreviation(nodes.Inline, nodes.TextElement):
  105     pass
  106 
  107 
  108 def abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
  109     text = utils.unescape(text)
  110     m = _abbr_re.search(text)
  111     if m is None:
  112         return [abbreviation(text, text)], []
  113     abbr = text[:m.start()].strip()
  114     expl = m.group(1)
  115     return [abbreviation(abbr, abbr, explanation=expl)], []
  116 
  117 roles.register_local_role('abbr', abbr_role)
  118
  ```
  --- 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/pelican/rstdirectives.py b/pelican/rstdirectives.py
  --- a/pelican/rstdirectives.py
  +++ b/pelican/rstdirectives.py
  @@ -32,7 +32,7 @@
               # no lexer found - use the text one instead of an exception
               lexer = TextLexer()
           # take an arbitrary option if more than one is given
  -        formatter = self.options and VARIANTS[self.options.keys()[0]] \
  +        formatter = self.options and VARIANTS[list(self.options.keys())[0]] \
                       or DEFAULT
           parsed = highlight('\n'.join(self.content), lexer, formatter)
           return [nodes.raw('', parsed, format='html')]
  
verification_info: {"golden_diff": "diff --git a/pelican/rstdirectives.py b/pelican/rstdirectives.py\n--- a/pelican/rstdirectives.py\n+++ b/pelican/rstdirectives.py\n@@ -32,7 +32,7 @@\n             # no lexer found - use the text one instead of an exception\n             lexer = TextLexer()\n         # take an arbitrary option if more than one is given\n-        formatter = self.options and VARIANTS[self.options.keys()[0]] \\\n+        formatter = self.options and VARIANTS[list(self.options.keys())[0]] \\\n                     or DEFAULT\n         parsed = highlight('\\n'.join(self.content), lexer, formatter)\n         return [nodes.raw('', parsed, format='html')]\n", "issue": "\"'dict_keys' object does not support indexing\" in Python 3 using sourcecode directive\nWhen I include a code-block with an option, like this:\n\n```\n.. sourcecode:: python\n   :linenos:\n\n   ...\n```\n\na WARNING appears and the corresponding file is not processed:\n\n```\nWARNING: Could not process /home/juanlu/Development/Python/pelican_test/myproject/content/2013-07-14_hello-world.rst\n'dict_keys' object does not support indexing\n```\n\nThe problem is here:\n\nhttps://github.com/getpelican/pelican/blob/master/pelican/rstdirectives.py#L35\n\nand the solution is detailed here:\n\nhttp://stackoverflow.com/questions/8953627/python-dictionary-keys-error\n\nI have read the guidelines but, even being a trivial fix:\n\n```\n--- rstdirectives.py    2013-07-14 12:41:00.188687997 +0200\n+++ rstdirectives.py.new    2013-07-14 12:36:25.982005000 +0200\n@@ -32,7 +32,7 @@\n             # no lexer found - use the text one instead of an exception\n             lexer = TextLexer()\n         # take an arbitrary option if more than one is given\n-        formatter = self.options and VARIANTS[self.options.keys()[0]] \\\n+        formatter = self.options and VARIANTS[list(self.options.keys())[0]] \\\n                     or DEFAULT\n         parsed = highlight('\\n'.join(self.content), lexer, formatter)\n         return [nodes.raw('', parsed, format='html')]\n```\n\nI don't have time to add docs, tests, run the test suite and, summing up, doing it properly. Hence the issue without pull request.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals, print_function\n\nfrom docutils import nodes, utils\nfrom docutils.parsers.rst import directives, roles, Directive\nfrom pygments.formatters import HtmlFormatter\nfrom pygments import highlight\nfrom pygments.lexers import get_lexer_by_name, TextLexer\nimport re\n\nINLINESTYLES = False\nDEFAULT = HtmlFormatter(noclasses=INLINESTYLES)\nVARIANTS = {\n    'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),\n}\n\n\nclass Pygments(Directive):\n    \"\"\" Source code syntax hightlighting.\n    \"\"\"\n    required_arguments = 1\n    optional_arguments = 0\n    final_argument_whitespace = True\n    option_spec = dict([(key, directives.flag) for key in VARIANTS])\n    has_content = True\n\n    def run(self):\n        self.assert_has_content()\n        try:\n            lexer = get_lexer_by_name(self.arguments[0])\n        except ValueError:\n            # no lexer found - use the text one instead of an exception\n            lexer = TextLexer()\n        # take an arbitrary option if more than one is given\n        formatter = self.options and VARIANTS[self.options.keys()[0]] \\\n                    or DEFAULT\n        parsed = highlight('\\n'.join(self.content), lexer, formatter)\n        return [nodes.raw('', parsed, format='html')]\n\ndirectives.register_directive('code-block', Pygments)\ndirectives.register_directive('sourcecode', Pygments)\n\n\nclass YouTube(Directive):\n    \"\"\" Embed YouTube video in posts.\n\n    Courtesy of Brian Hsu: https://gist.github.com/1422773\n\n    VIDEO_ID is required, with / height are optional integer,\n    and align could be left / center / right.\n\n    Usage:\n    .. youtube:: VIDEO_ID\n        :width: 640\n        :height: 480\n        :align: center\n    \"\"\"\n\n    def align(argument):\n        \"\"\"Conversion function for the \"align\" option.\"\"\"\n        return directives.choice(argument, ('left', 'center', 'right'))\n\n    required_arguments = 1\n    optional_arguments = 2\n    option_spec = {\n        'width': directives.positive_int,\n        'height': directives.positive_int,\n        'align': align\n    }\n\n    final_argument_whitespace = False\n    has_content = False\n\n    def run(self):\n        videoID = self.arguments[0].strip()\n        width = 420\n        height = 315\n        align = 'left'\n\n        if 'width' in self.options:\n            width = self.options['width']\n\n        if 'height' in self.options:\n            height = self.options['height']\n\n        if 'align' in self.options:\n            align = self.options['align']\n\n        url = 'http://www.youtube.com/embed/%s' % videoID\n        div_block = '<div class=\"youtube\" align=\"%s\">' % align\n        embed_block = '<iframe width=\"%s\" height=\"%s\" src=\"%s\" '\\\n                      'frameborder=\"0\"></iframe>' % (width, height, url)\n\n        return [\n            nodes.raw('', div_block, format='html'),\n            nodes.raw('', embed_block, format='html'),\n            nodes.raw('', '</div>', format='html')]\n\ndirectives.register_directive('youtube', YouTube)\n\n_abbr_re = re.compile('\\((.*)\\)$')\n\n\nclass abbreviation(nodes.Inline, nodes.TextElement):\n    pass\n\n\ndef abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):\n    text = utils.unescape(text)\n    m = _abbr_re.search(text)\n    if m is None:\n        return [abbreviation(text, text)], []\n    abbr = text[:m.start()].strip()\n    expl = m.group(1)\n    return [abbreviation(abbr, abbr, explanation=expl)], []\n\nroles.register_local_role('abbr', abbr_role)\n", "path": "pelican/rstdirectives.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals, print_function\n\nfrom docutils import nodes, utils\nfrom docutils.parsers.rst import directives, roles, Directive\nfrom pygments.formatters import HtmlFormatter\nfrom pygments import highlight\nfrom pygments.lexers import get_lexer_by_name, TextLexer\nimport re\n\nINLINESTYLES = False\nDEFAULT = HtmlFormatter(noclasses=INLINESTYLES)\nVARIANTS = {\n    'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),\n}\n\n\nclass Pygments(Directive):\n    \"\"\" Source code syntax hightlighting.\n    \"\"\"\n    required_arguments = 1\n    optional_arguments = 0\n    final_argument_whitespace = True\n    option_spec = dict([(key, directives.flag) for key in VARIANTS])\n    has_content = True\n\n    def run(self):\n        self.assert_has_content()\n        try:\n            lexer = get_lexer_by_name(self.arguments[0])\n        except ValueError:\n            # no lexer found - use the text one instead of an exception\n            lexer = TextLexer()\n        # take an arbitrary option if more than one is given\n        formatter = self.options and VARIANTS[list(self.options.keys())[0]] \\\n                    or DEFAULT\n        parsed = highlight('\\n'.join(self.content), lexer, formatter)\n        return [nodes.raw('', parsed, format='html')]\n\ndirectives.register_directive('code-block', Pygments)\ndirectives.register_directive('sourcecode', Pygments)\n\n\nclass YouTube(Directive):\n    \"\"\" Embed YouTube video in posts.\n\n    Courtesy of Brian Hsu: https://gist.github.com/1422773\n\n    VIDEO_ID is required, with / height are optional integer,\n    and align could be left / center / right.\n\n    Usage:\n    .. youtube:: VIDEO_ID\n        :width: 640\n        :height: 480\n        :align: center\n    \"\"\"\n\n    def align(argument):\n        \"\"\"Conversion function for the \"align\" option.\"\"\"\n        return directives.choice(argument, ('left', 'center', 'right'))\n\n    required_arguments = 1\n    optional_arguments = 2\n    option_spec = {\n        'width': directives.positive_int,\n        'height': directives.positive_int,\n        'align': align\n    }\n\n    final_argument_whitespace = False\n    has_content = False\n\n    def run(self):\n        videoID = self.arguments[0].strip()\n        width = 420\n        height = 315\n        align = 'left'\n\n        if 'width' in self.options:\n            width = self.options['width']\n\n        if 'height' in self.options:\n            height = self.options['height']\n\n        if 'align' in self.options:\n            align = self.options['align']\n\n        url = 'http://www.youtube.com/embed/%s' % videoID\n        div_block = '<div class=\"youtube\" align=\"%s\">' % align\n        embed_block = '<iframe width=\"%s\" height=\"%s\" src=\"%s\" '\\\n                      'frameborder=\"0\"></iframe>' % (width, height, url)\n\n        return [\n            nodes.raw('', div_block, format='html'),\n            nodes.raw('', embed_block, format='html'),\n            nodes.raw('', '</div>', format='html')]\n\ndirectives.register_directive('youtube', YouTube)\n\n_abbr_re = re.compile('\\((.*)\\)$')\n\n\nclass abbreviation(nodes.Inline, nodes.TextElement):\n    pass\n\n\ndef abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):\n    text = utils.unescape(text)\n    m = _abbr_re.search(text)\n    if m is None:\n        return [abbreviation(text, text)], []\n    abbr = text[:m.start()].strip()\n    expl = m.group(1)\n    return [abbreviation(abbr, abbr, explanation=expl)], []\n\nroles.register_local_role('abbr', abbr_role)\n", "path": "pelican/rstdirectives.py"}]}