Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(5)

Side by Side Diff: Tools/scripts/findnocoding.py

Issue 26581: Double coding cookie
Patch Set: Created 4 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Parser/tokenizer.c ('k') | 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 python3 1 #!/usr/bin/env python3
2 2
3 """List all those Python files that require a coding directive 3 """List all those Python files that require a coding directive
4 4
5 Usage: findnocoding.py dir1 [dir2...] 5 Usage: findnocoding.py dir1 [dir2...]
6 """ 6 """
7 7
8 __author__ = "Oleg Broytmann, Georg Brandl" 8 __author__ = "Oleg Broytmann, Georg Brandl"
9 9
10 import sys, os, re, getopt 10 import sys, os, re, getopt
(...skipping 14 matching lines...) Expand all
25 for filename in files: 25 for filename in files:
26 if filename.endswith(".py"): 26 if filename.endswith(".py"):
27 yield os.path.join(root, filename) 27 yield os.path.join(root, filename)
28 pysource = pysource() 28 pysource = pysource()
29 29
30 30
31 print("The pysource module is not available; " 31 print("The pysource module is not available; "
32 "no sophisticated Python source file search will be don e.", file=sys.stderr) 32 "no sophisticated Python source file search will be don e.", file=sys.stderr)
33 33
34 34
35 decl_re = re.compile(rb'^[ \t\f]*#.*coding[:=][ \t]*([-\w.]+)') 35 decl_re = re.compile(rb'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)')
36 blank_re = re.compile(rb'^[ \t\f]*(?:[#\r\n]|$)') 36 blank_re = re.compile(rb'^[ \t\f]*(?:[#\r\n]|$)')
37 37
38 def get_declaration(line): 38 def get_declaration(line):
39 match = decl_re.match(line) 39 match = decl_re.match(line)
40 if match: 40 if match:
41 return match.group(1) 41 return match.group(1)
42 return b'' 42 return b''
43 43
44 def has_correct_encoding(text, codec): 44 def has_correct_encoding(text, codec):
45 try: 45 try:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if not args: 98 if not args:
99 print(usage, file=sys.stderr) 99 print(usage, file=sys.stderr)
100 sys.exit(1) 100 sys.exit(1)
101 101
102 for fullpath in pysource.walk_python_files(args, is_python): 102 for fullpath in pysource.walk_python_files(args, is_python):
103 if debug: 103 if debug:
104 print("Testing for coding: %s" % fullpath) 104 print("Testing for coding: %s" % fullpath)
105 result = needs_declaration(fullpath) 105 result = needs_declaration(fullpath)
106 if result: 106 if result:
107 print(fullpath) 107 print(fullpath)
OLDNEW
« no previous file with comments | « Parser/tokenizer.c ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+