We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Disk read/write stats in diskdata isn't computed correctly when a disk is specified
When a disk is specified, a logic error in _get_io_stats() results in statistics for all drives being summed, rather than just the selected drive.

Additionally, the filtering is a simple string match, so specifying "sda" or "/dev/sda" will sum stats for "sda", "sda1", "sda2", etc resulting in incorrect values.

Pull request is incoming momentarily to fix both of these issues.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `py3status/modules/diskdata.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3 Display disk information.
4 
5 Configuration parameters:
6     cache_timeout: refresh interval for this module. (default 10)
7     disk: show stats for disk or partition, i.e. `sda1`. None for all disks.
8         (default None)
9     format: display format for this module.
10         (default "{disk}: {used_percent}% ({total})")
11     format_rate: display format for rates value
12         (default "[\?min_length=11 {value:.1f} {unit}]")
13     format_space: display format for disk space values
14         (default "[\?min_length=5 {value:.1f}]")
15     sector_size: size of the disk's sectors.
16         (default 512)
17     si_units: use SI units
18         (default False)
19     thresholds: thresholds to use for color changes
20         *(default {'free': [(0, 'bad'), (10, 'degraded'), (100, 'good')],
21         'total': [(0, "good"), (1024, 'degraded'), (1024 * 1024, 'bad')]})*
22     unit: unit to use. If the unit contains a multiplier prefix, only this
23         exact unit will ever be used
24         (default "B/s")
25 
26 Format placeholders:
27     {disk} the selected disk
28     {free} free space on disk in GB
29     {used} used space on disk in GB
30     {total_space} total space on disk in GB
31     {used_percent} used space on disk in %
32     {read} reading rate
33     {total} total IO rate
34     {write} writing rate
35 
36 format_rate placeholders:
37     {unit} name of the unit
38     {value} numeric value of the rate
39 
40 format_space placeholders:
41     {value} numeric value of the free/used space on the device
42 
43 Color thresholds:
44     {free} Change color based on the value of free
45     {used} Change color based on the value of used_percent
46     {read} Change color based on the value of read
47     {total} Change color based on the value of total
48     {write} Change color based on the value of write
49 
50 @author guiniol
51 @license BSD
52 
53 SAMPLE OUTPUT
54 {'full_text': 'all:  34.4% ( 82.0 KiB/s)'}
55 """
56 
57 from __future__ import division  # python2 compatibility
58 from time import time
59 
60 
61 class Py3status:
62     """
63     """
64     # available configuration parameters
65     cache_timeout = 10
66     disk = None
67     format = "{disk}: {used_percent}% ({total})"
68     format_rate = "[\?min_length=11 {value:.1f} {unit}]"
69     format_space = "[\?min_length=5 {value:.1f}]"
70     sector_size = 512
71     si_units = False
72     thresholds = {
73         'free': [(0, "bad"), (10, "degraded"), (100, "good")],
74         'total': [(0, "good"), (1024, "degraded"), (1024 * 1024, "bad")]
75     }
76     unit = "B/s"
77 
78     def post_config_hook(self):
79         """
80         Format of total, up and down placeholders under self.format.
81         As default, substitutes self.left_align and self.precision as %s and %s
82         Placeholders:
83             value - value (float)
84             unit - unit (string)
85         """
86         self.last_interface = None
87         self.last_stat = self._get_io_stats(self.disk)
88         self.last_time = time()
89 
90     def space_and_io(self):
91         self.values = {'disk': self.disk if self.disk else 'all'}
92 
93         if self.py3.format_contains(self.format, ['read', 'write', 'total']):
94             # time from previous check
95             ios = self._get_io_stats(self.disk)
96             timedelta = time() - self.last_time
97 
98             read = ios[0] - self.last_stat[0]
99             write = ios[1] - self.last_stat[1]
100 
101             # update last_ info
102             self.last_stat = self._get_io_stats(self.disk)
103             self.last_time = time()
104 
105             read /= timedelta
106             write /= timedelta
107 
108             total = read + write
109 
110             self.values['read'] = self._format_rate(read)
111             self.values['total'] = self._format_rate(total)
112             self.values['write'] = self._format_rate(write)
113             self.py3.threshold_get_color(read, 'read')
114             self.py3.threshold_get_color(total, 'total')
115             self.py3.threshold_get_color(write, 'write')
116 
117         if self.py3.format_contains(self.format, ['free', 'used*', 'total_space']):
118             free, used, used_percent, total_space = self._get_free_space(self.disk)
119 
120             self.values['free'] = self.py3.safe_format(self.format_space, {'value': free})
121             self.values['used'] = self.py3.safe_format(self.format_space, {'value': used})
122             self.values['used_percent'] = self.py3.safe_format(self.format_space,
123                                                                {'value': used_percent})
124             self.values['total_space'] = self.py3.safe_format(self.format_space,
125                                                               {'value': total_space})
126             self.py3.threshold_get_color(free, 'free')
127             self.py3.threshold_get_color(used, 'used')
128 
129         return {
130             'cached_until': self.py3.time_in(self.cache_timeout),
131             'full_text': self.py3.safe_format(self.format, self.values)
132         }
133 
134     def _get_free_space(self, disk):
135         if disk and not disk.startswith('/dev/'):
136             disk = '/dev/' + disk
137 
138         total = 0
139         used = 0
140         free = 0
141         devs = []
142 
143         df = self.py3.command_output('df')
144         for line in df.splitlines():
145             if (disk and line.startswith(disk)) or (disk is None and line.startswith('/dev/')):
146                 data = line.split()
147                 if data[0] in devs:
148                     # Make sure to count each block device only one time
149                     # some filesystems eg btrfs have multiple entries
150                     continue
151                 total += int(data[1]) / 1024 / 1024
152                 used += int(data[2]) / 1024 / 1024
153                 free += int(data[3]) / 1024 / 1024
154                 devs.append(data[0])
155 
156         if total == 0:
157             return free, used, 'err', total
158 
159         return free, used, 100 * used / total, total
160 
161     def _get_io_stats(self, disk):
162         if disk and disk.startswith('/dev/'):
163             disk = disk[5:]
164         read = 0
165         write = 0
166         with open('/proc/diskstats', 'r') as fd:
167             for line in fd:
168                 if disk and disk in line:
169                     data = line.split()
170                     read += int(data[5]) * self.sector_size
171                     write += int(data[9]) * self.sector_size
172                 else:
173                     data = line.split()
174                     if data[1] == '0':
175                         read += int(data[5]) * self.sector_size
176                         write += int(data[9]) * self.sector_size
177         return read, write
178 
179     def _format_rate(self, value):
180         """
181         Return formatted string
182         """
183         value, unit = self.py3.format_units(value, unit=self.unit, si=self.si_units)
184         return self.py3.safe_format(self.format_rate, {'value': value, 'unit': unit})
185 
186 
187 if __name__ == "__main__":
188     """
189     Run module in test mode.
190     """
191     from py3status.module_test import module_test
192     module_test(Py3status)
193
```
--- 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/py3status/modules/diskdata.py b/py3status/modules/diskdata.py
--- a/py3status/modules/diskdata.py
+++ b/py3status/modules/diskdata.py
@@ -165,12 +165,12 @@
         write = 0
         with open('/proc/diskstats', 'r') as fd:
             for line in fd:
