prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Translate 'library/http.server.po'
  This needs to reach 100% translated.
  
  The rendered version of this file will be available at https://docs.python.org/es/3.10/library/http.server.html once translated.
  Meanwhile, the English version is shown.
  
  Current stats for `library/http.server.po`:
  
  * Fuzzy: 4
  * Percent translated: 97.8%
  * Entries: 87 / 89
  * Untranslated: 2
  
  Please, comment here if you want this file to be assigned to you and an member will assign it to you as soon as possible, so you can start working on it.
  
  Remember to follow the steps in our [Contributing Guide](https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html).
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `scripts/translate.py`
  Content:
  ```
  1 import os
  2 import re
  3 import sys
  4 from typing import Dict, Tuple
  5 
  6 import polib
  7 
  8 VERBOSE = False
  9 DEBUG = False
  10 SKIP_TRANSLATED_ENTRIES = True
  11 
  12 try:
  13     from deep_translator import GoogleTranslator
  14 except ImportError:
  15     print("Error: This util script needs `deep_translator` to be installed")
  16     sys.exit(1)
  17 
  18 _patterns = [
  19     ":c:func:`[^`]+`",
  20     ":c:type:`[^`]+`",
  21     ":c:macro:`[^`]+`",
  22     ":c:member:`[^`]+`",
  23     ":c:data:`[^`]+`",
  24     ":py:data:`[^`]+`",
  25     ":py:mod:`[^`]+`",
  26     ":func:`[^`]+`",
  27     ":mod:`[^`]+`",
  28     ":ref:`[^`]+`",
  29     ":class:`[^`]+`",
  30     ":pep:`[^`]+`",
  31     ":data:`[^`]+`",
  32     ":exc:`[^`]+`",
  33     ":term:`[^`]+`",
  34     ":meth:`[^`]+`",
  35     ":envvar:`[^`]+`",
  36     ":file:`[^`]+`",
  37     ":attr:`[^`]+`",
  38     ":const:`[^`]+`",
  39     ":issue:`[^`]+`",
  40     ":opcode:`[^`]+`",
  41     ":option:`[^`]+`",
  42     ":program:`[^`]+`",
  43     ":keyword:`[^`]+`",
  44     ":RFC:`[^`]+`",
  45     ":doc:`[^`]+`",
  46     "``[^`]+``",
  47     "`[^`]+`__",
  48     "`[^`]+`_",
  49     "\*\*.+\*\*",  # bold text between **
  50     "\*.+\*",  # italic text between *
  51 ]
  52 
  53 _exps = [re.compile(e) for e in _patterns]
  54 
  55 def protect_sphinx_directives(s: str) -> Tuple[dict, str]:
  56     """
  57     Parameters:
  58         string containing the text to translate
  59 
  60     Returns:
  61         dictionary containing all the placeholder text as keys
  62         and the correct value.
  63     """
  64 
  65     i = 0
  66     d: Dict[str, str] = {}
  67     for exp in _exps:
  68         matches = exp.findall(s)
  69         if DEBUG:
  70             print(exp, matches)
  71         for match in matches:
  72             ph = f"XASDF{str(i).zfill(2)}"
  73             s = s.replace(match, ph)
  74             if ph in d and VERBOSE:
  75                 print(f"Error: {ph} is already in the dictionary")
  76                 print("new", match)
  77                 print("old", d[ph])
  78             d[ph] = match
  79             i += 1
  80     return d, s
  81 
  82 
  83 def undo_sphinx_directives_protection(placeholders: dict, translated_text: str) -> str:
  84     for ph, value in placeholders.items():
  85         translated_text = translated_text.replace(ph, value)
  86         if DEBUG:
  87             print(ph, value)
  88             print(translated_text)
  89     return translated_text
  90 
  91 
  92 if __name__ == "__main__":
  93     filename = sys.argv[1]
  94     if not os.path.isfile(filename):
  95         print(f"File not found: '{filename}'")
  96         sys.exit(-1)
  97 
  98     po = polib.pofile(filename)
  99     translator = GoogleTranslator(source="en", target="es")
  100 
  101     for entry in po:
  102         # If the entry has already a translation, skip.
  103         if SKIP_TRANSLATED_ENTRIES and entry.msgstr:
  104             continue
  105 
  106         print("\nEN|", entry.msgid)
  107         placeholders, temp_text = protect_sphinx_directives(entry.msgid)
  108         if VERBOSE:
  109             print(temp_text)
  110             print(placeholders)
  111 
  112         # Translate the temporary text without sphinx statements
  113         translated_text = translator.translate(temp_text)
  114 
  115         # Recover sphinx statements
  116         real_text = undo_sphinx_directives_protection(placeholders, translated_text)
  117         print("ES|", real_text)
  118 
  119         # Replace the po file translated entry
  120         entry.msgstr = real_text
  121 
  122     # Save the file after all the entries are translated
  123     po.save()
  124
  ```
  --- 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/scripts/translate.py b/scripts/translate.py
  --- a/scripts/translate.py
  +++ b/scripts/translate.py
  @@ -46,8 +46,8 @@
       "``[^`]+``",
       "`[^`]+`__",
       "`[^`]+`_",
  -    "\*\*.+\*\*",  # bold text between **
  -    "\*.+\*",  # italic text between *
  +    "\*\*[^\*]+\*\*",  # bold text between **
  +    "\*[^\*]+\*",  # italic text between *
   ]
   
   _exps = [re.compile(e) for e in _patterns]
  
