Joins lines with the appropriate connective whitespace. This puts a single space between consecutive lines, unless there's a blank line, in which case a full blank line is included. Args: lines: A list of lines to join. Returns: A string, the lines joined together.
(lines)
| 236 | |
| 237 | |
| 238 | def _join_lines(lines): |
| 239 | """Joins lines with the appropriate connective whitespace. |
| 240 | |
| 241 | This puts a single space between consecutive lines, unless there's a blank |
| 242 | line, in which case a full blank line is included. |
| 243 | |
| 244 | Args: |
| 245 | lines: A list of lines to join. |
| 246 | Returns: |
| 247 | A string, the lines joined together. |
| 248 | """ |
| 249 | # TODO(dbieber): Add parameters for variations in whitespace handling. |
| 250 | if not lines: |
| 251 | return None |
| 252 | |
| 253 | started = False |
| 254 | group_texts = [] # Full text of each section. |
| 255 | group_lines = [] # Lines within the current section. |
| 256 | for line in lines: |
| 257 | stripped_line = line.strip() |
| 258 | if stripped_line: |
| 259 | started = True |
| 260 | group_lines.append(stripped_line) |
| 261 | else: |
| 262 | if started: |
| 263 | group_text = ' '.join(group_lines) |
| 264 | group_texts.append(group_text) |
| 265 | group_lines = [] |
| 266 | |
| 267 | if group_lines: # Process the final group. |
| 268 | group_text = ' '.join(group_lines) |
| 269 | group_texts.append(group_text) |
| 270 | |
| 271 | return '\n\n'.join(group_texts) |
| 272 | |
| 273 | |
| 274 | def _get_or_create_arg_by_name(state, name, is_kwarg=False): |