prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  reddit: cannot view image
  - search: !re wallpaper dark blue
  - select some image
  - click "View Image" button
  
  Then the image should be shown but the searx start page is loaded. "View Page" shows the image. This is because image==page but this is an inconsistency (sort of)
  
  
  </issue>
  <code>
  [start of searx/engines/reddit.py]
  1 """
  2  Reddit
  3 
  4  @website      https://www.reddit.com/
  5  @provide-api  yes (https://www.reddit.com/dev/api)
  6 
  7  @using-api    yes
  8  @results      JSON
  9  @stable       yes
  10  @parse        url, title, content, thumbnail, publishedDate
  11 """
  12 
  13 import json
  14 from cgi import escape
  15 from urllib import urlencode
  16 from urlparse import urlparse
  17 from datetime import datetime
  18 
  19 # engine dependent config
  20 categories = ['general', 'images', 'news', 'social media']
  21 page_size = 25
  22 
  23 # search-url
  24 search_url = 'https://www.reddit.com/search.json?{query}'
  25 
  26 
  27 # do search-request
  28 def request(query, params):
  29     query = urlencode({'q': query,
  30                        'limit': page_size})
  31     params['url'] = search_url.format(query=query)
  32 
  33     return params
  34 
  35 
  36 # get response from search-request
  37 def response(resp):
  38     img_results = []
  39     text_results = []
  40 
  41     search_results = json.loads(resp.text)
  42 
  43     # return empty array if there are no results
  44     if 'data' not in search_results:
  45         return []
  46 
  47     posts = search_results.get('data', {}).get('children', [])
  48 
  49     # process results
  50     for post in posts:
  51         data = post['data']
  52 
  53         # extract post information
  54         params = {
  55             'url': data['url'],
  56             'title': data['title']
  57         }
  58 
  59         # if thumbnail field contains a valid URL, we need to change template
  60         thumbnail = data['thumbnail']
  61         url_info = urlparse(thumbnail)
  62         # netloc & path
  63         if url_info[1] != '' and url_info[2] != '':
  64             params['thumbnail_src'] = thumbnail
  65             params['template'] = 'images.html'
  66             img_results.append(params)
  67         else:
  68             created = datetime.fromtimestamp(data['created_utc'])
  69             content = escape(data['selftext'])
  70             if len(content) > 500:
  71                 content = content[:500] + '...'
  72             params['content'] = content
  73             params['publishedDate'] = created
  74             text_results.append(params)
  75 
  76     # show images first and text results second
  77     return img_results + text_results
  78
  [end of searx/engines/reddit.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/searx/engines/reddit.py b/searx/engines/reddit.py
  --- a/searx/engines/reddit.py
  +++ b/searx/engines/reddit.py
  @@ -13,7 +13,7 @@
   import json
   from cgi import escape
   from urllib import urlencode
  -from urlparse import urlparse
  +from urlparse import urlparse, urljoin
   from datetime import datetime
   
   # engine dependent config
  @@ -21,7 +21,8 @@
   page_size = 25
   
   # search-url
  -search_url = 'https://www.reddit.com/search.json?{query}'
  +base_url = 'https://www.reddit.com/'
  +search_url = base_url + 'search.json?{query}'
   
   
   # do search-request
  @@ -52,7 +53,7 @@
   
           # extract post information
           params = {
  -            'url': data['url'],
  +            'url': urljoin(base_url, data['permalink']),
               'title': data['title']
           }
   
  @@ -61,6 +62,7 @@
           url_info = urlparse(thumbnail)
           # netloc & path
           if url_info[1] != '' and url_info[2] != '':
  +            params['img_src'] = data['url']
               params['thumbnail_src'] = thumbnail
               params['template'] = 'images.html'
               img_results.append(params)
  
verification_info: {"golden_diff": "diff --git a/searx/engines/reddit.py b/searx/engines/reddit.py\n--- a/searx/engines/reddit.py\n+++ b/searx/engines/reddit.py\n@@ -13,7 +13,7 @@\n import json\n from cgi import escape\n from urllib import urlencode\n-from urlparse import urlparse\n+from urlparse import urlparse, urljoin\n from datetime import datetime\n \n # engine dependent config\n@@ -21,7 +21,8 @@\n page_size = 25\n \n # search-url\n-search_url = 'https://www.reddit.com/search.json?{query}'\n+base_url = 'https://www.reddit.com/'\n+search_url = base_url + 'search.json?{query}'\n \n \n # do search-request\n@@ -52,7 +53,7 @@\n \n         # extract post information\n         params = {\n-            'url': data['url'],\n+            'url': urljoin(base_url, data['permalink']),\n             'title': data['title']\n         }\n \n@@ -61,6 +62,7 @@\n         url_info = urlparse(thumbnail)\n         # netloc & path\n         if url_info[1] != '' and url_info[2] != '':\n+            params['img_src'] = data['url']\n             params['thumbnail_src'] = thumbnail\n             params['template'] = 'images.html'\n             img_results.append(params)\n", "issue": "reddit: cannot view image\n- search: !re wallpaper dark blue\n- select some image\n- click \"View Image\" button\n\nThen the image should be shown but the searx start page is loaded. \"View Page\" shows the image. This is because image==page but this is an inconsistency (sort of)\n\n", "before_files": [{"content": "\"\"\"\n Reddit\n\n @website      https://www.reddit.com/\n @provide-api  yes (https://www.reddit.com/dev/api)\n\n @using-api    yes\n @results      JSON\n @stable       yes\n @parse        url, title, content, thumbnail, publishedDate\n\"\"\"\n\nimport json\nfrom cgi import escape\nfrom urllib import urlencode\nfrom urlparse import urlparse\nfrom datetime import datetime\n\n# engine dependent config\ncategories = ['general', 'images', 'news', 'social media']\npage_size = 25\n\n# search-url\nsearch_url = 'https://www.reddit.com/search.json?{query}'\n\n\n# do search-request\ndef request(query, params):\n    query = urlencode({'q': query,\n                       'limit': page_size})\n    params['url'] = search_url.format(query=query)\n\n    return params\n\n\n# get response from search-request\ndef response(resp):\n    img_results = []\n    text_results = []\n\n    search_results = json.loads(resp.text)\n\n    # return empty array if there are no results\n    if 'data' not in search_results:\n        return []\n\n    posts = search_results.get('data', {}).get('children', [])\n\n    # process results\n    for post in posts:\n        data = post['data']\n\n        # extract post information\n        params = {\n            'url': data['url'],\n            'title': data['title']\n        }\n\n        # if thumbnail field contains a valid URL, we need to change template\n        thumbnail = data['thumbnail']\n        url_info = urlparse(thumbnail)\n        # netloc & path\n        if url_info[1] != '' and url_info[2] != '':\n            params['thumbnail_src'] = thumbnail\n            params['template'] = 'images.html'\n            img_results.append(params)\n        else:\n            created = datetime.fromtimestamp(data['created_utc'])\n            content = escape(data['selftext'])\n            if len(content) > 500:\n                content = content[:500] + '...'\n            params['content'] = content\n            params['publishedDate'] = created\n            text_results.append(params)\n\n    # show images first and text results second\n    return img_results + text_results\n", "path": "searx/engines/reddit.py"}]}