verification_info: {"golden_diff": "diff --git a/scripts/translate.py b/scripts/translate.py\n--- a/scripts/translate.py\n+++ b/scripts/translate.py\n@@ -46,8 +46,8 @@\n     \"``[^`]+``\",\n     \"`[^`]+`__\",\n     \"`[^`]+`_\",\n-    \"\\*\\*.+\\*\\*\",  # bold text between **\n-    \"\\*.+\\*\",  # italic text between *\n+    \"\\*\\*[^\\*]+\\*\\*\",  # bold text between **\n+    \"\\*[^\\*]+\\*\",  # italic text between *\n ]\n \n _exps = [re.compile(e) for e in _patterns]\n", "issue": "Translate 'library/http.server.po'\nThis needs to reach 100% translated.\n\nThe rendered version of this file will be available at https://docs.python.org/es/3.10/library/http.server.html once translated.\nMeanwhile, the English version is shown.\n\nCurrent stats for `library/http.server.po`:\n\n* Fuzzy: 4\n* Percent translated: 97.8%\n* Entries: 87 / 89\n* Untranslated: 2\n\nPlease, comment here if you want this file to be assigned to you and an member will assign it to you as soon as possible, so you can start working on it.\n\nRemember to follow the steps in our [Contributing Guide](https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html).\n", "before_files": [{"content": "import os\nimport re\nimport sys\nfrom typing import Dict, Tuple\n\nimport polib\n\nVERBOSE = False\nDEBUG = False\nSKIP_TRANSLATED_ENTRIES = True\n\ntry:\n    from deep_translator import GoogleTranslator\nexcept ImportError:\n    print(\"Error: This util script needs `deep_translator` to be installed\")\n    sys.exit(1)\n\n_patterns = [\n    \":c:func:`[^`]+`\",\n    \":c:type:`[^`]+`\",\n    \":c:macro:`[^`]+`\",\n    \":c:member:`[^`]+`\",\n    \":c:data:`[^`]+`\",\n    \":py:data:`[^`]+`\",\n    \":py:mod:`[^`]+`\",\n    \":func:`[^`]+`\",\n    \":mod:`[^`]+`\",\n    \":ref:`[^`]+`\",\n    \":class:`[^`]+`\",\n    \":pep:`[^`]+`\",\n    \":data:`[^`]+`\",\n    \":exc:`[^`]+`\",\n    \":term:`[^`]+`\",\n    \":meth:`[^`]+`\",\n    \":envvar:`[^`]+`\",\n    \":file:`[^`]+`\",\n    \":attr:`[^`]+`\",\n    \":const:`[^`]+`\",\n    \":issue:`[^`]+`\",\n    \":opcode:`[^`]+`\",\n    \":option:`[^`]+`\",\n    \":program:`[^`]+`\",\n    \":keyword:`[^`]+`\",\n    \":RFC:`[^`]+`\",\n    \":doc:`[^`]+`\",\n    \"``[^`]+``\",\n    \"`[^`]+`__\",\n    \"`[^`]+`_\",\n    \"\\*\\*.+\\*\\*\",  # bold text between **\n    \"\\*.+\\*\",  # italic text between *\n]\n\n_exps = [re.compile(e) for e in _patterns]\n\ndef protect_sphinx_directives(s: str) -> Tuple[dict, str]:\n    \"\"\"\n    Parameters:\n        string containing the text to translate\n\n    Returns:\n        dictionary containing all the placeholder text as keys\n        and the correct value.\n    \"\"\"\n\n    i = 0\n    d: Dict[str, str] = {}\n    for exp in _exps:\n        matches = exp.findall(s)\n        if DEBUG:\n            print(exp, matches)\n        for match in matches:\n            ph = f\"XASDF{str(i).zfill(2)}\"\n            s = s.replace(match, ph)\n            if ph in d and VERBOSE:\n                print(f\"Error: {ph} is already in the dictionary\")\n                print(\"new\", match)\n                print(\"old\", d[ph])\n            d[ph] = match\n            i += 1\n    return d, s\n\n\ndef undo_sphinx_directives_protection(placeholders: dict, translated_text: str) -> str:\n    for ph, value in placeholders.items():\n        translated_text = translated_text.replace(ph, value)\n        if DEBUG:\n            print(ph, value)\n            print(translated_text)\n    return translated_text\n\n\nif __name__ == \"__main__\":\n    filename = sys.argv[1]\n    if not os.path.isfile(filename):\n        print(f\"File not found: '{filename}'\")\n        sys.exit(-1)\n\n    po = polib.pofile(filename)\n    translator = GoogleTranslator(source=\"en\", target=\"es\")\n\n    for entry in po:\n        # If the entry has already a translation, skip.\n        if SKIP_TRANSLATED_ENTRIES and entry.msgstr:\n            continue\n\n        print(\"\\nEN|\", entry.msgid)\n        placeholders, temp_text = protect_sphinx_directives(entry.msgid)\n        if VERBOSE:\n            print(temp_text)\n            print(placeholders)\n\n        # Translate the temporary text without sphinx statements\n        translated_text = translator.translate(temp_text)\n\n        # Recover sphinx statements\n        real_text = undo_sphinx_directives_protection(placeholders, translated_text)\n        print(\"ES|\", real_text)\n\n        # Replace the po file translated entry\n        entry.msgstr = real_text\n\n    # Save the file after all the entries are translated\n    po.save()\n", "path": "scripts/translate.py"}], "after_files": [{"content": "import os\nimport re\nimport sys\nfrom typing import Dict, Tuple\n\nimport polib\n\nVERBOSE = False\nDEBUG = False\nSKIP_TRANSLATED_ENTRIES = True\n\ntry:\n    from deep_translator import GoogleTranslator\nexcept ImportError:\n    print(\"Error: This util script needs `deep_translator` to be installed\")\n    sys.exit(1)\n\n_patterns = [\n    \":c:func:`[^`]+`\",\n    \":c:type:`[^`]+`\",\n    \":c:macro:`[^`]+`\",\n    \":c:member:`[^`]+`\",\n    \":c:data:`[^`]+`\",\n    \":py:data:`[^`]+`\",\n    \":py:mod:`[^`]+`\",\n    \":func:`[^`]+`\",\n    \":mod:`[^`]+`\",\n    \":ref:`[^`]+`\",\n    \":class:`[^`]+`\",\n    \":pep:`[^`]+`\",\n    \":data:`[^`]+`\",\n    \":exc:`[^`]+`\",\n    \":term:`[^`]+`\",\n    \":meth:`[^`]+`\",\n    \":envvar:`[^`]+`\",\n    \":file:`[^`]+`\",\n    \":attr:`[^`]+`\",\n    \":const:`[^`]+`\",\n    \":issue:`[^`]+`\",\n    \":opcode:`[^`]+`\",\n    \":option:`[^`]+`\",\n    \":program:`[^`]+`\",\n    \":keyword:`[^`]+`\",\n    \":RFC:`[^`]+`\",\n    \":doc:`[^`]+`\",\n    \"``[^`]+``\",\n    \"`[^`]+`__\",\n    \"`[^`]+`_\",\n    \"\\*\\*[^\\*]+\\*\\*\",  # bold text between **\n    \"\\*[^\\*]+\\*\",  # italic text between *\n]\n\n_exps = [re.compile(e) for e in _patterns]\n\ndef protect_sphinx_directives(s: str) -> Tuple[dict, str]:\n    \"\"\"\n    Parameters:\n        string containing the text to translate\n\n    Returns:\n        dictionary containing all the placeholder text as keys\n        and the correct value.\n    \"\"\"\n\n    i = 0\n    d: Dict[str, str] = {}\n    for exp in _exps:\n        matches = exp.findall(s)\n        if DEBUG:\n            print(exp, matches)\n        for match in matches:\n            ph = f\"XASDF{str(i).zfill(2)}\"\n            s = s.replace(match, ph)\n            if ph in d and VERBOSE:\n                print(f\"Error: {ph} is already in the dictionary\")\n                print(\"new\", match)\n                print(\"old\", d[ph])\n            d[ph] = match\n            i += 1\n    return d, s\n\n\ndef undo_sphinx_directives_protection(placeholders: dict, translated_text: str) -> str:\n    for ph, value in placeholders.items():\n        translated_text = translated_text.replace(ph, value)\n        if DEBUG:\n            print(ph, value)\n            print(translated_text)\n    return translated_text\n\n\nif __name__ == \"__main__\":\n    filename = sys.argv[1]\n    if not os.path.isfile(filename):\n        print(f\"File not found: '{filename}'\")\n        sys.exit(-1)\n\n    po = polib.pofile(filename)\n    translator = GoogleTranslator(source=\"en\", target=\"es\")\n\n    for entry in po:\n        # If the entry has already a translation, skip.\n        if SKIP_TRANSLATED_ENTRIES and entry.msgstr:\n            continue\n\n        print(\"\\nEN|\", entry.msgid)\n        placeholders, temp_text = protect_sphinx_directives(entry.msgid)\n        if VERBOSE:\n            print(temp_text)\n            print(placeholders)\n\n        # Translate the temporary text without sphinx statements\n        translated_text = translator.translate(temp_text)\n\n        # Recover sphinx statements\n        real_text = undo_sphinx_directives_protection(placeholders, translated_text)\n        print(\"ES|\", real_text)\n\n        # Replace the po file translated entry\n        entry.msgstr = real_text\n\n    # Save the file after all the entries are translated\n    po.save()\n", "path": "scripts/translate.py"}]}