Return a line of extracted text from a file if that file is likely generated source code. for each of the first few lines of a source code file if generated keywords are found in the line as lowercase yield the line text as a 'potentially_ generated' annotation
(
location,
max_lines=150,
generated_keywords=GENERATED_KEYWORDS_LOWERED
)
| 210 | |
| 211 | |
| 212 | def get_generated_code_hint( |
| 213 | location, |
| 214 | max_lines=150, |
| 215 | generated_keywords=GENERATED_KEYWORDS_LOWERED |
| 216 | ): |
| 217 | """ |
| 218 | Return a line of extracted text from a file if that file is likely |
| 219 | generated source code. |
| 220 | |
| 221 | for each of the first few lines of a source code file |
| 222 | if generated keywords are found in the line as lowercase |
| 223 | yield the line text as a 'potentially_ generated' annotation |
| 224 | """ |
| 225 | T = typecode.contenttype.get_type(location) |
| 226 | if not T.is_text: |
| 227 | return |
| 228 | with open(location, 'rb') as filein: |
| 229 | for line in islice(filein, max_lines): |
| 230 | text = toascii(line.strip()).lower() |
| 231 | if any(kw in text.lower() for kw in generated_keywords): |
| 232 | # yield only the first 100 chars.. |
| 233 | yield text[:100] |
| 234 |
no test coverage detected