| 536 | /************************************************************************/ |
| 537 | |
| 538 | bool VRTDerivedRasterBand::InitializePython() |
| 539 | { |
| 540 | if (m_poPrivate->m_bPythonInitializationDone) |
| 541 | return m_poPrivate->m_bPythonInitializationSuccess; |
| 542 | |
| 543 | m_poPrivate->m_bPythonInitializationDone = true; |
| 544 | m_poPrivate->m_bPythonInitializationSuccess = false; |
| 545 | |
| 546 | const size_t nIdxDot = osFuncName.rfind("."); |
| 547 | CPLString osPythonModule; |
| 548 | CPLString osPythonFunction; |
| 549 | if (nIdxDot != std::string::npos) |
| 550 | { |
| 551 | osPythonModule = osFuncName.substr(0, nIdxDot); |
| 552 | osPythonFunction = osFuncName.substr(nIdxDot + 1); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | osPythonFunction = osFuncName; |
| 557 | } |
| 558 | |
| 559 | #ifndef GDAL_VRT_DISABLE_PYTHON |
| 560 | const char *pszPythonEnabled = |
| 561 | CPLGetConfigOption("GDAL_VRT_ENABLE_PYTHON", nullptr); |
| 562 | #else |
| 563 | const char *pszPythonEnabled = "NO"; |
| 564 | #endif |
| 565 | const CPLString osPythonEnabled( |
| 566 | pszPythonEnabled ? pszPythonEnabled : GDAL_VRT_ENABLE_PYTHON_DEFAULT); |
| 567 | |
| 568 | if (EQUAL(osPythonEnabled, "TRUSTED_MODULES")) |
| 569 | { |
| 570 | bool bIsTrustedModule = false; |
| 571 | const CPLString osVRTTrustedModules( |
| 572 | CPLGetConfigOption("GDAL_VRT_PYTHON_TRUSTED_MODULES", "")); |
| 573 | if (!osPythonModule.empty()) |
| 574 | { |
| 575 | char **papszTrustedModules = |
| 576 | CSLTokenizeString2(osVRTTrustedModules, ",", 0); |
| 577 | for (char **papszIter = papszTrustedModules; |
| 578 | !bIsTrustedModule && papszIter && *papszIter; ++papszIter) |
| 579 | { |
| 580 | const char *pszIterModule = *papszIter; |
| 581 | size_t nIterModuleLen = strlen(pszIterModule); |
| 582 | if (nIterModuleLen > 2 && |
| 583 | strncmp(pszIterModule + nIterModuleLen - 2, ".*", 2) == 0) |
| 584 | { |
| 585 | bIsTrustedModule = |
| 586 | (strncmp(osPythonModule, pszIterModule, |
| 587 | nIterModuleLen - 2) == 0) && |
| 588 | (osPythonModule.size() == nIterModuleLen - 2 || |
| 589 | (osPythonModule.size() >= nIterModuleLen && |
| 590 | osPythonModule[nIterModuleLen - 1] == '.')); |
| 591 | } |
| 592 | else if (nIterModuleLen >= 1 && |
| 593 | pszIterModule[nIterModuleLen - 1] == '*') |
| 594 | { |
| 595 | bIsTrustedModule = (strncmp(osPythonModule, pszIterModule, |
nothing calls this directly
no test coverage detected