Commit 465e6173 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

tools/metrics/histograms/extract_histograms.py: Python 3 support

Example error:
Traceback (most recent call last):
  File "../../tools/metrics/histograms/generate_expired_histograms_array.py", line 14, in <module>
    import extract_histograms
  File "C:\Google\chromium\src\tools\metrics\histograms\extract_histograms.py", line 60, in <module>
    import HTMLParser
ModuleNotFoundError: No module named 'HTMLParser'

Also fixed deprecation warnings:
C:\Google\chromium\src\tools\metrics\histograms\extract_histograms.py:150: DeprecationWarning: The unescape method is deprecated and will be removed in 3.5, use html.unescape() instead.
  return HTMLParser().unescape(line)
...C:\Google\chromium\src\tools\metrics\histograms\extract_histograms_test.py:481: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals('This is a summary with & and " and \'',

The changes are backwards compatible.

Bug: 941669
Change-Id: Ieb22e72b37ec26886f3ca1341e487be4f0ba3ab1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1830657
Auto-Submit: Raul Tambre <raul@tambre.ee>
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701265}
parent 98ad9d8c
......@@ -57,7 +57,13 @@ XML below will generate the following five histograms:
import copy
import datetime
import HTMLParser
try:
import html
except ImportError: # For Py2 compatibility
import HTMLParser
html = HTMLParser.HTMLParser()
import logging
import re
import xml.dom.minidom
......@@ -142,7 +148,7 @@ def NormalizeString(text):
# Unescape using default ASCII encoding. Unescapes any HTML escaped character
# like &quot; etc.
return HTMLParser.HTMLParser().unescape(line)
return html.unescape(line)
def _NormalizeAllAttributeValues(node):
......
......@@ -478,8 +478,8 @@ class ExtractHistogramsTest(unittest.TestCase):
self.assertFalse(have_errors)
self.assertIn('Test.Histogram', hists)
self.assertIn('summary', hists['Test.Histogram'])
self.assertEquals('This is a summary with & and " and \'',
hists['Test.Histogram']['summary'])
self.assertEqual('This is a summary with & and " and \'',
hists['Test.Histogram']['summary'])
if __name__ == "__main__":
logging.basicConfig(level=logging.ERROR + 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment