1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
###############################################################
# Copyright (c) 2017 ZTE Corporation
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
def _justify_pair(pair, width=80, padding_with='.'):
"""align first element along the left margin, second along the right, padding spaces"""
n = width - len(pair[0])
return '{key}{value:{c}>{n}}'.format(key=pair[0], value=pair[1], c=padding_with, n=n)
def justify(content, width=80, padding_with='.'):
if isinstance(content, list):
return '\n'.join([justify(item, width, padding_with) for item in content])
elif isinstance(content, dict):
return '\n'.join([justify(item, width, padding_with) for item in content.items()])
else:
return _justify_pair(content, width, padding_with)
|