prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Unifying division
  Since we are effectively creating a new language, we might as well fix one of the nastiest Python portability problems between 2 and 3: division. I propose to do an implicit "from **future** import division" at the top of any Hy module, as well as before starting the REPL, when running under Python 2.x.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `hy/importer.py`
  Content:
  ```
  1 # Copyright (c) 2013 Paul Tagliamonte <paultag@debian.org>
  2 #
  3 # Permission is hereby granted, free of charge, to any person obtaining a
  4 # copy of this software and associated documentation files (the "Software"),
  5 # to deal in the Software without restriction, including without limitation
  6 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  7 # and/or sell copies of the Software, and to permit persons to whom the
  8 # Software is furnished to do so, subject to the following conditions:
  9 #
  10 # The above copyright notice and this permission notice shall be included in
  11 # all copies or substantial portions of the Software.
  12 #
  13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  16 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19 # DEALINGS IN THE SOFTWARE.
  20 
  21 from py_compile import wr_long, MAGIC
  22 from hy.compiler import hy_compile
  23 from hy.models import HyObject
  24 from hy.core import process
  25 from hy.lex import tokenize
  26 
  27 
  28 from io import open
  29 import marshal
  30 import imp
  31 import sys
  32 import ast
  33 import os
  34 
  35 
  36 if sys.version_info[0] >= 3:
  37     from io import StringIO
  38 else:
  39     from StringIO import StringIO  # NOQA
  40 
  41 
  42 def import_buffer_to_hst(fd):
  43     tree = tokenize(fd.read() + "\n")
  44     tree = process(tree)
  45     return tree
  46 
  47 
  48 def import_file_to_hst(fpath):
  49     return import_buffer_to_hst(open(fpath, 'r', encoding='utf-8'))
  50 
  51 
  52 def import_file_to_ast(fpath):
  53     tree = import_file_to_hst(fpath)
  54     _ast = hy_compile(tree)
  55     return _ast
  56 
  57 
  58 def import_string_to_ast(buff):
  59     tree = import_buffer_to_hst(StringIO(buff))
  60     _ast = hy_compile(tree)
  61     return _ast
  62 
  63 
  64 def import_file_to_module(name, fpath):
  65     _ast = import_file_to_ast(fpath)
  66     mod = imp.new_module(name)
  67     mod.__file__ = fpath
  68     eval(compile(_ast, fpath, "exec"), mod.__dict__)
  69     return mod
  70 
  71 
  72 def hy_eval(hytree, namespace):
  73     foo = HyObject()
  74     foo.start_line = 0
  75     foo.end_line = 0
  76     foo.start_column = 0
  77     foo.end_column = 0
  78     hytree.replace(foo)
  79     _ast = hy_compile(hytree, root=ast.Expression)
  80     return eval(compile(_ast, "<eval>", "eval"), namespace)
  81 
  82 
  83 def write_hy_as_pyc(fname):
  84     with open(fname, 'U') as f:
  85         try:
  86             timestamp = long(os.fstat(f.fileno()).st_mtime)
  87         except AttributeError:
  88             timestamp = long(os.stat(fname).st_mtime)
  89 
  90     _ast = import_file_to_ast(fname)
  91     code = compile(_ast, fname, "exec")
  92     cfile = "%s.pyc" % fname[:-len(".hy")]
  93 
  94     with open(cfile, 'wb') as fc:
  95         fc.write('\0\0\0\0')
  96         wr_long(fc, timestamp)
  97         marshal.dump(code, fc)
  98         fc.flush()
  99         fc.seek(0, 0)
  100         fc.write(MAGIC)
  101 
  102 
  103 class HyFinder(object):
  104     def is_package(self, fullname):
  105         dirpath = "/".join(fullname.split("."))
  106         for pth in sys.path:
  107             pth = os.path.abspath(pth)
  108             composed_path = "%s/%s/__init__.hy" % (pth, dirpath)
  109             if os.path.exists(composed_path):
  110                 return True
  111         return False
  112 
  113     def find_on_path(self, fullname):
  114         fls = ["%s/__init__.hy", "%s.hy"]
  115         dirpath = "/".join(fullname.split("."))
  116 
  117         for pth in sys.path:
  118             pth = os.path.abspath(pth)
  119             for fp in fls:
  120                 composed_path = fp % ("%s/%s" % (pth, dirpath))
  121                 if os.path.exists(composed_path):
  122                     return composed_path
  123 
  124 
  125 class MetaLoader(HyFinder):
  126     def load_module(self, fullname):
  127         if fullname in sys.modules:
  128             return sys.modules[fullname]
  129 
  130         pth = self.find_on_path(fullname)
  131         if pth is None:
  132             return
  133 
  134         sys.modules[fullname] = None
  135         mod = import_file_to_module(fullname, pth)
  136 
  137         ispkg = self.is_package(fullname)
  138 
  139         mod.__file__ = pth
  140         mod.__loader__ = self
  141         mod.__name__ = fullname
  142 
  143         if ispkg:
  144             mod.__path__ = []
  145             mod.__package__ = fullname
  146         else:
  147             mod.__package__ = fullname.rpartition('.')[0]
  148 
  149         sys.modules[fullname] = mod
  150         return mod
  151 
  152 
  153 class MetaImporter(HyFinder):
  154     def find_module(self, fullname, path=None):
  155         pth = self.find_on_path(fullname)
  156         if pth is None:
  157             return
  158         return MetaLoader()
  159 
  160 
  161 sys.meta_path.append(MetaImporter())
  162 sys.path.insert(0, "")
  163
  ```
  --- 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/hy/importer.py b/hy/importer.py
  --- a/hy/importer.py
  +++ b/hy/importer.py
  @@ -31,7 +31,7 @@
   import sys
   import ast
   import os
  -
  +import __future__
   
   if sys.version_info[0] >= 3:
       from io import StringIO
  @@ -39,6 +39,10 @@
       from StringIO import StringIO  # NOQA
   
   
  +def compile_(ast, filename, mode):
  +    return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION)
  +
  +
   def import_buffer_to_hst(fd):
       tree = tokenize(fd.read() + "\n")
       tree = process(tree)
  @@ -65,7 +69,7 @@
       _ast = import_file_to_ast(fpath)
       mod = imp.new_module(name)
       mod.__file__ = fpath
  -    eval(compile(_ast, fpath, "exec"), mod.__dict__)
  +    eval(compile_(_ast, fpath, "exec"), mod.__dict__)
       return mod
   
   
  @@ -77,7 +81,7 @@
       foo.end_column = 0
       hytree.replace(foo)
       _ast = hy_compile(hytree, root=ast.Expression)
  -    return eval(compile(_ast, "<eval>", "eval"), namespace)
  +    return eval(compile_(_ast, "<eval>", "eval"), namespace)
   
   
   def write_hy_as_pyc(fname):
  @@ -88,7 +92,7 @@
               timestamp = long(os.stat(fname).st_mtime)
   
       _ast = import_file_to_ast(fname)
  -    code = compile(_ast, fname, "exec")
  +    code = compile_(_ast, fname, "exec")
       cfile = "%s.pyc" % fname[:-len(".hy")]
   
       with open(cfile, 'wb') as fc:
  
