0001from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
0002from httpencode.format import Format
0003
0004def load_xml(fp, content_type):
0005    return BeutifulStoneSoup(fp.read())
0006
0007def dump_xml_iter(data, content_type):
0008    return [data.prettify()]
0009
0010bsoup_xml = Format(
0011    'bsoup_xml', ['text/xml', 'application/xml'],
0012    type='BeautifulSoup',
0013    load=load_xml,
0014    dump_iter=dump_xml_iter,
0015    secure=True)
0016
0017def load_html(fp, content_type):
0018    return BeautifulSoup(fp.read())
0019
0020def dump_html_iter(data, content_type):
0021    return [data.prettify()]
0022
0023# Should include other HTML types
0024bsoup = Format(
0025    'bsoup', ['text/html'],
0026    type='BeautifulSoup',
0027    load=load_html,
0028    dump_iter=dump_html_iter,
0029    secure=True)