本文整理汇总了Python中six.moves.html_parser.HTMLParser.feed方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLParser.feed方法的具体用法?Python HTMLParser.feed怎么用?Python HTMLParser.feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.html_parser.HTMLParser
的用法示例。
在下文中一共展示了HTMLParser.feed方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: feed
# 需要导入模块: from six.moves.html_parser import HTMLParser [as 别名]
# 或者: from six.moves.html_parser.HTMLParser import feed [as 别名]
def feed(self, string):
try:
HTMLParser.feed(self, string)
except Exception as e: # pragma: no cover
import traceback
traceback.print_exc()
self.out.write(string)
示例2: feed
# 需要导入模块: from six.moves.html_parser import HTMLParser [as 别名]
# 或者: from six.moves.html_parser.HTMLParser import feed [as 别名]
def feed(self, data):
data = re.compile(r'<!((?!DOCTYPE|--|\[))', re.IGNORECASE).sub(r'<!\1', data)
data = re.sub(r'<([^<>\s]+?)\s*/>', self._shorttag_replace, data)
data = data.replace(''', "'")
data = data.replace('"', '"')
HTMLParser.feed(self, data)
HTMLParser.close(self)
示例3: feed
# 需要导入模块: from six.moves.html_parser import HTMLParser [as 别名]
# 或者: from six.moves.html_parser.HTMLParser import feed [as 别名]
def feed(self, *args, **kwargs):
try:
# With Python 2, super() cannot be used.
# See the comment for __init__().
HTMLParser.feed(self, *args, **kwargs)
except self.TruncationCompleted as exc:
self.truncate_at = exc.truncate_at
else:
self.truncate_at = None
示例4: cmd_genpot
# 需要导入模块: from six.moves.html_parser import HTMLParser [as 别名]
# 或者: from six.moves.html_parser.HTMLParser import feed [as 别名]
def cmd_genpot(config, options):
"""Generate the gettext pot file"""
os.chdir(config.source_dir)
po_path = os.path.join(config.source_dir, 'po')
if not os.path.isdir(po_path):
os.mkdir(po_path)
python_files = []
for root, dirs_dummy, files in os.walk(config.source_dir):
for file_name in files:
if file_name.endswith('.py'):
file_path = os.path.relpath(os.path.join(root, file_name),
config.source_dir)
python_files.append(file_path)
python_files.sort()
# First write out a stub .pot file containing just the translated
# activity name, then have xgettext merge the rest of the
# translations into that. (We can't just append the activity name
# to the end of the .pot file afterwards, because that might
# create a duplicate msgid.)
pot_file = os.path.join('po', '%s.pot' % config.bundle_name)
escaped_name = _po_escape(config.activity_name)
f = open(pot_file, 'w')
f.write('#: activity/activity.info:2\n')
f.write('msgid "%s"\n' % escaped_name)
f.write('msgstr ""\n')
if config.summary is not None:
escaped_summary = _po_escape(config.summary)
f.write('#: activity/activity.info:3\n')
f.write('msgid "%s"\n' % escaped_summary)
f.write('msgstr ""\n')
if config.description is not None:
parser = HTMLParser()
strings = []
parser.handle_data = strings.append
parser.feed(config.description)
for s in strings:
s = s.strip()
if s:
f.write('#: activity/activity.info:4\n')
f.write('msgid "%s"\n' % _po_escape(s))
f.write('msgstr ""\n')
f.close()
args = ['xgettext', '--join-existing', '--language=Python',
'--keyword=_', '--add-comments=TRANS:', '--output=%s' % pot_file]
args += python_files
retcode = subprocess.call(args)
if retcode:
print('ERROR - xgettext failed with return code %i.' % retcode)
示例5: feed
# 需要导入模块: from six.moves.html_parser import HTMLParser [as 别名]
# 或者: from six.moves.html_parser.HTMLParser import feed [as 别名]
def feed(self, string):
try:
HTMLParser.feed(self, string)
except Exception: # pragma: no cover
# only raised in 2.6
self.out.write(string)