0001-Add-python3-build-support.patch 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. From bf94b834e9beb4e7bc25dbc4c61f5e2db39e7cdc Mon Sep 17 00:00:00 2001
  2. From: James Hilliard <james.hilliard1@gmail.com>
  3. Date: Fri, 4 Feb 2022 15:43:35 -0700
  4. Subject: [PATCH] Add python3 build support
  5. Adapted from:
  6. https://github.com/archlinux/svntogit-packages/blob/6edf5f1aaea952d046aff89a2e0175258fe77361/trunk/qt5-webengine-chromium-python3.patch
  7. Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
  8. ---
  9. .../protobufs/binary_proto_generator.py | 8 +-
  10. .../tracing/generate_trace_viewer_grd.py | 2 +-
  11. chromium/mojo/public/tools/bindings/BUILD.gn | 2 +
  12. .../tools/bindings/gen_data_files_list.py | 8 +-
  13. .../generators/mojom_java_generator.py | 4 +
  14. .../tools/mojom/mojom/generate/generator.py | 14 ++--
  15. .../tools/mojom/mojom/generate/module.py | 3 +-
  16. .../mojom/mojom/generate/template_expander.py | 12 +--
  17. .../scripts/bind_gen/blink_v8_bridge.py | 6 +-
  18. .../scripts/bind_gen/callback_interface.py | 2 +-
  19. .../bindings/scripts/bind_gen/code_node.py | 10 +--
  20. .../bindings/scripts/bind_gen/codegen_expr.py | 15 ++--
  21. .../scripts/bind_gen/codegen_format.py | 2 +-
  22. .../scripts/bind_gen/codegen_utils.py | 2 +-
  23. .../bindings/scripts/bind_gen/dictionary.py | 2 +-
  24. .../bindings/scripts/bind_gen/interface.py | 82 +++++++++++--------
  25. .../scripts/bind_gen/mako_renderer.py | 2 +-
  26. .../bindings/scripts/bind_gen/style_format.py | 9 +-
  27. .../bindings/scripts/bind_gen/task_queue.py | 5 +-
  28. .../bindings/scripts/code_generator.py | 10 +++
  29. .../scripts/generate_origin_trial_features.py | 4 +-
  30. .../bindings/scripts/idl_definitions.py | 8 +-
  31. .../renderer/bindings/scripts/idl_reader.py | 4 +-
  32. .../renderer/bindings/scripts/idl_types.py | 2 +-
  33. .../renderer/bindings/scripts/utilities.py | 28 +++----
  34. .../renderer/bindings/scripts/v8_interface.py | 9 +-
  35. .../renderer/bindings/scripts/v8_methods.py | 4 +
  36. .../renderer/bindings/scripts/v8_utilities.py | 2 +-
  37. .../scripts/web_idl/callback_interface.py | 12 +--
  38. .../bindings/scripts/web_idl/database.py | 2 +-
  39. .../bindings/scripts/web_idl/exposure.py | 5 +-
  40. .../bindings/scripts/web_idl/function_like.py | 28 +++----
  41. .../bindings/scripts/web_idl/idl_compiler.py | 21 ++---
  42. .../bindings/scripts/web_idl/interface.py | 45 +++++-----
  43. .../bindings/scripts/web_idl/ir_builder.py | 29 ++++---
  44. .../bindings/scripts/web_idl/make_copy.py | 7 ++
  45. .../bindings/scripts/web_idl/namespace.py | 12 +--
  46. .../bindings/templates/dictionary_v8.cc.tmpl | 8 +-
  47. .../scripts/core/css/make_style_shorthands.py | 23 +++---
  48. .../properties/make_css_property_instances.py | 4 +-
  49. .../blink/renderer/build/scripts/gperf.py | 2 +-
  50. .../blink/renderer/build/scripts/in_file.py | 2 +-
  51. .../renderer/build/scripts/in_generator.py | 5 ++
  52. .../build/scripts/make_runtime_features.py | 2 +-
  53. .../scripts/templates/element_factory.cc.tmpl | 4 +-
  54. .../templates/element_type_helpers.cc.tmpl | 4 +-
  55. .../templates/element_type_helpers.h.tmpl | 2 +-
  56. .../build/scripts/templates/macros.tmpl | 4 +-
  57. .../templates/make_qualified_names.h.tmpl | 4 +-
  58. .../dawn/generator/generator_lib.py | 4 +
  59. .../devtools-frontend/src/BUILD.gn | 2 +
  60. .../scripts/build/build_inspector_overlay.py | 3 +-
  61. .../build/build_release_applications.py | 9 +-
  62. .../scripts/build/generate_devtools_grd.py | 4 +-
  63. .../src/scripts/build/modular_build.py | 6 +-
  64. chromium/third_party/jinja2/tests.py | 2 +-
  65. chromium/tools/metrics/ukm/gen_builders.py | 5 +-
  66. .../ui/ozone/generate_constructor_list.py | 13 ++-
  67. .../ui/ozone/generate_ozone_platform_list.py | 26 ++++--
  68. 59 files changed, 331 insertions(+), 229 deletions(-)
  69. diff --git a/chromium/components/resources/protobufs/binary_proto_generator.py b/chromium/components/resources/protobufs/binary_proto_generator.py
  70. index 7422ead9697..16365515f26 100755
  71. --- a/chromium/components/resources/protobufs/binary_proto_generator.py
  72. +++ b/chromium/components/resources/protobufs/binary_proto_generator.py
  73. @@ -7,7 +7,7 @@
  74. Converts a given ASCII proto into a binary resource.
  75. """
  76. -
  77. +from __future__ import print_function
  78. import abc
  79. import imp
  80. import optparse
  81. @@ -196,12 +196,12 @@ class BinaryProtoGenerator:
  82. self._ImportProtoModules(opts.path)
  83. if not self.VerifyArgs(opts):
  84. - print "Wrong arguments"
  85. + print("Wrong arguments")
  86. return 1
  87. try:
  88. self._GenerateBinaryProtos(opts)
  89. except Exception as e:
  90. - print "ERROR: Failed to render binary version of %s:\n %s\n%s" % (
  91. - opts.infile, str(e), traceback.format_exc())
  92. + print("ERROR: Failed to render binary version of %s:\n %s\n%s" %
  93. + (opts.infile, str(e), traceback.format_exc()))
  94. return 1
  95. diff --git a/chromium/content/browser/tracing/generate_trace_viewer_grd.py b/chromium/content/browser/tracing/generate_trace_viewer_grd.py
  96. index 037f9497dc2..be393d21f90 100755
  97. --- a/chromium/content/browser/tracing/generate_trace_viewer_grd.py
  98. +++ b/chromium/content/browser/tracing/generate_trace_viewer_grd.py
  99. @@ -74,7 +74,7 @@ def main(argv):
  100. for filename in parsed_args.source_files:
  101. add_file_to_grd(doc, os.path.basename(filename))
  102. - with open(parsed_args.output_filename, 'w') as output_file:
  103. + with open(parsed_args.output_filename, 'wb') as output_file:
  104. output_file.write(doc.toxml(encoding='UTF-8'))
  105. diff --git a/chromium/mojo/public/tools/bindings/BUILD.gn b/chromium/mojo/public/tools/bindings/BUILD.gn
  106. index fc04b5dd0b1..708958e438b 100644
  107. --- a/chromium/mojo/public/tools/bindings/BUILD.gn
  108. +++ b/chromium/mojo/public/tools/bindings/BUILD.gn
  109. @@ -2,9 +2,11 @@
  110. # Use of this source code is governed by a BSD-style license that can be
  111. # found in the LICENSE file.
  112. +import("//build/config/python.gni")
  113. import("//mojo/public/tools/bindings/mojom.gni")
  114. import("//third_party/jinja2/jinja2.gni")
  115. +# TODO(crbug.com/1194274): Investigate nondeterminism in Py3 builds.
  116. action("precompile_templates") {
  117. sources = mojom_generator_sources
  118. sources += [
  119. diff --git a/chromium/mojo/public/tools/bindings/gen_data_files_list.py b/chromium/mojo/public/tools/bindings/gen_data_files_list.py
  120. index 79c9e50efce..8b78d092418 100644
  121. --- a/chromium/mojo/public/tools/bindings/gen_data_files_list.py
  122. +++ b/chromium/mojo/public/tools/bindings/gen_data_files_list.py
  123. @@ -18,7 +18,6 @@ import os
  124. import re
  125. import sys
  126. -from cStringIO import StringIO
  127. from optparse import OptionParser
  128. sys.path.insert(
  129. @@ -41,12 +40,9 @@ def main():
  130. pattern = re.compile(options.pattern)
  131. files = [f for f in os.listdir(options.directory) if pattern.match(f)]
  132. - stream = StringIO()
  133. - for f in files:
  134. - print(f, file=stream)
  135. + contents = '\n'.join(f for f in files) + '\n'
  136. + WriteFile(contents, options.output)
  137. - WriteFile(stream.getvalue(), options.output)
  138. - stream.close()
  139. if __name__ == '__main__':
  140. sys.exit(main())
  141. diff --git a/chromium/mojo/public/tools/bindings/generators/mojom_java_generator.py b/chromium/mojo/public/tools/bindings/generators/mojom_java_generator.py
  142. index 96b2fdfae0c..00b9dccd00c 100644
  143. --- a/chromium/mojo/public/tools/bindings/generators/mojom_java_generator.py
  144. +++ b/chromium/mojo/public/tools/bindings/generators/mojom_java_generator.py
  145. @@ -25,6 +25,10 @@ sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir,
  146. 'build', 'android', 'gyp'))
  147. from util import build_utils
  148. +# TODO(crbug.com/1174969): Remove this once Python2 is obsoleted.
  149. +if sys.version_info.major != 2:
  150. + basestring = str
  151. + long = int
  152. GENERATOR_PREFIX = 'java'
  153. diff --git a/chromium/mojo/public/tools/mojom/mojom/generate/generator.py b/chromium/mojo/public/tools/mojom/mojom/generate/generator.py
  154. index de62260a5c9..4a1c73fcf82 100644
  155. --- a/chromium/mojo/public/tools/mojom/mojom/generate/generator.py
  156. +++ b/chromium/mojo/public/tools/mojom/mojom/generate/generator.py
  157. @@ -136,9 +136,14 @@ class Stylizer(object):
  158. def WriteFile(contents, full_path):
  159. # If |contents| is same with the file content, we skip updating.
  160. + if not isinstance(contents, bytes):
  161. + data = contents.encode('utf8')
  162. + else:
  163. + data = contents
  164. +
  165. if os.path.isfile(full_path):
  166. with open(full_path, 'rb') as destination_file:
  167. - if destination_file.read() == contents:
  168. + if destination_file.read() == data:
  169. return
  170. # Make sure the containing directory exists.
  171. @@ -146,11 +151,8 @@ def WriteFile(contents, full_path):
  172. fileutil.EnsureDirectoryExists(full_dir)
  173. # Dump the data to disk.
  174. - with open(full_path, "wb") as f:
  175. - if not isinstance(contents, bytes):
  176. - f.write(contents.encode('utf-8'))
  177. - else:
  178. - f.write(contents)
  179. + with open(full_path, 'wb') as f:
  180. + f.write(data)
  181. def AddComputedData(module):
  182. diff --git a/chromium/mojo/public/tools/mojom/mojom/generate/module.py b/chromium/mojo/public/tools/mojom/mojom/generate/module.py
  183. index ebbc9b322ea..3d026429bbc 100644
  184. --- a/chromium/mojo/public/tools/mojom/mojom/generate/module.py
  185. +++ b/chromium/mojo/public/tools/mojom/mojom/generate/module.py
  186. @@ -398,7 +398,8 @@ class Field(object):
  187. class StructField(Field):
  188. - pass
  189. + def __hash__(self):
  190. + return super(Field, self).__hash__()
  191. class UnionField(Field):
  192. diff --git a/chromium/mojo/public/tools/mojom/mojom/generate/template_expander.py b/chromium/mojo/public/tools/mojom/mojom/generate/template_expander.py
  193. index 7a300560246..8d9e26fb7f6 100644
  194. --- a/chromium/mojo/public/tools/mojom/mojom/generate/template_expander.py
  195. +++ b/chromium/mojo/public/tools/mojom/mojom/generate/template_expander.py
  196. @@ -75,9 +75,9 @@ def PrecompileTemplates(generator_modules, output_dir):
  197. os.path.dirname(module.__file__), generator.GetTemplatePrefix())
  198. ]))
  199. jinja_env.filters.update(generator.GetFilters())
  200. - jinja_env.compile_templates(
  201. - os.path.join(output_dir, "%s.zip" % generator.GetTemplatePrefix()),
  202. - extensions=["tmpl"],
  203. - zip="stored",
  204. - py_compile=True,
  205. - ignore_errors=False)
  206. + jinja_env.compile_templates(os.path.join(
  207. + output_dir, "%s.zip" % generator.GetTemplatePrefix()),
  208. + extensions=["tmpl"],
  209. + zip="stored",
  210. + py_compile=sys.version_info.major < 3,
  211. + ignore_errors=False)
  212. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/blink_v8_bridge.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/blink_v8_bridge.py
  213. index 3225ecca6e4..fc078d31b55 100644
  214. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/blink_v8_bridge.py
  215. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/blink_v8_bridge.py
  216. @@ -344,7 +344,7 @@ def make_default_value_expr(idl_type, default_value):
  217. """
  218. assert default_value.is_type_compatible_with(idl_type)
  219. - class DefaultValueExpr:
  220. + class DefaultValueExpr(object):
  221. _ALLOWED_SYMBOLS_IN_DEPS = ("isolate")
  222. def __init__(self, initializer_expr, initializer_deps,
  223. @@ -502,7 +502,7 @@ def make_v8_to_blink_value(blink_var_name,
  224. assert isinstance(blink_var_name, str)
  225. assert isinstance(v8_value_expr, str)
  226. assert isinstance(idl_type, web_idl.IdlType)
  227. - assert (argument_index is None or isinstance(argument_index, (int, long)))
  228. + assert (argument_index is None or isinstance(argument_index, int))
  229. assert (default_value is None
  230. or isinstance(default_value, web_idl.LiteralConstant))
  231. @@ -622,7 +622,7 @@ def make_v8_to_blink_value_variadic(blink_var_name, v8_array,
  232. """
  233. assert isinstance(blink_var_name, str)
  234. assert isinstance(v8_array, str)
  235. - assert isinstance(v8_array_start_index, (int, long))
  236. + assert isinstance(v8_array_start_index, int)
  237. assert isinstance(idl_type, web_idl.IdlType)
  238. pattern = ("auto&& ${{{_1}}} = "
  239. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/callback_interface.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/callback_interface.py
  240. index 4a6df513068..8b51f23a409 100644
  241. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/callback_interface.py
  242. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/callback_interface.py
  243. @@ -177,7 +177,7 @@ def generate_callback_interface(callback_interface_identifier):
  244. prop_install_mode=PropInstallMode.UNCONDITIONAL,
  245. trampoline_var_name=None,
  246. attribute_entries=[],
  247. - constant_entries=filter(is_unconditional, constant_entries),
  248. + constant_entries=list(filter(is_unconditional, constant_entries)),
  249. exposed_construct_entries=[],
  250. operation_entries=[])
  251. (install_interface_template_decl, install_interface_template_def,
  252. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/code_node.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/code_node.py
  253. index 52972fefe20..e5ae9d9629e 100644
  254. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/code_node.py
  255. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/code_node.py
  256. @@ -503,13 +503,13 @@ class CompositeNode(CodeNode):
  257. gensym_kwargs = {}
  258. template_vars = {}
  259. for arg in args:
  260. - assert isinstance(arg, (CodeNode, int, long, str))
  261. + assert isinstance(arg, (CodeNode, int, str))
  262. gensym = CodeNode.gensym()
  263. gensym_args.append("${{{}}}".format(gensym))
  264. template_vars[gensym] = arg
  265. for key, value in kwargs.items():
  266. - assert isinstance(key, (int, long, str))
  267. - assert isinstance(value, (CodeNode, int, long, str))
  268. + assert isinstance(key, (int, str))
  269. + assert isinstance(value, (CodeNode, int, str))
  270. gensym = CodeNode.gensym()
  271. gensym_kwargs[key] = "${{{}}}".format(gensym)
  272. template_vars[gensym] = value
  273. @@ -602,7 +602,7 @@ class ListNode(CodeNode):
  274. def insert(self, index, node):
  275. if node is None:
  276. return
  277. - assert isinstance(index, (int, long))
  278. + assert isinstance(index, int)
  279. assert isinstance(node, CodeNode)
  280. assert node.outer is None and node.prev is None
  281. @@ -721,7 +721,7 @@ class SymbolScopeNode(SequenceNode):
  282. if not scope_chains:
  283. return counts
  284. - self_index = iter(scope_chains).next().index(self)
  285. + self_index = next(iter(scope_chains)).index(self)
  286. scope_chains = map(
  287. lambda scope_chain: scope_chain[self_index + 1:], scope_chains)
  288. scope_to_likeliness = {}
  289. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
  290. index a229a6c71c9..5fa288dabf2 100644
  291. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
  292. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_expr.py
  293. @@ -109,7 +109,7 @@ def expr_and(terms):
  294. if any(term.is_always_false for term in terms):
  295. return _Expr(False)
  296. - terms = filter(lambda x: not x.is_always_true, terms)
  297. + terms = list(filter(lambda x: not x.is_always_true, terms))
  298. if not terms:
  299. return _Expr(True)
  300. if len(terms) == 1:
  301. @@ -124,7 +124,7 @@ def expr_or(terms):
  302. if any(term.is_always_true for term in terms):
  303. return _Expr(True)
  304. - terms = filter(lambda x: not x.is_always_false, terms)
  305. + terms = list(filter(lambda x: not x.is_always_false, terms))
  306. if not terms:
  307. return _Expr(False)
  308. if len(terms) == 1:
  309. @@ -222,7 +222,7 @@ def expr_from_exposure(exposure,
  310. elif exposure.only_in_secure_contexts is False:
  311. secure_context_term = _Expr(True)
  312. else:
  313. - terms = map(ref_enabled, exposure.only_in_secure_contexts)
  314. + terms = list(map(ref_enabled, exposure.only_in_secure_contexts))
  315. secure_context_term = expr_or(
  316. [_Expr("${is_in_secure_context}"),
  317. expr_not(expr_and(terms))])
  318. @@ -275,10 +275,11 @@ def expr_from_exposure(exposure,
  319. # [ContextEnabled]
  320. if exposure.context_enabled_features:
  321. - terms = map(
  322. - lambda feature: _Expr(
  323. - "${{context_feature_settings}}->is{}Enabled()".format(
  324. - feature)), exposure.context_enabled_features)
  325. + terms = list(
  326. + map(
  327. + lambda feature: _Expr(
  328. + "${{context_feature_settings}}->is{}Enabled()".format(
  329. + feature)), exposure.context_enabled_features))
  330. context_enabled_terms.append(
  331. expr_and([_Expr("${context_feature_settings}"),
  332. expr_or(terms)]))
  333. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_format.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_format.py
  334. index 87d26eec3ca..f3e9d38247e 100644
  335. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_format.py
  336. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_format.py
  337. @@ -23,7 +23,7 @@ class _TemplateFormatter(string.Formatter):
  338. self._template_formatter_indexing_count_ = 0
  339. def get_value(self, key, args, kwargs):
  340. - if isinstance(key, (int, long)):
  341. + if isinstance(key, int):
  342. return args[key]
  343. assert isinstance(key, str)
  344. if not key:
  345. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_utils.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_utils.py
  346. index 2bcc4fed49a..e72282aa696 100644
  347. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_utils.py
  348. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/codegen_utils.py
  349. @@ -116,4 +116,4 @@ def write_code_node_to_file(code_node, filepath):
  350. # stderr=format_result.error_message))
  351. #
  352. # web_idl.file_io.write_to_file_if_changed(filepath, format_result.contents)
  353. - web_idl.file_io.write_to_file_if_changed(filepath, rendered_text)
  354. + web_idl.file_io.write_to_file_if_changed(filepath, rendered_text.encode('utf-8'))
  355. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/dictionary.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/dictionary.py
  356. index b39f0100410..4d68202296b 100644
  357. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/dictionary.py
  358. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/dictionary.py
  359. @@ -993,7 +993,7 @@ def make_dict_trace_func(cg_context):
  360. _2 = _blink_member_name(member).value_var
  361. return TextNode(_format(pattern, _1=_1, _2=_2))
  362. - body.extend(map(make_trace_member_node, own_members))
  363. + body.extend(list(map(make_trace_member_node, own_members)))
  364. body.append(TextNode("BaseClass::Trace(visitor);"))
  365. return func_decl, func_def
  366. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
  367. index 10ff30656ad..bfdf7128aac 100644
  368. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
  369. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/interface.py
  370. @@ -582,7 +582,7 @@ def _make_blink_api_call(code_node,
  371. overriding_args=None):
  372. assert isinstance(code_node, SymbolScopeNode)
  373. assert isinstance(cg_context, CodeGenContext)
  374. - assert num_of_args is None or isinstance(num_of_args, (int, long))
  375. + assert num_of_args is None or isinstance(num_of_args, int)
  376. assert (overriding_args is None
  377. or (isinstance(overriding_args, (list, tuple))
  378. and all(isinstance(arg, str) for arg in overriding_args)))
  379. @@ -1196,8 +1196,10 @@ def make_overload_dispatcher(cg_context):
  380. did_use_break = did_use_break or can_fail
  381. conditional = expr_or(
  382. - map(lambda item: expr_from_exposure(item.function_like.exposure),
  383. - items))
  384. + list(
  385. + map(
  386. + lambda item: expr_from_exposure(item.function_like.exposure
  387. + ), items)))
  388. if not conditional.is_always_true:
  389. node = CxxUnlikelyIfNode(cond=conditional, body=node)
  390. @@ -4642,7 +4644,7 @@ class _PropEntryConstructorGroup(_PropEntryBase):
  391. def __init__(self, is_context_dependent, exposure_conditional, world,
  392. constructor_group, ctor_callback_name, ctor_func_length):
  393. assert isinstance(ctor_callback_name, str)
  394. - assert isinstance(ctor_func_length, (int, long))
  395. + assert isinstance(ctor_func_length, int)
  396. _PropEntryBase.__init__(self, is_context_dependent,
  397. exposure_conditional, world, constructor_group)
  398. @@ -4670,7 +4672,7 @@ class _PropEntryOperationGroup(_PropEntryBase):
  399. op_func_length,
  400. no_alloc_direct_callback_name=None):
  401. assert isinstance(op_callback_name, str)
  402. - assert isinstance(op_func_length, (int, long))
  403. + assert isinstance(op_func_length, int)
  404. _PropEntryBase.__init__(self, is_context_dependent,
  405. exposure_conditional, world, operation_group)
  406. @@ -5175,9 +5177,9 @@ def make_install_interface_template(cg_context, function_name, class_name, api_c
  407. ])
  408. if class_like.identifier == "CSSStyleDeclaration":
  409. - css_properties = filter(
  410. - lambda attr: "CSSProperty" in attr.extended_attributes,
  411. - class_like.attributes)
  412. + css_properties = list(
  413. + filter(lambda attr: "CSSProperty" in attr.extended_attributes,
  414. + class_like.attributes))
  415. if css_properties:
  416. prop_name_list = "".join(
  417. map(lambda attr: "\"{}\", ".format(attr.identifier),
  418. @@ -5567,8 +5569,8 @@ ${instance_object} = ${v8_context}->Global()->GetPrototype().As<v8::Object>();\
  419. "V8DOMConfiguration::InstallConstants(${isolate}, "
  420. "${interface_template}, ${prototype_template}, "
  421. "kConstantCallbackTable, base::size(kConstantCallbackTable));")
  422. - constant_callback_entries = filter(lambda entry: entry.const_callback_name,
  423. - constant_entries)
  424. + constant_callback_entries = list(filter(lambda entry: entry.const_callback_name,
  425. + constant_entries))
  426. install_properties(table_name, constant_callback_entries,
  427. _make_constant_callback_registration_table,
  428. installer_call_text)
  429. @@ -5584,8 +5586,8 @@ ${instance_object} = ${v8_context}->Global()->GetPrototype().As<v8::Object>();\
  430. "V8DOMConfiguration::InstallConstants(${isolate}, "
  431. "${interface_template}, ${prototype_template}, "
  432. "kConstantValueTable, base::size(kConstantValueTable));")
  433. - constant_value_entries = filter(
  434. - lambda entry: not entry.const_callback_name, constant_entries)
  435. + constant_value_entries = list(filter(
  436. + lambda entry: not entry.const_callback_name, constant_entries))
  437. install_properties(table_name, constant_value_entries,
  438. _make_constant_value_registration_table,
  439. installer_call_text)
  440. @@ -6336,8 +6338,8 @@ def make_v8_context_snapshot_api(cg_context, component, attribute_entries,
  441. assert isinstance(component, web_idl.Component)
  442. derived_interfaces = cg_context.interface.deriveds
  443. - derived_names = map(lambda interface: interface.identifier,
  444. - derived_interfaces)
  445. + derived_names = list(
  446. + map(lambda interface: interface.identifier, derived_interfaces))
  447. derived_names.append(cg_context.interface.identifier)
  448. if not ("Window" in derived_names or "HTMLDocument" in derived_names):
  449. return None, None
  450. @@ -6411,9 +6413,11 @@ def _make_v8_context_snapshot_get_reference_table_function(
  451. collect_callbacks(named_properties_object_callback_defs)
  452. collect_callbacks(cross_origin_property_callback_defs)
  453. - entry_nodes = map(
  454. - lambda name: TextNode("reinterpret_cast<intptr_t>({}),".format(name)),
  455. - filter(None, callback_names))
  456. + entry_nodes = list(
  457. + map(
  458. + lambda name: TextNode("reinterpret_cast<intptr_t>({}),".format(name
  459. + )),
  460. + filter(None, callback_names)))
  461. table_node = ListNode([
  462. TextNode("using namespace ${class_name}Callbacks;"),
  463. TextNode("static const intptr_t kReferenceTable[] = {"),
  464. @@ -6451,10 +6455,11 @@ def _make_v8_context_snapshot_install_props_per_context_function(
  465. class_name=None,
  466. prop_install_mode=PropInstallMode.V8_CONTEXT_SNAPSHOT,
  467. trampoline_var_name=None,
  468. - attribute_entries=filter(selector, attribute_entries),
  469. - constant_entries=filter(selector, constant_entries),
  470. - exposed_construct_entries=filter(selector, exposed_construct_entries),
  471. - operation_entries=filter(selector, operation_entries))
  472. + attribute_entries=list(filter(selector, attribute_entries)),
  473. + constant_entries=list(filter(selector, constant_entries)),
  474. + exposed_construct_entries=list(
  475. + filter(selector, exposed_construct_entries)),
  476. + operation_entries=list(filter(selector, operation_entries)))
  477. return func_decl, func_def
  478. @@ -6810,11 +6815,11 @@ def generate_interface(interface_identifier):
  479. class_name=impl_class_name,
  480. prop_install_mode=PropInstallMode.UNCONDITIONAL,
  481. trampoline_var_name=tp_install_unconditional_props,
  482. - attribute_entries=filter(is_unconditional, attribute_entries),
  483. - constant_entries=filter(is_unconditional, constant_entries),
  484. - exposed_construct_entries=filter(is_unconditional,
  485. - exposed_construct_entries),
  486. - operation_entries=filter(is_unconditional, operation_entries))
  487. + attribute_entries=list(filter(is_unconditional, attribute_entries)),
  488. + constant_entries=list(filter(is_unconditional, constant_entries)),
  489. + exposed_construct_entries=list(
  490. + filter(is_unconditional, exposed_construct_entries)),
  491. + operation_entries=list(filter(is_unconditional, operation_entries)))
  492. (install_context_independent_props_decl,
  493. install_context_independent_props_def,
  494. install_context_independent_props_trampoline) = make_install_properties(
  495. @@ -6823,11 +6828,14 @@ def generate_interface(interface_identifier):
  496. class_name=impl_class_name,
  497. prop_install_mode=PropInstallMode.CONTEXT_INDEPENDENT,
  498. trampoline_var_name=tp_install_context_independent_props,
  499. - attribute_entries=filter(is_context_independent, attribute_entries),
  500. - constant_entries=filter(is_context_independent, constant_entries),
  501. - exposed_construct_entries=filter(is_context_independent,
  502. - exposed_construct_entries),
  503. - operation_entries=filter(is_context_independent, operation_entries))
  504. + attribute_entries=list(
  505. + filter(is_context_independent, attribute_entries)),
  506. + constant_entries=list(filter(is_context_independent,
  507. + constant_entries)),
  508. + exposed_construct_entries=list(
  509. + filter(is_context_independent, exposed_construct_entries)),
  510. + operation_entries=list(
  511. + filter(is_context_independent, operation_entries)))
  512. (install_context_dependent_props_decl, install_context_dependent_props_def,
  513. install_context_dependent_props_trampoline) = make_install_properties(
  514. cg_context,
  515. @@ -6835,11 +6843,13 @@ def generate_interface(interface_identifier):
  516. class_name=impl_class_name,
  517. prop_install_mode=PropInstallMode.CONTEXT_DEPENDENT,
  518. trampoline_var_name=tp_install_context_dependent_props,
  519. - attribute_entries=filter(is_context_dependent, attribute_entries),
  520. - constant_entries=filter(is_context_dependent, constant_entries),
  521. - exposed_construct_entries=filter(is_context_dependent,
  522. - exposed_construct_entries),
  523. - operation_entries=filter(is_context_dependent, operation_entries))
  524. + attribute_entries=list(filter(is_context_dependent,
  525. + attribute_entries)),
  526. + constant_entries=list(filter(is_context_dependent, constant_entries)),
  527. + exposed_construct_entries=list(
  528. + filter(is_context_dependent, exposed_construct_entries)),
  529. + operation_entries=list(filter(is_context_dependent,
  530. + operation_entries)))
  531. (install_interface_template_decl, install_interface_template_def,
  532. install_interface_template_trampoline) = make_install_interface_template(
  533. cg_context,
  534. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/mako_renderer.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/mako_renderer.py
  535. index b4c70553863..f3a2fcd772d 100644
  536. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/mako_renderer.py
  537. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/mako_renderer.py
  538. @@ -105,7 +105,7 @@ class MakoRenderer(object):
  539. on_error = self._caller_stack_on_error
  540. if (len(current) <= len(on_error)
  541. and all(current[i] == on_error[i]
  542. - for i in xrange(len(current)))):
  543. + for i in range(len(current)))):
  544. pass # Error happened in a deeper caller.
  545. else:
  546. self._caller_stack_on_error = list(self._caller_stack)
  547. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/style_format.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/style_format.py
  548. index dc3493cc394..017d3d47bb3 100644
  549. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/style_format.py
  550. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/style_format.py
  551. @@ -70,8 +70,13 @@ def gn_format(contents, filename=None):
  552. def _invoke_format_command(command_line, filename, contents):
  553. - proc = subprocess.Popen(
  554. - command_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  555. + kwargs = {}
  556. + if sys.version_info.major != 2:
  557. + kwargs['encoding'] = 'utf-8'
  558. + proc = subprocess.Popen(command_line,
  559. + stdin=subprocess.PIPE,
  560. + stdout=subprocess.PIPE,
  561. + **kwargs)
  562. stdout_output, stderr_output = proc.communicate(input=contents)
  563. exit_code = proc.wait()
  564. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/task_queue.py b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/task_queue.py
  565. index 0d8f4c0f303..e666a9b668e 100644
  566. --- a/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/task_queue.py
  567. +++ b/chromium/third_party/blink/renderer/bindings/scripts/bind_gen/task_queue.py
  568. @@ -2,6 +2,7 @@
  569. # Use of this source code is governed by a BSD-style license that can be
  570. # found in the LICENSE file.
  571. +import functools
  572. import multiprocessing
  573. from .package_initializer import package_initializer
  574. @@ -76,7 +77,7 @@ class TaskQueue(object):
  575. if not report_progress:
  576. return
  577. - done_count = reduce(
  578. + done_count = functools.reduce(
  579. lambda count, worker_task: count + bool(worker_task.ready()),
  580. self._worker_tasks, 0)
  581. report_progress(len(self._worker_tasks), done_count)
  582. @@ -85,4 +86,4 @@ class TaskQueue(object):
  583. def _task_queue_run_tasks(tasks):
  584. for task in tasks:
  585. func, args, kwargs = task
  586. - apply(func, args, kwargs)
  587. + func(*args, **kwargs)
  588. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/code_generator.py b/chromium/third_party/blink/renderer/bindings/scripts/code_generator.py
  589. index e8280be7213..e49e6eb965e 100644
  590. --- a/chromium/third_party/blink/renderer/bindings/scripts/code_generator.py
  591. +++ b/chromium/third_party/blink/renderer/bindings/scripts/code_generator.py
  592. @@ -13,6 +13,7 @@ import re
  593. import sys
  594. from idl_types import set_ancestors, IdlType
  595. +from itertools import groupby
  596. from v8_globals import includes
  597. from v8_interface import constant_filters
  598. from v8_types import set_component_dirs
  599. @@ -43,6 +44,7 @@ TEMPLATES_DIR = os.path.normpath(
  600. # after path[0] == invoking script dir
  601. sys.path.insert(1, THIRD_PARTY_DIR)
  602. import jinja2
  603. +from jinja2.filters import make_attrgetter, environmentfilter
  604. def generate_indented_conditional(code, conditional):
  605. @@ -88,6 +90,13 @@ def runtime_enabled_if(code, name):
  606. return generate_indented_conditional(code, function)
  607. +@environmentfilter
  608. +def do_stringify_key_group_by(environment, value, attribute):
  609. + expr = make_attrgetter(environment, attribute)
  610. + key = lambda item: '' if expr(item) is None else str(expr(item))
  611. + return groupby(sorted(value, key=key), expr)
  612. +
  613. +
  614. def initialize_jinja_env(cache_dir):
  615. jinja_env = jinja2.Environment(
  616. loader=jinja2.FileSystemLoader(TEMPLATES_DIR),
  617. @@ -117,6 +126,7 @@ def initialize_jinja_env(cache_dir):
  618. })
  619. jinja_env.filters.update(constant_filters())
  620. jinja_env.filters.update(method_filters())
  621. + jinja_env.filters["stringifykeygroupby"] = do_stringify_key_group_by
  622. return jinja_env
  623. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/generate_origin_trial_features.py b/chromium/third_party/blink/renderer/bindings/scripts/generate_origin_trial_features.py
  624. index 130004eae83..04c0fabcef2 100755
  625. --- a/chromium/third_party/blink/renderer/bindings/scripts/generate_origin_trial_features.py
  626. +++ b/chromium/third_party/blink/renderer/bindings/scripts/generate_origin_trial_features.py
  627. @@ -80,7 +80,7 @@ def read_idl_file(reader, idl_filename):
  628. assert len(interfaces) == 1, (
  629. "Expected one interface in file %r, found %d" %
  630. (idl_filename, len(interfaces)))
  631. - return (interfaces.values()[0], includes)
  632. + return (list(interfaces.values())[0], includes)
  633. def interface_is_global(interface):
  634. @@ -281,7 +281,7 @@ def main():
  635. info_provider = create_component_info_provider(
  636. os.path.normpath(options.info_dir), options.target_component)
  637. - idl_filenames = map(str.strip, open(options.idl_files_list))
  638. + idl_filenames = list(map(str.strip, open(options.idl_files_list)))
  639. generate_origin_trial_features(info_provider, options, idl_filenames)
  640. return 0
  641. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/idl_definitions.py b/chromium/third_party/blink/renderer/bindings/scripts/idl_definitions.py
  642. index 14e6e9d3f87..b027818aef2 100644
  643. --- a/chromium/third_party/blink/renderer/bindings/scripts/idl_definitions.py
  644. +++ b/chromium/third_party/blink/renderer/bindings/scripts/idl_definitions.py
  645. @@ -394,7 +394,8 @@ class IdlInterface(object):
  646. else:
  647. raise ValueError('Unrecognized node class: %s' % child_class)
  648. - if len(filter(None, [self.iterable, self.maplike, self.setlike])) > 1:
  649. + if len(list(filter(None,
  650. + [self.iterable, self.maplike, self.setlike]))) > 1:
  651. raise ValueError(
  652. 'Interface can only have one of iterable<>, maplike<> and setlike<>.'
  653. )
  654. @@ -512,6 +513,9 @@ class IdlAttribute(TypedObject):
  655. def accept(self, visitor):
  656. visitor.visit_attribute(self)
  657. + def __lt__(self, other):
  658. + return self.name < other.name
  659. +
  660. ################################################################################
  661. # Constants
  662. @@ -852,7 +856,7 @@ class IdlIncludes(object):
  663. ################################################################################
  664. -class Exposure:
  665. +class Exposure(object):
  666. """An Exposure holds one Exposed or RuntimeEnabled condition.
  667. Each exposure has two properties: exposed and runtime_enabled.
  668. Exposure(e, r) corresponds to [Exposed(e r)]. Exposure(e) corresponds to
  669. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/idl_reader.py b/chromium/third_party/blink/renderer/bindings/scripts/idl_reader.py
  670. index 8d72865a6ca..b80eebdcd61 100644
  671. --- a/chromium/third_party/blink/renderer/bindings/scripts/idl_reader.py
  672. +++ b/chromium/third_party/blink/renderer/bindings/scripts/idl_reader.py
  673. @@ -55,8 +55,8 @@ def validate_blink_idl_definitions(idl_filename, idl_file_basename,
  674. definitions. There is no filename convention in this case.
  675. - Otherwise, an IDL file is invalid.
  676. """
  677. - targets = (
  678. - definitions.interfaces.values() + definitions.dictionaries.values())
  679. + targets = (list(definitions.interfaces.values()) +
  680. + list(definitions.dictionaries.values()))
  681. number_of_targets = len(targets)
  682. if number_of_targets > 1:
  683. raise Exception(
  684. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/idl_types.py b/chromium/third_party/blink/renderer/bindings/scripts/idl_types.py
  685. index cd4f0c3513b..ab95e9c0b08 100644
  686. --- a/chromium/third_party/blink/renderer/bindings/scripts/idl_types.py
  687. +++ b/chromium/third_party/blink/renderer/bindings/scripts/idl_types.py
  688. @@ -349,7 +349,7 @@ class IdlUnionType(IdlTypeBase):
  689. return True
  690. def single_matching_member_type(self, predicate):
  691. - matching_types = filter(predicate, self.flattened_member_types)
  692. + matching_types = list(filter(predicate, self.flattened_member_types))
  693. if len(matching_types) > 1:
  694. raise ValueError('%s is ambiguous.' % self.name)
  695. return matching_types[0] if matching_types else None
  696. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/utilities.py b/chromium/third_party/blink/renderer/bindings/scripts/utilities.py
  697. index e1677ee7bd6..3c5006f064f 100644
  698. --- a/chromium/third_party/blink/renderer/bindings/scripts/utilities.py
  699. +++ b/chromium/third_party/blink/renderer/bindings/scripts/utilities.py
  700. @@ -196,8 +196,9 @@ class ComponentInfoProviderModules(ComponentInfoProvider):
  701. @property
  702. def callback_functions(self):
  703. - return dict(self._component_info_core['callback_functions'].items() +
  704. - self._component_info_modules['callback_functions'].items())
  705. + return dict(
  706. + list(self._component_info_core['callback_functions'].items()) +
  707. + list(self._component_info_modules['callback_functions'].items()))
  708. @property
  709. def specifier_for_export(self):
  710. @@ -209,8 +210,8 @@ class ComponentInfoProviderModules(ComponentInfoProvider):
  711. def load_interfaces_info_overall_pickle(info_dir):
  712. - with open(os.path.join(info_dir,
  713. - 'interfaces_info.pickle')) as interface_info_file:
  714. + with open(os.path.join(info_dir, 'interfaces_info.pickle'),
  715. + mode='rb') as interface_info_file:
  716. return pickle.load(interface_info_file)
  717. @@ -236,23 +237,20 @@ def merge_dict_recursively(target, diff):
  718. def create_component_info_provider_core(info_dir):
  719. interfaces_info = load_interfaces_info_overall_pickle(info_dir)
  720. - with open(
  721. - os.path.join(info_dir, 'core',
  722. - 'component_info_core.pickle')) as component_info_file:
  723. + with open(os.path.join(info_dir, 'core', 'component_info_core.pickle'),
  724. + mode='rb') as component_info_file:
  725. component_info = pickle.load(component_info_file)
  726. return ComponentInfoProviderCore(interfaces_info, component_info)
  727. def create_component_info_provider_modules(info_dir):
  728. interfaces_info = load_interfaces_info_overall_pickle(info_dir)
  729. - with open(
  730. - os.path.join(info_dir, 'core',
  731. - 'component_info_core.pickle')) as component_info_file:
  732. + with open(os.path.join(info_dir, 'core', 'component_info_core.pickle'),
  733. + mode='rb') as component_info_file:
  734. component_info_core = pickle.load(component_info_file)
  735. - with open(
  736. - os.path.join(
  737. - info_dir, 'modules',
  738. - 'component_info_modules.pickle')) as component_info_file:
  739. + with open(os.path.join(info_dir, 'modules',
  740. + 'component_info_modules.pickle'),
  741. + mode='rb') as component_info_file:
  742. component_info_modules = pickle.load(component_info_file)
  743. return ComponentInfoProviderModules(interfaces_info, component_info_core,
  744. component_info_modules)
  745. @@ -356,7 +354,7 @@ def write_pickle_file(pickle_filename, data):
  746. pickle_filename = abs(pickle_filename)
  747. # If |data| is same with the file content, we skip updating.
  748. if os.path.isfile(pickle_filename):
  749. - with open(pickle_filename) as pickle_file:
  750. + with open(pickle_filename, 'rb') as pickle_file:
  751. try:
  752. if pickle.load(pickle_file) == data:
  753. return
  754. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/v8_interface.py b/chromium/third_party/blink/renderer/bindings/scripts/v8_interface.py
  755. index a43260414db..a85b03abe75 100644
  756. --- a/chromium/third_party/blink/renderer/bindings/scripts/v8_interface.py
  757. +++ b/chromium/third_party/blink/renderer/bindings/scripts/v8_interface.py
  758. @@ -189,7 +189,7 @@ def context_enabled_features(attributes):
  759. return sorted([
  760. member for member in members
  761. if member.get(KEY) and not member.get('exposed_test')
  762. - ])
  763. + ], key=lambda item: item['name'])
  764. def member_filter_by_name(members, name):
  765. return [member for member in members if member[KEY] == name]
  766. @@ -612,7 +612,8 @@ def interface_context(interface, interfaces, component_info):
  767. sorted(
  768. origin_trial_features(interface, context['constants'],
  769. context['attributes'], context['methods']) +
  770. - context_enabled_features(context['attributes'])),
  771. + context_enabled_features(context['attributes']),
  772. + key=lambda item: item['name']),
  773. })
  774. if context['optional_features']:
  775. includes.add('platform/bindings/v8_per_context_data.h')
  776. @@ -1356,9 +1357,9 @@ def resolution_tests_methods(effective_overloads):
  777. # Extract argument and IDL type to simplify accessing these in each loop.
  778. arguments = [method['arguments'][index] for method in methods]
  779. - arguments_methods = zip(arguments, methods)
  780. + arguments_methods = list(zip(arguments, methods))
  781. idl_types = [argument['idl_type_object'] for argument in arguments]
  782. - idl_types_methods = zip(idl_types, methods)
  783. + idl_types_methods = list(zip(idl_types, methods))
  784. # We can’t do a single loop through all methods or simply sort them, because
  785. # a method may be listed in multiple steps of the resolution algorithm, and
  786. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/v8_methods.py b/chromium/third_party/blink/renderer/bindings/scripts/v8_methods.py
  787. index 5f1f89a3def..6ee8a407798 100644
  788. --- a/chromium/third_party/blink/renderer/bindings/scripts/v8_methods.py
  789. +++ b/chromium/third_party/blink/renderer/bindings/scripts/v8_methods.py
  790. @@ -46,6 +46,10 @@ import v8_types
  791. import v8_utilities
  792. from v8_utilities import (has_extended_attribute_value, is_unforgeable)
  793. +# TODO: Remove this once Python2 is obsoleted.
  794. +if sys.version_info.major != 2:
  795. + basestring = str
  796. +
  797. def method_is_visible(method, interface_is_partial):
  798. if 'overloads' in method:
  799. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/v8_utilities.py b/chromium/third_party/blink/renderer/bindings/scripts/v8_utilities.py
  800. index 2ecd6923320..fcfc48371b1 100644
  801. --- a/chromium/third_party/blink/renderer/bindings/scripts/v8_utilities.py
  802. +++ b/chromium/third_party/blink/renderer/bindings/scripts/v8_utilities.py
  803. @@ -271,7 +271,7 @@ EXPOSED_WORKERS = set([
  804. ])
  805. -class ExposureSet:
  806. +class ExposureSet(object):
  807. """An ExposureSet is a collection of Exposure instructions."""
  808. def __init__(self, exposures=None):
  809. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/callback_interface.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/callback_interface.py
  810. index 13fb7c7068d..b73b7710687 100644
  811. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/callback_interface.py
  812. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/callback_interface.py
  813. @@ -91,11 +91,13 @@ class CallbackInterface(UserDefinedType, WithExtendedAttributes,
  814. for operation_ir in ir.operations
  815. ])
  816. self._operation_groups = tuple([
  817. - OperationGroup(
  818. - operation_group_ir,
  819. - filter(lambda x: x.identifier == operation_group_ir.identifier,
  820. - self._operations),
  821. - owner=self) for operation_group_ir in ir.operation_groups
  822. + OperationGroup(operation_group_ir,
  823. + list(
  824. + filter(
  825. + lambda x: x.identifier == operation_group_ir
  826. + .identifier, self._operations)),
  827. + owner=self)
  828. + for operation_group_ir in ir.operation_groups
  829. ])
  830. @property
  831. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/database.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/database.py
  832. index c92cf48eb2a..f5d59129449 100644
  833. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/database.py
  834. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/database.py
  835. @@ -156,4 +156,4 @@ class Database(object):
  836. return self._view_by_kind(Database._Kind.UNION)
  837. def _view_by_kind(self, kind):
  838. - return self._impl.find_by_kind(kind).values()
  839. + return list(self._impl.find_by_kind(kind).values())
  840. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/exposure.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/exposure.py
  841. index abaeef39c30..e36cf7439ae 100644
  842. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/exposure.py
  843. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/exposure.py
  844. @@ -8,8 +8,11 @@ from .runtime_enabled_features import RuntimeEnabledFeatures
  845. class _Feature(str):
  846. """Represents a runtime-enabled feature."""
  847. + def __new__(cls, value):
  848. + return str.__new__(cls, value)
  849. +
  850. def __init__(self, value):
  851. - str.__init__(self, value)
  852. + str.__init__(self)
  853. self._is_context_dependent = (
  854. RuntimeEnabledFeatures.is_context_dependent(self))
  855. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/function_like.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/function_like.py
  856. index 648c70d803d..1712f19c672 100644
  857. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/function_like.py
  858. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/function_like.py
  859. @@ -71,8 +71,9 @@ class FunctionLike(WithIdentifier):
  860. def num_of_required_arguments(self):
  861. """Returns the number of required arguments."""
  862. return len(
  863. - filter(lambda arg: not (arg.is_optional or arg.is_variadic),
  864. - self.arguments))
  865. + list(
  866. + filter(lambda arg: not (arg.is_optional or arg.is_variadic),
  867. + self.arguments)))
  868. class OverloadGroup(WithIdentifier):
  869. @@ -171,8 +172,7 @@ class OverloadGroup(WithIdentifier):
  870. Returns the effective overload set.
  871. https://heycam.github.io/webidl/#compute-the-effective-overload-set
  872. """
  873. - assert argument_count is None or isinstance(argument_count,
  874. - (int, long))
  875. + assert argument_count is None or isinstance(argument_count, int)
  876. N = argument_count
  877. S = []
  878. @@ -188,21 +188,21 @@ class OverloadGroup(WithIdentifier):
  879. S.append(
  880. OverloadGroup.EffectiveOverloadItem(
  881. - X, map(lambda arg: arg.idl_type, X.arguments),
  882. - map(lambda arg: arg.optionality, X.arguments)))
  883. + X, list(map(lambda arg: arg.idl_type, X.arguments)),
  884. + list(map(lambda arg: arg.optionality, X.arguments))))
  885. if X.is_variadic:
  886. - for i in xrange(n, max(maxarg, N)):
  887. - t = map(lambda arg: arg.idl_type, X.arguments)
  888. - o = map(lambda arg: arg.optionality, X.arguments)
  889. - for _ in xrange(n, i + 1):
  890. + for i in range(n, max(maxarg, N)):
  891. + t = list(map(lambda arg: arg.idl_type, X.arguments))
  892. + o = list(map(lambda arg: arg.optionality, X.arguments))
  893. + for _ in range(n, i + 1):
  894. t.append(X.arguments[-1].idl_type)
  895. o.append(X.arguments[-1].optionality)
  896. S.append(OverloadGroup.EffectiveOverloadItem(X, t, o))
  897. - t = map(lambda arg: arg.idl_type, X.arguments)
  898. - o = map(lambda arg: arg.optionality, X.arguments)
  899. - for i in xrange(n - 1, -1, -1):
  900. + t = list(map(lambda arg: arg.idl_type, X.arguments))
  901. + o = list(map(lambda arg: arg.optionality, X.arguments))
  902. + for i in range(n - 1, -1, -1):
  903. if X.arguments[i].optionality == IdlType.Optionality.REQUIRED:
  904. break
  905. S.append(OverloadGroup.EffectiveOverloadItem(X, t[:i], o[:i]))
  906. @@ -222,7 +222,7 @@ class OverloadGroup(WithIdentifier):
  907. for item in items)
  908. assert len(items) > 1
  909. - for index in xrange(len(items[0].type_list)):
  910. + for index in range(len(items[0].type_list)):
  911. # Assume that the given items are valid, and we only need to test
  912. # the two types.
  913. if OverloadGroup.are_distinguishable_types(
  914. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/idl_compiler.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/idl_compiler.py
  915. index c5ee2bd8a3d..58315072480 100644
  916. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/idl_compiler.py
  917. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/idl_compiler.py
  918. @@ -149,8 +149,8 @@ class IdlCompiler(object):
  919. for old_ir in old_irs:
  920. new_ir = make_copy(old_ir)
  921. self._ir_map.add(new_ir)
  922. - new_ir.attributes = filter(not_disabled, new_ir.attributes)
  923. - new_ir.operations = filter(not_disabled, new_ir.operations)
  924. + new_ir.attributes = list(filter(not_disabled, new_ir.attributes))
  925. + new_ir.operations = list(filter(not_disabled, new_ir.operations))
  926. def _record_defined_in_partial_and_mixin(self):
  927. old_irs = self._ir_map.irs_of_kinds(
  928. @@ -231,7 +231,7 @@ class IdlCompiler(object):
  929. only_to_members_of_partial_or_mixin=False)
  930. propagate_to_exposure(propagate)
  931. - map(process_member_like, ir.iter_all_members())
  932. + list(map(process_member_like, ir.iter_all_members()))
  933. def process_member_like(ir):
  934. propagate = functools.partial(propagate_extattr, ir=ir)
  935. @@ -257,7 +257,7 @@ class IdlCompiler(object):
  936. self._ir_map.move_to_new_phase()
  937. - map(process_interface_like, old_irs)
  938. + list(map(process_interface_like, old_irs))
  939. def _determine_blink_headers(self):
  940. irs = self._ir_map.irs_of_kinds(
  941. @@ -422,9 +422,9 @@ class IdlCompiler(object):
  942. assert not new_interface.deriveds
  943. derived_set = identifier_to_derived_set.get(
  944. new_interface.identifier, set())
  945. - new_interface.deriveds = map(
  946. - lambda id_: self._ref_to_idl_def_factory.create(id_),
  947. - sorted(derived_set))
  948. + new_interface.deriveds = list(
  949. + map(lambda id_: self._ref_to_idl_def_factory.create(id_),
  950. + sorted(derived_set)))
  951. def _supplement_missing_html_constructor_operation(self):
  952. # Temporary mitigation of misuse of [HTMLConstructor]
  953. @@ -553,7 +553,8 @@ class IdlCompiler(object):
  954. self._ir_map.add(new_ir)
  955. for group in new_ir.iter_all_overload_groups():
  956. - exposures = map(lambda overload: overload.exposure, group)
  957. + exposures = list(map(lambda overload: overload.exposure,
  958. + group))
  959. # [Exposed]
  960. if any(not exposure.global_names_and_features
  961. @@ -653,8 +654,8 @@ class IdlCompiler(object):
  962. constructs = set()
  963. for global_name in global_names:
  964. constructs.update(exposed_map.get(global_name, []))
  965. - new_ir.exposed_constructs = map(
  966. - self._ref_to_idl_def_factory.create, sorted(constructs))
  967. + new_ir.exposed_constructs = list(
  968. + map(self._ref_to_idl_def_factory.create, sorted(constructs)))
  969. assert not new_ir.legacy_window_aliases
  970. if new_ir.identifier != 'Window':
  971. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py
  972. index 65d24e529d1..067ef2eb0b2 100644
  973. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py
  974. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/interface.py
  975. @@ -180,8 +180,9 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
  976. self._constructor_groups = tuple([
  977. ConstructorGroup(
  978. group_ir,
  979. - filter(lambda x: x.identifier == group_ir.identifier,
  980. - self._constructors),
  981. + list(
  982. + filter(lambda x: x.identifier == group_ir.identifier,
  983. + self._constructors)),
  984. owner=self) for group_ir in ir.constructor_groups
  985. ])
  986. assert len(self._constructor_groups) <= 1
  987. @@ -192,8 +193,9 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
  988. self._named_constructor_groups = tuple([
  989. ConstructorGroup(
  990. group_ir,
  991. - filter(lambda x: x.identifier == group_ir.identifier,
  992. - self._named_constructors),
  993. + list(
  994. + filter(lambda x: x.identifier == group_ir.identifier,
  995. + self._named_constructors)),
  996. owner=self) for group_ir in ir.named_constructor_groups
  997. ])
  998. self._operations = tuple([
  999. @@ -203,22 +205,23 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
  1000. self._operation_groups = tuple([
  1001. OperationGroup(
  1002. group_ir,
  1003. - filter(lambda x: x.identifier == group_ir.identifier,
  1004. - self._operations),
  1005. + list(
  1006. + filter(lambda x: x.identifier == group_ir.identifier,
  1007. + self._operations)),
  1008. owner=self) for group_ir in ir.operation_groups
  1009. ])
  1010. self._exposed_constructs = tuple(ir.exposed_constructs)
  1011. self._legacy_window_aliases = tuple(ir.legacy_window_aliases)
  1012. self._indexed_and_named_properties = None
  1013. - indexed_and_named_property_operations = filter(
  1014. - lambda x: x.is_indexed_or_named_property_operation,
  1015. - self._operations)
  1016. + indexed_and_named_property_operations = list(
  1017. + filter(lambda x: x.is_indexed_or_named_property_operation,
  1018. + self._operations))
  1019. if indexed_and_named_property_operations:
  1020. self._indexed_and_named_properties = IndexedAndNamedProperties(
  1021. indexed_and_named_property_operations, owner=self)
  1022. self._stringifier = None
  1023. - stringifier_operation_irs = filter(lambda x: x.is_stringifier,
  1024. - ir.operations)
  1025. + stringifier_operation_irs = list(
  1026. + filter(lambda x: x.is_stringifier, ir.operations))
  1027. if stringifier_operation_irs:
  1028. assert len(stringifier_operation_irs) == 1
  1029. op_ir = make_copy(stringifier_operation_irs[0])
  1030. @@ -231,8 +234,9 @@ class Interface(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
  1031. attribute = None
  1032. if operation.stringifier_attribute:
  1033. attr_id = operation.stringifier_attribute
  1034. - attributes = filter(lambda x: x.identifier == attr_id,
  1035. - self._attributes)
  1036. + attributes = list(
  1037. + filter(lambda x: x.identifier == attr_id,
  1038. + self._attributes))
  1039. assert len(attributes) == 1
  1040. attribute = attributes[0]
  1041. self._stringifier = Stringifier(operation, attribute, owner=self)
  1042. @@ -578,8 +582,9 @@ class Iterable(WithDebugInfo):
  1043. self._operation_groups = tuple([
  1044. OperationGroup(
  1045. group_ir,
  1046. - filter(lambda x: x.identifier == group_ir.identifier,
  1047. - self._operations),
  1048. + list(
  1049. + filter(lambda x: x.identifier == group_ir.identifier,
  1050. + self._operations)),
  1051. owner=owner) for group_ir in ir.operation_groups
  1052. ])
  1053. @@ -666,8 +671,9 @@ class Maplike(WithDebugInfo):
  1054. self._operation_groups = tuple([
  1055. OperationGroup(
  1056. group_ir,
  1057. - filter(lambda x: x.identifier == group_ir.identifier,
  1058. - self._operations),
  1059. + list(
  1060. + filter(lambda x: x.identifier == group_ir.identifier,
  1061. + self._operations)),
  1062. owner=owner) for group_ir in ir.operation_groups
  1063. ])
  1064. @@ -755,8 +761,9 @@ class Setlike(WithDebugInfo):
  1065. self._operation_groups = tuple([
  1066. OperationGroup(
  1067. group_ir,
  1068. - filter(lambda x: x.identifier == group_ir.identifier,
  1069. - self._operations),
  1070. + list(
  1071. + filter(lambda x: x.identifier == group_ir.identifier,
  1072. + self._operations)),
  1073. owner=owner) for group_ir in ir.operation_groups
  1074. ])
  1075. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/ir_builder.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/ir_builder.py
  1076. index e9aeff4ab82..d80554d603e 100644
  1077. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/ir_builder.py
  1078. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/ir_builder.py
  1079. @@ -2,6 +2,8 @@
  1080. # Use of this source code is governed by a BSD-style license that can be
  1081. # found in the LICENSE file.
  1082. +import sys
  1083. +
  1084. from .argument import Argument
  1085. from .ast_group import AstGroup
  1086. from .attribute import Attribute
  1087. @@ -30,6 +32,11 @@ from .operation import Operation
  1088. from .typedef import Typedef
  1089. +# TODO: Remove this once Python2 is obsoleted.
  1090. +if sys.version_info.major != 2:
  1091. + long = int
  1092. +
  1093. +
  1094. def load_and_register_idl_definitions(filepaths, register_ir,
  1095. create_ref_to_idl_def, idl_type_factory):
  1096. """
  1097. @@ -160,7 +167,7 @@ class _IRBuilder(object):
  1098. child_nodes = list(node.GetChildren())
  1099. extended_attributes = self._take_extended_attributes(child_nodes)
  1100. - members = map(self._build_interface_member, child_nodes)
  1101. + members = list(map(self._build_interface_member, child_nodes))
  1102. attributes = []
  1103. constants = []
  1104. operations = []
  1105. @@ -302,7 +309,7 @@ class _IRBuilder(object):
  1106. child_nodes = list(node.GetChildren())
  1107. inherited = self._take_inheritance(child_nodes)
  1108. extended_attributes = self._take_extended_attributes(child_nodes)
  1109. - own_members = map(self._build_dictionary_member, child_nodes)
  1110. + own_members = list(map(self._build_dictionary_member, child_nodes))
  1111. return Dictionary.IR(
  1112. identifier=Identifier(node.GetName()),
  1113. @@ -336,7 +343,7 @@ class _IRBuilder(object):
  1114. child_nodes = list(node.GetChildren())
  1115. extended_attributes = self._take_extended_attributes(child_nodes)
  1116. - members = map(self._build_interface_member, child_nodes)
  1117. + members = list(map(self._build_interface_member, child_nodes))
  1118. constants = []
  1119. operations = []
  1120. for member in members:
  1121. @@ -456,8 +463,8 @@ class _IRBuilder(object):
  1122. assert len(child_nodes) == 1
  1123. child = child_nodes[0]
  1124. if child.GetClass() == 'Arguments':
  1125. - arguments = map(build_extattr_argument,
  1126. - child.GetChildren())
  1127. + arguments = list(
  1128. + map(build_extattr_argument, child.GetChildren()))
  1129. elif child.GetClass() == 'Call':
  1130. assert len(child.GetChildren()) == 1
  1131. grand_child = child.GetChildren()[0]
  1132. @@ -486,7 +493,9 @@ class _IRBuilder(object):
  1133. assert node.GetClass() == 'ExtAttributes'
  1134. return ExtendedAttributes(
  1135. - filter(None, map(build_extended_attribute, node.GetChildren())))
  1136. + list(
  1137. + filter(None, map(build_extended_attribute,
  1138. + node.GetChildren()))))
  1139. def _build_inheritance(self, node):
  1140. assert node.GetClass() == 'Inherit'
  1141. @@ -506,7 +515,7 @@ class _IRBuilder(object):
  1142. def _build_iterable(self, node):
  1143. assert node.GetClass() == 'Iterable'
  1144. - types = map(self._build_type, node.GetChildren())
  1145. + types = list(map(self._build_type, node.GetChildren()))
  1146. assert len(types) == 1 or len(types) == 2
  1147. if len(types) == 1: # value iterator
  1148. key_type, value_type = (None, types[0])
  1149. @@ -584,7 +593,7 @@ class _IRBuilder(object):
  1150. def _build_maplike(self, node, interface_identifier):
  1151. assert node.GetClass() == 'Maplike'
  1152. assert isinstance(interface_identifier, Identifier)
  1153. - types = map(self._build_type, node.GetChildren())
  1154. + types = list(map(self._build_type, node.GetChildren()))
  1155. assert len(types) == 2
  1156. key_type, value_type = types
  1157. is_readonly = bool(node.GetProperty('READONLY'))
  1158. @@ -676,7 +685,7 @@ class _IRBuilder(object):
  1159. def _build_setlike(self, node, interface_identifier):
  1160. assert node.GetClass() == 'Setlike'
  1161. assert isinstance(interface_identifier, Identifier)
  1162. - types = map(self._build_type, node.GetChildren())
  1163. + types = list(map(self._build_type, node.GetChildren()))
  1164. assert len(types) == 1
  1165. value_type = types[0]
  1166. is_readonly = bool(node.GetProperty('READONLY'))
  1167. @@ -838,7 +847,7 @@ class _IRBuilder(object):
  1168. def build_union_type(node, extended_attributes):
  1169. return self._idl_type_factory.union_type(
  1170. - member_types=map(self._build_type, node.GetChildren()),
  1171. + member_types=list(map(self._build_type, node.GetChildren())),
  1172. is_optional=is_optional,
  1173. extended_attributes=extended_attributes,
  1174. debug_info=self._build_debug_info(node))
  1175. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/make_copy.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/make_copy.py
  1176. index a7a2b11f3f0..2f6b61300ff 100644
  1177. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/make_copy.py
  1178. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/make_copy.py
  1179. @@ -3,6 +3,13 @@
  1180. # found in the LICENSE file.
  1181. +import sys
  1182. +
  1183. +# TODO: Remove this once Python2 is obsoleted.
  1184. +if sys.version_info.major != 2:
  1185. + long = int
  1186. + basestring = str
  1187. +
  1188. def make_copy(obj, memo=None):
  1189. """
  1190. Creates a copy of the given object, which should be an IR or part of IR.
  1191. diff --git a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/namespace.py b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/namespace.py
  1192. index eeabef97cbe..bd7e98907f3 100644
  1193. --- a/chromium/third_party/blink/renderer/bindings/scripts/web_idl/namespace.py
  1194. +++ b/chromium/third_party/blink/renderer/bindings/scripts/web_idl/namespace.py
  1195. @@ -107,11 +107,13 @@ class Namespace(UserDefinedType, WithExtendedAttributes, WithCodeGeneratorInfo,
  1196. for operation_ir in ir.operations
  1197. ])
  1198. self._operation_groups = tuple([
  1199. - OperationGroup(
  1200. - operation_group_ir,
  1201. - filter(lambda x: x.identifier == operation_group_ir.identifier,
  1202. - self._operations),
  1203. - owner=self) for operation_group_ir in ir.operation_groups
  1204. + OperationGroup(operation_group_ir,
  1205. + list(
  1206. + filter(
  1207. + lambda x: x.identifier == operation_group_ir
  1208. + .identifier, self._operations)),
  1209. + owner=self)
  1210. + for operation_group_ir in ir.operation_groups
  1211. ])
  1212. @property
  1213. diff --git a/chromium/third_party/blink/renderer/bindings/templates/dictionary_v8.cc.tmpl b/chromium/third_party/blink/renderer/bindings/templates/dictionary_v8.cc.tmpl
  1214. index 0add9c45a38..dc910f6d227 100644
  1215. --- a/chromium/third_party/blink/renderer/bindings/templates/dictionary_v8.cc.tmpl
  1216. +++ b/chromium/third_party/blink/renderer/bindings/templates/dictionary_v8.cc.tmpl
  1217. @@ -59,9 +59,9 @@ void {{v8_class}}::ToImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8_value, {
  1218. DCHECK(executionContext);
  1219. {% endif %}{# has_origin_trial_members #}
  1220. {% endif %}{# members #}
  1221. - {% for origin_trial_test, origin_trial_member_list in members | groupby('origin_trial_feature_name') %}
  1222. + {% for origin_trial_test, origin_trial_member_list in members | stringifykeygroupby('origin_trial_feature_name') %}
  1223. {% filter origin_trial_enabled(origin_trial_test, "executionContext") %}
  1224. - {% for feature_name, member_list in origin_trial_member_list | groupby('runtime_enabled_feature_name') %}
  1225. + {% for feature_name, member_list in origin_trial_member_list | stringifykeygroupby('runtime_enabled_feature_name') %}
  1226. {% filter runtime_enabled(feature_name) %}
  1227. {% for member in member_list %}
  1228. v8::Local<v8::Value> {{member.v8_value}};
  1229. @@ -147,9 +147,9 @@ bool toV8{{cpp_class}}(const {{cpp_class}}* impl, v8::Local<v8::Object> dictiona
  1230. DCHECK(executionContext);
  1231. {% endif %}{# has_origin_trial_members #}
  1232. {% endif %}{# members #}
  1233. - {% for origin_trial_test, origin_trial_member_list in members | groupby('origin_trial_feature_name') %}
  1234. + {% for origin_trial_test, origin_trial_member_list in members | stringifykeygroupby('origin_trial_feature_name') %}
  1235. {% filter origin_trial_enabled(origin_trial_test, "executionContext") %}
  1236. - {% for feature_name, member_list in origin_trial_member_list | groupby('runtime_enabled_feature_name') %}
  1237. + {% for feature_name, member_list in origin_trial_member_list | stringifykeygroupby('runtime_enabled_feature_name') %}
  1238. {% filter runtime_enabled(feature_name) %}
  1239. {% for member in member_list %}
  1240. v8::Local<v8::Value> {{member.v8_value}};
  1241. diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py b/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py
  1242. index 1799cd5a153..5f43ffabc26 100755
  1243. --- a/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py
  1244. +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/make_style_shorthands.py
  1245. @@ -71,7 +71,7 @@ class Expansion(object):
  1246. def enabled_longhands(self):
  1247. include = lambda longhand: not longhand[
  1248. 'runtime_flag'] or self.is_enabled(longhand['runtime_flag'])
  1249. - return filter(include, self._longhands)
  1250. + return list(filter(include, self._longhands))
  1251. @property
  1252. def index(self):
  1253. @@ -87,8 +87,9 @@ class Expansion(object):
  1254. def create_expansions(longhands):
  1255. flags = collect_runtime_flags(longhands)
  1256. - expansions = map(lambda mask: Expansion(longhands, flags, mask),
  1257. - range(1 << len(flags)))
  1258. + expansions = list(
  1259. + map(lambda mask: Expansion(longhands, flags, mask),
  1260. + range(1 << len(flags))))
  1261. assert len(expansions) > 0
  1262. # We generate 2^N expansions for N flags, so enforce some limit.
  1263. assert len(flags) <= 4, 'Too many runtime flags for a single shorthand'
  1264. @@ -114,14 +115,14 @@ class StylePropertyShorthandWriter(json5_generator.Writer):
  1265. self._longhand_dictionary = defaultdict(list)
  1266. for property_ in json5_properties.shorthands:
  1267. - property_['longhand_enum_keys'] = map(enum_key_for_css_property,
  1268. - property_['longhands'])
  1269. - property_['longhand_property_ids'] = map(id_for_css_property,
  1270. - property_['longhands'])
  1271. -
  1272. - longhands = map(
  1273. - lambda name: json5_properties.properties_by_name[name],
  1274. - property_['longhands'])
  1275. + property_['longhand_enum_keys'] = list(
  1276. + map(enum_key_for_css_property, property_['longhands']))
  1277. + property_['longhand_property_ids'] = list(
  1278. + map(id_for_css_property, property_['longhands']))
  1279. +
  1280. + longhands = list(
  1281. + map(lambda name: json5_properties.properties_by_name[name],
  1282. + property_['longhands']))
  1283. property_['expansions'] = create_expansions(longhands)
  1284. for longhand_enum_key in property_['longhand_enum_keys']:
  1285. self._longhand_dictionary[longhand_enum_key].append(property_)
  1286. diff --git a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_instances.py b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_instances.py
  1287. index 75030ac577e..f72aadee17d 100755
  1288. --- a/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_instances.py
  1289. +++ b/chromium/third_party/blink/renderer/build/scripts/core/css/properties/make_css_property_instances.py
  1290. @@ -42,8 +42,8 @@ class CSSPropertyInstancesWriter(json5_generator.Writer):
  1291. aliases = self._css_properties.aliases
  1292. # Lists of PropertyClassData.
  1293. - self._property_classes_by_id = map(self.get_class, properties)
  1294. - self._alias_classes_by_id = map(self.get_class, aliases)
  1295. + self._property_classes_by_id = list(map(self.get_class, properties))
  1296. + self._alias_classes_by_id = list(map(self.get_class, aliases))
  1297. # Sort by enum value.
  1298. self._property_classes_by_id.sort(key=lambda t: t.enum_value)
  1299. diff --git a/chromium/third_party/blink/renderer/build/scripts/gperf.py b/chromium/third_party/blink/renderer/build/scripts/gperf.py
  1300. index 5ee49056be4..db72660d471 100644
  1301. --- a/chromium/third_party/blink/renderer/build/scripts/gperf.py
  1302. +++ b/chromium/third_party/blink/renderer/build/scripts/gperf.py
  1303. @@ -95,7 +95,7 @@ def main():
  1304. open(args.output_file, 'wb').write(
  1305. generate_gperf(gperf_path,
  1306. - open(infile).read(), gperf_args))
  1307. + open(infile).read(), gperf_args).encode('utf-8'))
  1308. if __name__ == '__main__':
  1309. diff --git a/chromium/third_party/blink/renderer/build/scripts/in_file.py b/chromium/third_party/blink/renderer/build/scripts/in_file.py
  1310. index 28adc050f1e..58113483e57 100644
  1311. --- a/chromium/third_party/blink/renderer/build/scripts/in_file.py
  1312. +++ b/chromium/third_party/blink/renderer/build/scripts/in_file.py
  1313. @@ -66,7 +66,7 @@ class InFile(object):
  1314. self._defaults = defaults
  1315. self._valid_values = copy.deepcopy(
  1316. valid_values if valid_values else {})
  1317. - self._parse(map(str.strip, lines))
  1318. + self._parse(list(map(str.strip, lines)))
  1319. @classmethod
  1320. def load_from_files(self, file_paths, defaults, valid_values,
  1321. diff --git a/chromium/third_party/blink/renderer/build/scripts/in_generator.py b/chromium/third_party/blink/renderer/build/scripts/in_generator.py
  1322. index e46740a2e85..ab1981ad1e3 100644
  1323. --- a/chromium/third_party/blink/renderer/build/scripts/in_generator.py
  1324. +++ b/chromium/third_party/blink/renderer/build/scripts/in_generator.py
  1325. @@ -32,10 +32,15 @@ import os
  1326. import os.path
  1327. import shlex
  1328. import shutil
  1329. +import sys
  1330. import optparse
  1331. from in_file import InFile
  1332. +# TODO: Remove this once Python2 is obsoleted.
  1333. +if sys.version_info.major != 2:
  1334. + basestring = str
  1335. +
  1336. #########################################################
  1337. # This is now deprecated - use json5_generator.py instead
  1338. diff --git a/chromium/third_party/blink/renderer/build/scripts/make_runtime_features.py b/chromium/third_party/blink/renderer/build/scripts/make_runtime_features.py
  1339. index cafe8d94a8e..6925a4fa580 100755
  1340. --- a/chromium/third_party/blink/renderer/build/scripts/make_runtime_features.py
  1341. +++ b/chromium/third_party/blink/renderer/build/scripts/make_runtime_features.py
  1342. @@ -138,7 +138,7 @@ class RuntimeFeatureWriter(BaseRuntimeFeatureWriter):
  1343. except Exception:
  1344. # If trouble unpickling, overwrite
  1345. pass
  1346. - with open(os.path.abspath(file_name), 'w') as pickle_file:
  1347. + with open(os.path.abspath(file_name), 'wb') as pickle_file:
  1348. pickle.dump(features_map, pickle_file)
  1349. def _template_inputs(self):
  1350. diff --git a/chromium/third_party/blink/renderer/build/scripts/templates/element_factory.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/templates/element_factory.cc.tmpl
  1351. index dc3f44c5b10..3eefcf9f0ee 100644
  1352. --- a/chromium/third_party/blink/renderer/build/scripts/templates/element_factory.cc.tmpl
  1353. +++ b/chromium/third_party/blink/renderer/build/scripts/templates/element_factory.cc.tmpl
  1354. @@ -26,7 +26,7 @@ using {{namespace}}FunctionMap = HashMap<AtomicString, {{namespace}}ConstructorF
  1355. static {{namespace}}FunctionMap* g_{{namespace|lower}}_constructors = nullptr;
  1356. -{% for tag in tags|sort if not tag.noConstructor %}
  1357. +{% for tag in tags|sort(attribute='name') if not tag.noConstructor %}
  1358. static {{namespace}}Element* {{namespace}}{{tag.name.to_upper_camel_case()}}Constructor(
  1359. Document& document, const CreateElementFlags flags) {
  1360. {% if tag.runtimeEnabled %}
  1361. @@ -52,7 +52,7 @@ static void Create{{namespace}}FunctionMap() {
  1362. // Empty array initializer lists are illegal [dcl.init.aggr] and will not
  1363. // compile in MSVC. If tags list is empty, add check to skip this.
  1364. static const Create{{namespace}}FunctionMapData data[] = {
  1365. - {% for tag in tags|sort if not tag.noConstructor %}
  1366. + {% for tag in tags|sort(attribute='name') if not tag.noConstructor %}
  1367. { {{cpp_namespace}}::{{tag|symbol}}Tag, {{namespace}}{{tag.name.to_upper_camel_case()}}Constructor },
  1368. {% endfor %}
  1369. };
  1370. diff --git a/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.cc.tmpl b/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.cc.tmpl
  1371. index 9bfc489e048..5f86184e879 100644
  1372. --- a/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.cc.tmpl
  1373. +++ b/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.cc.tmpl
  1374. @@ -22,7 +22,7 @@ HTMLTypeMap CreateHTMLTypeMap() {
  1375. const char* name;
  1376. HTMLElementType type;
  1377. } kTags[] = {
  1378. - {% for tag in tags|sort %}
  1379. + {% for tag in tags|sort(attribute='name') %}
  1380. { "{{tag.name}}", HTMLElementType::k{{tag.js_interface}} },
  1381. {% endfor %}
  1382. };
  1383. @@ -42,7 +42,7 @@ HTMLElementType htmlElementTypeForTag(const AtomicString& tagName, const Documen
  1384. if (it == html_type_map.end())
  1385. return HTMLElementType::kHTMLUnknownElement;
  1386. - {% for tag in tags|sort %}
  1387. + {% for tag in tags|sort(attribute='name') %}
  1388. {% if tag.runtimeEnabled %}
  1389. if (tagName == "{{tag.name}}") {
  1390. if (!RuntimeEnabledFeatures::{{tag.runtimeEnabled}}Enabled(document->GetExecutionContext())) {
  1391. diff --git a/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.h.tmpl
  1392. index 1b5297d52dc..edecc81d9d4 100644
  1393. --- a/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.h.tmpl
  1394. +++ b/chromium/third_party/blink/renderer/build/scripts/templates/element_type_helpers.h.tmpl
  1395. @@ -15,7 +15,7 @@ namespace blink {
  1396. class Document;
  1397. // Type checking.
  1398. -{% for tag in tags|sort if not tag.multipleTagNames and not tag.noTypeHelpers %}
  1399. +{% for tag in tags|sort(attribute='name') if not tag.multipleTagNames and not tag.noTypeHelpers %}
  1400. class {{tag.interface}};
  1401. template <>
  1402. inline bool IsElementOfType<const {{tag.interface}}>(const Node& node) {
  1403. diff --git a/chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl b/chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl
  1404. index 0244433af2e..dcdbb02a56c 100644
  1405. --- a/chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl
  1406. +++ b/chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl
  1407. @@ -25,7 +25,7 @@
  1408. {% macro trie_leaf(index, object, return_macro, lowercase_data) %}
  1409. -{% set name, value = object.items()[0] %}
  1410. +{% set name, value = (object.items()|list)[0] %}
  1411. {% if name|length %}
  1412. if (
  1413. {%- for c in name -%}
  1414. @@ -45,7 +45,7 @@ return {{ return_macro(value) }};
  1415. {% macro trie_switch(trie, index, return_macro, lowercase_data) %}
  1416. -{% if trie|length == 1 and trie.values()[0] is string %}
  1417. +{% if trie|length == 1 and (trie.values()|list)[0] is string %}
  1418. {{ trie_leaf(index, trie, return_macro, lowercase_data) -}}
  1419. {% else %}
  1420. {% if lowercase_data %}
  1421. diff --git a/chromium/third_party/blink/renderer/build/scripts/templates/make_qualified_names.h.tmpl b/chromium/third_party/blink/renderer/build/scripts/templates/make_qualified_names.h.tmpl
  1422. index cb05c6c4315..bd5566b03e7 100644
  1423. --- a/chromium/third_party/blink/renderer/build/scripts/templates/make_qualified_names.h.tmpl
  1424. +++ b/chromium/third_party/blink/renderer/build/scripts/templates/make_qualified_names.h.tmpl
  1425. @@ -24,12 +24,12 @@ namespace {{cpp_namespace}} {
  1426. {{symbol_export}}extern const WTF::AtomicString& {{namespace_prefix}}NamespaceURI;
  1427. // Tags
  1428. -{% for tag in tags|sort %}
  1429. +{% for tag in tags|sort(attribute='name') %}
  1430. {{symbol_export}}extern const blink::{{namespace}}QualifiedName& {{tag|symbol}}Tag;
  1431. {% endfor %}
  1432. // Attributes
  1433. -{% for attr in attrs|sort %}
  1434. +{% for attr in attrs|sort(attribute='name') %}
  1435. {{symbol_export}}extern const blink::QualifiedName& {{attr|symbol}}Attr;
  1436. {% endfor %}
  1437. diff --git a/chromium/third_party/dawn/generator/generator_lib.py b/chromium/third_party/dawn/generator/generator_lib.py
  1438. index 5e3734d7833..e3d46bd194f 100644
  1439. --- a/chromium/third_party/dawn/generator/generator_lib.py
  1440. +++ b/chromium/third_party/dawn/generator/generator_lib.py
  1441. @@ -201,6 +201,10 @@ def _compute_python_dependencies(root_dir=None):
  1442. paths = set()
  1443. for path in module_paths:
  1444. + # Builtin/namespaced modules may return None for the file path.
  1445. + if not path:
  1446. + continue
  1447. +
  1448. path = os.path.abspath(path)
  1449. if not path.startswith(root_dir):
  1450. diff --git a/chromium/third_party/devtools-frontend/src/BUILD.gn b/chromium/third_party/devtools-frontend/src/BUILD.gn
  1451. index cd488e88b60..ea1dc3d9a79 100644
  1452. --- a/chromium/third_party/devtools-frontend/src/BUILD.gn
  1453. +++ b/chromium/third_party/devtools-frontend/src/BUILD.gn
  1454. @@ -2,6 +2,8 @@
  1455. # Use of this source code is governed by a BSD-style license that can be
  1456. # found in the LICENSE file.
  1457. +import("//build/config/python.gni")
  1458. +
  1459. import("//third_party/blink/public/public_features.gni")
  1460. import("./all_devtools_files.gni")
  1461. import("./all_devtools_modules.gni")
  1462. diff --git a/chromium/third_party/devtools-frontend/src/scripts/build/build_inspector_overlay.py b/chromium/third_party/devtools-frontend/src/scripts/build/build_inspector_overlay.py
  1463. index d6666e8b74f..0f7a661e632 100644
  1464. --- a/chromium/third_party/devtools-frontend/src/scripts/build/build_inspector_overlay.py
  1465. +++ b/chromium/third_party/devtools-frontend/src/scripts/build/build_inspector_overlay.py
  1466. @@ -45,7 +45,8 @@ def rollup(input_path, output_path, filename, max_size, rollup_plugin):
  1467. ['--format', 'iife', '-n', 'InspectorOverlay'] + ['--input', target] +
  1468. ['--plugin', rollup_plugin],
  1469. stdout=subprocess.PIPE,
  1470. - stderr=subprocess.PIPE)
  1471. + stderr=subprocess.PIPE,
  1472. + text=True)
  1473. out, error = rollup_process.communicate()
  1474. if not out:
  1475. raise Exception("rollup failed: " + error)
  1476. diff --git a/chromium/third_party/devtools-frontend/src/scripts/build/build_release_applications.py b/chromium/third_party/devtools-frontend/src/scripts/build/build_release_applications.py
  1477. index fa8e73d34af..7d0b84b2171 100644
  1478. --- a/chromium/third_party/devtools-frontend/src/scripts/build/build_release_applications.py
  1479. +++ b/chromium/third_party/devtools-frontend/src/scripts/build/build_release_applications.py
  1480. @@ -10,7 +10,7 @@ Builds applications in release mode:
  1481. and the application loader into a single script.
  1482. """
  1483. -from cStringIO import StringIO
  1484. +from io import StringIO
  1485. from os import path
  1486. from os.path import join
  1487. import copy
  1488. @@ -145,8 +145,7 @@ class ReleaseBuilder(object):
  1489. resource_content = read_file(path.join(self.application_dir, resource_name))
  1490. if not (resource_name.endswith('.html')
  1491. or resource_name.endswith('md')):
  1492. - resource_content += resource_source_url(resource_name).encode(
  1493. - 'utf-8')
  1494. + resource_content += resource_source_url(resource_name)
  1495. resource_content = resource_content.replace('\\', '\\\\')
  1496. resource_content = resource_content.replace('\n', '\\n')
  1497. resource_content = resource_content.replace('"', '\\"')
  1498. @@ -173,7 +172,9 @@ class ReleaseBuilder(object):
  1499. def _concatenate_application_script(self, output):
  1500. output.write('Root.allDescriptors.push(...%s);' % self._release_module_descriptors())
  1501. if self.descriptors.extends:
  1502. - output.write('Root.applicationDescriptor.modules.push(...%s);' % json.dumps(self.descriptors.application.values()))
  1503. + output.write(
  1504. + 'Root.applicationDescriptor.modules.push(...%s);' %
  1505. + json.dumps(list(self.descriptors.application.values())))
  1506. else:
  1507. output.write('Root.applicationDescriptor = %s;' % self.descriptors.application_json())
  1508. diff --git a/chromium/third_party/devtools-frontend/src/scripts/build/generate_devtools_grd.py b/chromium/third_party/devtools-frontend/src/scripts/build/generate_devtools_grd.py
  1509. index be510c48d76..c6a59c90298 100644
  1510. --- a/chromium/third_party/devtools-frontend/src/scripts/build/generate_devtools_grd.py
  1511. +++ b/chromium/third_party/devtools-frontend/src/scripts/build/generate_devtools_grd.py
  1512. @@ -123,7 +123,7 @@ def main(argv):
  1513. try:
  1514. os.makedirs(path.join(output_directory, 'Images'))
  1515. - except OSError, e:
  1516. + except OSError as e:
  1517. if e.errno != errno.EEXIST:
  1518. raise e
  1519. @@ -147,7 +147,7 @@ def main(argv):
  1520. shutil.copy(path.join(dirname, filename), path.join(output_directory, 'Images'))
  1521. add_file_to_grd(doc, path.join('Images', filename))
  1522. - with open(parsed_args.output_filename, 'w') as output_file:
  1523. + with open(parsed_args.output_filename, 'wb') as output_file:
  1524. output_file.write(doc.toxml(encoding='UTF-8'))
  1525. diff --git a/chromium/third_party/devtools-frontend/src/scripts/build/modular_build.py b/chromium/third_party/devtools-frontend/src/scripts/build/modular_build.py
  1526. index 0ba695d3810..bb1da2f9f8d 100644
  1527. --- a/chromium/third_party/devtools-frontend/src/scripts/build/modular_build.py
  1528. +++ b/chromium/third_party/devtools-frontend/src/scripts/build/modular_build.py
  1529. @@ -7,6 +7,8 @@
  1530. Utilities for the modular DevTools build.
  1531. """
  1532. +from __future__ import print_function
  1533. +
  1534. import collections
  1535. from os import path
  1536. import os
  1537. @@ -40,7 +42,7 @@ def load_and_parse_json(filename):
  1538. try:
  1539. return json.loads(read_file(filename))
  1540. except:
  1541. - print 'ERROR: Failed to parse %s' % filename
  1542. + print('ERROR: Failed to parse %s' % filename)
  1543. raise
  1544. class Descriptors:
  1545. @@ -57,7 +59,7 @@ class Descriptors:
  1546. def application_json(self):
  1547. result = dict()
  1548. - result['modules'] = self.application.values()
  1549. + result['modules'] = list(self.application.values())
  1550. return json.dumps(result)
  1551. def all_compiled_files(self):
  1552. diff --git a/chromium/third_party/jinja2/tests.py b/chromium/third_party/jinja2/tests.py
  1553. index 0adc3d4dbcb..b14f85ff148 100644
  1554. --- a/chromium/third_party/jinja2/tests.py
  1555. +++ b/chromium/third_party/jinja2/tests.py
  1556. @@ -10,7 +10,7 @@
  1557. """
  1558. import operator
  1559. import re
  1560. -from collections import Mapping
  1561. +from collections.abc import Mapping
  1562. from jinja2.runtime import Undefined
  1563. from jinja2._compat import text_type, string_types, integer_types
  1564. import decimal
  1565. diff --git a/chromium/tools/metrics/ukm/gen_builders.py b/chromium/tools/metrics/ukm/gen_builders.py
  1566. index f9f61d90a56..44e46fae8cc 100755
  1567. --- a/chromium/tools/metrics/ukm/gen_builders.py
  1568. +++ b/chromium/tools/metrics/ukm/gen_builders.py
  1569. @@ -48,9 +48,10 @@ def ReadFilteredData(path):
  1570. data = ukm_model.UKM_XML_TYPE.Parse(ukm_file.read())
  1571. event_tag = ukm_model._EVENT_TYPE.tag
  1572. metric_tag = ukm_model._METRIC_TYPE.tag
  1573. - data[event_tag] = filter(ukm_model.IsNotObsolete, data[event_tag])
  1574. + data[event_tag] = list(filter(ukm_model.IsNotObsolete, data[event_tag]))
  1575. for event in data[event_tag]:
  1576. - event[metric_tag] = filter(ukm_model.IsNotObsolete, event[metric_tag])
  1577. + event[metric_tag] = list(
  1578. + filter(ukm_model.IsNotObsolete, event[metric_tag]))
  1579. return data
  1580. diff --git a/chromium/ui/ozone/generate_constructor_list.py b/chromium/ui/ozone/generate_constructor_list.py
  1581. index 8d800636c97..04fa18e93df 100755
  1582. --- a/chromium/ui/ozone/generate_constructor_list.py
  1583. +++ b/chromium/ui/ozone/generate_constructor_list.py
  1584. @@ -45,12 +45,15 @@ Example Output: ./ui/ozone/generate_constructor_list.py \
  1585. } // namespace ui
  1586. """
  1587. +try:
  1588. + from StringIO import StringIO # for Python 2
  1589. +except ImportError:
  1590. + from io import StringIO # for Python 3
  1591. import optparse
  1592. import os
  1593. import collections
  1594. import re
  1595. import sys
  1596. -import string
  1597. def GetTypedefName(typename):
  1598. @@ -68,7 +71,7 @@ def GetConstructorName(typename, platform):
  1599. This is just "Create" + typename + platform.
  1600. """
  1601. - return 'Create' + typename + string.capitalize(platform)
  1602. + return 'Create' + typename + platform.capitalize()
  1603. def GenerateConstructorList(out, namespace, export, typenames, platforms,
  1604. @@ -163,12 +166,14 @@ def main(argv):
  1605. sys.exit(1)
  1606. # Write to standard output or file specified by --output_cc.
  1607. - out_cc = sys.stdout
  1608. + out_cc = getattr(sys.stdout, 'buffer', sys.stdout)
  1609. if options.output_cc:
  1610. out_cc = open(options.output_cc, 'wb')
  1611. - GenerateConstructorList(out_cc, options.namespace, options.export,
  1612. + out_cc_str = StringIO()
  1613. + GenerateConstructorList(out_cc_str, options.namespace, options.export,
  1614. typenames, platforms, includes, usings)
  1615. + out_cc.write(out_cc_str.getvalue().encode('utf-8'))
  1616. if options.output_cc:
  1617. out_cc.close()
  1618. diff --git a/chromium/ui/ozone/generate_ozone_platform_list.py b/chromium/ui/ozone/generate_ozone_platform_list.py
  1619. index d47c398259b..2702b68b9bd 100755
  1620. --- a/chromium/ui/ozone/generate_ozone_platform_list.py
  1621. +++ b/chromium/ui/ozone/generate_ozone_platform_list.py
  1622. @@ -49,12 +49,15 @@ Example Output: ./generate_ozone_platform_list.py --default wayland dri wayland
  1623. """
  1624. +try:
  1625. + from StringIO import StringIO # for Python 2
  1626. +except ImportError:
  1627. + from io import StringIO # for Python 3
  1628. import optparse
  1629. import os
  1630. import collections
  1631. import re
  1632. import sys
  1633. -import string
  1634. def GetConstantName(name):
  1635. @@ -63,7 +66,7 @@ def GetConstantName(name):
  1636. We just capitalize the platform name and prepend "CreateOzonePlatform".
  1637. """
  1638. - return 'kPlatform' + string.capitalize(name)
  1639. + return 'kPlatform' + name.capitalize()
  1640. def GeneratePlatformListText(out, platforms):
  1641. @@ -149,9 +152,9 @@ def main(argv):
  1642. platforms.insert(0, options.default)
  1643. # Write to standard output or file specified by --output_{cc,h}.
  1644. - out_cc = sys.stdout
  1645. - out_h = sys.stdout
  1646. - out_txt = sys.stdout
  1647. + out_cc = getattr(sys.stdout, 'buffer', sys.stdout)
  1648. + out_h = getattr(sys.stdout, 'buffer', sys.stdout)
  1649. + out_txt = getattr(sys.stdout, 'buffer', sys.stdout)
  1650. if options.output_cc:
  1651. out_cc = open(options.output_cc, 'wb')
  1652. if options.output_h:
  1653. @@ -159,9 +162,16 @@ def main(argv):
  1654. if options.output_txt:
  1655. out_txt = open(options.output_txt, 'wb')
  1656. - GeneratePlatformListText(out_txt, platforms)
  1657. - GeneratePlatformListHeader(out_h, platforms)
  1658. - GeneratePlatformListSource(out_cc, platforms)
  1659. + out_txt_str = StringIO()
  1660. + out_h_str = StringIO()
  1661. + out_cc_str = StringIO()
  1662. +
  1663. + GeneratePlatformListText(out_txt_str, platforms)
  1664. + out_txt.write(out_txt_str.getvalue().encode('utf-8'))
  1665. + GeneratePlatformListHeader(out_h_str, platforms)
  1666. + out_h.write(out_h_str.getvalue().encode('utf-8'))
  1667. + GeneratePlatformListSource(out_cc_str, platforms)
  1668. + out_cc.write(out_cc_str.getvalue().encode('utf-8'))
  1669. if options.output_cc:
  1670. out_cc.close()
  1671. --
  1672. 2.25.1