MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / find

Function find

src/cluecode/finder.py:50–70  ·  view source on GitHub ↗

Yield match and matched lines for patterns found in file at location as a tuple of (key, found text, text line). `patterns` is a list of tuples (key, compiled regex). Note: the location can be a list of lines for testing convenience.

(location, patterns)

Source from the content-addressed store, hash-verified

48
49
50def find(location, patterns):
51 """
52 Yield match and matched lines for patterns found in file at location as a
53 tuple of (key, found text, text line). `patterns` is a list of tuples (key,
54 compiled regex).
55
56 Note: the location can be a list of lines for testing convenience.
57 """
58 if TRACE:
59 from pprint import pformat
60 loc = pformat(location)
61 logger_debug('find(location=%(loc)r,\n patterns=%(patterns)r)' % locals())
62
63 for line_number, line in analysis.numbered_text_lines(location, demarkup=False):
64 for key, pattern in patterns:
65 for match in pattern.findall(line):
66
67 if TRACE:
68 logger_debug('find: yielding match: key=%(key)r, '
69 'match=%(match)r,\n line=%(line)r' % locals())
70 yield key, toascii(match), line, line_number
71
72
73def unique_filter(matches):

Callers 4

find_emailsFunction · 0.85
find_urlsFunction · 0.85
find_patternFunction · 0.85

Calls 2

toasciiFunction · 0.90
logger_debugFunction · 0.70