prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  XDG_DATA_DIRS environment variable being overriden when running packaged app
  I have a simple app that runs a local Flask web server and opens a web browser to show it on start up using the following command: 
  
      webbrowser.open('http://localhost:%d' % port, new=2, autoraise=True)
  
  When I run it in development mode, this works fine. However, when it's packaged using pyinstaller and run as an executable, I get this:
  
      gvfs-open: http://localhost:5000: error opening location: No application is registered as handling this file
  
  The order of the browser's web browser will try is the same in both instances: 
  
      'xdg-open', 'gvfs-open', 'gnome-open', 'x-www-browser', 'firefox'
  
  I tried using specific commands using `webbrowser.get(NAME).open` but none worked (except Firefox). 
  
  It seems like the XDG_DATA_DIRS environment variable is being over ridden: 
  
  `print('XDG_DATA_DIRS: ' + os.environ.get('XDG_DATA_DIRS', 'not found'))` 
  
  yields 
  
  `/usr/share/ubuntu:/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/var/lib/snapd/desktop` 
  
  in development mode and 
  
  `SOURCE_DIR/dist/linux/app/share`
  
  in the packaged executable. 
  
  I'm using Python 3.5.2 and pyinstaller 3.3.1 on Ubuntu 16.04 with the command 
  
      pyinstaller --add-data="static:static" app.py
  
  Stack overflow link: https://stackoverflow.com/questions/51657864/pyinstaller-webbrowser-open-doesnt-work-in-packaged-app
  
  </issue>
  <code>
  [start of PyInstaller/hooks/rthooks/pyi_rth_glib.py]
  1 #-----------------------------------------------------------------------------
  2 # Copyright (c) 2015-2022, PyInstaller Development Team.
  3 #
  4 # Licensed under the Apache License, Version 2.0 (the "License");
  5 # you may not use this file except in compliance with the License.
  6 #
  7 # The full license is in the file COPYING.txt, distributed with this software.
  8 #
  9 # SPDX-License-Identifier: Apache-2.0
  10 #-----------------------------------------------------------------------------
  11 
  12 import os
  13 import sys
  14 
  15 os.environ['XDG_DATA_DIRS'] = os.path.join(sys._MEIPASS, 'share')
  16
  [end of PyInstaller/hooks/rthooks/pyi_rth_glib.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/PyInstaller/hooks/rthooks/pyi_rth_glib.py b/PyInstaller/hooks/rthooks/pyi_rth_glib.py
  --- a/PyInstaller/hooks/rthooks/pyi_rth_glib.py
  +++ b/PyInstaller/hooks/rthooks/pyi_rth_glib.py
  @@ -12,4 +12,20 @@
   import os
   import sys
   
  -os.environ['XDG_DATA_DIRS'] = os.path.join(sys._MEIPASS, 'share')
  +# Prepend the frozen application's data dir to XDG_DATA_DIRS. We need to avoid overwriting the existing paths in order
  +# to allow the frozen application to run system-installed applications (for example, launch a web browser via the
  +# webbrowser module on Linux). Should the user desire complete isolation of the frozen application from the system,
  +# they need to clean up XDG_DATA_DIRS at the start of their program (i.e., remove all entries but first).
  +pyi_data_dir = os.path.join(sys._MEIPASS, 'share')
  +
  +xdg_data_dirs = os.environ.get('XDG_DATA_DIRS', None)
  +if xdg_data_dirs:
  +    if pyi_data_dir not in xdg_data_dirs:
  +        xdg_data_dirs = pyi_data_dir + os.pathsep + xdg_data_dirs
  +else:
  +    xdg_data_dirs = pyi_data_dir
  +os.environ['XDG_DATA_DIRS'] = xdg_data_dirs
  +
  +# Cleanup aux variables
  +del xdg_data_dirs
  +del pyi_data_dir
  
verification_info: {"golden_diff": "diff --git a/PyInstaller/hooks/rthooks/pyi_rth_glib.py b/PyInstaller/hooks/rthooks/pyi_rth_glib.py\n--- a/PyInstaller/hooks/rthooks/pyi_rth_glib.py\n+++ b/PyInstaller/hooks/rthooks/pyi_rth_glib.py\n@@ -12,4 +12,20 @@\n import os\n import sys\n \n-os.environ['XDG_DATA_DIRS'] = os.path.join(sys._MEIPASS, 'share')\n+# Prepend the frozen application's data dir to XDG_DATA_DIRS. We need to avoid overwriting the existing paths in order\n+# to allow the frozen application to run system-installed applications (for example, launch a web browser via the\n+# webbrowser module on Linux). Should the user desire complete isolation of the frozen application from the system,\n+# they need to clean up XDG_DATA_DIRS at the start of their program (i.e., remove all entries but first).\n+pyi_data_dir = os.path.join(sys._MEIPASS, 'share')\n+\n+xdg_data_dirs = os.environ.get('XDG_DATA_DIRS', None)\n+if xdg_data_dirs:\n+    if pyi_data_dir not in xdg_data_dirs:\n+        xdg_data_dirs = pyi_data_dir + os.pathsep + xdg_data_dirs\n+else:\n+    xdg_data_dirs = pyi_data_dir\n+os.environ['XDG_DATA_DIRS'] = xdg_data_dirs\n+\n+# Cleanup aux variables\n+del xdg_data_dirs\n+del pyi_data_dir\n", "issue": "XDG_DATA_DIRS environment variable being overriden when running packaged app\nI have a simple app that runs a local Flask web server and opens a web browser to show it on start up using the following command: \r\n\r\n    webbrowser.open('http://localhost:%d' % port, new=2, autoraise=True)\r\n\r\nWhen I run it in development mode, this works fine. However, when it's packaged using pyinstaller and run as an executable, I get this:\r\n\r\n    gvfs-open: http://localhost:5000: error opening location: No application is registered as handling this file\r\n\r\nThe order of the browser's web browser will try is the same in both instances: \r\n\r\n    'xdg-open', 'gvfs-open', 'gnome-open', 'x-www-browser', 'firefox'\r\n\r\nI tried using specific commands using `webbrowser.get(NAME).open` but none worked (except Firefox). \r\n\r\nIt seems like the XDG_DATA_DIRS environment variable is being over ridden: \r\n\r\n`print('XDG_DATA_DIRS: ' + os.environ.get('XDG_DATA_DIRS', 'not found'))` \r\n\r\nyields \r\n\r\n`/usr/share/ubuntu:/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop:/var/lib/snapd/desktop` \r\n\r\nin development mode and \r\n\r\n`SOURCE_DIR/dist/linux/app/share`\r\n\r\nin the packaged executable. \r\n\r\nI'm using Python 3.5.2 and pyinstaller 3.3.1 on Ubuntu 16.04 with the command \r\n\r\n    pyinstaller --add-data=\"static:static\" app.py\r\n\r\nStack overflow link: https://stackoverflow.com/questions/51657864/pyinstaller-webbrowser-open-doesnt-work-in-packaged-app\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2015-2022, PyInstaller Development Team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#\n# SPDX-License-Identifier: Apache-2.0\n#-----------------------------------------------------------------------------\n\nimport os\nimport sys\n\nos.environ['XDG_DATA_DIRS'] = os.path.join(sys._MEIPASS, 'share')\n", "path": "PyInstaller/hooks/rthooks/pyi_rth_glib.py"}]}