]> git.phdru.name Git - bookmarks_db.git/blobdiff - parse_html/bkmk_ph_htmlparser.py
Change parse_html to parse strings, not files
[bookmarks_db.git] / parse_html / bkmk_ph_htmlparser.py
index d7020b03e933a9d822c541fe9c3936a5e0310ee1..0798467386bda9ab993df160f1d4937b1e1802d9 100644 (file)
@@ -1,10 +1,11 @@
 """HTML Parser using Pythons' HTMLParser
 
 This file is a part of Bookmarks database and Internet robot.
+
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 1997-2013 PhiloSoft Design"
+__copyright__ = "Copyright (C) 1997-2014 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['parse_html']
@@ -79,17 +80,13 @@ class HTMLParser(_HTMLParser):
          self.icon = href
 
 
-def parse_html(filename, charset=None, log=None):
-   infile = open(filename, 'r')
+def parse_html(html_text, charset=None, log=None):
    parser = HTMLParser(charset)
 
-   for line in infile:
-      try:
-         parser.feed(line)
-      except (HTMLParseError, HTMLHeadDone):
-         break
-
-   infile.close()
+   try:
+      parser.feed(html_text)
+   except (HTMLParseError, HTMLHeadDone):
+      pass
 
    try:
       parser.close()