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

Method _replace_props

src/packagedcode/maven.py:519–548  ·  view source on GitHub ↗
(cls, text, properties)

Source from the content-addressed store, hash-verified

517
518 @classmethod
519 def _replace_props(cls, text, properties):
520 if not text:
521 return text
522
523 def subfunc(matchobj):
524 """Return the replacement value for a matched property key."""
525 key = matchobj.group(1)
526 # does this key contain a substring?
527 real_key, start_end = _get_substring_expression(key)
528 if not start_end:
529 value = properties.get(key)
530
531 return value
532 # apply the substring transform
533 value = properties.get(real_key)
534 if not value:
535 return value
536 start, end = start_end
537 return substring(value, start, end)
538
539 result = pom.PROPERTY_RE.sub(subfunc, text)
540 # we loop a maximum of 5 times to avoid cases of infinite recursion
541 cycles = 5
542 while cycles > 0 and result and pom.PROPERTY_RE.match(result):
543 result = pom.PROPERTY_RE.sub(subfunc, result)
544 cycles -= 1
545
546 if not result:
547 result = text
548 return result.strip()
549
550 def _replace_properties(self, text, properties=None):
551 # copied from pymavem.pom.Pom

Calls 1

matchMethod · 0.80