(string)
| 187 | |
| 188 | |
| 189 | def limit_size(string): |
| 190 | maxbytes = 800000 * 20 |
| 191 | if sys.stdout.isatty(): |
| 192 | maxlines = 500 |
| 193 | max_line = 500 |
| 194 | else: |
| 195 | max_line = 5000 |
| 196 | maxlines = 1000 |
| 197 | lines = string.splitlines() |
| 198 | for i, line in enumerate(lines): |
| 199 | if len(line) > max_line: |
| 200 | lines[i] = line[:max_line] + '[..]' |
| 201 | if len(lines) > maxlines: |
| 202 | lines = lines[0:maxlines // 2] + ['[..]'] + lines[-maxlines // 2:] |
| 203 | lines.append('(not all output shown. See `limit_size`)') |
| 204 | string = '\n'.join(lines) + '\n' |
| 205 | if len(string) > maxbytes: |
| 206 | string = string[0:maxbytes // 2] + '\n[..]\n' + string[-maxbytes // 2:] |
| 207 | return string |
| 208 | |
| 209 | |
| 210 | def create_file(name, contents, binary=False, absolute=False): |
no test coverage detected