import os

VARIABLES = [
    'REMOTE_ADDR',
    'SERVER_ADDR',
    'HTTPS',
    'REQUEST_SCHEME',
    'HTTP_HOST',
    'SERVER_NAME',
    'SCRIPT_NAME',
    'QUERY_STRING',
]


def print_headers_if_needed():
    if not os.environ['SCRIPT_NAME'].endswith('.php'):
        print('Content-Type: text/html;charset=UTF-8')
        print()


def print_environment():
    print('<table>')
    for key, value in sorted(os.environ.items()):
        print('''
<tr><td>{}</td><td>{}</td></tr>
'''.format(key, value))
    print('</table>')


def print_variables():
    print('<table>')
    for v in VARIABLES:
        print('''
<tr><td>{}</td><td>{}</td></tr>
'''.format(v, os.environ[v]))
    print('</table>')
