prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  yum.repos.d parser is too tolerant
  The yum repos d parser will accept almost anything, including binary.
  
  </issue>
  <code>
  [start of insights/parsers/yum_repos_d.py]
  1 from .. import Parser, parser, get_active_lines, LegacyItemAccess
  2 from insights.specs import Specs
  3 
  4 
  5 @parser(Specs.yum_repos_d)
  6 class YumReposD(LegacyItemAccess, Parser):
  7     """Class to parse the files under ``yum.repos.d`` """
  8 
  9     def get(self, key):
  10         return self.data.get(key)
  11 
  12     def parse_content(self, content):
  13         '''
  14         Return an object contains a dict.
  15         {
  16             "rhel-source": {
  17                 "gpgcheck": "1",
  18                 "gpgkey": ["file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release",
  19                            "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak"]
  20                 "enabled": "0",
  21                 "name": "Red Hat Enterprise Linux $releasever - $basearch - Source",
  22                 "baseurl": "ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/"
  23             }
  24         }
  25         ----------------------------------------------------
  26         There are several files in 'yum.repos.d' directory, which have the same
  27         format.  For example:
  28         --------one of the files : rhel-source.repo---------
  29         [rhel-source]
  30         name=Red Hat Enterprise Linux $releasever - $basearch - Source
  31         baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/
  32         enabled=0
  33         gpgcheck=1
  34         gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
  35                file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak
  36         '''
  37         repos_dict = {}
  38         section_dict = {}
  39         key = None
  40         for line in get_active_lines(content):
  41             if line.startswith('['):
  42                 section_dict = {}
  43                 repos_dict[line[1:-1]] = section_dict
  44             elif '=' in line:
  45                 key, value = [s.strip() for s in line.split("=", 1)]
  46                 if key in ('baseurl', 'gpgkey'):
  47                     section_dict[key] = [v.strip() for v in value.split(",")]
  48                 else:
  49                     section_dict[key] = value
  50             else:
  51                 if key and isinstance(section_dict[key], list):
  52                     section_dict[key].extend(v.strip() for v in line.split(","))
  53                 # Otherwise ignore line if no key or we don't store multiple values
  54         self.data = repos_dict
  55 
  56     def __iter__(self):
  57         for repo in self.data:
  58             yield repo
  59
  [end of insights/parsers/yum_repos_d.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/insights/parsers/yum_repos_d.py b/insights/parsers/yum_repos_d.py
  --- a/insights/parsers/yum_repos_d.py
  +++ b/insights/parsers/yum_repos_d.py
  @@ -1,5 +1,39 @@
  -from .. import Parser, parser, get_active_lines, LegacyItemAccess
  +import re
  +import string
  +
  +from .. import Parser, parser, LegacyItemAccess
   from insights.specs import Specs
  +from insights.parsr import (Char, EOF, HangingString, InSet, Many, OneLineComment, Opt,
  +                            skip_none, String, WithIndent, WS)
  +
  +
  +header_chars = (set(string.printable) - set(string.whitespace) - set("[]")) | set(" ")
  +sep_chars = set(":=")
  +key_chars = header_chars - sep_chars - set(" ")
  +value_chars = set(string.printable) - set("\n\r")
  +
  +LeftEnd = WS >> Char("[") << WS
  +RightEnd = WS >> Char("]") << WS
  +Header = LeftEnd >> String(header_chars) << RightEnd
  +Key = WS >> String(key_chars) << WS
  +Sep = InSet(sep_chars)
  +Value = WS >> HangingString(value_chars)
  +KVPair = WithIndent(Key + Opt(Sep >> Value))
  +Comment = WS >> (OneLineComment("#") | OneLineComment(";")).map(lambda x: None)
  +
  +Line = Comment | KVPair.map(tuple)
  +Sect = (Header + Many(Line).map(skip_none).map(dict)).map(tuple)
  +Doc = Many(Comment | Sect).map(skip_none).map(dict)
  +Top = Doc << WS << EOF
  +
  +
  +def parse_yum_repos(content):
  +    doc = Top(content)
  +    for k, v in doc.items():
  +        for special in ("baseurl", "gpgkey"):
  +            if special in v:
  +                v[special] = [i.strip() for i in re.split(",| ", v[special])]
  +    return doc
   
   
   @parser(Specs.yum_repos_d)
  @@ -10,7 +44,7 @@
           return self.data.get(key)
   
       def parse_content(self, content):
  -        '''
  +        """
           Return an object contains a dict.
           {
               "rhel-source": {
  @@ -33,25 +67,8 @@
           gpgcheck=1
           gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
                  file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak
  -        '''
  -        repos_dict = {}
  -        section_dict = {}
  -        key = None
  -        for line in get_active_lines(content):
  -            if line.startswith('['):
  -                section_dict = {}
  -                repos_dict[line[1:-1]] = section_dict
  -            elif '=' in line:
  -                key, value = [s.strip() for s in line.split("=", 1)]
  -                if key in ('baseurl', 'gpgkey'):
  -                    section_dict[key] = [v.strip() for v in value.split(",")]
  -                else:
  -                    section_dict[key] = value
  -            else:
  -                if key and isinstance(section_dict[key], list):
  -                    section_dict[key].extend(v.strip() for v in line.split(","))
  -                # Otherwise ignore line if no key or we don't store multiple values
  -        self.data = repos_dict
  +        """
  +        self.data = parse_yum_repos("\n".join(content))
   
       def __iter__(self):
           for repo in self.data:
  
verification_info: {"golden_diff": "diff --git a/insights/parsers/yum_repos_d.py b/insights/parsers/yum_repos_d.py\n--- a/insights/parsers/yum_repos_d.py\n+++ b/insights/parsers/yum_repos_d.py\n@@ -1,5 +1,39 @@\n-from .. import Parser, parser, get_active_lines, LegacyItemAccess\n+import re\n+import string\n+\n+from .. import Parser, parser, LegacyItemAccess\n from insights.specs import Specs\n+from insights.parsr import (Char, EOF, HangingString, InSet, Many, OneLineComment, Opt,\n+                            skip_none, String, WithIndent, WS)\n+\n+\n+header_chars = (set(string.printable) - set(string.whitespace) - set(\"[]\")) | set(\" \")\n+sep_chars = set(\":=\")\n+key_chars = header_chars - sep_chars - set(\" \")\n+value_chars = set(string.printable) - set(\"\\n\\r\")\n+\n+LeftEnd = WS >> Char(\"[\") << WS\n+RightEnd = WS >> Char(\"]\") << WS\n+Header = LeftEnd >> String(header_chars) << RightEnd\n+Key = WS >> String(key_chars) << WS\n+Sep = InSet(sep_chars)\n+Value = WS >> HangingString(value_chars)\n+KVPair = WithIndent(Key + Opt(Sep >> Value))\n+Comment = WS >> (OneLineComment(\"#\") | OneLineComment(\";\")).map(lambda x: None)\n+\n+Line = Comment | KVPair.map(tuple)\n+Sect = (Header + Many(Line).map(skip_none).map(dict)).map(tuple)\n+Doc = Many(Comment | Sect).map(skip_none).map(dict)\n+Top = Doc << WS << EOF\n+\n+\n+def parse_yum_repos(content):\n+    doc = Top(content)\n+    for k, v in doc.items():\n+        for special in (\"baseurl\", \"gpgkey\"):\n+            if special in v:\n+                v[special] = [i.strip() for i in re.split(\",| \", v[special])]\n+    return doc\n \n \n @parser(Specs.yum_repos_d)\n@@ -10,7 +44,7 @@\n         return self.data.get(key)\n \n     def parse_content(self, content):\n-        '''\n+        \"\"\"\n         Return an object contains a dict.\n         {\n             \"rhel-source\": {\n@@ -33,25 +67,8 @@\n         gpgcheck=1\n         gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release\n                file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak\n-        '''\n-        repos_dict = {}\n-        section_dict = {}\n-        key = None\n-        for line in get_active_lines(content):\n-            if line.startswith('['):\n-                section_dict = {}\n-                repos_dict[line[1:-1]] = section_dict\n-            elif '=' in line:\n-                key, value = [s.strip() for s in line.split(\"=\", 1)]\n-                if key in ('baseurl', 'gpgkey'):\n-                    section_dict[key] = [v.strip() for v in value.split(\",\")]\n-                else:\n-                    section_dict[key] = value\n-            else:\n-                if key and isinstance(section_dict[key], list):\n-                    section_dict[key].extend(v.strip() for v in line.split(\",\"))\n-                # Otherwise ignore line if no key or we don't store multiple values\n-        self.data = repos_dict\n+        \"\"\"\n+        self.data = parse_yum_repos(\"\\n\".join(content))\n \n     def __iter__(self):\n         for repo in self.data:\n", "issue": "yum.repos.d parser is too tolerant\nThe yum repos d parser will accept almost anything, including binary.\n", "before_files": [{"content": "from .. import Parser, parser, get_active_lines, LegacyItemAccess\nfrom insights.specs import Specs\n\n\n@parser(Specs.yum_repos_d)\nclass YumReposD(LegacyItemAccess, Parser):\n    \"\"\"Class to parse the files under ``yum.repos.d`` \"\"\"\n\n    def get(self, key):\n        return self.data.get(key)\n\n    def parse_content(self, content):\n        '''\n        Return an object contains a dict.\n        {\n            \"rhel-source\": {\n                \"gpgcheck\": \"1\",\n                \"gpgkey\": [\"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release\",\n                           \"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak\"]\n                \"enabled\": \"0\",\n                \"name\": \"Red Hat Enterprise Linux $releasever - $basearch - Source\",\n                \"baseurl\": \"ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/\"\n            }\n        }\n        ----------------------------------------------------\n        There are several files in 'yum.repos.d' directory, which have the same\n        format.  For example:\n        --------one of the files : rhel-source.repo---------\n        [rhel-source]\n        name=Red Hat Enterprise Linux $releasever - $basearch - Source\n        baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/SRPMS/\n        enabled=0\n        gpgcheck=1\n        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release\n               file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release_bak\n        '''\n        repos_dict = {}\n        section_dict = {}\n        key = None\n        for line in get_active_lines(content):\n            if line.startswith('['):\n                section_dict = {}\n                repos_dict[line[1:-1]] = section_dict\n            elif '=' in line:\n                key, value = [s.strip() for s in line.split(\"=\", 1)]\n                if key in ('baseurl', 'gpgkey'):\n                    section_dict[key] = [v.strip() for v in value.split(\",\")]\n                else:\n                    section_dict[key] = value\n            else:\n                if key and isinstance(section_dict[key], list):\n                    section_dict[key].extend(v.strip() for v in line.split(\",\"))\n                # Otherwise ignore line if no key or we don't store multiple values\n        self.data = repos_dict\n\n    def __iter__(self):\n        for repo in self.data:\n            yield repo\n", "path": "insights/parsers/yum_repos_d.py"}]}