prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add query type to linux.dig action
  ## SUMMARY
  
  I would like the ability to query TXT records and noticed there is no way to specify a query type to the dig action. 
  
  ### STACKSTORM VERSION
  
  `st2 3.6.0, on Python 3.6.8`
  
  ## Steps to reproduce the problem
  
  I attempted a few ways to add "TXT" to the query by adding to queryopts or try appending to the string hostname. Upon looking at the code I realized nothing like that would work.
  
  ## Expected Results
  
  Get a list returned of TXT records
  
  ## Some sample code to add it
  
  ```
  class DigAction(Action):
      def run(self, rand, count, nameserver, hostname, queryopts, querytype): # Add querytype parameter
          opt_list = []
          output = []
  
          cmd_args = ["dig"]
          if nameserver:
              nameserver = "@" + nameserver
              cmd_args.append(nameserver)
  
          if isinstance(queryopts, str) and "," in queryopts:
              opt_list = queryopts.split(",")
          else:
              opt_list.append(queryopts)
  
          cmd_args.extend(["+" + option for option in opt_list])
  
          cmd_args.append(hostname)
          cmd_args.append(querytype) # append query type (Default is set to "A" in dig.yaml)
  
          try:
              raw_result = subprocess.Popen(
                  cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE
              ).communicate()[0]
  
              if sys.version_info >= (3,):
                  # This function might call getpreferred encoding unless we pass
                  # do_setlocale=False.
                  encoding = locale.getpreferredencoding(do_setlocale=False)
                  result_list_str = raw_result.decode(encoding)
              else:
                  result_list_str = str(raw_result)
  
              if querytype.lower() == "txt":   # improve the output formatting result of TXT records
                  result_list_str = result_list_str.replace('"', '')   # strip quotes so we don't see \" wrapped around output
              result_list = list(filter(None, result_list_str.split("\n")))
  ```
  
  I only spent a few minutes on this code to test making it work for me. It could be improved on to make sure works for other types as well. I added inline comments to show the only lines I added
  
  </issue>
  <code>
  [start of contrib/linux/actions/dig.py]
  1 #! /usr/bin/python
  2 
  3 # Copyright 2020 The StackStorm Authors.
  4 # Copyright 2019 Extreme Networks, Inc.
  5 #
  6 # Licensed under the Apache License, Version 2.0 (the "License");
  7 # you may not use this file except in compliance with the License.
  8 # You may obtain a copy of the License at
  9 #
  10 #     http://www.apache.org/licenses/LICENSE-2.0
  11 #
  12 # Unless required by applicable law or agreed to in writing, software
  13 # distributed under the License is distributed on an "AS IS" BASIS,
  14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15 # See the License for the specific language governing permissions and
  16 # limitations under the License.
  17 
  18 import errno
  19 import locale
  20 import subprocess
  21 import random
  22 import sys
  23 
  24 from st2common.runners.base_action import Action
  25 
  26 
  27 class DigAction(Action):
  28     def run(self, rand, count, nameserver, hostname, queryopts):
  29         opt_list = []
  30         output = []
  31 
  32         cmd_args = ["dig"]
  33         if nameserver:
  34             nameserver = "@" + nameserver
  35             cmd_args.append(nameserver)
  36 
  37         if isinstance(queryopts, str) and "," in queryopts:
  38             opt_list = queryopts.split(",")
  39         else:
  40             opt_list.append(queryopts)
  41 
  42         cmd_args.extend(["+" + option for option in opt_list])
  43 
  44         cmd_args.append(hostname)
  45 
  46         try:
  47             raw_result = subprocess.Popen(
  48                 cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE
  49             ).communicate()[0]
  50 
  51             if sys.version_info >= (3,):
  52                 # This function might call getpreferred encoding unless we pass
  53                 # do_setlocale=False.
  54                 encoding = locale.getpreferredencoding(do_setlocale=False)
  55                 result_list_str = raw_result.decode(encoding)
  56             else:
  57                 result_list_str = str(raw_result)
  58 
  59             result_list = list(filter(None, result_list_str.split("\n")))
  60 
  61         # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat
  62         # for Python3:
  63         # except FileNotFoundError as e:
  64         except OSError as e:
  65             if e.errno == errno.ENOENT:
  66                 return (
  67                     False,
  68                     "Can't find dig installed in the path (usually /usr/bin/dig). If "
  69                     "dig isn't installed, you can install it with 'sudo yum install "
  70                     "bind-utils' or 'sudo apt install dnsutils'",
  71                 )
  72             else:
  73                 raise e
  74 
  75         if int(count) > len(result_list) or count <= 0:
  76             count = len(result_list)
  77 
  78         output = result_list[0:count]
  79         if rand is True:
  80             random.shuffle(output)
  81         return output
  82
  [end of contrib/linux/actions/dig.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/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py
  --- a/contrib/linux/actions/dig.py
  +++ b/contrib/linux/actions/dig.py
  @@ -25,7 +25,7 @@
   
   
   class DigAction(Action):
  -    def run(self, rand, count, nameserver, hostname, queryopts):
  +    def run(self, rand, count, nameserver, hostname, queryopts, querytype):
           opt_list = []
           output = []
   
  @@ -42,6 +42,7 @@
           cmd_args.extend(["+" + option for option in opt_list])
   
           cmd_args.append(hostname)
  +        cmd_args.append(querytype)
   
           try:
               raw_result = subprocess.Popen(
  @@ -56,6 +57,10 @@
               else:
                   result_list_str = str(raw_result)
   
  +            # Better format the output when the type is TXT
  +            if querytype.lower() == "txt":
  +                result_list_str = result_list_str.replace('"', "")
  +
               result_list = list(filter(None, result_list_str.split("\n")))
   
           # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat
  
verification_info: {"golden_diff": "diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py\n--- a/contrib/linux/actions/dig.py\n+++ b/contrib/linux/actions/dig.py\n@@ -25,7 +25,7 @@\n \n \n class DigAction(Action):\n-    def run(self, rand, count, nameserver, hostname, queryopts):\n+    def run(self, rand, count, nameserver, hostname, queryopts, querytype):\n         opt_list = []\n         output = []\n \n@@ -42,6 +42,7 @@\n         cmd_args.extend([\"+\" + option for option in opt_list])\n \n         cmd_args.append(hostname)\n+        cmd_args.append(querytype)\n \n         try:\n             raw_result = subprocess.Popen(\n@@ -56,6 +57,10 @@\n             else:\n                 result_list_str = str(raw_result)\n \n+            # Better format the output when the type is TXT\n+            if querytype.lower() == \"txt\":\n+                result_list_str = result_list_str.replace('\"', \"\")\n+\n             result_list = list(filter(None, result_list_str.split(\"\\n\")))\n \n         # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat\n", "issue": "Add query type to linux.dig action\n## SUMMARY\r\n\r\nI would like the ability to query TXT records and noticed there is no way to specify a query type to the dig action. \r\n\r\n### STACKSTORM VERSION\r\n\r\n`st2 3.6.0, on Python 3.6.8`\r\n\r\n## Steps to reproduce the problem\r\n\r\nI attempted a few ways to add \"TXT\" to the query by adding to queryopts or try appending to the string hostname. Upon looking at the code I realized nothing like that would work.\r\n\r\n## Expected Results\r\n\r\nGet a list returned of TXT records\r\n\r\n## Some sample code to add it\r\n\r\n```\r\nclass DigAction(Action):\r\n    def run(self, rand, count, nameserver, hostname, queryopts, querytype): # Add querytype parameter\r\n        opt_list = []\r\n        output = []\r\n\r\n        cmd_args = [\"dig\"]\r\n        if nameserver:\r\n            nameserver = \"@\" + nameserver\r\n            cmd_args.append(nameserver)\r\n\r\n        if isinstance(queryopts, str) and \",\" in queryopts:\r\n            opt_list = queryopts.split(\",\")\r\n        else:\r\n            opt_list.append(queryopts)\r\n\r\n        cmd_args.extend([\"+\" + option for option in opt_list])\r\n\r\n        cmd_args.append(hostname)\r\n        cmd_args.append(querytype) # append query type (Default is set to \"A\" in dig.yaml)\r\n\r\n        try:\r\n            raw_result = subprocess.Popen(\r\n                cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE\r\n            ).communicate()[0]\r\n\r\n            if sys.version_info >= (3,):\r\n                # This function might call getpreferred encoding unless we pass\r\n                # do_setlocale=False.\r\n                encoding = locale.getpreferredencoding(do_setlocale=False)\r\n                result_list_str = raw_result.decode(encoding)\r\n            else:\r\n                result_list_str = str(raw_result)\r\n\r\n            if querytype.lower() == \"txt\":   # improve the output formatting result of TXT records\r\n                result_list_str = result_list_str.replace('\"', '')   # strip quotes so we don't see \\\" wrapped around output\r\n            result_list = list(filter(None, result_list_str.split(\"\\n\")))\r\n```\r\n\r\nI only spent a few minutes on this code to test making it work for me. It could be improved on to make sure works for other types as well. I added inline comments to show the only lines I added\n", "before_files": [{"content": "#! /usr/bin/python\n\n# Copyright 2020 The StackStorm Authors.\n# Copyright 2019 Extreme Networks, 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\nimport errno\nimport locale\nimport subprocess\nimport random\nimport sys\n\nfrom st2common.runners.base_action import Action\n\n\nclass DigAction(Action):\n    def run(self, rand, count, nameserver, hostname, queryopts):\n        opt_list = []\n        output = []\n\n        cmd_args = [\"dig\"]\n        if nameserver:\n            nameserver = \"@\" + nameserver\n            cmd_args.append(nameserver)\n\n        if isinstance(queryopts, str) and \",\" in queryopts:\n            opt_list = queryopts.split(\",\")\n        else:\n            opt_list.append(queryopts)\n\n        cmd_args.extend([\"+\" + option for option in opt_list])\n\n        cmd_args.append(hostname)\n\n        try:\n            raw_result = subprocess.Popen(\n                cmd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE\n            ).communicate()[0]\n\n            if sys.version_info >= (3,):\n                # This function might call getpreferred encoding unless we pass\n                # do_setlocale=False.\n                encoding = locale.getpreferredencoding(do_setlocale=False)\n                result_list_str = raw_result.decode(encoding)\n            else:\n                result_list_str = str(raw_result)\n\n            result_list = list(filter(None, result_list_str.split(\"\\n\")))\n\n        # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat\n        # for Python3:\n        # except FileNotFoundError as e:\n        except OSError as e:\n            if e.errno == errno.ENOENT:\n                return (\n                    False,\n                    \"Can't find dig installed in the path (usually /usr/bin/dig). If \"\n                    \"dig isn't installed, you can install it with 'sudo yum install \"\n                    \"bind-utils' or 'sudo apt install dnsutils'\",\n                )\n            else:\n                raise e\n\n        if int(count) > len(result_list) or count <= 0:\n            count = len(result_list)\n\n        output = result_list[0:count]\n        if rand is True:\n            random.shuffle(output)\n        return output\n", "path": "contrib/linux/actions/dig.py"}]}