Return data reformatted to specified width with comment header.
(data, limit, comment_header)
| 154 | return "\n".join(new) |
| 155 | |
| 156 | def reformat_comment(data, limit, comment_header): |
| 157 | """Return data reformatted to specified width with comment header.""" |
| 158 | |
| 159 | # Remove header from the comment lines |
| 160 | lc = len(comment_header) |
| 161 | data = "\n".join(line[lc:] for line in data.split("\n")) |
| 162 | # Reformat to maxformatwidth chars or a 20 char width, |
| 163 | # whichever is greater. |
| 164 | format_width = max(limit - len(comment_header), 20) |
| 165 | newdata = reformat_paragraph(data, format_width) |
| 166 | # re-split and re-insert the comment header. |
| 167 | newdata = newdata.split("\n") |
| 168 | # If the block ends in a \n, we don't want the comment prefix |
| 169 | # inserted after it. (Im not sure it makes sense to reformat a |
| 170 | # comment block that is not made of complete lines, but whatever!) |
| 171 | # Can't think of a clean solution, so we hack away |
| 172 | block_suffix = "" |
| 173 | if not newdata[-1]: |
| 174 | block_suffix = "\n" |
| 175 | newdata = newdata[:-1] |
| 176 | return '\n'.join(comment_header+line for line in newdata) + block_suffix |
| 177 | |
| 178 | def is_all_white(line): |
| 179 | """Return True if line is empty or all whitespace.""" |
no test coverage detected
searching dependent graphs…