155 hold a list containing details about the error/ warnings |
155 hold a list containing details about the error/ warnings |
156 (file name, line number, column, codestring (only at syntax |
156 (file name, line number, column, codestring (only at syntax |
157 errors), the message, a list with arguments for the message) |
157 errors), the message, a list with arguments for the message) |
158 @rtype dict |
158 @rtype dict |
159 """ |
159 """ |
160 try: |
160 if codestring: |
161 from yaml import MarkedYAMLError, safe_load_all # __IGNORE_WARNING_I10__ |
161 try: |
162 except ImportError: |
162 from yaml import MarkedYAMLError, safe_load_all # __IGNORE_WARNING_I10__ |
163 error = "pyyaml not available. Install it via the PyPI interface." |
163 except ImportError: |
164 return [{"error": (file, 0, 0, "", error)}] |
164 error = "pyyaml not available. Install it via the PyPI interface." |
|
165 return [{"error": (file, 0, 0, "", error)}] |
165 |
166 |
166 try: |
167 try: |
167 for _obj in safe_load_all(codestring): |
168 for _obj in safe_load_all(codestring): |
168 # do nothing with it, just to get parse errors |
169 # do nothing with it, just to get parse errors |
169 pass |
170 pass |
170 except MarkedYAMLError as exc: |
171 except MarkedYAMLError as exc: |
171 if exc.problem_mark: |
172 if exc.problem_mark: |
172 line = exc.problem_mark.line + 1 |
173 line = exc.problem_mark.line + 1 |
173 column = exc.problem_mark.column |
174 column = exc.problem_mark.column |
174 else: |
175 else: |
175 line, column = 0, 0 |
176 line, column = 0, 0 |
176 error = exc.problem |
177 error = exc.problem |
177 |
178 |
178 cline = min(len(codestring.splitlines()), int(line)) - 1 |
179 cline = min(len(codestring.splitlines()), int(line)) - 1 |
179 code = codestring.splitlines()[cline] |
180 code = codestring.splitlines()[cline] |
180 |
181 |
181 return [{"error": (file, line, column, code, error)}] |
182 return [{"error": (file, line, column, code, error)}] |
182 |
183 |
183 return [{}] |
184 return [{}] |