63 pass |
63 pass |
64 |
64 |
65 return codestring |
65 return codestring |
66 |
66 |
67 |
67 |
68 def extractLineFlags(line, startComment="#", endComment=""): |
68 def extractLineFlags(line, startComment="#", endComment="", flagsLine=False): |
69 """ |
69 """ |
70 Function to extract flags starting and ending with '__' from a line |
70 Function to extract flags starting and ending with '__' from a line |
71 comment. |
71 comment. |
72 |
72 |
73 @param line line to extract flags from (string) |
73 @param line line to extract flags from (string) |
74 @keyparam startComment string identifying the start of the comment (string) |
74 @keyparam startComment string identifying the start of the comment (string) |
75 @keyparam endComment string identifying the end of a comment (string) |
75 @keyparam endComment string identifying the end of a comment (string) |
|
76 @keyparam flagsLine flag indicating to check for a flags only line (bool) |
76 @return list containing the extracted flags (list of strings) |
77 @return list containing the extracted flags (list of strings) |
77 """ |
78 """ |
78 flags = [] |
79 flags = [] |
79 |
80 |
80 pos = line.rfind(startComment) |
81 if not flagsLine or ( |
81 if pos >= 0: |
82 flagsLine and line.strip().startswith(startComment)): |
82 comment = line[pos + len(startComment):].strip() |
83 pos = line.rfind(startComment) |
83 if endComment: |
84 if pos >= 0: |
84 comment = comment.replace("endComment", "") |
85 comment = line[pos + len(startComment):].strip() |
85 flags = [f.strip() for f in comment.split() |
86 if endComment: |
86 if (f.startswith("__") and f.endswith("__"))] |
87 endPos = line.rfind(endComment) |
|
88 if endPos >= 0: |
|
89 comment = comment[:endPos] |
|
90 flags = [f.strip() for f in comment.split() |
|
91 if (f.startswith("__") and f.endswith("__"))] |
87 return flags |
92 return flags |
88 |
93 |
89 |
94 |
90 def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
95 def syntaxAndPyflakesCheck(filename, codestring, checkFlakes=True, |
91 ignoreStarImportWarnings=False): |
96 ignoreStarImportWarnings=False): |
280 isinstance(warning, ImportStarUsage) |
285 isinstance(warning, ImportStarUsage) |
281 ): |
286 ): |
282 continue |
287 continue |
283 |
288 |
284 _fn, lineno, col, message, msg_args = warning.getMessageData() |
289 _fn, lineno, col, message, msg_args = warning.getMessageData() |
285 if "__IGNORE_WARNING__" not in extractLineFlags( |
290 lineFlags = extractLineFlags(lines[lineno - 1].strip()) |
286 lines[lineno - 1].strip()): |
291 try: |
|
292 lineFlags += extractLineFlags(lines[lineno].strip(), |
|
293 flagsLine=True) |
|
294 except IndexError: |
|
295 pass |
|
296 if "__IGNORE_WARNING__" not in lineFlags: |
287 results.append((_fn, lineno, col, "", message, msg_args)) |
297 results.append((_fn, lineno, col, "", message, msg_args)) |
288 except SyntaxError as err: |
298 except SyntaxError as err: |
289 if err.text.strip(): |
299 if err.text.strip(): |
290 msg = err.text.strip() |
300 msg = err.text.strip() |
291 else: |
301 else: |