<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def teardown_tempdir(dir):
    r'''
    Cleanup temporary directory.
    '''

    if ssh_conn:
        delete_tree(dir)

    assert_valid_dir(dir)
    shutil.rmtree(dir)