def tidy_html(html_buffer, cleaning_lib='<STR_LIT>'):
if CFG_TIDY_INSTALLED and cleaning_lib == '<STR_LIT>':<EOL><INDENT>options = dict(output_xhtml=<NUM_LIT:1>,<EOL>show_body_only=<NUM_LIT:1>,<EOL>merge_divs=<NUM_LIT:0>,<EOL>wrap=<NUM_LIT:0>)<EOL>try:<EOL><INDENT>output = str(tidy.parseString(html_buffer, **options))<EOL><DEDENT>except:<EOL><INDENT>output = html_buffer<EOL><DEDENT><DEDENT>elif CFG_BEAUTIFULSOUP_INSTALLED and cleaning_lib == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>output = str(BeautifulSoup(html_buffer).prettify())<EOL><DEDENT>except:<EOL><INDENT>output = html_buffer<EOL><DEDENT><DEDENT>else:<EOL><INDENT>output = html_buffer<EOL><DEDENT>return output<EOL>
Tidy up the input HTML using one of the installed cleaning
libraries.

@param html_buffer: the input HTML to clean up
@type html_buffer: string
@param cleaning_lib: chose the preferred library to clean the HTML. One of:
                     - utidylib
                     - beautifulsoup
@return: a cleaned version of the input HTML
@note: requires uTidylib or BeautifulSoup to be installed. If the chosen library is missing, the input X{html_buffer} is returned I{as is}.