def get_spdx_id_matches(self, query, from_spdx_id_lines=True, **kwargs): """ Matching strategy for SPDX-Licensed-Identifier style of expressions. If `from_spdx_id_lines` is True detect only in the SPDX license identifier lines found in the query. Otherwise use the whole query for detection. """ matches = [] if from_spdx_id_lines: qrs_and_texts = query.spdx_lid_query_runs_and_text() else: # If we are not specifically looking at a single SPDX-Licene- # identifier line, then use the whole query run with the whole text. # Note this can only work for small texts or this will likely make # the expression parser choke if you feed it large texts query_lines = [ln for _, ln in tokenize.query_lines(query.location, query.query_string)] qrs_and_texts = query.whole_query_run(), u'\n'.join(query_lines) qrs_and_texts = [qrs_and_texts] for query_run, detectable_text in qrs_and_texts: if not query_run.matchables: # this could happen if there was some negative match applied continue spdx_match = match_spdx_lid.spdx_id_match( self, query_run, detectable_text) query_run.subtract(spdx_match.qspan) matches.append(spdx_match) return matches
def get_spdx_id_matches( self, query, from_spdx_id_lines=True, expression_symbols=None, **kwargs, ): """ Matching strategy for SPDX-Licensed-Identifier style of expressions. If `from_spdx_id_lines` is True detect only in the SPDX license identifier lines found in the query. Otherwise use the whole query for detection. Use the ``expression_symbols`` mapping of {lowered key: LicenseSymbol} if provided. Otherwise use the standard SPDX license symbols. """ matches = [] if from_spdx_id_lines: qrs_and_texts = query.spdx_lid_query_runs_and_text() else: # If we are not specifically looking at a single SPDX-Licene- # identifier line, then use the whole query run with the whole text. # Note this can only work for small texts or this will likely make # the expression parser choke if you feed it large texts query_lines = tokenize.query_lines(query.location, query.query_string) query_lines = [ln for _, ln in query_lines] qrs_and_texts = query.whole_query_run(), u'\n'.join(query_lines) qrs_and_texts = [qrs_and_texts] for query_run, detectable_text in qrs_and_texts: if not query_run.matchables: continue if TRACE_SPDX_LID: logger_debug( 'get_spdx_id_matches:', 'query_run:', query_run, 'detectable_text:', detectable_text, ) spdx_match = match_spdx_lid.spdx_id_match( idx=self, query_run=query_run, text=detectable_text, expression_symbols=expression_symbols, ) if spdx_match: query_run.subtract(spdx_match.qspan) matches.append(spdx_match) return matches