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

Side by Side Diff: mojo/public/tools/bindings/mojom_bindings_generator.py

Issue 285413003: Mojo: Remove dangerous default argument in mojom_bindings_generatory.py: ProcessFile(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """The frontend for the Mojo bindings system.""" 6 """The frontend for the Mojo bindings system."""
7 7
8 8
9 import argparse 9 import argparse
10 import imp 10 import imp
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 67
68 def MakeImportStackMessage(imported_filename_stack): 68 def MakeImportStackMessage(imported_filename_stack):
69 """Make a (human-readable) message listing a chain of imports. (Returned 69 """Make a (human-readable) message listing a chain of imports. (Returned
70 string begins with a newline (if nonempty) and does not end with one.)""" 70 string begins with a newline (if nonempty) and does not end with one.)"""
71 return ''.join( 71 return ''.join(
72 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \ 72 reversed(["\n %s was imported by %s" % (a, b) for (a, b) in \
73 zip(imported_filename_stack[1:], imported_filename_stack)])) 73 zip(imported_filename_stack[1:], imported_filename_stack)]))
74 74
75 75
76 # Disable Check for dangerous default arguments (they're "private" keyword 76 # Disable check for dangerous default arguments (they're "private" keyword
77 # arguments): 77 # arguments; note that we want |_processed_files| to memoize across invocations
78 # of |ProcessFile()|):
78 # pylint: disable=W0102 79 # pylint: disable=W0102
79 def ProcessFile(args, remaining_args, generator_modules, filename, 80 def ProcessFile(args, remaining_args, generator_modules, filename,
80 _processed_files={}, _imported_filename_stack=[]): 81 _processed_files={}, _imported_filename_stack=None):
81 # Memoized results. 82 # Memoized results.
82 if filename in _processed_files: 83 if filename in _processed_files:
83 return _processed_files[filename] 84 return _processed_files[filename]
84 85
86 if _imported_filename_stack is None:
87 _imported_filename_stack = []
88
85 # Ensure we only visit each file once. 89 # Ensure we only visit each file once.
86 if filename in _imported_filename_stack: 90 if filename in _imported_filename_stack:
87 print "%s: Error: Circular dependency" % filename + \ 91 print "%s: Error: Circular dependency" % filename + \
88 MakeImportStackMessage(_imported_filename_stack + [filename]) 92 MakeImportStackMessage(_imported_filename_stack + [filename])
89 sys.exit(1) 93 sys.exit(1)
90 94
91 try: 95 try:
92 with open(filename) as f: 96 with open(filename) as f:
93 source = f.read() 97 source = f.read()
94 except IOError as e: 98 except IOError as e:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 os.makedirs(args.output_dir) 167 os.makedirs(args.output_dir)
164 168
165 for filename in args.filename: 169 for filename in args.filename:
166 ProcessFile(args, remaining_args, generator_modules, filename) 170 ProcessFile(args, remaining_args, generator_modules, filename)
167 171
168 return 0 172 return 0
169 173
170 174
171 if __name__ == "__main__": 175 if __name__ == "__main__":
172 sys.exit(main()) 176 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698