summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
Diffstat (limited to 'bs4')
-rw-r--r--bs4/__init__.py4
-rw-r--r--bs4/diagnose.py24
2 files changed, 22 insertions, 6 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index 88177d6..a5e7a86 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -17,8 +17,8 @@ http://www.crummy.com/software/BeautifulSoup/bs4/doc/
"""
__author__ = "Leonard Richardson (leonardr@segfault.org)"
-__version__ = "4.1.3"
-__copyright__ = "Copyright (c) 2004-2012 Leonard Richardson"
+__version__ = "4.2.0"
+__copyright__ = "Copyright (c) 2004-2013 Leonard Richardson"
__license__ = "MIT"
__all__ = ['BeautifulSoup']
diff --git a/bs4/diagnose.py b/bs4/diagnose.py
index daaf523..e336633 100644
--- a/bs4/diagnose.py
+++ b/bs4/diagnose.py
@@ -1,13 +1,22 @@
"""Diagnostic functions, mainly for use when doing tech support."""
from StringIO import StringIO
from HTMLParser import HTMLParser
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup, __version__
from bs4.builder import builder_registry
+import os
import traceback
import sys
def diagnose(data):
"""Diagnostic suite for isolating common problems."""
+ print "Diagnostic running on Beautiful Soup %s" % __version__
+ print "Python version %s" % sys.version
+
+ if hasattr(data, 'read'):
+ data = data.read()
+ elif os.path.exists(data):
+ print '"%s" looks like a filename. Reading data from the file.' % data
+ data = open(data).read()
basic_parsers = ["html.parser", "html5lib", "lxml"]
for name in basic_parsers:
for builder in builder_registry.builders:
@@ -21,18 +30,25 @@ def diagnose(data):
if 'lxml' in basic_parsers:
basic_parsers.append(["lxml", "xml"])
+ from lxml import etree
+ print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION))
+
+ if 'html5lib' in basic_parsers:
+ import html5lib
+ print "Found html5lib version %s" % html5lib.__version__
+ print
for parser in basic_parsers:
- print "Trying to parse your data with %s" % parser
+ print "Trying to parse your markup with %s" % parser
success = False
try:
soup = BeautifulSoup(data, parser)
success = True
except Exception, e:
- print "%s could not parse the document." % parser
+ print "%s could not parse the markup." % parser
traceback.print_exc()
if success:
- print "Here's what %s did with the document:" % parser
+ print "Here's what %s did with the markup:" % parser
print soup.prettify()
print "-" * 80