prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Wikipedia bot crashes when the query contains multiple word delimit by underscore.
  The bot is under `contrib_bots/bots`.  Some error handling is needed.
  
  </issue>
  <code>
  [start of contrib_bots/bots/wikipedia/wikipedia.py]
  1 from __future__ import absolute_import
  2 from __future__ import print_function
  3 import requests
  4 import logging
  5 
  6 # See readme.md for instructions on running this code.
  7 
  8 class WikipediaHandler(object):
  9     '''
  10     This plugin facilitates searching Wikipedia for a
  11     specific key term and returns the top article from the
  12     search. It looks for messages starting with '@wikipedia'
  13      or '@wiki'.
  14 
  15     In this example, we write all Wikipedia searches into
  16     the same stream that it was called from, but this code
  17     could be adapted to write Wikipedia searches to some
  18     kind of external issue tracker as well.
  19     '''
  20 
  21     def usage(self):
  22         return '''
  23             This plugin will allow users to directly search
  24             Wikipedia for a specific key term and get the top
  25             article that is returned from the search. Users
  26             should preface searches with "@wikipedia" or
  27             "@wiki".
  28             '''
  29 
  30     def triage_message(self, message, client):
  31         original_content = message['content']
  32 
  33         # This next line of code is defensive, as we
  34         # never want to get into an infinite loop of posting Wikipedia
  35         # searches for own Wikipedia searches!
  36         if message['sender_full_name'] == 'wikipedia-bot':
  37             return False
  38         is_wikipedia = (original_content.startswith('@wiki') or
  39                         original_content.startswith('@wikipedia'))
  40 
  41         return is_wikipedia
  42 
  43     def handle_message(self, message, client, state_handler):
  44         query = message['content']
  45 
  46         for prefix in ['@wikipedia', '@wiki']:
  47             if query.startswith(prefix):
  48                 query = query[len(prefix)+1:]
  49                 break
  50 
  51         query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'
  52                            'list=search&srsearch=%s&format=json' % (query,))
  53         try:
  54             data = requests.get(query_wiki_link)
  55         except requests.exceptions.RequestException:
  56             logging.error('broken link')
  57             return
  58 
  59         if data.status_code != 200:
  60             logging.error('unsuccessful data')
  61             return
  62 
  63         search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
  64         url = 'https://wikipedia.org/wiki/' + search_string
  65         new_content = 'For search term "' + query
  66         if len(data.json()['query']['search']) == 0:
  67             new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'
  68         else:
  69             new_content = new_content + '", ' + url
  70 
  71         client.send_message(dict(
  72             type=message['type'],
  73             to=message['display_recipient'],
  74             subject=message['subject'],
  75             content=new_content,
  76         ))
  77 
  78 handler_class = WikipediaHandler
  79
  [end of contrib_bots/bots/wikipedia/wikipedia.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py
  --- a/contrib_bots/bots/wikipedia/wikipedia.py
  +++ b/contrib_bots/bots/wikipedia/wikipedia.py
  @@ -60,12 +60,12 @@
               logging.error('unsuccessful data')
               return
   
  -        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
  -        url = 'https://wikipedia.org/wiki/' + search_string
           new_content = 'For search term "' + query
           if len(data.json()['query']['search']) == 0:
               new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'
           else:
  +            search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')
  +            url = 'https://en.wikipedia.org/wiki/' + search_string
               new_content = new_content + '", ' + url
   
           client.send_message(dict(
  
verification_info: {"golden_diff": "diff --git a/contrib_bots/bots/wikipedia/wikipedia.py b/contrib_bots/bots/wikipedia/wikipedia.py\n--- a/contrib_bots/bots/wikipedia/wikipedia.py\n+++ b/contrib_bots/bots/wikipedia/wikipedia.py\n@@ -60,12 +60,12 @@\n             logging.error('unsuccessful data')\n             return\n \n-        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n-        url = 'https://wikipedia.org/wiki/' + search_string\n         new_content = 'For search term \"' + query\n         if len(data.json()['query']['search']) == 0:\n             new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'\n         else:\n+            search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n+            url = 'https://en.wikipedia.org/wiki/' + search_string\n             new_content = new_content + '\", ' + url\n \n         client.send_message(dict(\n", "issue": "Wikipedia bot crashes when the query contains multiple word delimit by underscore.\nThe bot is under `contrib_bots/bots`.  Some error handling is needed.\n", "before_files": [{"content": "from __future__ import absolute_import\nfrom __future__ import print_function\nimport requests\nimport logging\n\n# See readme.md for instructions on running this code.\n\nclass WikipediaHandler(object):\n    '''\n    This plugin facilitates searching Wikipedia for a\n    specific key term and returns the top article from the\n    search. It looks for messages starting with '@wikipedia'\n     or '@wiki'.\n\n    In this example, we write all Wikipedia searches into\n    the same stream that it was called from, but this code\n    could be adapted to write Wikipedia searches to some\n    kind of external issue tracker as well.\n    '''\n\n    def usage(self):\n        return '''\n            This plugin will allow users to directly search\n            Wikipedia for a specific key term and get the top\n            article that is returned from the search. Users\n            should preface searches with \"@wikipedia\" or\n            \"@wiki\".\n            '''\n\n    def triage_message(self, message, client):\n        original_content = message['content']\n\n        # This next line of code is defensive, as we\n        # never want to get into an infinite loop of posting Wikipedia\n        # searches for own Wikipedia searches!\n        if message['sender_full_name'] == 'wikipedia-bot':\n            return False\n        is_wikipedia = (original_content.startswith('@wiki') or\n                        original_content.startswith('@wikipedia'))\n\n        return is_wikipedia\n\n    def handle_message(self, message, client, state_handler):\n        query = message['content']\n\n        for prefix in ['@wikipedia', '@wiki']:\n            if query.startswith(prefix):\n                query = query[len(prefix)+1:]\n                break\n\n        query_wiki_link = ('https://en.wikipedia.org/w/api.php?action=query&'\n                           'list=search&srsearch=%s&format=json' % (query,))\n        try:\n            data = requests.get(query_wiki_link)\n        except requests.exceptions.RequestException:\n            logging.error('broken link')\n            return\n\n        if data.status_code != 200:\n            logging.error('unsuccessful data')\n            return\n\n        search_string = data.json()['query']['search'][0]['title'].replace(' ', '_')\n        url = 'https://wikipedia.org/wiki/' + search_string\n        new_content = 'For search term \"' + query\n        if len(data.json()['query']['search']) == 0:\n            new_content = 'I am sorry. The search term you provided is not found :slightly_frowning_face:'\n        else:\n            new_content = new_content + '\", ' + url\n\n        client.send_message(dict(\n            type=message['type'],\n            to=message['display_recipient'],\n            subject=message['subject'],\n            content=new_content,\n        ))\n\nhandler_class = WikipediaHandler\n", "path": "contrib_bots/bots/wikipedia/wikipedia.py"}]}