We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
shutil.ReadError: Unknown archive format (tar.xz)
```
Dowloading enet from http://enet.bespin.org/download/enet-1.3.13.tar.gz
Downloading patch from https://github.com/ignatenkobrain/meson_wrap_example/raw/master/subprojects/enet-meson.tar.xz
Traceback (most recent call last):
  File "/home/brain/git/meson/meson.py", line 188, in run
    app.generate()
  File "/home/brain/git/meson/meson.py", line 129, in generate
    intr.run()
  File "/home/brain/git/meson/interpreter.py", line 871, in run
    self.evaluate_codeblock(self.ast)
  File "/home/brain/git/meson/interpreter.py", line 893, in evaluate_codeblock
    raise e
  File "/home/brain/git/meson/interpreter.py", line 887, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/home/brain/git/meson/interpreter.py", line 951, in evaluate_statement
    return self.evaluate_if(cur)
  File "/home/brain/git/meson/interpreter.py", line 1757, in evaluate_if
    self.evaluate_codeblock(node.elseblock)
  File "/home/brain/git/meson/interpreter.py", line 893, in evaluate_codeblock
    raise e
  File "/home/brain/git/meson/interpreter.py", line 887, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/home/brain/git/meson/interpreter.py", line 943, in evaluate_statement
    return self.assignment(cur)
  File "/home/brain/git/meson/interpreter.py", line 1637, in assignment
    value = self.evaluate_statement(node.value)
  File "/home/brain/git/meson/interpreter.py", line 941, in evaluate_statement
    return self.function_call(cur)
  File "/home/brain/git/meson/interpreter.py", line 1618, in function_call
    return self.funcs[func_name](node, self.flatten(posargs), kwargs)
  File "/home/brain/git/meson/interpreter.py", line 60, in wrapped
    return f(self, node, args, kwargs)
  File "/home/brain/git/meson/interpreter.py", line 52, in wrapped
    return f(self, node, args, kwargs)
  File "/home/brain/git/meson/interpreter.py", line 1071, in func_subproject
    resolved = r.resolve(dirname)
  File "/home/brain/git/meson/wrap.py", line 64, in resolve
    self.extract_package(p)
  File "/home/brain/git/meson/wrap.py", line 128, in extract_package
    shutil.unpack_archive(os.path.join(self.cachedir, package.get('patch_filename')), self.subdir_root)
  File "/usr/lib64/python3.4/shutil.py", line 953, in unpack_archive
    raise ReadError("Unknown archive format '{0}'".format(filename))
shutil.ReadError: Unknown archive format '/home/brain/meson_wrap/subprojects/packagecache/enet-meson.tar.xz'
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wrap.py`
Content:
```
1 # Copyright 2015 The Meson development team
2 
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import mlog
16 import urllib.request, os, hashlib, shutil
17 import subprocess
18 
19 class PackageDefinition:
20     def __init__(self, fname):
21         self.values = {}
22         ifile = open(fname)
23         first = ifile.readline().strip()
24 
25         if first == '[wrap-file]':
26             self.type = 'file'
27         elif first == '[wrap-git]':
28             self.type = 'git'
29         else:
30             raise RuntimeError('Invalid format of package file')
31         for line in ifile:
32             line = line.strip()
33             if line == '':
34                 continue
35             (k, v) = line.split('=', 1)
36             k = k.strip()
37             v = v.strip()
38             self.values[k] = v
39 
40     def get(self, key):
41         return self.values[key]
42 
43     def has_patch(self):
44         return 'patch_url' in self.values
45 
46 class Resolver:
47     def __init__(self, subdir_root):
48         self.subdir_root = subdir_root
49         self.cachedir = os.path.join(self.subdir_root, 'packagecache')
50 
51     def resolve(self, packagename):
52         fname = os.path.join(self.subdir_root, packagename + '.wrap')
53         dirname = os.path.join(self.subdir_root, packagename)
54         if not os.path.isfile(fname):
55             if os.path.isdir(dirname):
56                 # No wrap file but dir exists -> user put it there manually.
57                 return packagename 
58             return None
59         p = PackageDefinition(fname)
60         if p.type == 'file':
61             if not os.path.isdir(self.cachedir):
62                 os.mkdir(self.cachedir)
63             self.download(p, packagename)
64             self.extract_package(p)
65         elif p.type == 'git':
66             self.get_git(p)
67         else:
68             raise RuntimeError('Unreachable code.')
69         return p.get('directory')
70 
71     def get_git(self, p):
72         checkoutdir = os.path.join(self.subdir_root, p.get('directory'))
73         revno = p.get('revision')
74         is_there = os.path.isdir(checkoutdir)
75         if is_there:
76             if revno.lower() == 'head':
77                 subprocess.check_call(['git', 'pull'], cwd=checkoutdir)
78             else:
79                 if subprocess.call(['git', 'checkout', revno], cwd=checkoutdir) != 0:
80                     subprocess.check_call(['git', 'fetch'], cwd=checkoutdir)
81                     subprocess.check_call(['git', 'checkout', revno],
82                                           cwd=checkoutdir)
83         else:
84             subprocess.check_call(['git', 'clone', p.get('url'),
85                                    p.get('directory')], cwd=self.subdir_root)
86             if revno.lower() != 'head':
87                 subprocess.check_call(['git', 'checkout', revno],
88                                       cwd=checkoutdir)
89 
90 
91     def get_data(self, url):
92         u = urllib.request.urlopen(url)
93         data = u.read()
94         u.close()
95         h = hashlib.sha256()
96         h.update(data)
97         hashvalue = h.hexdigest()
98         return (data, hashvalue)
99 
100     def download(self, p, packagename):
101         ofname = os.path.join(self.cachedir, p.get('source_filename'))
102         if os.path.exists(ofname):
103             mlog.log('Using', mlog.bold(packagename), 'from cache.')
104             return
105         srcurl = p.get('source_url')
106         mlog.log('Dowloading', mlog.bold(packagename), 'from', srcurl)
107         (srcdata, dhash) = self.get_data(srcurl)
108         expected = p.get('source_hash')
109         if dhash != expected:
110             raise RuntimeError('Incorrect hash for source %s:\n %s expected\n %s actual.' % (packagename, expected, dhash))
111         if p.has_patch():
112             purl = p.get('patch_url')
113             mlog.log('Downloading patch from', mlog.bold(purl))
114             (pdata, phash) = self.get_data(purl)
115             expected = p.get('patch_hash')
116             if phash != expected:
117                 raise RuntimeError('Incorrect hash for patch %s:\n %s expected\n %s actual' % (packagename, expected, phash))
118             open(os.path.join(self.cachedir, p.get('patch_filename')), 'wb').write(pdata)
119         else:
120             mlog.log('Package does not require patch.')
121         open(ofname, 'wb').write(srcdata)
122 
123     def extract_package(self, package):
124         if os.path.isdir(os.path.join(self.subdir_root, package.get('directory'))):
125             return
126         shutil.unpack_archive(os.path.join(self.cachedir, package.get('source_filename')), self.subdir_root)
127         if package.has_patch():
128             shutil.unpack_archive(os.path.join(self.cachedir, package.get('patch_filename')), self.subdir_root)
129
```
--- 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()