-                if disk and disk in line:
-                    data = line.split()
-                    read += int(data[5]) * self.sector_size
-                    write += int(data[9]) * self.sector_size
+                data = line.split()
+                if disk:
+                    if data[2] == disk:
+                        read += int(data[5]) * self.sector_size
+                        write += int(data[9]) * self.sector_size
                 else:
-                    data = line.split()
                     if data[1] == '0':
                         read += int(data[5]) * self.sector_size
                         write += int(data[9]) * self.sector_size

{"golden_diff": "diff --git a/py3status/modules/diskdata.py b/py3status/modules/diskdata.py\n--- a/py3status/modules/diskdata.py\n+++ b/py3status/modules/diskdata.py\n@@ -165,12 +165,12 @@\n         write = 0\n         with open('/proc/diskstats', 'r') as fd:\n             for line in fd:\n-                if disk and disk in line:\n-                    data = line.split()\n-                    read += int(data[5]) * self.sector_size\n-                    write += int(data[9]) * self.sector_size\n+                data = line.split()\n+                if disk:\n+                    if data[2] == disk:\n+                        read += int(data[5]) * self.sector_size\n+                        write += int(data[9]) * self.sector_size\n                 else:\n-                    data = line.split()\n                     if data[1] == '0':\n                         read += int(data[5]) * self.sector_size\n                         write += int(data[9]) * self.sector_size\n", "issue": "Disk read/write stats in diskdata isn't computed correctly when a disk is specified\nWhen a disk is specified, a logic error in _get_io_stats() results in statistics for all drives being summed, rather than just the selected drive.\r\n\r\nAdditionally, the filtering is a simple string match, so specifying \"sda\" or \"/dev/sda\" will sum stats for \"sda\", \"sda1\", \"sda2\", etc resulting in incorrect values.\r\n\r\nPull request is incoming momentarily to fix both of these issues.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay disk information.\n\nConfiguration parameters:\n    cache_timeout: refresh interval for this module. (default 10)\n    disk: show stats for disk or partition, i.e. `sda1`. None for all disks.\n        (default None)\n    format: display format for this module.\n        (default \"{disk}: {used_percent}% ({total})\")\n    format_rate: display format for rates value\n        (default \"[\\?min_length=11 {value:.1f} {unit}]\")\n    format_space: display format for disk space values\n        (default \"[\\?min_length=5 {value:.1f}]\")\n    sector_size: size of the disk's sectors.\n        (default 512)\n    si_units: use SI units\n        (default False)\n    thresholds: thresholds to use for color changes\n        *(default {'free': [(0, 'bad'), (10, 'degraded'), (100, 'good')],\n        'total': [(0, \"good\"), (1024, 'degraded'), (1024 * 1024, 'bad')]})*\n    unit: unit to use. If the unit contains a multiplier prefix, only this\n        exact unit will ever be used\n        (default \"B/s\")\n\nFormat placeholders:\n    {disk} the selected disk\n    {free} free space on disk in GB\n    {used} used space on disk in GB\n    {total_space} total space on disk in GB\n    {used_percent} used space on disk in %\n    {read} reading rate\n    {total} total IO rate\n    {write} writing rate\n\nformat_rate placeholders:\n    {unit} name of the unit\n    {value} numeric value of the rate\n\nformat_space placeholders:\n    {value} numeric value of the free/used space on the device\n\nColor thresholds:\n    {free} Change color based on the value of free\n    {used} Change color based on the value of used_percent\n    {read} Change color based on the value of read\n    {total} Change color based on the value of total\n    {write} Change color based on the value of write\n\n@author guiniol\n@license BSD\n\nSAMPLE OUTPUT\n{'full_text': 'all:  34.4% ( 82.0 KiB/s)'}\n\"\"\"\n\nfrom __future__ import division  # python2 compatibility\nfrom time import time\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    cache_timeout = 10\n    disk = None\n    format = \"{disk}: {used_percent}% ({total})\"\n    format_rate = \"[\\?min_length=11 {value:.1f} {unit}]\"\n    format_space = \"[\\?min_length=5 {value:.1f}]\"\n    sector_size = 512\n    si_units = False\n    thresholds = {\n        'free': [(0, \"bad\"), (10, \"degraded\"), (100, \"good\")],\n        'total': [(0, \"good\"), (1024, \"degraded\"), (1024 * 1024, \"bad\")]\n    }\n    unit = \"B/s\"\n\n    def post_config_hook(self):\n        \"\"\"\n        Format of total, up and down placeholders under self.format.\n        As default, substitutes self.left_align and self.precision as %s and %s\n        Placeholders:\n            value - value (float)\n            unit - unit (string)\n        \"\"\"\n        self.last_interface = None\n        self.last_stat = self._get_io_stats(self.disk)\n        self.last_time = time()\n\n    def space_and_io(self):\n        self.values = {'disk': self.disk if self.disk else 'all'}\n\n        if self.py3.format_contains(self.format, ['read', 'write', 'total']):\n            # time from previous check\n            ios = self._get_io_stats(self.disk)\n            timedelta = time() - self.last_time\n\n            read = ios[0] - self.last_stat[0]\n            write = ios[1] - self.last_stat[1]\n\n            # update last_ info\n            self.last_stat = self._get_io_stats(self.disk)\n            self.last_time = time()\n\n            read /= timedelta\n            write /= timedelta\n\n            total = read + write\n\n            self.values['read'] = self._format_rate(read)\n            self.values['total'] = self._format_rate(total)\n            self.values['write'] = self._format_rate(write)\n            self.py3.threshold_get_color(read, 'read')\n            self.py3.threshold_get_color(total, 'total')\n            self.py3.threshold_get_color(write, 'write')\n\n        if self.py3.format_contains(self.format, ['free', 'used*', 'total_space']):\n            free, used, used_percent, total_space = self._get_free_space(self.disk)\n\n            self.values['free'] = self.py3.safe_format(self.format_space, {'value': free})\n            self.values['used'] = self.py3.safe_format(self.format_space, {'value': used})\n            self.values['used_percent'] = self.py3.safe_format(self.format_space,\n                                                               {'value': used_percent})\n            self.values['total_space'] = self.py3.safe_format(self.format_space,\n                                                              {'value': total_space})\n            self.py3.threshold_get_color(free, 'free')\n            self.py3.threshold_get_color(used, 'used')\n\n        return {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.py3.safe_format(self.format, self.values)\n        }\n\n    def _get_free_space(self, disk):\n        if disk and not disk.startswith('/dev/'):\n            disk = '/dev/' + disk\n\n        total = 0\n        used = 0\n        free = 0\n        devs = []\n\n        df = self.py3.command_output('df')\n        for line in df.splitlines():\n            if (disk and line.startswith(disk)) or (disk is None and line.startswith('/dev/')):\n                data = line.split()\n                if data[0] in devs:\n                    # Make sure to count each block device only one time\n                    # some filesystems eg btrfs have multiple entries\n                    continue\n                total += int(data[1]) / 1024 / 1024\n                used += int(data[2]) / 1024 / 1024\n                free += int(data[3]) / 1024 / 1024\n                devs.append(data[0])\n\n        if total == 0:\n            return free, used, 'err', total\n\n        return free, used, 100 * used / total, total\n\n    def _get_io_stats(self, disk):\n        if disk and disk.startswith('/dev/'):\n            disk = disk[5:]\n        read = 0\n        write = 0\n        with open('/proc/diskstats', 'r') as fd:\n            for line in fd:\n                if disk and disk in line:\n                    data = line.split()\n                    read += int(data[5]) * self.sector_size\n                    write += int(data[9]) * self.sector_size\n                else:\n                    data = line.split()\n                    if data[1] == '0':\n                        read += int(data[5]) * self.sector_size\n                        write += int(data[9]) * self.sector_size\n        return read, write\n\n    def _format_rate(self, value):\n        \"\"\"\n        Return formatted string\n        \"\"\"\n        value, unit = self.py3.format_units(value, unit=self.unit, si=self.si_units)\n        return self.py3.safe_format(self.format_rate, {'value': value, 'unit': unit})\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n    module_test(Py3status)\n", "path": "py3status/modules/diskdata.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nDisplay disk information.\n\nConfiguration parameters:\n    cache_timeout: refresh interval for this module. (default 10)\n    disk: show stats for disk or partition, i.e. `sda1`. None for all disks.\n        (default None)\n    format: display format for this module.\n        (default \"{disk}: {used_percent}% ({total})\")\n    format_rate: display format for rates value\n        (default \"[\\?min_length=11 {value:.1f} {unit}]\")\n    format_space: display format for disk space values\n        (default \"[\\?min_length=5 {value:.1f}]\")\n    sector_size: size of the disk's sectors.\n        (default 512)\n    si_units: use SI units\n        (default False)\n    thresholds: thresholds to use for color changes\n        *(default {'free': [(0, 'bad'), (10, 'degraded'), (100, 'good')],\n        'total': [(0, \"good\"), (1024, 'degraded'), (1024 * 1024, 'bad')]})*\n    unit: unit to use. If the unit contains a multiplier prefix, only this\n        exact unit will ever be used\n        (default \"B/s\")\n\nFormat placeholders:\n    {disk} the selected disk\n    {free} free space on disk in GB\n    {used} used space on disk in GB\n    {total_space} total space on disk in GB\n    {used_percent} used space on disk in %\n    {read} reading rate\n    {total} total IO rate\n    {write} writing rate\n\nformat_rate placeholders:\n    {unit} name of the unit\n    {value} numeric value of the rate\n\nformat_space placeholders:\n    {value} numeric value of the free/used space on the device\n\nColor thresholds:\n    {free} Change color based on the value of free\n    {used} Change color based on the value of used_percent\n    {read} Change color based on the value of read\n    {total} Change color based on the value of total\n    {write} Change color based on the value of write\n\n@author guiniol\n@license BSD\n\nSAMPLE OUTPUT\n{'full_text': 'all:  34.4% ( 82.0 KiB/s)'}\n\"\"\"\n\nfrom __future__ import division  # python2 compatibility\nfrom time import time\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    cache_timeout = 10\n    disk = None\n    format = \"{disk}: {used_percent}% ({total})\"\n    format_rate = \"[\\?min_length=11 {value:.1f} {unit}]\"\n    format_space = \"[\\?min_length=5 {value:.1f}]\"\n    sector_size = 512\n    si_units = False\n    thresholds = {\n        'free': [(0, \"bad\"), (10, \"degraded\"), (100, \"good\")],\n        'total': [(0, \"good\"), (1024, \"degraded\"), (1024 * 1024, \"bad\")]\n    }\n    unit = \"B/s\"\n\n    def post_config_hook(self):\n        \"\"\"\n        Format of total, up and down placeholders under self.format.\n        As default, substitutes self.left_align and self.precision as %s and %s\n        Placeholders:\n            value - value (float)\n            unit - unit (string)\n        \"\"\"\n        self.last_interface = None\n        self.last_stat = self._get_io_stats(self.disk)\n        self.last_time = time()\n\n    def space_and_io(self):\n        self.values = {'disk': self.disk if self.disk else 'all'}\n\n        if self.py3.format_contains(self.format, ['read', 'write', 'total']):\n            # time from previous check\n            ios = self._get_io_stats(self.disk)\n            timedelta = time() - self.last_time\n\n            read = ios[0] - self.last_stat[0]\n            write = ios[1] - self.last_stat[1]\n\n            # update last_ info\n            self.last_stat = self._get_io_stats(self.disk)\n            self.last_time = time()\n\n            read /= timedelta\n            write /= timedelta\n\n            total = read + write\n\n            self.values['read'] = self._format_rate(read)\n            self.values['total'] = self._format_rate(total)\n            self.values['write'] = self._format_rate(write)\n            self.py3.threshold_get_color(read, 'read')\n            self.py3.threshold_get_color(total, 'total')\n            self.py3.threshold_get_color(write, 'write')\n\n        if self.py3.format_contains(self.format, ['free', 'used*', 'total_space']):\n            free, used, used_percent, total_space = self._get_free_space(self.disk)\n\n            self.values['free'] = self.py3.safe_format(self.format_space, {'value': free})\n            self.values['used'] = self.py3.safe_format(self.format_space, {'value': used})\n            self.values['used_percent'] = self.py3.safe_format(self.format_space,\n                                                               {'value': used_percent})\n            self.values['total_space'] = self.py3.safe_format(self.format_space,\n                                                              {'value': total_space})\n            self.py3.threshold_get_color(free, 'free')\n            self.py3.threshold_get_color(used, 'used')\n\n        return {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.py3.safe_format(self.format, self.values)\n        }\n\n    def _get_free_space(self, disk):\n        if disk and not disk.startswith('/dev/'):\n            disk = '/dev/' + disk\n\n        total = 0\n        used = 0\n        free = 0\n        devs = []\n\n        df = self.py3.command_output('df')\n        for line in df.splitlines():\n            if (disk and line.startswith(disk)) or (disk is None and line.startswith('/dev/')):\n                data = line.split()\n                if data[0] in devs:\n                    # Make sure to count each block device only one time\n                    # some filesystems eg btrfs have multiple entries\n                    continue\n                total += int(data[1]) / 1024 / 1024\n                used += int(data[2]) / 1024 / 1024\n                free += int(data[3]) / 1024 / 1024\n                devs.append(data[0])\n\n        if total == 0:\n            return free, used, 'err', total\n\n        return free, used, 100 * used / total, total\n\n    def _get_io_stats(self, disk):\n        if disk and disk.startswith('/dev/'):\n            disk = disk[5:]\n        read = 0\n        write = 0\n        with open('/proc/diskstats', 'r') as fd:\n            for line in fd:\n                data = line.split()\n                if disk:\n                    if data[2] == disk:\n                        read += int(data[5]) * self.sector_size\n                        write += int(data[9]) * self.sector_size\n                else:\n                    if data[1] == '0':\n                        read += int(data[5]) * self.sector_size\n                        write += int(data[9]) * self.sector_size\n        return read, write\n\n    def _format_rate(self, value):\n        \"\"\"\n        Return formatted string\n        \"\"\"\n        value, unit = self.py3.format_units(value, unit=self.unit, si=self.si_units)\n        return self.py3.safe_format(self.format_rate, {'value': value, 'unit': unit})\n\n\nif __name__ == \"__main__\":\n    \"\"\"\n    Run module in test mode.\n    \"\"\"\n    from py3status.module_test import module_test\n    module_test(Py3status)\n", "path": "py3status/modules/diskdata.py"}]}