We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
mpd_status' max_width bogus?
`max_width` doesn't seem to do what it is supposed to do. 

When displaying a long title (like `Georg Danzer - Ballade von verstecken Tschurifetzen - Re-Mastered`), the title gets _longer_, the _smaller_ the value is. 

--- 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/mpd_status.py`
Content:
```
1 # coding: utf-8
2 """
3 Display information from mpd.
4 
5 Configuration parameters:
6     cache_timeout: how often we refresh this module in seconds (default 2)
7     format: template string (see below)
8         (default '%state% [[[%artist%] - %title%]|[%file%]]')
9     hide_when_paused: hide the status if state is paused (default False)
10     hide_when_stopped: hide the status if state is stopped (default True)
11     host: mpd host (default 'localhost')
12     max_width: maximum status length (default 120)
13     password: mpd password (default None)
14     port: mpd port (default '6600')
15     state_pause: label to display for "paused" state (default '[pause]')
16     state_play: label to display for "playing" state (default '[play]')
17     state_stop: label to display for "stopped" state (default '[stop]')
18 
19 Color options:
20     color_pause: Paused, default color_degraded
21     color_play: Playing, default color_good
22     color_stop: Stopped, default color_bad
23 
24 Requires:
25     python-mpd2: (NOT python2-mpd2)
26 ```
27 # pip install python-mpd2
28 ```
29 
30 Refer to the mpc(1) manual page for the list of available placeholders to be
31 used in `format`.
32 You can also use the %state% placeholder, that will be replaced with the state
33 label (play, pause or stop).
34 Every placeholder can also be prefixed with `next_` to retrieve the data for
35 the song following the one currently playing.
36 
37 You can also use {} instead of %% for placeholders (backward compatibility).
38 
39 Examples of `format`
40 ```
41 # Show state and (artist -) title, if no title fallback to file:
42 %state% [[[%artist% - ]%title%]|[%file%]]
43 
44 # Alternative legacy syntax:
45 {state} [[[{artist} - ]{title}]|[{file}]]
46 
47 # Show state, [duration], title (or file) and next song title (or file):
48 %state% \[%time%\] [%title%|%file%] → [%next_title%|%next_file%]
49 ```
50 
51 @author shadowprince, zopieux
52 @license Eclipse Public License
53 """
54 
55 import ast
56 import datetime
57 import itertools
58 import socket
59 from mpd import MPDClient, CommandError
60 
61 
62 def parse_template(instr, value_getter, found=True):
63     """
64     MPC-like parsing of `instr` using `value_getter` callable to retrieve the
65     text representation of placeholders.
66     """
67     instr = iter(instr)
68     ret = []
69     for char in instr:
70         if char in '%{':
71             endchar = '%' if char == '%' else '}'
72             key = ''.join(itertools.takewhile(lambda e: e != endchar, instr))
73             value = value_getter(key)
74             if value:
75                 found = True
76                 ret.append(value)
77             else:
78                 found = False
79         elif char == '#':
80             ret.append(next(instr, '#'))
81         elif char == '\\':
82             ln = next(instr, '\\')
83             if ln in 'abtnvfr':
84                 ret.append(ast.literal_eval('"\\{}"'.format(ln)))
85             else:
86                 ret.append(ln)
87         elif char == '[':
88             subret, found = parse_template(instr, value_getter, found)
89             subret = ''.join(subret)
90             ret.append(subret)
91         elif char == ']':
92             if found:
93                 ret = ''.join(ret)
94                 return ret, True
95             else:
96                 return '', False
97         elif char == '|':
98             subret, subfound = parse_template(instr, value_getter, found)
99             if found:
100                 pass
101             elif subfound:
102                 ret.append(''.join(subret))
103                 found = True
104             else:
105                 return '', False
106         elif char == '&':
107             subret, subfound = parse_template(instr, value_getter, found)
108             if found and subfound:
109                 subret = ''.join(subret)
110                 ret.append(subret)
111             else:
112                 return '', False
113         else:
114             ret.append(char)
115 
116     ret = ''.join(ret)
117     return ret, found
118 
119 
120 def song_attr(song, attr):
121     def parse_mtime(date_str):
122         return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')
123 
124     if attr == 'time':
125         try:
126             duration = int(song['time'])
127             if duration > 0:
128                 minutes, seconds = divmod(duration, 60)
129                 return '{:d}:{:02d}'.format(minutes, seconds)
130             raise ValueError
131         except (KeyError, ValueError):
132             return ''
133     elif attr == 'position':
134         try:
135             return '{}'.format(int(song['pos']) + 1)
136         except (KeyError, ValueError):
137             return ''
138     elif attr == 'mtime':
139         return parse_mtime(song['last-modified']).strftime('%c')
140     elif attr == 'mdate':
141         return parse_mtime(song['last-modified']).strftime('%x')
142 
143     return song.get(attr, '')
144 
145 
146 class Py3status:
147     """
148     """
149     # available configuration parameters
150     cache_timeout = 2
151     format = '%state% [[[%artist%] - %title%]|[%file%]]'
152     hide_when_paused = False
153     hide_when_stopped = True
154     host = 'localhost'
155     max_width = 120
156     password = None
157     port = '6600'
158     state_pause = '[pause]'
159     state_play = '[play]'
160     state_stop = '[stop]'
161 
162     def __init__(self):
163         self.text = ''
164 
165     def _state_character(self, state):
166         if state == 'play':
167             return self.state_play
168         elif state == 'pause':
169             return self.state_pause
170         elif state == 'stop':
171             return self.state_stop
172         return '?'
173 
174     def current_track(self):
175         try:
176             c = MPDClient()
177             c.connect(host=self.host, port=self.port)
178             if self.password:
179                 c.password(self.password)
180 
181             status = c.status()
182             song = int(status.get('song', 0))
183             next_song = int(status.get('nextsong', 0))
184 
185             state = status.get('state')
186 
187             if ((state == 'pause' and self.hide_when_paused) or
188                     (state == 'stop' and self.hide_when_stopped)):
189                 text = ''
190 
191             else:
192                 playlist_info = c.playlistinfo()
193                 try:
194                     song = playlist_info[song]
195                 except IndexError:
196                     song = {}
197                 try:
198                     next_song = playlist_info[next_song]
199                 except IndexError:
200                     next_song = {}
201 
202                 song['state'] = next_song['state'] \
203                               = self._state_character(state)
204 
205                 def attr_getter(attr):
206                     if attr.startswith('next_'):
207                         return song_attr(next_song, attr[5:])
208                     return song_attr(song, attr)
209 
210                 text, _ = parse_template(self.format, attr_getter)
211 
212         except socket.error:
213             text = "Failed to connect to mpd!"
214             state = None
215         except CommandError:
216             text = "Failed to authenticate to mpd!"
217             state = None
218             c.disconnect()
219         else:
220             c.disconnect()
221 
222         if len(text) > self.max_width:
223             text = text[:-self.max_width - 3] + '...'
224 
225         if self.text != text:
226             transformed = True
227             self.text = text
228         else:
229             transformed = False
230 
231         response = {
232             'cached_until': self.py3.time_in(self.cache_timeout),
233             'full_text': self.text,
234             'transformed': transformed
235         }
236 
237         if state:
238             if state == 'play':
239                 response['color'] = self.py3.COLOR_PLAY or self.py3.COLOR_GOOD
240             elif state == 'pause':
241                 response['color'] = (self.py3.COLOR_PAUSE or
242                                      self.py3.COLOR_DEGRADED)
243             elif state == 'stop':
244                 response['color'] = self.py3.COLOR_STOP or self.py3.COLOR_BAD
245 
246         return response
247 
248 
249 if __name__ == "__main__":
250     """
251     Run module in test mode.
252     """
253     from py3status.module_test import module_test
254     module_test(Py3status)
255
```
--- 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/mpd_status.py b/py3status/modules/mpd_status.py
--- a/py3status/modules/mpd_status.py
+++ b/py3status/modules/mpd_status.py
@@ -220,7 +220,7 @@
             c.disconnect()
 
         if len(text) > self.max_width:
-            text = text[:-self.max_width - 3] + '...'
+            text = u'{}...'.format(text[:self.max_width - 3])
 
         if self.text != text:
             transformed = True

{"golden_diff": "diff --git a/py3status/modules/mpd_status.py b/py3status/modules/mpd_status.py\n--- a/py3status/modules/mpd_status.py\n+++ b/py3status/modules/mpd_status.py\n@@ -220,7 +220,7 @@\n             c.disconnect()\n \n         if len(text) > self.max_width:\n-            text = text[:-self.max_width - 3] + '...'\n+            text = u'{}...'.format(text[:self.max_width - 3])\n \n         if self.text != text:\n             transformed = True\n", "issue": "mpd_status' max_width bogus?\n`max_width` doesn't seem to do what it is supposed to do. \r\n\r\nWhen displaying a long title (like `Georg Danzer - Ballade von verstecken Tschurifetzen - Re-Mastered`), the title gets _longer_, the _smaller_ the value is. \n", "before_files": [{"content": "# coding: utf-8\n\"\"\"\nDisplay information from mpd.\n\nConfiguration parameters:\n    cache_timeout: how often we refresh this module in seconds (default 2)\n    format: template string (see below)\n        (default '%state% [[[%artist%] - %title%]|[%file%]]')\n    hide_when_paused: hide the status if state is paused (default False)\n    hide_when_stopped: hide the status if state is stopped (default True)\n    host: mpd host (default 'localhost')\n    max_width: maximum status length (default 120)\n    password: mpd password (default None)\n    port: mpd port (default '6600')\n    state_pause: label to display for \"paused\" state (default '[pause]')\n    state_play: label to display for \"playing\" state (default '[play]')\n    state_stop: label to display for \"stopped\" state (default '[stop]')\n\nColor options:\n    color_pause: Paused, default color_degraded\n    color_play: Playing, default color_good\n    color_stop: Stopped, default color_bad\n\nRequires:\n    python-mpd2: (NOT python2-mpd2)\n```\n# pip install python-mpd2\n```\n\nRefer to the mpc(1) manual page for the list of available placeholders to be\nused in `format`.\nYou can also use the %state% placeholder, that will be replaced with the state\nlabel (play, pause or stop).\nEvery placeholder can also be prefixed with `next_` to retrieve the data for\nthe song following the one currently playing.\n\nYou can also use {} instead of %% for placeholders (backward compatibility).\n\nExamples of `format`\n```\n# Show state and (artist -) title, if no title fallback to file:\n%state% [[[%artist% - ]%title%]|[%file%]]\n\n# Alternative legacy syntax:\n{state} [[[{artist} - ]{title}]|[{file}]]\n\n# Show state, [duration], title (or file) and next song title (or file):\n%state% \\[%time%\\] [%title%|%file%] \u2192 [%next_title%|%next_file%]\n```\n\n@author shadowprince, zopieux\n@license Eclipse Public License\n\"\"\"\n\nimport ast\nimport datetime\nimport itertools\nimport socket\nfrom mpd import MPDClient, CommandError\n\n\ndef parse_template(instr, value_getter, found=True):\n    \"\"\"\n    MPC-like parsing of `instr` using `value_getter` callable to retrieve the\n    text representation of placeholders.\n    \"\"\"\n    instr = iter(instr)\n    ret = []\n    for char in instr:\n        if char in '%{':\n            endchar = '%' if char == '%' else '}'\n            key = ''.join(itertools.takewhile(lambda e: e != endchar, instr))\n            value = value_getter(key)\n            if value:\n                found = True\n                ret.append(value)\n            else:\n                found = False\n        elif char == '#':\n            ret.append(next(instr, '#'))\n        elif char == '\\\\':\n            ln = next(instr, '\\\\')\n            if ln in 'abtnvfr':\n                ret.append(ast.literal_eval('\"\\\\{}\"'.format(ln)))\n            else:\n                ret.append(ln)\n        elif char == '[':\n            subret, found = parse_template(instr, value_getter, found)\n            subret = ''.join(subret)\n            ret.append(subret)\n        elif char == ']':\n            if found:\n                ret = ''.join(ret)\n                return ret, True\n            else:\n                return '', False\n        elif char == '|':\n            subret, subfound = parse_template(instr, value_getter, found)\n            if found:\n                pass\n            elif subfound:\n                ret.append(''.join(subret))\n                found = True\n            else:\n                return '', False\n        elif char == '&':\n            subret, subfound = parse_template(instr, value_getter, found)\n            if found and subfound:\n                subret = ''.join(subret)\n                ret.append(subret)\n            else:\n                return '', False\n        else:\n            ret.append(char)\n\n    ret = ''.join(ret)\n    return ret, found\n\n\ndef song_attr(song, attr):\n    def parse_mtime(date_str):\n        return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')\n\n    if attr == 'time':\n        try:\n            duration = int(song['time'])\n            if duration > 0:\n                minutes, seconds = divmod(duration, 60)\n                return '{:d}:{:02d}'.format(minutes, seconds)\n            raise ValueError\n        except (KeyError, ValueError):\n            return ''\n    elif attr == 'position':\n        try:\n            return '{}'.format(int(song['pos']) + 1)\n        except (KeyError, ValueError):\n            return ''\n    elif attr == 'mtime':\n        return parse_mtime(song['last-modified']).strftime('%c')\n    elif attr == 'mdate':\n        return parse_mtime(song['last-modified']).strftime('%x')\n\n    return song.get(attr, '')\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    cache_timeout = 2\n    format = '%state% [[[%artist%] - %title%]|[%file%]]'\n    hide_when_paused = False\n    hide_when_stopped = True\n    host = 'localhost'\n    max_width = 120\n    password = None\n    port = '6600'\n    state_pause = '[pause]'\n    state_play = '[play]'\n    state_stop = '[stop]'\n\n    def __init__(self):\n        self.text = ''\n\n    def _state_character(self, state):\n        if state == 'play':\n            return self.state_play\n        elif state == 'pause':\n            return self.state_pause\n        elif state == 'stop':\n            return self.state_stop\n        return '?'\n\n    def current_track(self):\n        try:\n            c = MPDClient()\n            c.connect(host=self.host, port=self.port)\n            if self.password:\n                c.password(self.password)\n\n            status = c.status()\n            song = int(status.get('song', 0))\n            next_song = int(status.get('nextsong', 0))\n\n            state = status.get('state')\n\n            if ((state == 'pause' and self.hide_when_paused) or\n                    (state == 'stop' and self.hide_when_stopped)):\n                text = ''\n\n            else:\n                playlist_info = c.playlistinfo()\n                try:\n                    song = playlist_info[song]\n                except IndexError:\n                    song = {}\n                try:\n                    next_song = playlist_info[next_song]\n                except IndexError:\n                    next_song = {}\n\n                song['state'] = next_song['state'] \\\n                              = self._state_character(state)\n\n                def attr_getter(attr):\n                    if attr.startswith('next_'):\n                        return song_attr(next_song, attr[5:])\n                    return song_attr(song, attr)\n\n                text, _ = parse_template(self.format, attr_getter)\n\n        except socket.error:\n            text = \"Failed to connect to mpd!\"\n            state = None\n        except CommandError:\n            text = \"Failed to authenticate to mpd!\"\n            state = None\n            c.disconnect()\n        else:\n            c.disconnect()\n\n        if len(text) > self.max_width:\n            text = text[:-self.max_width - 3] + '...'\n\n        if self.text != text:\n            transformed = True\n            self.text = text\n        else:\n            transformed = False\n\n        response = {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.text,\n            'transformed': transformed\n        }\n\n        if state:\n            if state == 'play':\n                response['color'] = self.py3.COLOR_PLAY or self.py3.COLOR_GOOD\n            elif state == 'pause':\n                response['color'] = (self.py3.COLOR_PAUSE or\n                                     self.py3.COLOR_DEGRADED)\n            elif state == 'stop':\n                response['color'] = self.py3.COLOR_STOP or self.py3.COLOR_BAD\n\n        return response\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/mpd_status.py"}], "after_files": [{"content": "# coding: utf-8\n\"\"\"\nDisplay information from mpd.\n\nConfiguration parameters:\n    cache_timeout: how often we refresh this module in seconds (default 2)\n    format: template string (see below)\n        (default '%state% [[[%artist%] - %title%]|[%file%]]')\n    hide_when_paused: hide the status if state is paused (default False)\n    hide_when_stopped: hide the status if state is stopped (default True)\n    host: mpd host (default 'localhost')\n    max_width: maximum status length (default 120)\n    password: mpd password (default None)\n    port: mpd port (default '6600')\n    state_pause: label to display for \"paused\" state (default '[pause]')\n    state_play: label to display for \"playing\" state (default '[play]')\n    state_stop: label to display for \"stopped\" state (default '[stop]')\n\nColor options:\n    color_pause: Paused, default color_degraded\n    color_play: Playing, default color_good\n    color_stop: Stopped, default color_bad\n\nRequires:\n    python-mpd2: (NOT python2-mpd2)\n```\n# pip install python-mpd2\n```\n\nRefer to the mpc(1) manual page for the list of available placeholders to be\nused in `format`.\nYou can also use the %state% placeholder, that will be replaced with the state\nlabel (play, pause or stop).\nEvery placeholder can also be prefixed with `next_` to retrieve the data for\nthe song following the one currently playing.\n\nYou can also use {} instead of %% for placeholders (backward compatibility).\n\nExamples of `format`\n```\n# Show state and (artist -) title, if no title fallback to file:\n%state% [[[%artist% - ]%title%]|[%file%]]\n\n# Alternative legacy syntax:\n{state} [[[{artist} - ]{title}]|[{file}]]\n\n# Show state, [duration], title (or file) and next song title (or file):\n%state% \\[%time%\\] [%title%|%file%] \u2192 [%next_title%|%next_file%]\n```\n\n@author shadowprince, zopieux\n@license Eclipse Public License\n\"\"\"\n\nimport ast\nimport datetime\nimport itertools\nimport socket\nfrom mpd import MPDClient, CommandError\n\n\ndef parse_template(instr, value_getter, found=True):\n    \"\"\"\n    MPC-like parsing of `instr` using `value_getter` callable to retrieve the\n    text representation of placeholders.\n    \"\"\"\n    instr = iter(instr)\n    ret = []\n    for char in instr:\n        if char in '%{':\n            endchar = '%' if char == '%' else '}'\n            key = ''.join(itertools.takewhile(lambda e: e != endchar, instr))\n            value = value_getter(key)\n            if value:\n                found = True\n                ret.append(value)\n            else:\n                found = False\n        elif char == '#':\n            ret.append(next(instr, '#'))\n        elif char == '\\\\':\n            ln = next(instr, '\\\\')\n            if ln in 'abtnvfr':\n                ret.append(ast.literal_eval('\"\\\\{}\"'.format(ln)))\n            else:\n                ret.append(ln)\n        elif char == '[':\n            subret, found = parse_template(instr, value_getter, found)\n            subret = ''.join(subret)\n            ret.append(subret)\n        elif char == ']':\n            if found:\n                ret = ''.join(ret)\n                return ret, True\n            else:\n                return '', False\n        elif char == '|':\n            subret, subfound = parse_template(instr, value_getter, found)\n            if found:\n                pass\n            elif subfound:\n                ret.append(''.join(subret))\n                found = True\n            else:\n                return '', False\n        elif char == '&':\n            subret, subfound = parse_template(instr, value_getter, found)\n            if found and subfound:\n                subret = ''.join(subret)\n                ret.append(subret)\n            else:\n                return '', False\n        else:\n            ret.append(char)\n\n    ret = ''.join(ret)\n    return ret, found\n\n\ndef song_attr(song, attr):\n    def parse_mtime(date_str):\n        return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%SZ')\n\n    if attr == 'time':\n        try:\n            duration = int(song['time'])\n            if duration > 0:\n                minutes, seconds = divmod(duration, 60)\n                return '{:d}:{:02d}'.format(minutes, seconds)\n            raise ValueError\n        except (KeyError, ValueError):\n            return ''\n    elif attr == 'position':\n        try:\n            return '{}'.format(int(song['pos']) + 1)\n        except (KeyError, ValueError):\n            return ''\n    elif attr == 'mtime':\n        return parse_mtime(song['last-modified']).strftime('%c')\n    elif attr == 'mdate':\n        return parse_mtime(song['last-modified']).strftime('%x')\n\n    return song.get(attr, '')\n\n\nclass Py3status:\n    \"\"\"\n    \"\"\"\n    # available configuration parameters\n    cache_timeout = 2\n    format = '%state% [[[%artist%] - %title%]|[%file%]]'\n    hide_when_paused = False\n    hide_when_stopped = True\n    host = 'localhost'\n    max_width = 120\n    password = None\n    port = '6600'\n    state_pause = '[pause]'\n    state_play = '[play]'\n    state_stop = '[stop]'\n\n    def __init__(self):\n        self.text = ''\n\n    def _state_character(self, state):\n        if state == 'play':\n            return self.state_play\n        elif state == 'pause':\n            return self.state_pause\n        elif state == 'stop':\n            return self.state_stop\n        return '?'\n\n    def current_track(self):\n        try:\n            c = MPDClient()\n            c.connect(host=self.host, port=self.port)\n            if self.password:\n                c.password(self.password)\n\n            status = c.status()\n            song = int(status.get('song', 0))\n            next_song = int(status.get('nextsong', 0))\n\n            state = status.get('state')\n\n            if ((state == 'pause' and self.hide_when_paused) or\n                    (state == 'stop' and self.hide_when_stopped)):\n                text = ''\n\n            else:\n                playlist_info = c.playlistinfo()\n                try:\n                    song = playlist_info[song]\n                except IndexError:\n                    song = {}\n                try:\n                    next_song = playlist_info[next_song]\n                except IndexError:\n                    next_song = {}\n\n                song['state'] = next_song['state'] \\\n                              = self._state_character(state)\n\n                def attr_getter(attr):\n                    if attr.startswith('next_'):\n                        return song_attr(next_song, attr[5:])\n                    return song_attr(song, attr)\n\n                text, _ = parse_template(self.format, attr_getter)\n\n        except socket.error:\n            text = \"Failed to connect to mpd!\"\n            state = None\n        except CommandError:\n            text = \"Failed to authenticate to mpd!\"\n            state = None\n            c.disconnect()\n        else:\n            c.disconnect()\n\n        if len(text) > self.max_width:\n            text = u'{}...'.format(text[:self.max_width - 3])\n\n        if self.text != text:\n            transformed = True\n            self.text = text\n        else:\n            transformed = False\n\n        response = {\n            'cached_until': self.py3.time_in(self.cache_timeout),\n            'full_text': self.text,\n            'transformed': transformed\n        }\n\n        if state:\n            if state == 'play':\n                response['color'] = self.py3.COLOR_PLAY or self.py3.COLOR_GOOD\n            elif state == 'pause':\n                response['color'] = (self.py3.COLOR_PAUSE or\n                                     self.py3.COLOR_DEGRADED)\n            elif state == 'stop':\n                response['color'] = self.py3.COLOR_STOP or self.py3.COLOR_BAD\n\n        return response\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/mpd_status.py"}]}