prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  GrepTask issue
  ```
  2021-04-28 17:13:25 [ERROR] GrepTask Task failed with exception: [a bytes-like object is required, not 'str']
  2021-04-28 17:13:25 [ERROR] Traceback (most recent call last):
    File "/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/__init__.py", line 893, in run_wrapper
      self.result = self.run(evidence, self.result)
    File "/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/grep.py", line 49, in run
      fh.write('\n'.join(patterns))
    File "/usr/lib/python3.6/tempfile.py", line 624, in func_wrapper
      return func(*args, **kwargs)
  TypeError: a bytes-like object is required, not 'str'
  
  2021-04-28 17:13:26 [ERROR] GrepTask Task failed with exception: [a bytes-like object is required, not 'str']
  2021-04-28 17:13:26 [INFO] Traceback (most recent call last):
    File "/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/__init__.py", line 893, in run_wrapper
      self.result = self.run(evidence, self.result)
    File "/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/grep.py", line 49, in run
      fh.write('\n'.join(patterns))
    File "/usr/lib/python3.6/tempfile.py", line 624, in func_wrapper
      return func(*args, **kwargs)
  TypeError: a bytes-like object is required, not 'str'
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `turbinia/workers/grep.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 # Copyright 2015 Google Inc.
  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 # You may obtain a copy of the License at
  7 #
  8 #      http://www.apache.org/licenses/LICENSE-2.0
  9 #
  10 # Unless required by applicable law or agreed to in writing, software
  11 # distributed under the License is distributed on an "AS IS" BASIS,
  12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 # See the License for the specific language governing permissions and
  14 # limitations under the License.
  15 """Task to filter a text file using extended regular expression patterns."""
  16 
  17 from __future__ import unicode_literals
  18 
  19 import os
  20 from tempfile import NamedTemporaryFile
  21 
  22 from turbinia.evidence import FilteredTextFile
  23 from turbinia.workers import TurbiniaTask
  24 
  25 
  26 class GrepTask(TurbiniaTask):
  27   """Filter input based on extended regular expression patterns."""
  28 
  29   def run(self, evidence, result):
  30     """Run grep binary.
  31 
  32     Args:
  33         evidence (Evidence object):  The evidence we will process
  34         result (TurbiniaTaskResult): The object to place task results into.
  35 
  36     Returns:
  37         TurbiniaTaskResult object.
  38     """
  39 
  40     patterns = evidence.config.get('filter_patterns')
  41     if not patterns:
  42       result.close(self, success=True, status='No patterns supplied, exit task')
  43       return result
  44 
  45     # Create temporary file to write patterns to.
  46     # Used as input to grep (-f).
  47     with NamedTemporaryFile(dir=self.output_dir, delete=False) as fh:
  48       patterns_file_path = fh.name
  49       fh.write('\n'.join(patterns))
  50 
  51     # Create a path that we can write the new file to.
  52     base_name = os.path.basename(evidence.local_path)
  53     output_file_path = os.path.join(
  54         self.output_dir, '{0:s}.filtered'.format(base_name))
  55 
  56     output_evidence = FilteredTextFile(source_path=output_file_path)
  57     cmd = 'grep -E -b -n -f {0:s} {1:s} > {2:s}'.format(
  58         patterns_file_path, evidence.local_path, output_file_path)
  59 
  60     result.log('Running [{0:s}]'.format(cmd))
  61     ret, result = self.execute(
  62         cmd, result, new_evidence=[output_evidence], shell=True,
  63         success_codes=[0, 1])
  64 
  65     # Grep returns 0 on success and 1 if no results are found.
  66     if ret == 0:
  67       status = 'Grep Task found results in {0:s}'.format(evidence.name)
  68       result.close(self, success=True, status=status)
  69     elif ret == 1:
  70       status = 'Grep Task did not find any results in {0:s}'.format(
  71           evidence.name)
  72       result.close(self, success=True, status=status)
  73     else:
  74       result.close(self, success=False)
  75 
  76     return result
  77
  ```
  --- 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/turbinia/workers/grep.py b/turbinia/workers/grep.py
  --- a/turbinia/workers/grep.py
  +++ b/turbinia/workers/grep.py
  @@ -46,7 +46,7 @@
       # Used as input to grep (-f).
       with NamedTemporaryFile(dir=self.output_dir, delete=False) as fh:
         patterns_file_path = fh.name
  -      fh.write('\n'.join(patterns))
  +      fh.write('\n'.join(patterns.encode('utf-8')))
   
       # Create a path that we can write the new file to.
       base_name = os.path.basename(evidence.local_path)
  
verification_info: {"golden_diff": "diff --git a/turbinia/workers/grep.py b/turbinia/workers/grep.py\n--- a/turbinia/workers/grep.py\n+++ b/turbinia/workers/grep.py\n@@ -46,7 +46,7 @@\n     # Used as input to grep (-f).\n     with NamedTemporaryFile(dir=self.output_dir, delete=False) as fh:\n       patterns_file_path = fh.name\n-      fh.write('\\n'.join(patterns))\n+      fh.write('\\n'.join(patterns.encode('utf-8')))\n \n     # Create a path that we can write the new file to.\n     base_name = os.path.basename(evidence.local_path)\n", "issue": "GrepTask issue\n```\r\n2021-04-28 17:13:25 [ERROR] GrepTask Task failed with exception: [a bytes-like object is required, not 'str']\r\n2021-04-28 17:13:25 [ERROR] Traceback (most recent call last):\r\n  File \"/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/__init__.py\", line 893, in run_wrapper\r\n    self.result = self.run(evidence, self.result)\r\n  File \"/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/grep.py\", line 49, in run\r\n    fh.write('\\n'.join(patterns))\r\n  File \"/usr/lib/python3.6/tempfile.py\", line 624, in func_wrapper\r\n    return func(*args, **kwargs)\r\nTypeError: a bytes-like object is required, not 'str'\r\n\r\n2021-04-28 17:13:26 [ERROR] GrepTask Task failed with exception: [a bytes-like object is required, not 'str']\r\n2021-04-28 17:13:26 [INFO] Traceback (most recent call last):\r\n  File \"/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/__init__.py\", line 893, in run_wrapper\r\n    self.result = self.run(evidence, self.result)\r\n  File \"/usr/local/lib/python3.6/dist-packages/turbinia-20210330-py3.6.egg/turbinia/workers/grep.py\", line 49, in run\r\n    fh.write('\\n'.join(patterns))\r\n  File \"/usr/lib/python3.6/tempfile.py\", line 624, in func_wrapper\r\n    return func(*args, **kwargs)\r\nTypeError: a bytes-like object is required, not 'str'\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2015 Google Inc.\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\"\"\"Task to filter a text file using extended regular expression patterns.\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport os\nfrom tempfile import NamedTemporaryFile\n\nfrom turbinia.evidence import FilteredTextFile\nfrom turbinia.workers import TurbiniaTask\n\n\nclass GrepTask(TurbiniaTask):\n  \"\"\"Filter input based on extended regular expression patterns.\"\"\"\n\n  def run(self, evidence, result):\n    \"\"\"Run grep binary.\n\n    Args:\n        evidence (Evidence object):  The evidence we will process\n        result (TurbiniaTaskResult): The object to place task results into.\n\n    Returns:\n        TurbiniaTaskResult object.\n    \"\"\"\n\n    patterns = evidence.config.get('filter_patterns')\n    if not patterns:\n      result.close(self, success=True, status='No patterns supplied, exit task')\n      return result\n\n    # Create temporary file to write patterns to.\n    # Used as input to grep (-f).\n    with NamedTemporaryFile(dir=self.output_dir, delete=False) as fh:\n      patterns_file_path = fh.name\n      fh.write('\\n'.join(patterns))\n\n    # Create a path that we can write the new file to.\n    base_name = os.path.basename(evidence.local_path)\n    output_file_path = os.path.join(\n        self.output_dir, '{0:s}.filtered'.format(base_name))\n\n    output_evidence = FilteredTextFile(source_path=output_file_path)\n    cmd = 'grep -E -b -n -f {0:s} {1:s} > {2:s}'.format(\n        patterns_file_path, evidence.local_path, output_file_path)\n\n    result.log('Running [{0:s}]'.format(cmd))\n    ret, result = self.execute(\n        cmd, result, new_evidence=[output_evidence], shell=True,\n        success_codes=[0, 1])\n\n    # Grep returns 0 on success and 1 if no results are found.\n    if ret == 0:\n      status = 'Grep Task found results in {0:s}'.format(evidence.name)\n      result.close(self, success=True, status=status)\n    elif ret == 1:\n      status = 'Grep Task did not find any results in {0:s}'.format(\n          evidence.name)\n      result.close(self, success=True, status=status)\n    else:\n      result.close(self, success=False)\n\n    return result\n", "path": "turbinia/workers/grep.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Copyright 2015 Google Inc.\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\"\"\"Task to filter a text file using extended regular expression patterns.\"\"\"\n\nfrom __future__ import unicode_literals\n\nimport os\nfrom tempfile import NamedTemporaryFile\n\nfrom turbinia.evidence import FilteredTextFile\nfrom turbinia.workers import TurbiniaTask\n\n\nclass GrepTask(TurbiniaTask):\n  \"\"\"Filter input based on extended regular expression patterns.\"\"\"\n\n  def run(self, evidence, result):\n    \"\"\"Run grep binary.\n\n    Args:\n        evidence (Evidence object):  The evidence we will process\n        result (TurbiniaTaskResult): The object to place task results into.\n\n    Returns:\n        TurbiniaTaskResult object.\n    \"\"\"\n\n    patterns = evidence.config.get('filter_patterns')\n    if not patterns:\n      result.close(self, success=True, status='No patterns supplied, exit task')\n      return result\n\n    # Create temporary file to write patterns to.\n    # Used as input to grep (-f).\n    with NamedTemporaryFile(dir=self.output_dir, delete=False) as fh:\n      patterns_file_path = fh.name\n      fh.write('\\n'.join(patterns.encode('utf-8')))\n\n    # Create a path that we can write the new file to.\n    base_name = os.path.basename(evidence.local_path)\n    output_file_path = os.path.join(\n        self.output_dir, '{0:s}.filtered'.format(base_name))\n\n    output_evidence = FilteredTextFile(source_path=output_file_path)\n    cmd = 'grep -E -b -n -f {0:s} {1:s} > {2:s}'.format(\n        patterns_file_path, evidence.local_path, output_file_path)\n\n    result.log('Running [{0:s}]'.format(cmd))\n    ret, result = self.execute(\n        cmd, result, new_evidence=[output_evidence], shell=True,\n        success_codes=[0, 1])\n\n    # Grep returns 0 on success and 1 if no results are found.\n    if ret == 0:\n      status = 'Grep Task found results in {0:s}'.format(evidence.name)\n      result.close(self, success=True, status=status)\n    elif ret == 1:\n      status = 'Grep Task did not find any results in {0:s}'.format(\n          evidence.name)\n      result.close(self, success=True, status=status)\n    else:\n      result.close(self, success=False)\n\n    return result\n", "path": "turbinia/workers/grep.py"}]}