Attempts to dedent the lines to the edge. Looks at no. of leading spaces in line 2, and removes up to that number of blanks from other lines.
(comment)
| 161 | |
| 162 | |
| 163 | def dedent(comment): |
| 164 | """Attempts to dedent the lines to the edge. Looks at no. |
| 165 | of leading spaces in line 2, and removes up to that number |
| 166 | of blanks from other lines.""" |
| 167 | commentLines = string.split(comment, '\n') |
| 168 | if len(commentLines) < 2: |
| 169 | cleaned = map(string.lstrip, commentLines) |
| 170 | else: |
| 171 | spc = 0 |
| 172 | for char in commentLines[1]: |
| 173 | if char in string.whitespace: |
| 174 | spc = spc + 1 |
| 175 | else: |
| 176 | break |
| 177 | #now check other lines |
| 178 | cleaned = [] |
| 179 | for line in commentLines: |
| 180 | for i in range(min(len(line),spc)): |
| 181 | if line[0] in string.whitespace: |
| 182 | line = line[1:] |
| 183 | cleaned.append(line) |
| 184 | return string.join(cleaned, '\n') |
| 185 | |
| 186 | |
| 187 |
no test coverage detected