未验证 提交 fccab36e 编写于 作者: D dzhwinter 提交者: GitHub

"fix python encode error" (#7613)

上级 47753a96
...@@ -77,10 +77,13 @@ def lang_type(filename): ...@@ -77,10 +77,13 @@ def lang_type(filename):
elif filename.endswith(".proto"): elif filename.endswith(".proto"):
return "C" return "C"
else: else:
print("Unsupported filetype") print("Unsupported filetype %s", filename)
exit(0) exit(0)
PYTHON_ENCODE = re.compile("^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)")
def main(argv=None): def main(argv=None):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Checker for copyright declaration.') description='Checker for copyright declaration.')
...@@ -89,8 +92,15 @@ def main(argv=None): ...@@ -89,8 +92,15 @@ def main(argv=None):
retv = 0 retv = 0
for filename in args.filenames: for filename in args.filenames:
first_line = io.open(filename).readline() fd = io.open(filename)
if "COPYRIGHT" in first_line.upper() : continue first_line = fd.readline()
if "COPYRIGHT" in first_line.upper(): continue
if filename.endswith(".py"):
second_line = fd.readline()
if first_line.startswith("#!") or PYTHON_ENCODE.match(
second_line) != None or PYTHON_ENCODE.match(
first_line) != None:
continue
original_contents = io.open(filename).read() original_contents = io.open(filename).read()
new_contents = generate_copyright( new_contents = generate_copyright(
COPYRIGHT, lang_type(filename)) + original_contents COPYRIGHT, lang_type(filename)) + original_contents
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册