verification_info: {"golden_diff": "diff --git a/hy/importer.py b/hy/importer.py\n--- a/hy/importer.py\n+++ b/hy/importer.py\n@@ -31,7 +31,7 @@\n import sys\n import ast\n import os\n-\n+import __future__\n \n if sys.version_info[0] >= 3:\n     from io import StringIO\n@@ -39,6 +39,10 @@\n     from StringIO import StringIO  # NOQA\n \n \n+def compile_(ast, filename, mode):\n+    return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION)\n+\n+\n def import_buffer_to_hst(fd):\n     tree = tokenize(fd.read() + \"\\n\")\n     tree = process(tree)\n@@ -65,7 +69,7 @@\n     _ast = import_file_to_ast(fpath)\n     mod = imp.new_module(name)\n     mod.__file__ = fpath\n-    eval(compile(_ast, fpath, \"exec\"), mod.__dict__)\n+    eval(compile_(_ast, fpath, \"exec\"), mod.__dict__)\n     return mod\n \n \n@@ -77,7 +81,7 @@\n     foo.end_column = 0\n     hytree.replace(foo)\n     _ast = hy_compile(hytree, root=ast.Expression)\n-    return eval(compile(_ast, \"<eval>\", \"eval\"), namespace)\n+    return eval(compile_(_ast, \"<eval>\", \"eval\"), namespace)\n \n \n def write_hy_as_pyc(fname):\n@@ -88,7 +92,7 @@\n             timestamp = long(os.stat(fname).st_mtime)\n \n     _ast = import_file_to_ast(fname)\n-    code = compile(_ast, fname, \"exec\")\n+    code = compile_(_ast, fname, \"exec\")\n     cfile = \"%s.pyc\" % fname[:-len(\".hy\")]\n \n     with open(cfile, 'wb') as fc:\n", "issue": "Unifying division\nSince we are effectively creating a new language, we might as well fix one of the nastiest Python portability problems between 2 and 3: division. I propose to do an implicit \"from **future** import division\" at the top of any Hy module, as well as before starting the REPL, when running under Python 2.x.\n\n", "before_files": [{"content": "# Copyright (c) 2013 Paul Tagliamonte <paultag@debian.org>\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the \"Software\"),\n# to deal in the Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish, distribute, sublicense,\n# and/or sell copies of the Software, and to permit persons to whom the\n# Software is furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\n# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n# DEALINGS IN THE SOFTWARE.\n\nfrom py_compile import wr_long, MAGIC\nfrom hy.compiler import hy_compile\nfrom hy.models import HyObject\nfrom hy.core import process\nfrom hy.lex import tokenize\n\n\nfrom io import open\nimport marshal\nimport imp\nimport sys\nimport ast\nimport os\n\n\nif sys.version_info[0] >= 3:\n    from io import StringIO\nelse:\n    from StringIO import StringIO  # NOQA\n\n\ndef import_buffer_to_hst(fd):\n    tree = tokenize(fd.read() + \"\\n\")\n    tree = process(tree)\n    return tree\n\n\ndef import_file_to_hst(fpath):\n    return import_buffer_to_hst(open(fpath, 'r', encoding='utf-8'))\n\n\ndef import_file_to_ast(fpath):\n    tree = import_file_to_hst(fpath)\n    _ast = hy_compile(tree)\n    return _ast\n\n\ndef import_string_to_ast(buff):\n    tree = import_buffer_to_hst(StringIO(buff))\n    _ast = hy_compile(tree)\n    return _ast\n\n\ndef import_file_to_module(name, fpath):\n    _ast = import_file_to_ast(fpath)\n    mod = imp.new_module(name)\n    mod.__file__ = fpath\n    eval(compile(_ast, fpath, \"exec\"), mod.__dict__)\n    return mod\n\n\ndef hy_eval(hytree, namespace):\n    foo = HyObject()\n    foo.start_line = 0\n    foo.end_line = 0\n    foo.start_column = 0\n    foo.end_column = 0\n    hytree.replace(foo)\n    _ast = hy_compile(hytree, root=ast.Expression)\n    return eval(compile(_ast, \"<eval>\", \"eval\"), namespace)\n\n\ndef write_hy_as_pyc(fname):\n    with open(fname, 'U') as f:\n        try:\n            timestamp = long(os.fstat(f.fileno()).st_mtime)\n        except AttributeError:\n            timestamp = long(os.stat(fname).st_mtime)\n\n    _ast = import_file_to_ast(fname)\n    code = compile(_ast, fname, \"exec\")\n    cfile = \"%s.pyc\" % fname[:-len(\".hy\")]\n\n    with open(cfile, 'wb') as fc:\n        fc.write('\\0\\0\\0\\0')\n        wr_long(fc, timestamp)\n        marshal.dump(code, fc)\n        fc.flush()\n        fc.seek(0, 0)\n        fc.write(MAGIC)\n\n\nclass HyFinder(object):\n    def is_package(self, fullname):\n        dirpath = \"/\".join(fullname.split(\".\"))\n        for pth in sys.path:\n            pth = os.path.abspath(pth)\n            composed_path = \"%s/%s/__init__.hy\" % (pth, dirpath)\n            if os.path.exists(composed_path):\n                return True\n        return False\n\n    def find_on_path(self, fullname):\n        fls = [\"%s/__init__.hy\", \"%s.hy\"]\n        dirpath = \"/\".join(fullname.split(\".\"))\n\n        for pth in sys.path:\n            pth = os.path.abspath(pth)\n            for fp in fls:\n                composed_path = fp % (\"%s/%s\" % (pth, dirpath))\n                if os.path.exists(composed_path):\n                    return composed_path\n\n\nclass MetaLoader(HyFinder):\n    def load_module(self, fullname):\n        if fullname in sys.modules:\n            return sys.modules[fullname]\n\n        pth = self.find_on_path(fullname)\n        if pth is None:\n            return\n\n        sys.modules[fullname] = None\n        mod = import_file_to_module(fullname, pth)\n\n        ispkg = self.is_package(fullname)\n\n        mod.__file__ = pth\n        mod.__loader__ = self\n        mod.__name__ = fullname\n\n        if ispkg:\n            mod.__path__ = []\n            mod.__package__ = fullname\n        else:\n            mod.__package__ = fullname.rpartition('.')[0]\n\n        sys.modules[fullname] = mod\n        return mod\n\n\nclass MetaImporter(HyFinder):\n    def find_module(self, fullname, path=None):\n        pth = self.find_on_path(fullname)\n        if pth is None:\n            return\n        return MetaLoader()\n\n\nsys.meta_path.append(MetaImporter())\nsys.path.insert(0, \"\")\n", "path": "hy/importer.py"}], "after_files": [{"content": "# Copyright (c) 2013 Paul Tagliamonte <paultag@debian.org>\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the \"Software\"),\n# to deal in the Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish, distribute, sublicense,\n# and/or sell copies of the Software, and to permit persons to whom the\n# Software is furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\n# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n# DEALINGS IN THE SOFTWARE.\n\nfrom py_compile import wr_long, MAGIC\nfrom hy.compiler import hy_compile\nfrom hy.models import HyObject\nfrom hy.core import process\nfrom hy.lex import tokenize\n\n\nfrom io import open\nimport marshal\nimport imp\nimport sys\nimport ast\nimport os\nimport __future__\n\nif sys.version_info[0] >= 3:\n    from io import StringIO\nelse:\n    from StringIO import StringIO  # NOQA\n\n\ndef compile_(ast, filename, mode):\n    return compile(ast, filename, mode, __future__.CO_FUTURE_DIVISION)\n\n\ndef import_buffer_to_hst(fd):\n    tree = tokenize(fd.read() + \"\\n\")\n    tree = process(tree)\n    return tree\n\n\ndef import_file_to_hst(fpath):\n    return import_buffer_to_hst(open(fpath, 'r', encoding='utf-8'))\n\n\ndef import_file_to_ast(fpath):\n    tree = import_file_to_hst(fpath)\n    _ast = hy_compile(tree)\n    return _ast\n\n\ndef import_string_to_ast(buff):\n    tree = import_buffer_to_hst(StringIO(buff))\n    _ast = hy_compile(tree)\n    return _ast\n\n\ndef import_file_to_module(name, fpath):\n    _ast = import_file_to_ast(fpath)\n    mod = imp.new_module(name)\n    mod.__file__ = fpath\n    eval(compile_(_ast, fpath, \"exec\"), mod.__dict__)\n    return mod\n\n\ndef hy_eval(hytree, namespace):\n    foo = HyObject()\n    foo.start_line = 0\n    foo.end_line = 0\n    foo.start_column = 0\n    foo.end_column = 0\n    hytree.replace(foo)\n    _ast = hy_compile(hytree, root=ast.Expression)\n    return eval(compile_(_ast, \"<eval>\", \"eval\"), namespace)\n\n\ndef write_hy_as_pyc(fname):\n    with open(fname, 'U') as f:\n        try:\n            timestamp = long(os.fstat(f.fileno()).st_mtime)\n        except AttributeError:\n            timestamp = long(os.stat(fname).st_mtime)\n\n    _ast = import_file_to_ast(fname)\n    code = compile_(_ast, fname, \"exec\")\n    cfile = \"%s.pyc\" % fname[:-len(\".hy\")]\n\n    with open(cfile, 'wb') as fc:\n        fc.write('\\0\\0\\0\\0')\n        wr_long(fc, timestamp)\n        marshal.dump(code, fc)\n        fc.flush()\n        fc.seek(0, 0)\n        fc.write(MAGIC)\n\n\nclass HyFinder(object):\n    def is_package(self, fullname):\n        dirpath = \"/\".join(fullname.split(\".\"))\n        for pth in sys.path:\n            pth = os.path.abspath(pth)\n            composed_path = \"%s/%s/__init__.hy\" % (pth, dirpath)\n            if os.path.exists(composed_path):\n                return True\n        return False\n\n    def find_on_path(self, fullname):\n        fls = [\"%s/__init__.hy\", \"%s.hy\"]\n        dirpath = \"/\".join(fullname.split(\".\"))\n\n        for pth in sys.path:\n            pth = os.path.abspath(pth)\n            for fp in fls:\n                composed_path = fp % (\"%s/%s\" % (pth, dirpath))\n                if os.path.exists(composed_path):\n                    return composed_path\n\n\nclass MetaLoader(HyFinder):\n    def load_module(self, fullname):\n        if fullname in sys.modules:\n            return sys.modules[fullname]\n\n        pth = self.find_on_path(fullname)\n        if pth is None:\n            return\n\n        sys.modules[fullname] = None\n        mod = import_file_to_module(fullname, pth)\n\n        ispkg = self.is_package(fullname)\n\n        mod.__file__ = pth\n        mod.__loader__ = self\n        mod.__name__ = fullname\n\n        if ispkg:\n            mod.__path__ = []\n            mod.__package__ = fullname\n        else:\n            mod.__package__ = fullname.rpartition('.')[0]\n\n        sys.modules[fullname] = mod\n        return mod\n\n\nclass MetaImporter(HyFinder):\n    def find_module(self, fullname, path=None):\n        pth = self.find_on_path(fullname)\n        if pth is None:\n            return\n        return MetaLoader()\n\n\nsys.meta_path.append(MetaImporter())\nsys.path.insert(0, \"\")\n", "path": "hy/importer.py"}]}