Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1054)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_converter.py

Issue 2037743002: Support converting utf-16 files when importing w3c tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Support converting utf-16 files when importing w3c tests. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_converter_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 6 #
7 # 1. Redistributions of source code must retain the above 7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following 8 # copyright notice, this list of conditions and the following
9 # disclaimer. 9 # disclaimer.
10 # 2. Redistributions in binary form must reproduce the above 10 # 2. Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 """Converts a file's contents so the Blink layout test runner can run it. 40 """Converts a file's contents so the Blink layout test runner can run it.
41 41
42 Returns: 42 Returns:
43 A pair: the list of modified properties, and the modified text if the file was modified, None otherwise. 43 A pair: the list of modified properties, and the modified text if the file was modified, None otherwise.
44 """ 44 """
45 contents = host.filesystem.read_binary_file(filename) 45 contents = host.filesystem.read_binary_file(filename)
46 converter = _W3CTestConverter(new_path, filename, reference_support_info, ho st) 46 converter = _W3CTestConverter(new_path, filename, reference_support_info, ho st)
47 if filename.endswith('.css'): 47 if filename.endswith('.css'):
48 return converter.add_webkit_prefix_to_unprefixed_properties(contents.dec ode('utf-8')) 48 return converter.add_webkit_prefix_to_unprefixed_properties(contents.dec ode('utf-8'))
49 else: 49 else:
50 converter.feed(contents.decode('utf-8')) 50 try:
51 converter.feed(contents.decode('utf-8'))
52 except UnicodeDecodeError:
53 converter.feed(contents.decode('utf-16'))
51 converter.close() 54 converter.close()
52 return converter.output() 55 return converter.output()
53 56
54 57
55 class _W3CTestConverter(HTMLParser): 58 class _W3CTestConverter(HTMLParser):
56 """A HTMLParser subclass which converts a HTML file as it is parsed. 59 """A HTMLParser subclass which converts a HTML file as it is parsed.
57 60
58 After the feed() method is called, the converted document will be stored 61 After the feed() method is called, the converted document will be stored
59 in converted_data, and can be retrieved with the output() method. 62 in converted_data, and can be retrieved with the output() method.
60 """ 63 """
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 self.converted_data.extend(['&#', name, ';']) 211 self.converted_data.extend(['&#', name, ';'])
209 212
210 def handle_comment(self, data): 213 def handle_comment(self, data):
211 self.converted_data.extend(['<!-- ', data, ' -->']) 214 self.converted_data.extend(['<!-- ', data, ' -->'])
212 215
213 def handle_decl(self, decl): 216 def handle_decl(self, decl):
214 self.converted_data.extend(['<!', decl, '>']) 217 self.converted_data.extend(['<!', decl, '>'])
215 218
216 def handle_pi(self, data): 219 def handle_pi(self, data):
217 self.converted_data.extend(['<?', data, '>']) 220 self.converted_data.extend(['<?', data, '>'])
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_converter_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698