bug 1310980, remove bookmarks.html parser, we haven't used that in ages.
MozReview-Commit-ID: HY5ywEXrBiN
--- a/compare_locales/parser.py
+++ b/compare_locales/parser.py
@@ -1,17 +1,16 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import re
import bisect
import codecs
import logging
-from HTMLParser import HTMLParser
__constructors = []
class Entity(object):
'''
Abstraction layer for a localizable entity.
Currently supported are grammars of the form:
@@ -432,148 +431,12 @@ class IniParser(Parser):
'''
def __init__(self):
self.reHeader = re.compile('^((?:\s*|[;#].*)\n)*\[.+?\]\n', re.M)
self.reKey = re.compile('(\s*)((?:[;#].*\n\s*)*)((.+?)=(.*))(\n?)')
self.reFooter = re.compile('\s*([;#].*\s*)*$')
Parser.__init__(self)
-DECL, COMMENT, START, END, CONTENT = range(5)
-
-
-class BookmarksParserInner(HTMLParser):
-
- class Token(object):
- _type = None
- content = ''
-
- def __str__(self):
- return self.content
-
- class DeclToken(Token):
- _type = DECL
-
- def __init__(self, decl):
- self.content = decl
- pass
-
- def __str__(self):
- return '<!%s>' % self.content
- pass
-
- class CommentToken(Token):
- _type = COMMENT
-
- def __init__(self, comment):
- self.content = comment
- pass
-
- def __str__(self):
- return '<!--%s-->' % self.content
- pass
-
- class StartToken(Token):
- _type = START
-
- def __init__(self, tag, attrs, content):
- self.tag = tag
- self.attrs = dict(attrs)
- self.content = content
- pass
- pass
-
- class EndToken(Token):
- _type = END
-
- def __init__(self, tag):
- self.tag = tag
- pass
-
- def __str__(self):
- return '</%s>' % self.tag.upper()
- pass
-
- class ContentToken(Token):
- _type = CONTENT
-
- def __init__(self, content):
- self.content = content
- pass
- pass
-
- def __init__(self):
- HTMLParser.__init__(self)
- self.tokens = []
-
- def parse(self, contents):
- self.tokens = []
- self.feed(contents)
- self.close()
- return self.tokens
-
- # Called when we hit an end DL tag to reset the folder selections
- def handle_decl(self, decl):
- self.tokens.append(self.DeclToken(decl))
-
- # Called when we hit an end DL tag to reset the folder selections
- def handle_comment(self, comment):
- self.tokens.append(self.CommentToken(comment))
-
- def handle_starttag(self, tag, attrs):
- self.tokens.append(self.StartToken(tag, attrs,
- self.get_starttag_text()))
-
- # Called when text data is encountered
- def handle_data(self, data):
- if self.tokens[-1]._type == CONTENT:
- self.tokens[-1].content += data
- else:
- self.tokens.append(self.ContentToken(data))
-
- def handle_charref(self, data):
- self.handle_data('&#%s;' % data)
-
- def handle_entityref(self, data):
- self.handle_data('&%s;' % data)
-
- # Called when we hit an end DL tag to reset the folder selections
- def handle_endtag(self, tag):
- self.tokens.append(self.EndToken(tag))
-
-
-class BookmarksParser(Parser):
- canMerge = False
-
- class BMEntity(object):
- def __init__(self, key, val):
- self.key = key
- self.val = val
-
- def __iter__(self):
- p = BookmarksParserInner()
- tks = p.parse(self.contents)
- i = 0
- k = []
- for i in xrange(len(tks)):
- t = tks[i]
- if t._type == START:
- k.append(t.tag)
- keys = t.attrs.keys()
- keys.sort()
- for attrname in keys:
- yield self.BMEntity('.'.join(k) + '.@' + attrname,
- t.attrs[attrname])
- if i + 1 < len(tks) and tks[i+1]._type == CONTENT:
- i += 1
- t = tks[i]
- v = t.content.strip()
- if v:
- yield self.BMEntity('.'.join(k), v)
- elif t._type == END:
- k.pop()
-
-
__constructors = [('\\.dtd$', DTDParser()),
('\\.properties$', PropertiesParser()),
('\\.ini$', IniParser()),
- ('\\.inc$', DefinesParser()),
- ('bookmarks\\.html$', BookmarksParser())]
+ ('\\.inc$', DefinesParser())]