```

diff --git a/wrap.py b/wrap.py
--- a/wrap.py
+++ b/wrap.py
@@ -15,6 +15,7 @@
 import mlog
 import urllib.request, os, hashlib, shutil
 import subprocess
+import sys
 
 class PackageDefinition:
     def __init__(self, fname):
@@ -121,6 +122,13 @@
         open(ofname, 'wb').write(srcdata)
 
     def extract_package(self, package):
+        if sys.version_info < (3, 5):
+            try:
+                import lzma
+                del lzma
+                shutil.register_unpack_format('xztar', ['.tar.xz', '.txz'], shutil._unpack_tarfile, [], "xz'ed tar-file")
+            except ImportError:
+                pass
         if os.path.isdir(os.path.join(self.subdir_root, package.get('directory'))):
             return
         shutil.unpack_archive(os.path.join(self.cachedir, package.get('source_filename')), self.subdir_root)

{"golden_diff": "diff --git a/wrap.py b/wrap.py\n--- a/wrap.py\n+++ b/wrap.py\n@@ -15,6 +15,7 @@\n import mlog\n import urllib.request, os, hashlib, shutil\n import subprocess\n+import sys\n \n class PackageDefinition:\n     def __init__(self, fname):\n@@ -121,6 +122,13 @@\n         open(ofname, 'wb').write(srcdata)\n \n     def extract_package(self, package):\n+        if sys.version_info < (3, 5):\n+            try:\n+                import lzma\n+                del lzma\n+                shutil.register_unpack_format('xztar', ['.tar.xz', '.txz'], shutil._unpack_tarfile, [], \"xz'ed tar-file\")\n+            except ImportError:\n+                pass\n         if os.path.isdir(os.path.join(self.subdir_root, package.get('directory'))):\n             return\n         shutil.unpack_archive(os.path.join(self.cachedir, package.get('source_filename')), self.subdir_root)\n", "issue": "shutil.ReadError: Unknown archive format (tar.xz)\n```\nDowloading enet from http://enet.bespin.org/download/enet-1.3.13.tar.gz\nDownloading patch from https://github.com/ignatenkobrain/meson_wrap_example/raw/master/subprojects/enet-meson.tar.xz\nTraceback (most recent call last):\n  File \"/home/brain/git/meson/meson.py\", line 188, in run\n    app.generate()\n  File \"/home/brain/git/meson/meson.py\", line 129, in generate\n    intr.run()\n  File \"/home/brain/git/meson/interpreter.py\", line 871, in run\n    self.evaluate_codeblock(self.ast)\n  File \"/home/brain/git/meson/interpreter.py\", line 893, in evaluate_codeblock\n    raise e\n  File \"/home/brain/git/meson/interpreter.py\", line 887, in evaluate_codeblock\n    self.evaluate_statement(cur)\n  File \"/home/brain/git/meson/interpreter.py\", line 951, in evaluate_statement\n    return self.evaluate_if(cur)\n  File \"/home/brain/git/meson/interpreter.py\", line 1757, in evaluate_if\n    self.evaluate_codeblock(node.elseblock)\n  File \"/home/brain/git/meson/interpreter.py\", line 893, in evaluate_codeblock\n    raise e\n  File \"/home/brain/git/meson/interpreter.py\", line 887, in evaluate_codeblock\n    self.evaluate_statement(cur)\n  File \"/home/brain/git/meson/interpreter.py\", line 943, in evaluate_statement\n    return self.assignment(cur)\n  File \"/home/brain/git/meson/interpreter.py\", line 1637, in assignment\n    value = self.evaluate_statement(node.value)\n  File \"/home/brain/git/meson/interpreter.py\", line 941, in evaluate_statement\n    return self.function_call(cur)\n  File \"/home/brain/git/meson/interpreter.py\", line 1618, in function_call\n    return self.funcs[func_name](node, self.flatten(posargs), kwargs)\n  File \"/home/brain/git/meson/interpreter.py\", line 60, in wrapped\n    return f(self, node, args, kwargs)\n  File \"/home/brain/git/meson/interpreter.py\", line 52, in wrapped\n    return f(self, node, args, kwargs)\n  File \"/home/brain/git/meson/interpreter.py\", line 1071, in func_subproject\n    resolved = r.resolve(dirname)\n  File \"/home/brain/git/meson/wrap.py\", line 64, in resolve\n    self.extract_package(p)\n  File \"/home/brain/git/meson/wrap.py\", line 128, in extract_package\n    shutil.unpack_archive(os.path.join(self.cachedir, package.get('patch_filename')), self.subdir_root)\n  File \"/usr/lib64/python3.4/shutil.py\", line 953, in unpack_archive\n    raise ReadError(\"Unknown archive format '{0}'\".format(filename))\nshutil.ReadError: Unknown archive format '/home/brain/meson_wrap/subprojects/packagecache/enet-meson.tar.xz'\n```\n\n", "before_files": [{"content": "# Copyright 2015 The Meson 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# You may obtain a copy of the License at\n\n#     http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport mlog\nimport urllib.request, os, hashlib, shutil\nimport subprocess\n\nclass PackageDefinition:\n    def __init__(self, fname):\n        self.values = {}\n        ifile = open(fname)\n        first = ifile.readline().strip()\n\n        if first == '[wrap-file]':\n            self.type = 'file'\n        elif first == '[wrap-git]':\n            self.type = 'git'\n        else:\n            raise RuntimeError('Invalid format of package file')\n        for line in ifile:\n            line = line.strip()\n            if line == '':\n                continue\n            (k, v) = line.split('=', 1)\n            k = k.strip()\n            v = v.strip()\n            self.values[k] = v\n\n    def get(self, key):\n        return self.values[key]\n\n    def has_patch(self):\n        return 'patch_url' in self.values\n\nclass Resolver:\n    def __init__(self, subdir_root):\n        self.subdir_root = subdir_root\n        self.cachedir = os.path.join(self.subdir_root, 'packagecache')\n\n    def resolve(self, packagename):\n        fname = os.path.join(self.subdir_root, packagename + '.wrap')\n        dirname = os.path.join(self.subdir_root, packagename)\n        if not os.path.isfile(fname):\n            if os.path.isdir(dirname):\n                # No wrap file but dir exists -> user put it there manually.\n                return packagename \n            return None\n        p = PackageDefinition(fname)\n        if p.type == 'file':\n            if not os.path.isdir(self.cachedir):\n                os.mkdir(self.cachedir)\n            self.download(p, packagename)\n            self.extract_package(p)\n        elif p.type == 'git':\n            self.get_git(p)\n        else:\n            raise RuntimeError('Unreachable code.')\n        return p.get('directory')\n\n    def get_git(self, p):\n        checkoutdir = os.path.join(self.subdir_root, p.get('directory'))\n        revno = p.get('revision')\n        is_there = os.path.isdir(checkoutdir)\n        if is_there:\n            if revno.lower() == 'head':\n                subprocess.check_call(['git', 'pull'], cwd=checkoutdir)\n            else:\n                if subprocess.call(['git', 'checkout', revno], cwd=checkoutdir) != 0:\n                    subprocess.check_call(['git', 'fetch'], cwd=checkoutdir)\n                    subprocess.check_call(['git', 'checkout', revno],\n                                          cwd=checkoutdir)\n        else:\n            subprocess.check_call(['git', 'clone', p.get('url'),\n                                   p.get('directory')], cwd=self.subdir_root)\n            if revno.lower() != 'head':\n                subprocess.check_call(['git', 'checkout', revno],\n                                      cwd=checkoutdir)\n\n\n    def get_data(self, url):\n        u = urllib.request.urlopen(url)\n        data = u.read()\n        u.close()\n        h = hashlib.sha256()\n        h.update(data)\n        hashvalue = h.hexdigest()\n        return (data, hashvalue)\n\n    def download(self, p, packagename):\n        ofname = os.path.join(self.cachedir, p.get('source_filename'))\n        if os.path.exists(ofname):\n            mlog.log('Using', mlog.bold(packagename), 'from cache.')\n            return\n        srcurl = p.get('source_url')\n        mlog.log('Dowloading', mlog.bold(packagename), 'from', srcurl)\n        (srcdata, dhash) = self.get_data(srcurl)\n        expected = p.get('source_hash')\n        if dhash != expected:\n            raise RuntimeError('Incorrect hash for source %s:\\n %s expected\\n %s actual.' % (packagename, expected, dhash))\n        if p.has_patch():\n            purl = p.get('patch_url')\n            mlog.log('Downloading patch from', mlog.bold(purl))\n            (pdata, phash) = self.get_data(purl)\n            expected = p.get('patch_hash')\n            if phash != expected:\n                raise RuntimeError('Incorrect hash for patch %s:\\n %s expected\\n %s actual' % (packagename, expected, phash))\n            open(os.path.join(self.cachedir, p.get('patch_filename')), 'wb').write(pdata)\n        else:\n            mlog.log('Package does not require patch.')\n        open(ofname, 'wb').write(srcdata)\n\n    def extract_package(self, package):\n        if os.path.isdir(os.path.join(self.subdir_root, package.get('directory'))):\n            return\n        shutil.unpack_archive(os.path.join(self.cachedir, package.get('source_filename')), self.subdir_root)\n        if package.has_patch():\n            shutil.unpack_archive(os.path.join(self.cachedir, package.get('patch_filename')), self.subdir_root)\n", "path": "wrap.py"}], "after_files": [{"content": "# Copyright 2015 The Meson 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# You may obtain a copy of the License at\n\n#     http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport mlog\nimport urllib.request, os, hashlib, shutil\nimport subprocess\nimport sys\n\nclass PackageDefinition:\n    def __init__(self, fname):\n        self.values = {}\n        ifile = open(fname)\n        first = ifile.readline().strip()\n\n        if first == '[wrap-file]':\n            self.type = 'file'\n        elif first == '[wrap-git]':\n            self.type = 'git'\n        else:\n            raise RuntimeError('Invalid format of package file')\n        for line in ifile:\n            line = line.strip()\n            if line == '':\n                continue\n            (k, v) = line.split('=', 1)\n            k = k.strip()\n            v = v.strip()\n            self.values[k] = v\n\n    def get(self, key):\n        return self.values[key]\n\n    def has_patch(self):\n        return 'patch_url' in self.values\n\nclass Resolver:\n    def __init__(self, subdir_root):\n        self.subdir_root = subdir_root\n        self.cachedir = os.path.join(self.subdir_root, 'packagecache')\n\n    def resolve(self, packagename):\n        fname = os.path.join(self.subdir_root, packagename + '.wrap')\n        dirname = os.path.join(self.subdir_root, packagename)\n        if not os.path.isfile(fname):\n            if os.path.isdir(dirname):\n                # No wrap file but dir exists -> user put it there manually.\n                return packagename \n            return None\n        p = PackageDefinition(fname)\n        if p.type == 'file':\n            if not os.path.isdir(self.cachedir):\n                os.mkdir(self.cachedir)\n            self.download(p, packagename)\n            self.extract_package(p)\n        elif p.type == 'git':\n            self.get_git(p)\n        else:\n            raise RuntimeError('Unreachable code.')\n        return p.get('directory')\n\n    def get_git(self, p):\n        checkoutdir = os.path.join(self.subdir_root, p.get('directory'))\n        revno = p.get('revision')\n        is_there = os.path.isdir(checkoutdir)\n        if is_there:\n            if revno.lower() == 'head':\n                subprocess.check_call(['git', 'pull'], cwd=checkoutdir)\n            else:\n                if subprocess.call(['git', 'checkout', revno], cwd=checkoutdir) != 0:\n                    subprocess.check_call(['git', 'fetch'], cwd=checkoutdir)\n                    subprocess.check_call(['git', 'checkout', revno],\n                                          cwd=checkoutdir)\n        else:\n            subprocess.check_call(['git', 'clone', p.get('url'),\n                                   p.get('directory')], cwd=self.subdir_root)\n            if revno.lower() != 'head':\n                subprocess.check_call(['git', 'checkout', revno],\n                                      cwd=checkoutdir)\n\n\n    def get_data(self, url):\n        u = urllib.request.urlopen(url)\n        data = u.read()\n        u.close()\n        h = hashlib.sha256()\n        h.update(data)\n        hashvalue = h.hexdigest()\n        return (data, hashvalue)\n\n    def download(self, p, packagename):\n        ofname = os.path.join(self.cachedir, p.get('source_filename'))\n        if os.path.exists(ofname):\n            mlog.log('Using', mlog.bold(packagename), 'from cache.')\n            return\n        srcurl = p.get('source_url')\n        mlog.log('Dowloading', mlog.bold(packagename), 'from', srcurl)\n        (srcdata, dhash) = self.get_data(srcurl)\n        expected = p.get('source_hash')\n        if dhash != expected:\n            raise RuntimeError('Incorrect hash for source %s:\\n %s expected\\n %s actual.' % (packagename, expected, dhash))\n        if p.has_patch():\n            purl = p.get('patch_url')\n            mlog.log('Downloading patch from', mlog.bold(purl))\n            (pdata, phash) = self.get_data(purl)\n            expected = p.get('patch_hash')\n            if phash != expected:\n                raise RuntimeError('Incorrect hash for patch %s:\\n %s expected\\n %s actual' % (packagename, expected, phash))\n            open(os.path.join(self.cachedir, p.get('patch_filename')), 'wb').write(pdata)\n        else:\n            mlog.log('Package does not require patch.')\n        open(ofname, 'wb').write(srcdata)\n\n    def extract_package(self, package):\n        if sys.version_info < (3, 5):\n            try:\n                import lzma\n                del lzma\n                shutil.register_unpack_format('xztar', ['.tar.xz', '.txz'], shutil._unpack_tarfile, [], \"xz'ed tar-file\")\n            except ImportError:\n                pass\n        if os.path.isdir(os.path.join(self.subdir_root, package.get('directory'))):\n            return\n        shutil.unpack_archive(os.path.join(self.cachedir, package.get('source_filename')), self.subdir_root)\n        if package.has_patch():\n            shutil.unpack_archive(os.path.join(self.cachedir, package.get('patch_filename')), self.subdir_root)\n", "path": "wrap.py"}]}