Return a unicode text pretty representation of data (as YAML or else) if data is a sequence or mapping or the data as-is otherwise
(data)
| 235 | |
| 236 | |
| 237 | def pretty(data): |
| 238 | """ |
| 239 | Return a unicode text pretty representation of data (as YAML or else) if |
| 240 | data is a sequence or mapping or the data as-is otherwise |
| 241 | """ |
| 242 | if not data: |
| 243 | return None |
| 244 | seqtypes = list, tuple |
| 245 | maptypes = dict, dict |
| 246 | coltypes = seqtypes + maptypes |
| 247 | if isinstance(data, seqtypes): |
| 248 | if len(data) == 1 and isinstance(data[0], str): |
| 249 | return data[0].strip() |
| 250 | if isinstance(data, coltypes): |
| 251 | return saneyaml.dump( |
| 252 | data, indent=2, encoding='utf-8').decode('utf-8').strip() |
| 253 | return data |
| 254 | |
| 255 | |
| 256 | def get_package_columns(_columns=set()): |