bozo.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. .. _advanced.bozo:
  2. Bozo Detection
  3. ==============
  4. :program:`Universal Feed Parser` can parse feeds whether they are well-formed
  5. :abbr:`XML (Extensible Markup Language)` or not. However, since some
  6. applications may wish to reject or warn users about non-well-formed feeds,
  7. :program:`Universal Feed Parser` sets the ``bozo`` bit when it detects that a
  8. feed is not well-formed. Thanks to `Tim Bray
  9. <http://www.tbray.org/ongoing/When/200x/2004/01/11/PostelPilgrim>`_ for
  10. suggesting this terminology.
  11. Detecting a non-well-formed feed
  12. --------------------------------
  13. ::
  14. >>> d = feedparser.parse('http://feedparser.org/docs/examples/atom10.xml')
  15. >>> d.bozo
  16. 0
  17. >>> d = feedparser.parse('http://feedparser.org/tests/illformed/rss/aaa_illformed.xml')
  18. >>> d.bozo
  19. 1
  20. >>> d.bozo_exception
  21. <xml.sax._exceptions.SAXParseException instance at 0x00BAAA08>
  22. >>> exc = d.bozo_exception
  23. >>> exc.getMessage()
  24. "expected '>'\\n"
  25. >>> exc.getLineNumber()
  26. 6
  27. There are many reasons an :abbr:`XML (Extensible Markup Language)` document
  28. could be non-well-formed besides this example (incomplete end tags) See
  29. :ref:`advanced.encoding` for some other ways to trip the bozo bit.