papersearch 0.6.10 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -21
- package/NOTICE +51 -0
- package/README.en.md +13 -13
- package/README.md +13 -13
- package/assets/federation-map.en.png +0 -0
- package/assets/federation-map.png +0 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.d.ts +27 -17
- package/dist/capabilities/download/batch/batch.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batch.js +440 -278
- package/dist/capabilities/download/batch/batch.js.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts +21 -0
- package/dist/capabilities/download/batch/batchFolder.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchFolder.js +206 -0
- package/dist/capabilities/download/batch/batchFolder.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.d.ts +1 -1
- package/dist/capabilities/download/batch/batchPapers.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchPapers.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/batch}/batchSummary.d.ts +7 -9
- package/dist/capabilities/download/batch/batchSummary.d.ts.map +1 -0
- package/dist/capabilities/download/batch/batchSummary.js +269 -0
- package/dist/capabilities/download/batch/batchSummary.js.map +1 -0
- package/dist/capabilities/download/batch/networkLoss.d.ts +31 -0
- package/dist/capabilities/download/batch/networkLoss.d.ts.map +1 -0
- package/dist/capabilities/download/batch/networkLoss.js +67 -0
- package/dist/capabilities/download/batch/networkLoss.js.map +1 -0
- package/dist/capabilities/download/batch/resume.d.ts +76 -0
- package/dist/capabilities/download/batch/resume.d.ts.map +1 -0
- package/dist/capabilities/download/batch/resume.js +231 -0
- package/dist/capabilities/download/batch/resume.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts +14 -0
- package/dist/capabilities/download/content/markdown/pageVisit.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js +52 -0
- package/dist/capabilities/download/content/markdown/pageVisit.js.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts +87 -0
- package/dist/capabilities/download/content/markdown/pro.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/pro.js +109 -0
- package/dist/capabilities/download/content/markdown/pro.js.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts +34 -0
- package/dist/capabilities/download/content/markdown/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/shortfall.js +99 -0
- package/dist/capabilities/download/content/markdown/shortfall.js.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts +9 -0
- package/dist/capabilities/download/content/markdown/stats.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/stats.js +39 -0
- package/dist/capabilities/download/content/markdown/stats.js.map +1 -0
- package/dist/capabilities/download/content/markdown/step.d.ts +50 -0
- package/dist/capabilities/download/content/markdown/step.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/step.js +343 -0
- package/dist/capabilities/download/content/markdown/step.js.map +1 -0
- package/dist/capabilities/download/content/markdown/types.d.ts +120 -0
- package/dist/capabilities/download/content/markdown/types.d.ts.map +1 -0
- package/dist/capabilities/download/content/markdown/types.js +8 -0
- package/dist/capabilities/download/content/markdown/types.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.d.ts +13 -4
- package/dist/capabilities/download/content/pdf/DownloadTier.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/DownloadTier.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.d.ts +5 -5
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/OpenAccessFallbackService.js +26 -14
- package/dist/capabilities/download/content/pdf/OpenAccessFallbackService.js.map +1 -0
- package/dist/capabilities/download/content/pdf/arxiv.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.js +2 -2
- package/dist/capabilities/download/content/pdf/arxiv.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/identity.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/identity.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/oaHosts.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/pmcCloud.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.js +2 -2
- package/dist/capabilities/download/content/pdf/open/pmcCloud.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/elsevier.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/index.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.js +3 -3
- package/dist/capabilities/download/content/pdf/open/publisherApi/springer.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/directPdfUrl.js +3 -3
- package/dist/capabilities/download/content/pdf/open/tiers/directPdfUrl.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts +5 -0
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/preprint.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/preprint.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/primary.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/publisherApi.js +5 -5
- package/dist/capabilities/download/content/pdf/open/tiers/publisherApi.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.d.ts +1 -1
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/repositories.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/repositories.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.d.ts.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/scihub.js.map +1 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts +3 -0
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/unpaywall.js +2 -2
- package/dist/capabilities/download/content/pdf/open/tiers/unpaywall.js.map +1 -0
- package/dist/capabilities/download/content/pdf/school.d.ts +4 -0
- package/dist/capabilities/download/content/pdf/school.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery/tiers/entitledAccess.js → download/content/pdf/school.js} +16 -38
- package/dist/capabilities/download/content/pdf/school.js.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts +27 -0
- package/dist/capabilities/download/content/supplements/fetch.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/fetch.js +150 -0
- package/dist/capabilities/download/content/supplements/fetch.js.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts +11 -0
- package/dist/capabilities/download/content/supplements/shortfall.d.ts.map +1 -0
- package/dist/capabilities/download/content/supplements/shortfall.js +24 -0
- package/dist/capabilities/download/content/supplements/shortfall.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/handler.d.ts +12 -4
- package/dist/capabilities/download/handler.d.ts.map +1 -0
- package/dist/capabilities/download/handler.js +275 -0
- package/dist/capabilities/download/handler.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.d.ts +3 -3
- package/dist/capabilities/download/index.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/index.js +2 -2
- package/dist/capabilities/download/index.js.map +1 -0
- package/dist/capabilities/download/outputLayout.d.ts.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/outputLayout.js +63 -6
- package/dist/capabilities/download/outputLayout.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/schemas.d.ts +143 -18
- package/dist/capabilities/download/schemas.d.ts.map +1 -0
- package/dist/capabilities/download/schemas.js +126 -0
- package/dist/capabilities/download/schemas.js.map +1 -0
- package/dist/capabilities/{pdf-discovery → download}/tools.d.ts +68 -6
- package/dist/capabilities/download/tools.d.ts.map +1 -0
- package/dist/capabilities/download/tools.js +197 -0
- package/dist/capabilities/download/tools.js.map +1 -0
- package/dist/capabilities/download/types.d.ts +222 -0
- package/dist/capabilities/download/types.d.ts.map +1 -0
- package/dist/capabilities/download/types.js +7 -0
- package/dist/capabilities/download/types.js.map +1 -0
- package/dist/cli.js +98 -17
- package/dist/cli.js.map +1 -1
- package/dist/config/edition.d.ts +8 -0
- package/dist/config/edition.d.ts.map +1 -0
- package/dist/config/edition.js +31 -0
- package/dist/config/edition.js.map +1 -0
- package/dist/core/handleToolCall.d.ts +1 -1
- package/dist/core/handleToolCall.d.ts.map +1 -1
- package/dist/core/handleToolCall.js +1 -1
- package/dist/core/handleToolCall.js.map +1 -1
- package/dist/core/schemas.d.ts +1 -1
- package/dist/core/schemas.d.ts.map +1 -1
- package/dist/core/schemas.js +1 -1
- package/dist/core/schemas.js.map +1 -1
- package/dist/core/tools.d.ts +2 -1
- package/dist/core/tools.d.ts.map +1 -1
- package/dist/core/tools.js +8 -2
- package/dist/core/tools.js.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.d.ts.map +1 -1
- package/dist/infrastructure/pdf/PdfIdentity.js +76 -5
- package/dist/infrastructure/pdf/PdfIdentity.js.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.d.ts +12 -2
- package/dist/infrastructure/runlog/RunLedger.d.ts.map +1 -1
- package/dist/infrastructure/runlog/RunLedger.js +39 -11
- package/dist/infrastructure/runlog/RunLedger.js.map +1 -1
- package/dist/infrastructure/runlog/failureClass.d.ts +9 -6
- package/dist/infrastructure/runlog/failureClass.d.ts.map +1 -1
- package/dist/infrastructure/runlog/failureClass.js +81 -41
- package/dist/infrastructure/runlog/failureClass.js.map +1 -1
- package/dist/infrastructure/school/SchoolAttempt.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.js +12 -3
- package/dist/infrastructure/school/SchoolAttempt.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.d.ts +17 -0
- package/dist/infrastructure/school/SchoolMcpClient.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolMcpClient.js +99 -10
- package/dist/infrastructure/school/SchoolMcpClient.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.d.ts +1 -0
- package/dist/infrastructure/school/SchoolProgress.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolProgress.js +1 -0
- package/dist/infrastructure/school/SchoolProgress.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.d.ts +7 -1
- package/dist/infrastructure/school/SchoolReadiness.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolReadiness.js +10 -2
- package/dist/infrastructure/school/SchoolReadiness.js.map +1 -0
- package/dist/infrastructure/school/SchoolResultNormalizer.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.js +72 -3
- package/dist/infrastructure/school/SchoolResultNormalizer.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.d.ts +2 -1
- package/dist/infrastructure/school/index.d.ts.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/index.js +3 -2
- package/dist/infrastructure/school/index.js.map +1 -0
- package/dist/{capabilities/pdf-discovery → infrastructure}/school/types.d.ts +85 -5
- package/dist/infrastructure/school/types.d.ts.map +1 -0
- package/dist/infrastructure/school/types.js +5 -0
- package/dist/infrastructure/school/types.js.map +1 -0
- package/dist/management/capability-profile/schoolReadiness.d.ts +1 -1
- package/dist/management/capability-profile/schoolReadiness.d.ts.map +1 -1
- package/dist/management/capability-profile/schoolReadiness.js +1 -1
- package/dist/management/capability-profile/schoolReadiness.js.map +1 -1
- package/dist/management/failures/exportReport.d.ts +6 -0
- package/dist/management/failures/exportReport.d.ts.map +1 -1
- package/dist/management/failures/exportReport.js +28 -18
- package/dist/management/failures/exportReport.js.map +1 -1
- package/dist/management/failures/index.d.ts +3 -0
- package/dist/management/failures/index.d.ts.map +1 -1
- package/dist/management/failures/index.js +5 -2
- package/dist/management/failures/index.js.map +1 -1
- package/dist/management/failures/markdownReport.d.ts +55 -0
- package/dist/management/failures/markdownReport.d.ts.map +1 -0
- package/dist/management/failures/markdownReport.js +96 -0
- package/dist/management/failures/markdownReport.js.map +1 -0
- package/dist/management/pro/install.d.ts +58 -0
- package/dist/management/pro/install.d.ts.map +1 -0
- package/dist/management/pro/install.js +235 -0
- package/dist/management/pro/install.js.map +1 -0
- package/dist/management/reports/index.d.ts.map +1 -1
- package/dist/management/reports/index.js +4 -1
- package/dist/management/reports/index.js.map +1 -1
- package/dist/management/school/autoUpdate.d.ts +4 -3
- package/dist/management/school/autoUpdate.d.ts.map +1 -1
- package/dist/management/school/autoUpdate.js +6 -4
- package/dist/management/school/autoUpdate.js.map +1 -1
- package/dist/management/school/cliProgress.d.ts +1 -1
- package/dist/management/school/cliProgress.d.ts.map +1 -1
- package/dist/management/school/cliProgress.js +1 -0
- package/dist/management/school/cliProgress.js.map +1 -1
- package/dist/management/school/host.js +1 -1
- package/dist/management/school/host.js.map +1 -1
- package/dist/management/school/installer.d.ts +1 -2
- package/dist/management/school/installer.d.ts.map +1 -1
- package/dist/management/school/installer.js.map +1 -1
- package/dist/management/school/legacy.js +1 -1
- package/dist/management/school/legacy.js.map +1 -1
- package/dist/management/school/settingsWindow.d.ts +14 -3
- package/dist/management/school/settingsWindow.d.ts.map +1 -1
- package/dist/management/school/settingsWindow.js +14 -4
- package/dist/management/school/settingsWindow.js.map +1 -1
- package/dist/management/skills/autoSync.d.ts +3 -3
- package/dist/management/skills/autoSync.d.ts.map +1 -1
- package/dist/management/skills/autoSync.js +13 -20
- package/dist/management/skills/autoSync.js.map +1 -1
- package/dist/services/OpenAccessFallbackService.d.ts +3 -3
- package/dist/services/OpenAccessFallbackService.d.ts.map +1 -1
- package/dist/services/OpenAccessFallbackService.js +1 -1
- package/dist/services/OpenAccessFallbackService.js.map +1 -1
- package/dist/skills/SkillInstaller.d.ts +26 -0
- package/dist/skills/SkillInstaller.d.ts.map +1 -1
- package/dist/skills/SkillInstaller.js +80 -10
- package/dist/skills/SkillInstaller.js.map +1 -1
- package/package.json +10 -2
- package/school/LICENSE +661 -21
- package/school/LICENSE-scansci-pdf +21 -0
- package/school/NOTICE +10 -0
- package/school/README.md +1 -1
- package/school/paper_search_school/_core/__init__.py +2 -1
- package/school/paper_search_school/adapters/__init__.py +3 -3
- package/school/paper_search_school/adapters/acm/__init__.py +7 -1
- package/school/paper_search_school/adapters/acs/__init__.py +4 -0
- package/school/paper_search_school/adapters/aha_journals/__init__.py +5 -1
- package/school/paper_search_school/adapters/aip/__init__.py +17 -0
- package/school/paper_search_school/adapters/ams/__init__.py +36 -0
- package/school/paper_search_school/adapters/annual_reviews/__init__.py +24 -1
- package/school/paper_search_school/adapters/aps/__init__.py +118 -0
- package/school/paper_search_school/adapters/asce/__init__.py +7 -1
- package/school/paper_search_school/adapters/base.py +21 -1
- package/school/paper_search_school/adapters/bmj/__init__.py +54 -0
- package/school/paper_search_school/adapters/copernicus/__init__.py +35 -0
- package/school/paper_search_school/adapters/dovepress/__init__.py +31 -0
- package/school/paper_search_school/adapters/elsevier/__init__.py +33 -0
- package/school/paper_search_school/adapters/frontiers/__init__.py +46 -1
- package/school/paper_search_school/adapters/ieee/__init__.py +94 -2
- package/school/paper_search_school/adapters/iop/__init__.py +65 -0
- package/school/paper_search_school/adapters/jama/__init__.py +4 -0
- package/school/paper_search_school/adapters/karger/__init__.py +6 -1
- package/school/paper_search_school/adapters/lww/__init__.py +3 -0
- package/school/paper_search_school/adapters/lww/ovid.py +28 -0
- package/school/paper_search_school/adapters/mdpi/__init__.py +73 -0
- package/school/paper_search_school/adapters/nejm/__init__.py +5 -1
- package/school/paper_search_school/adapters/neurology/__init__.py +5 -1
- package/school/paper_search_school/adapters/optica/__init__.py +49 -0
- package/school/paper_search_school/adapters/oup/__init__.py +34 -2
- package/school/paper_search_school/adapters/platforms/atypon/__init__.py +83 -2
- package/school/paper_search_school/adapters/platforms/figshare/__init__.py +0 -3
- package/school/paper_search_school/adapters/platforms/silverchair/__init__.py +76 -0
- package/school/paper_search_school/adapters/plos/__init__.py +85 -2
- package/school/paper_search_school/adapters/pnas/__init__.py +5 -1
- package/school/paper_search_school/adapters/royal_society/__init__.py +17 -0
- package/school/paper_search_school/adapters/rsc/__init__.py +4 -1
- package/school/paper_search_school/adapters/sage/__init__.py +6 -0
- package/school/paper_search_school/adapters/science/__init__.py +5 -1
- package/school/paper_search_school/adapters/springer/__init__.py +102 -0
- package/school/paper_search_school/adapters/taylor_francis/__init__.py +11 -1
- package/school/paper_search_school/adapters/thieme/__init__.py +46 -0
- package/school/paper_search_school/adapters/wiley/__init__.py +28 -0
- package/school/paper_search_school/adapters/world_scientific/__init__.py +15 -4
- package/school/paper_search_school/assets/capsule.html +607 -41
- package/school/paper_search_school/assets/capsule_en.json +314 -5
- package/school/paper_search_school/browser/__init__.py +5 -2
- package/school/paper_search_school/browser/backend.py +161 -9
- package/school/paper_search_school/browser/batch_session.py +76 -2
- package/school/paper_search_school/browser/challenge/__init__.py +13 -0
- package/school/paper_search_school/browser/{challenges.py → challenge/detection.py} +1 -1
- package/school/paper_search_school/browser/{challenge_interaction.py → challenge/interaction.py} +92 -19
- package/school/paper_search_school/browser/challenge/pointer.py +228 -0
- package/school/paper_search_school/browser/challenge/prompt.py +154 -0
- package/school/paper_search_school/browser/challenge/warmup.py +90 -0
- package/school/paper_search_school/browser/driver.py +12 -0
- package/school/paper_search_school/browser/profiles.py +54 -3
- package/school/paper_search_school/browser/watchdog.py +8 -0
- package/school/paper_search_school/cli.py +150 -10
- package/school/paper_search_school/cold_start.py +5 -2
- package/school/paper_search_school/config.py +25 -1
- package/school/paper_search_school/download_diagnostics.py +3 -2
- package/school/paper_search_school/edition.py +22 -0
- package/school/paper_search_school/engine/access_rules.py +62 -2
- package/school/paper_search_school/engine/batch.py +56 -12
- package/school/paper_search_school/engine/batch_access.py +12 -1
- package/school/paper_search_school/engine/batch_capture.py +309 -9
- package/school/paper_search_school/engine/batch_common.py +3 -1
- package/school/paper_search_school/engine/batch_institution.py +145 -21
- package/school/paper_search_school/engine/batch_login.py +554 -21
- package/school/paper_search_school/engine/batch_waits.py +76 -1
- package/school/paper_search_school/engine/bridge.py +139 -7
- package/school/paper_search_school/engine/fulltext_page.py +340 -0
- package/school/paper_search_school/engine/pdf_guard.py +65 -5
- package/school/paper_search_school/engine/router.py +3 -2
- package/school/paper_search_school/engine/supplement_transfer.py +22 -7
- package/school/paper_search_school/engine/supplements.py +5 -8
- package/school/paper_search_school/federations/__init__.py +9 -6
- package/school/paper_search_school/{carsi_schools.py → federations/carsi.py} +1 -1
- package/school/paper_search_school/federations/{builtin → data/asia}/cstcloud.json +2 -2
- package/school/paper_search_school/federations/{builtin → data/europe}/eduidhu.json +2 -2
- package/school/paper_search_school/login_routes.py +45 -0
- package/school/paper_search_school/markdown_report.py +426 -0
- package/school/paper_search_school/orchestrator.py +25 -1
- package/school/paper_search_school/pro_status.py +192 -0
- package/school/paper_search_school/progress_capsule.py +192 -2
- package/school/paper_search_school/progress_reporter.py +100 -16
- package/school/paper_search_school/progress_status.py +1 -1
- package/school/paper_search_school/progress_view.py +171 -26
- package/school/paper_search_school/publishers/profiles.py +6 -0
- package/school/paper_search_school/rate_limit.py +7 -0
- package/school/paper_search_school/report_sanitizer.py +25 -11
- package/school/paper_search_school/school_login.py +373 -0
- package/school/paper_search_school/schools/__init__.py +7 -0
- package/school/paper_search_school/{federations/schools.py → schools/lookup.py} +3 -3
- package/school/paper_search_school/schools/saved.py +111 -0
- package/school/paper_search_school/server.py +53 -9
- package/school/paper_search_school/user_settings.py +14 -0
- package/school/pyproject.toml +3 -2
- package/skills/paper-search/SKILL.md +11 -12
- package/skills/paper-search/references/browser-download.md +20 -15
- package/skills/paper-search/references/capability-routing.md +1 -1
- package/skills/paper-search/references/cli-contract.md +7 -5
- package/skills/paper-search/references/management-layer.md +3 -3
- package/skills/paper-search/references/publisher-support.md +5 -5
- package/skills/paper-search/references/school-setup.md +14 -0
- package/skills/paper-search/references/troubleshooting.md +0 -1
- package/assets/ask-with-skill.png +0 -0
- package/dist/capabilities/pdf-discovery/DownloadTier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/DownloadTier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/OpenAccessFallbackService.js.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/arxiv.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batch.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchPapers.js.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/batchSummary.js +0 -191
- package/dist/capabilities/pdf-discovery/batchSummary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/handler.js +0 -166
- package/dist/capabilities/pdf-discovery/handler.js.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/identity.js.map +0 -1
- package/dist/capabilities/pdf-discovery/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/oaHosts.js.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/outputLayout.js.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/pmcCloud.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/elsevier.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/publisherApi/springer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.d.ts +0 -22
- package/dist/capabilities/pdf-discovery/resume.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/resume.js +0 -114
- package/dist/capabilities/pdf-discovery/resume.js.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/schemas.js +0 -75
- package/dist/capabilities/pdf-discovery/schemas.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolAttempt.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolMcpClient.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolProgress.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolReadiness.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/SchoolResultNormalizer.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/index.js.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/school/types.js +0 -2
- package/dist/capabilities/pdf-discovery/school/types.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/directPdfUrl.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts +0 -10
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/entitledAccess.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts +0 -5
- package/dist/capabilities/pdf-discovery/tiers/preprint.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/preprint.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/primary.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/primary.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/publisherApi.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/repositories.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/scihub.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/scihub.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts +0 -3
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tiers/unpaywall.js.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/tools.js +0 -146
- package/dist/capabilities/pdf-discovery/tools.js.map +0 -1
- package/dist/capabilities/pdf-discovery/types.d.ts +0 -102
- package/dist/capabilities/pdf-discovery/types.d.ts.map +0 -1
- package/dist/capabilities/pdf-discovery/types.js +0 -2
- package/dist/capabilities/pdf-discovery/types.js.map +0 -1
- /package/dist/capabilities/{pdf-discovery → download/batch}/batchPapers.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/DownloadTier.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/arxiv.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf}/identity.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/oaHosts.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/pmcCloud.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/elsevier.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/index.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/publisherApi/springer.d.ts +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/primary.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download/content/pdf/open}/tiers/scihub.js +0 -0
- /package/dist/capabilities/{pdf-discovery → download}/outputLayout.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolAttempt.d.ts +0 -0
- /package/dist/{capabilities/pdf-discovery → infrastructure}/school/SchoolResultNormalizer.d.ts +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidbf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidma.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/eduidtg.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/fidern.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/garnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/maren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ngrenid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rafiki.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/rif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/safire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/africa}/ternet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/caf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/cofre.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/colfire.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/fenix.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/incommon.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/americas}/minga.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/azsciencenet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/carsi.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/cynet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/gakunin.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/hkaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/infed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/irfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/iucc.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/kafe.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/liaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/maeen.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/omren.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/pkifed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sgaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/sifulan.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/tigerfed.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/asia}/yetkim.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaieduhr.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aaiedumk.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/aconet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/arnesaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/belnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/bif.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/dfnaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/edugate.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidcz.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/eduidlu.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/febas.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/feide.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/grnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/haka.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/iamres.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idedume.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/idem.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/laife.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/leaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/litnet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/peano.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/pionierid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rash.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/rctsaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/renater.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ricerkanet.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/roedunetid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/safeid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/sir.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/surfconext.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/swamid.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/switchaai.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/taat.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/ukfederation.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/europe}/wayf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/global}/openathens.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/aaf.json +0 -0
- /package/school/paper_search_school/federations/{builtin → data/oceania}/tuakiri.json +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""A human-shaped pointer approach before one bounded verification press.
|
|
2
|
+
|
|
3
|
+
Cloudflare's Turnstile scores the pointer history that leads to a press on its
|
|
4
|
+
checkbox: a press that arrives with no preceding movement is the shape an
|
|
5
|
+
automated click has, which is why the interactive check can start again on the
|
|
6
|
+
same box that was already clicked. This module moves the browser's own pointer
|
|
7
|
+
along a slightly curved path into the widget and lets it rest there.
|
|
8
|
+
|
|
9
|
+
The press itself stays with the element's actionability-checked click in
|
|
10
|
+
``challenge_interaction``: nothing here reads or writes page state, navigates,
|
|
11
|
+
clicks, or decides whether verification passed. The pointer is the driver's own
|
|
12
|
+
(CDP ``Input.dispatchMouseEvent`` through Playwright's ``page.mouse``), so every
|
|
13
|
+
move is a trusted event, as a person's is.
|
|
14
|
+
|
|
15
|
+
A page without a pointer, a box without usable geometry, or a move that fails
|
|
16
|
+
because the widget went away all end the approach with ``False`` and no harm:
|
|
17
|
+
the caller then presses as it did before this module existed.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import math
|
|
22
|
+
import os
|
|
23
|
+
import random
|
|
24
|
+
import time
|
|
25
|
+
import weakref
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
#: Longest approach, before the caller's own action budget is considered.
|
|
29
|
+
APPROACH_LIMIT_SEC = 0.5
|
|
30
|
+
#: The shortest approach still worth doing: a press with a visible path in.
|
|
31
|
+
MIN_LIMIT_SEC = 0.12
|
|
32
|
+
#: ``PAPER_SEARCH_POINTER_PATH=fast``: a shorter path for a tight retry budget.
|
|
33
|
+
FAST_LIMIT_SEC = 0.25
|
|
34
|
+
#: Path segments: enough to look moved, few enough for a short action budget.
|
|
35
|
+
_STEPS = (8, 14)
|
|
36
|
+
#: How far in front of the widget the pointer starts.
|
|
37
|
+
_START_DISTANCE = (220, 520)
|
|
38
|
+
_STEP_SLEEP = (0.005, 0.012)
|
|
39
|
+
_REST_SLEEP = (0.04, 0.10)
|
|
40
|
+
#: Where each page's pointer was left, so a repeated press starts from there
|
|
41
|
+
#: instead of teleporting to a new random corner: two presses on the same box
|
|
42
|
+
#: then look like one hand, not two.
|
|
43
|
+
_LAST: "weakref.WeakKeyDictionary[Any, tuple[float, float]]" = weakref.WeakKeyDictionary()
|
|
44
|
+
#: Pages that cannot be weakly referenced (test doubles, driver proxies): their
|
|
45
|
+
#: last point by identity, bounded so a long run cannot grow it without limit.
|
|
46
|
+
_LAST_BY_ID: dict[int, tuple[float, float]] = {}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _last_point(page: Any) -> tuple[float, float] | None:
|
|
50
|
+
try:
|
|
51
|
+
return _LAST.get(page)
|
|
52
|
+
except TypeError:
|
|
53
|
+
return _LAST_BY_ID.get(id(page))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _remember_point(page: Any, point: tuple[float, float]) -> None:
|
|
57
|
+
try:
|
|
58
|
+
_LAST[page] = point
|
|
59
|
+
except TypeError:
|
|
60
|
+
if len(_LAST_BY_ID) > 256:
|
|
61
|
+
_LAST_BY_ID.clear()
|
|
62
|
+
_LAST_BY_ID[id(page)] = point
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _bezier(start: tuple[float, float], c1: tuple[float, float],
|
|
66
|
+
c2: tuple[float, float], end: tuple[float, float],
|
|
67
|
+
t: float) -> tuple[float, float]:
|
|
68
|
+
u = 1.0 - t
|
|
69
|
+
return (
|
|
70
|
+
u ** 3 * start[0] + 3 * u ** 2 * t * c1[0] + 3 * u * t ** 2 * c2[0] + t ** 3 * end[0],
|
|
71
|
+
u ** 3 * start[1] + 3 * u ** 2 * t * c1[1] + 3 * u * t ** 2 * c2[1] + t ** 3 * end[1],
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def press(page: Any, rect: dict[str, Any], *, point: dict[str, float] | None = None,
|
|
76
|
+
hold_sec: tuple[float, float] = (0.05, 0.12),
|
|
77
|
+
rng: random.Random | None = None) -> bool:
|
|
78
|
+
"""Press the point and hold it for as long as a hand does.
|
|
79
|
+
|
|
80
|
+
Playwright's own click presses and releases in the same instant; a person
|
|
81
|
+
holds the button for tens of milliseconds. Before pressing, the outer
|
|
82
|
+
document is asked what sits under the point: anything that is not the
|
|
83
|
+
widget's own frame means an overlay would take the press, and the caller
|
|
84
|
+
keeps its checked click instead.
|
|
85
|
+
|
|
86
|
+
Nothing here navigates or reads a verification result.
|
|
87
|
+
"""
|
|
88
|
+
mouse = getattr(page, "mouse", None)
|
|
89
|
+
if not all(callable(getattr(mouse, name, None)) for name in ("move", "down", "up")):
|
|
90
|
+
return False
|
|
91
|
+
try:
|
|
92
|
+
left, top = float(rect["x"]), float(rect["y"])
|
|
93
|
+
width, height = float(rect.get("width") or 0.0), float(rect.get("height") or 0.0)
|
|
94
|
+
except (AttributeError, KeyError, TypeError, ValueError):
|
|
95
|
+
return False
|
|
96
|
+
if not all(math.isfinite(value) for value in (left, top, width, height)) or width <= 0 or height <= 0:
|
|
97
|
+
return False
|
|
98
|
+
landed = point if isinstance(point, dict) else {"x": width / 2, "y": height / 2}
|
|
99
|
+
try:
|
|
100
|
+
target = (left + float(landed["x"]), top + float(landed["y"]))
|
|
101
|
+
except (KeyError, TypeError, ValueError):
|
|
102
|
+
return False
|
|
103
|
+
if not all(math.isfinite(value) for value in target):
|
|
104
|
+
return False
|
|
105
|
+
|
|
106
|
+
from ..driver import Error
|
|
107
|
+
|
|
108
|
+
try:
|
|
109
|
+
hit = page.evaluate("""([x, y]) => {
|
|
110
|
+
const el = document.elementFromPoint(x, y);
|
|
111
|
+
return el ? el.tagName : '';
|
|
112
|
+
}""", [target[0], target[1]])
|
|
113
|
+
except Error:
|
|
114
|
+
return False
|
|
115
|
+
if str(hit or "").upper() != "IFRAME":
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
random_source = rng if rng is not None else random.Random()
|
|
119
|
+
try:
|
|
120
|
+
mouse.move(target[0], target[1], steps=1)
|
|
121
|
+
mouse.down()
|
|
122
|
+
time.sleep(max(0.0, random_source.uniform(*hold_sec)))
|
|
123
|
+
mouse.up()
|
|
124
|
+
except Error:
|
|
125
|
+
return False
|
|
126
|
+
return True
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def budget_for(timeout_ms: int) -> float:
|
|
130
|
+
"""The approach's share of one click's action budget.
|
|
131
|
+
|
|
132
|
+
Two fifths of the caller's budget leaves the hover, the stability check and
|
|
133
|
+
the press itself their room, which matters for the short retry budgets the
|
|
134
|
+
engine hands the third attempt.
|
|
135
|
+
|
|
136
|
+
``PAPER_SEARCH_POINTER_PATH`` picks the cost: ``off`` presses as before this
|
|
137
|
+
module existed, ``fast`` caps the path at ``FAST_LIMIT_SEC``, and the default
|
|
138
|
+
takes the fuller path.
|
|
139
|
+
"""
|
|
140
|
+
mode = os.environ.get("PAPER_SEARCH_POINTER_PATH", "").strip().lower()
|
|
141
|
+
if mode in {"off", "0", "false", "no"}:
|
|
142
|
+
return 0.0
|
|
143
|
+
cap = FAST_LIMIT_SEC if mode in {"fast", "1", "on"} else APPROACH_LIMIT_SEC
|
|
144
|
+
return max(MIN_LIMIT_SEC, min(cap, max(0, timeout_ms) / 1000 * 0.4))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def approach(page: Any, rect: dict[str, Any], *, point: dict[str, float] | None = None,
|
|
148
|
+
limit_sec: float = APPROACH_LIMIT_SEC,
|
|
149
|
+
rng: random.Random | None = None) -> bool:
|
|
150
|
+
"""Move the pointer into ``rect`` (a viewport box) and leave it on ``point``.
|
|
151
|
+
|
|
152
|
+
``point`` is the box-relative press point (``{"x": 28, "y": 32.5}``); it
|
|
153
|
+
defaults to the box's centre. Returns whether the pointer was moved at all.
|
|
154
|
+
"""
|
|
155
|
+
mouse = getattr(page, "mouse", None)
|
|
156
|
+
move = getattr(mouse, "move", None)
|
|
157
|
+
if not callable(move) or limit_sec <= 0:
|
|
158
|
+
return False
|
|
159
|
+
try:
|
|
160
|
+
left, top = float(rect["x"]), float(rect["y"])
|
|
161
|
+
width, height = float(rect.get("width") or 0.0), float(rect.get("height") or 0.0)
|
|
162
|
+
except (AttributeError, KeyError, TypeError, ValueError):
|
|
163
|
+
return False
|
|
164
|
+
if not all(math.isfinite(value) for value in (left, top, width, height)):
|
|
165
|
+
return False
|
|
166
|
+
if width <= 0 or height <= 0:
|
|
167
|
+
return False
|
|
168
|
+
landed = point if isinstance(point, dict) else {"x": width / 2, "y": height / 2}
|
|
169
|
+
try:
|
|
170
|
+
target = (left + float(landed["x"]), top + float(landed["y"]))
|
|
171
|
+
except (KeyError, TypeError, ValueError):
|
|
172
|
+
return False
|
|
173
|
+
if not all(math.isfinite(value) for value in target):
|
|
174
|
+
return False
|
|
175
|
+
|
|
176
|
+
random_source = rng if rng is not None else random.Random()
|
|
177
|
+
until = time.monotonic() + max(0.0, limit_sec)
|
|
178
|
+
try:
|
|
179
|
+
previous = _last_point(page)
|
|
180
|
+
except TypeError: # a page object that keeps no identity
|
|
181
|
+
previous = None
|
|
182
|
+
if previous is not None and math.dist(previous, target) <= _START_DISTANCE[1] * 2:
|
|
183
|
+
# The hand is still where the last press left it: move from there, so
|
|
184
|
+
# two presses on the same box read as one hand and not two.
|
|
185
|
+
start = (previous[0] + random_source.uniform(-2.0, 2.0),
|
|
186
|
+
previous[1] + random_source.uniform(-2.0, 2.0))
|
|
187
|
+
steps = max(4, min(_STEPS[1], int(math.dist(start, target) / 10) + 4))
|
|
188
|
+
bend_share = 0.08
|
|
189
|
+
else:
|
|
190
|
+
angle = random_source.uniform(0.0, math.tau)
|
|
191
|
+
distance = random_source.uniform(*_START_DISTANCE)
|
|
192
|
+
start = (target[0] + math.cos(angle) * distance, target[1] + math.sin(angle) * distance)
|
|
193
|
+
steps = random_source.randint(*_STEPS)
|
|
194
|
+
bend_share = 0.26
|
|
195
|
+
# The hand does not travel straight: control points sit off the line by a
|
|
196
|
+
# share of the distance, then close in on the box.
|
|
197
|
+
dx, dy = target[0] - start[0], target[1] - start[1]
|
|
198
|
+
span = math.hypot(dx, dy) or 1.0
|
|
199
|
+
normal = (-dy / span, dx / span)
|
|
200
|
+
bend = random_source.uniform(-bend_share, bend_share) * span
|
|
201
|
+
c1 = (start[0] + dx * random_source.uniform(0.25, 0.45) + normal[0] * bend,
|
|
202
|
+
start[1] + dy * random_source.uniform(0.25, 0.45) + normal[1] * bend)
|
|
203
|
+
c2 = (start[0] + dx * random_source.uniform(0.60, 0.80) + normal[0] * bend * 0.4,
|
|
204
|
+
start[1] + dy * random_source.uniform(0.60, 0.80) + normal[1] * bend * 0.4)
|
|
205
|
+
|
|
206
|
+
from ..driver import Error # late: the module imports the driver's error classes
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
move(start[0], start[1], steps=1)
|
|
210
|
+
for index in range(1, steps + 1):
|
|
211
|
+
now = time.monotonic()
|
|
212
|
+
if now >= until:
|
|
213
|
+
break
|
|
214
|
+
x, y = _bezier(start, c1, c2, target, index / steps)
|
|
215
|
+
move(x + random_source.uniform(-1.0, 1.0), y + random_source.uniform(-1.0, 1.0), steps=1)
|
|
216
|
+
time.sleep(min(random_source.uniform(*_STEP_SLEEP), max(0.0, until - time.monotonic())))
|
|
217
|
+
# A path cut short still ends on the box, and the final move lands on the
|
|
218
|
+
# press point itself rather than near it: the press follows this.
|
|
219
|
+
move(target[0], target[1], steps=1)
|
|
220
|
+
time.sleep(min(random_source.uniform(*_REST_SLEEP), max(0.0, until - time.monotonic())))
|
|
221
|
+
except Error:
|
|
222
|
+
# The widget or its page went away mid-approach; the press decides.
|
|
223
|
+
return False
|
|
224
|
+
try:
|
|
225
|
+
_remember_point(page, target)
|
|
226
|
+
except TypeError:
|
|
227
|
+
pass
|
|
228
|
+
return True
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"""One bounded press on another provider's own confirmation control.
|
|
2
|
+
|
|
3
|
+
Turnstile's checkbox has its own module (``challenge_interaction``). The same
|
|
4
|
+
kind of control on the other providers' interstitials — reCAPTCHA v2's "I'm not
|
|
5
|
+
a robot", hCaptcha's checkbox, AWS WAF's "Verify you are human" button — is a
|
|
6
|
+
press the program can make as well: it starts the provider's own check and
|
|
7
|
+
answers no puzzle. A puzzle that follows is the user's, and
|
|
8
|
+
``needs_manual_verification`` hands the page over as before.
|
|
9
|
+
|
|
10
|
+
Off unless ``PAPER_SEARCH_AUTO_CONFIRM`` is ``0`` (user, 2026-11-18: the
|
|
11
|
+
control is pressed as well; only the puzzle behind it stays the user's). On a
|
|
12
|
+
page the user is watching, a press can still turn a short wait into an image
|
|
13
|
+
challenge, so the switch exists to turn it off per run. Turnstile is unaffected:
|
|
14
|
+
the program clicks its box either way.
|
|
15
|
+
|
|
16
|
+
Nothing here solves a puzzle, reads a response token, navigates, or decides
|
|
17
|
+
that verification passed.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import time
|
|
24
|
+
from typing import Any, Literal
|
|
25
|
+
from urllib.parse import urlsplit
|
|
26
|
+
|
|
27
|
+
from . import pointer
|
|
28
|
+
|
|
29
|
+
#: Provider frames and the one control each shows before any puzzle.
|
|
30
|
+
_FRAMES: tuple[tuple[str, re.Pattern[str], str], ...] = (
|
|
31
|
+
("reCAPTCHA", re.compile(r"^https://(?:www\.)?(?:google\.com|recaptcha\.net)/recaptcha/"
|
|
32
|
+
r"(?:api2|enterprise)/anchor"), "#recaptcha-anchor, .recaptcha-checkbox"),
|
|
33
|
+
("hCaptcha", re.compile(r"^https://(?:[a-z0-9-]+\.)*hcaptcha\.com/captcha/"), "#checkbox"),
|
|
34
|
+
)
|
|
35
|
+
#: AWS WAF's own button: the only control on its interstitial, and its puzzle
|
|
36
|
+
#: follows a press on it.
|
|
37
|
+
_AWS_WAF = re.compile(r"^https://[^/]*\.captcha\.awswaf\.com/")
|
|
38
|
+
_AWS_BUTTONS = ("button:has-text('Verify you are human')",
|
|
39
|
+
"button:has-text('Verify you are a human')",
|
|
40
|
+
"button:has-text('verify you are human')")
|
|
41
|
+
#: The longest one press may take, including its approach.
|
|
42
|
+
PRESS_LIMIT_SEC = 3.0
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def enabled() -> bool:
|
|
46
|
+
"""Whether pressing another provider's own confirmation control is allowed.
|
|
47
|
+
|
|
48
|
+
On unless ``PAPER_SEARCH_AUTO_CONFIRM`` is 0 (user, 2026-11-18: these
|
|
49
|
+
controls are pressed as well). Only the confirmation control is pressed —
|
|
50
|
+
the puzzle behind it stays the user's, and ``needs_manual_verification``
|
|
51
|
+
hands that over as before.
|
|
52
|
+
"""
|
|
53
|
+
value = os.environ.get("PAPER_SEARCH_AUTO_CONFIRM", "").strip().lower()
|
|
54
|
+
return value not in {"0", "false", "no", "off"}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _unchecked(control: Any) -> bool:
|
|
58
|
+
"""Not already pressed: ``aria-checked`` false, or no such attribute."""
|
|
59
|
+
try:
|
|
60
|
+
state = (control.get_attribute("aria-checked") or "").strip().lower()
|
|
61
|
+
except Exception: # noqa: BLE001 - a read that fails leaves the control alone
|
|
62
|
+
state = "true"
|
|
63
|
+
return state in {"false", ""}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _press(page: Any, control: Any, *, box: dict[str, Any] | None,
|
|
67
|
+
remaining_ms: int) -> bool:
|
|
68
|
+
"""Approach the control, then let its own actionable click press it."""
|
|
69
|
+
if box:
|
|
70
|
+
pointer.approach(page, box, limit_sec=pointer.budget_for(remaining_ms))
|
|
71
|
+
control.click(timeout=remaining_ms, no_wait_after=True)
|
|
72
|
+
return True
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def click_confirm_control(page: Any, *, timeout_ms: int, checkpoint: Any = None,
|
|
76
|
+
observation: Any = None) -> Literal["absent", "clicked", "unavailable"]:
|
|
77
|
+
"""One press on the first visible confirmation control of a known provider."""
|
|
78
|
+
from ..driver import Error, TimeoutError
|
|
79
|
+
|
|
80
|
+
def note(reason: str) -> None:
|
|
81
|
+
if observation is not None:
|
|
82
|
+
observation(reason)
|
|
83
|
+
|
|
84
|
+
until = time.monotonic() + max(0.0, timeout_ms) / 1000
|
|
85
|
+
unavailable = False
|
|
86
|
+
frames = getattr(page, "frames", ())
|
|
87
|
+
frames = frames if isinstance(frames, (list, tuple)) else ()
|
|
88
|
+
for frame in frames:
|
|
89
|
+
if checkpoint is not None:
|
|
90
|
+
checkpoint()
|
|
91
|
+
if time.monotonic() >= until:
|
|
92
|
+
return "unavailable" if unavailable else "absent"
|
|
93
|
+
url = str(getattr(frame, "url", "") or "")
|
|
94
|
+
for name, pattern, selector in _FRAMES:
|
|
95
|
+
if not pattern.search(url):
|
|
96
|
+
continue
|
|
97
|
+
try:
|
|
98
|
+
controls = frame.locator(selector)
|
|
99
|
+
count = controls.count()
|
|
100
|
+
if not count:
|
|
101
|
+
continue
|
|
102
|
+
control = controls.first
|
|
103
|
+
if not control.is_visible() or not control.is_enabled() or not _unchecked(control):
|
|
104
|
+
note(f"{name}: not actionable")
|
|
105
|
+
unavailable = True
|
|
106
|
+
continue
|
|
107
|
+
remaining_ms = int((until - time.monotonic()) * 1000)
|
|
108
|
+
if remaining_ms <= 0:
|
|
109
|
+
return "unavailable"
|
|
110
|
+
_press(page, control, box=control.bounding_box(), remaining_ms=remaining_ms)
|
|
111
|
+
note(f"{name}: control pressed")
|
|
112
|
+
return "clicked"
|
|
113
|
+
except TimeoutError:
|
|
114
|
+
note(f"{name}: actionability timeout")
|
|
115
|
+
unavailable = True
|
|
116
|
+
except Error as exc:
|
|
117
|
+
if any(text in str(exc).lower() for text in (
|
|
118
|
+
"frame was detached", "frame has been detached", "element is not attached",
|
|
119
|
+
"execution context was destroyed")):
|
|
120
|
+
unavailable = True
|
|
121
|
+
continue
|
|
122
|
+
raise
|
|
123
|
+
|
|
124
|
+
# AWS WAF puts its button on the outer page, not in a provider frame.
|
|
125
|
+
try:
|
|
126
|
+
on_aws = any(_AWS_WAF.match(str(script.get_attribute("src") or ""))
|
|
127
|
+
for script in page.locator("script[src]").all())
|
|
128
|
+
except (Error, AttributeError, TypeError):
|
|
129
|
+
on_aws = False
|
|
130
|
+
if not on_aws:
|
|
131
|
+
return "unavailable" if unavailable else "absent"
|
|
132
|
+
for selector in _AWS_BUTTONS:
|
|
133
|
+
if time.monotonic() >= until:
|
|
134
|
+
return "unavailable"
|
|
135
|
+
try:
|
|
136
|
+
buttons = page.locator(selector)
|
|
137
|
+
if not buttons.count():
|
|
138
|
+
continue
|
|
139
|
+
button = buttons.first
|
|
140
|
+
if not button.is_visible() or not button.is_enabled():
|
|
141
|
+
continue
|
|
142
|
+
remaining_ms = int((until - time.monotonic()) * 1000)
|
|
143
|
+
if remaining_ms <= 0:
|
|
144
|
+
return "unavailable"
|
|
145
|
+
_press(page, button, box=button.bounding_box(), remaining_ms=remaining_ms)
|
|
146
|
+
note("AWS WAF: control pressed")
|
|
147
|
+
return "clicked"
|
|
148
|
+
except TimeoutError:
|
|
149
|
+
unavailable = True
|
|
150
|
+
except Error as exc:
|
|
151
|
+
if not any(text in str(exc).lower() for text in ("element is not attached",)):
|
|
152
|
+
raise
|
|
153
|
+
unavailable = True
|
|
154
|
+
return "unavailable" if unavailable else "absent"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Visit a site's own root once per run before opening its articles.
|
|
2
|
+
|
|
3
|
+
Cloudflare grants two kinds of clearance (developers.cloudflare.com, read
|
|
4
|
+
2026-11-18): challenge clearance from passing a check, and precursor clearance
|
|
5
|
+
that it keeps updating from session behaviour. A browser that arrives straight
|
|
6
|
+
at a deep article URL has neither — the site sees a session that began at the
|
|
7
|
+
article. Opening the root first gives it a first-party document to read before
|
|
8
|
+
the article, which is what the published warm-up implementations do
|
|
9
|
+
(patchright-docker's ``--warmup``, curlwright's stealth warm-up).
|
|
10
|
+
|
|
11
|
+
Nothing here waits for verification, clicks a control, or decides access: a
|
|
12
|
+
root visit that ends on a challenge is left alone and the existing verification
|
|
13
|
+
wait on the article page handles it. The root opens in its own tab and that tab
|
|
14
|
+
is closed again, so the article's page and its listeners are untouched.
|
|
15
|
+
|
|
16
|
+
The browser is the same one the download already uses (the user's Chrome or the
|
|
17
|
+
user's ego over the same Patchright driver), never a second browser.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from collections.abc import Iterable
|
|
22
|
+
from typing import Any
|
|
23
|
+
from urllib.parse import urlsplit
|
|
24
|
+
|
|
25
|
+
#: Longest root visit. The article keeps its own 60 s navigation budget.
|
|
26
|
+
WARMUP_TIMEOUT_MS = 12_000
|
|
27
|
+
#: Time the root page gets after its document is parsed, for the site's own
|
|
28
|
+
#: scripts (challenge platform included) to run once.
|
|
29
|
+
SETTLE_MS = 600
|
|
30
|
+
|
|
31
|
+
#: Sites whose root was already visited in this process. One visit per site is
|
|
32
|
+
#: the point: a second one in the same session adds nothing Cloudflare reads.
|
|
33
|
+
_visited: set[str] = set()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def site_root(url: str) -> str:
|
|
37
|
+
"""``https://host/`` for a page URL, or "" when the URL has no usable site."""
|
|
38
|
+
parsed = urlsplit(str(url or ""))
|
|
39
|
+
if parsed.scheme not in {"http", "https"} or not parsed.hostname:
|
|
40
|
+
return ""
|
|
41
|
+
return f"{parsed.scheme}://{parsed.netloc}/"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def reset(hosts: Iterable[str] | None = None) -> None:
|
|
45
|
+
"""Forget the visited sites (tests, or a new download run)."""
|
|
46
|
+
_visited.clear() if hosts is None else _visited.difference_update(
|
|
47
|
+
host.lower() for host in hosts)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def warm(page: Any, url: str, *, timeout_ms: int = WARMUP_TIMEOUT_MS,
|
|
51
|
+
settle_ms: int = SETTLE_MS) -> str:
|
|
52
|
+
"""Visit the site root of ``url`` once; ``warmed``, ``skipped`` or ``failed``.
|
|
53
|
+
|
|
54
|
+
``skipped`` covers a URL without a site and a site already visited. A visit
|
|
55
|
+
that raises is ``failed`` and the download continues: this is an extra
|
|
56
|
+
first-party document, not a step the article depends on. Watchdog and
|
|
57
|
+
cancellation errors still reach the caller.
|
|
58
|
+
"""
|
|
59
|
+
from .. import watchdog
|
|
60
|
+
|
|
61
|
+
root = site_root(url)
|
|
62
|
+
if not root:
|
|
63
|
+
return "skipped"
|
|
64
|
+
site = urlsplit(root).netloc.lower()
|
|
65
|
+
if site in _visited:
|
|
66
|
+
return "skipped"
|
|
67
|
+
_visited.add(site)
|
|
68
|
+
|
|
69
|
+
context = getattr(page, "context", None)
|
|
70
|
+
open_tab = getattr(context, "new_page", None)
|
|
71
|
+
if not callable(open_tab):
|
|
72
|
+
return "skipped"
|
|
73
|
+
|
|
74
|
+
tab: Any = None
|
|
75
|
+
try:
|
|
76
|
+
tab = open_tab()
|
|
77
|
+
tab.goto(root, wait_until="domcontentloaded", timeout=max(1_000, timeout_ms))
|
|
78
|
+
if settle_ms > 0:
|
|
79
|
+
tab.wait_for_timeout(settle_ms)
|
|
80
|
+
return "warmed"
|
|
81
|
+
except Exception as exc: # noqa: BLE001 - the article's own navigation decides
|
|
82
|
+
if isinstance(exc, (watchdog.CallAbandoned, watchdog.BrowserUnresponsive)):
|
|
83
|
+
raise
|
|
84
|
+
return "failed"
|
|
85
|
+
finally:
|
|
86
|
+
try:
|
|
87
|
+
if tab is not None and not tab.is_closed():
|
|
88
|
+
tab.close()
|
|
89
|
+
except Exception: # noqa: BLE001 - a tab that will not close is not the article's problem
|
|
90
|
+
pass
|
|
@@ -22,6 +22,18 @@ def is_driver_error(exc: BaseException, name: str = "") -> bool:
|
|
|
22
22
|
return type(exc).__module__.startswith("patchright.") and (not name or type(exc).__name__ == name)
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
#: What a call says once the driver process is gone: the call it was answering, then
|
|
26
|
+
#: every later call of the process (builtin Exception and RuntimeError, not the
|
|
27
|
+
#: driver's own classes). Windows, 2026-11-18: after 753 Cell papers the driver and
|
|
28
|
+
#: its Chrome were gone, and 88 papers failed within a second each.
|
|
29
|
+
_DRIVER_GONE = ("Connection closed while reading from the driver", "no running event loop")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def driver_lost(exc: BaseException) -> bool:
|
|
33
|
+
"""The connection to the driver is gone: no call of this process reaches a browser again."""
|
|
34
|
+
return any(words in str(exc) for words in _DRIVER_GONE)
|
|
35
|
+
|
|
36
|
+
|
|
25
37
|
def sync_bases() -> list[type]:
|
|
26
38
|
"""The SyncBase classes whose calls the watchdog times."""
|
|
27
39
|
from patchright._impl import _sync_base
|
|
@@ -12,13 +12,18 @@ import re
|
|
|
12
12
|
import time
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
from typing import Any
|
|
15
|
+
from urllib.parse import urlparse
|
|
15
16
|
|
|
16
17
|
logger = logging.getLogger(__name__)
|
|
17
18
|
PROFILE_RELEASE_TIMEOUT_SEC = 20.0
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
SESSION_COOKIES_FILE = ".paper-search-session-cookies.json"
|
|
21
|
-
|
|
22
|
+
# How long a saved school login is restored (config: browser_login_session_max_age_hours).
|
|
23
|
+
# Each paper runs in its own browser, so a session cookie lives on only through this file;
|
|
24
|
+
# the school's server decides when the login really ends, and one it still accepts should
|
|
25
|
+
# outlast the night (user, 2026-11-19; it was 12 hours).
|
|
26
|
+
SESSION_COOKIES_MAX_AGE_SEC = 30 * 24 * 3600
|
|
22
27
|
|
|
23
28
|
|
|
24
29
|
def _save_session_cookies(context: Any, profile: Path) -> None:
|
|
@@ -47,13 +52,13 @@ def _save_session_cookies(context: Any, profile: Path) -> None:
|
|
|
47
52
|
logger.debug("browser_backend: session cookies not saved: %s", type(exc).__name__)
|
|
48
53
|
|
|
49
54
|
|
|
50
|
-
def _restore_session_cookies(context: Any, profile: Path) -> int:
|
|
55
|
+
def _restore_session_cookies(context: Any, profile: Path, max_age_sec: float = SESSION_COOKIES_MAX_AGE_SEC) -> int:
|
|
51
56
|
path = profile / SESSION_COOKIES_FILE
|
|
52
57
|
try:
|
|
53
58
|
data = json.loads(path.read_text(encoding="utf-8"))
|
|
54
59
|
except Exception:
|
|
55
60
|
return 0
|
|
56
|
-
if time.time() - float(data.get("saved_at", 0)) >
|
|
61
|
+
if time.time() - float(data.get("saved_at", 0)) > max_age_sec:
|
|
57
62
|
return 0
|
|
58
63
|
restored = 0
|
|
59
64
|
for cookie in data.get("cookies") or []:
|
|
@@ -65,6 +70,52 @@ def _restore_session_cookies(context: Any, profile: Path) -> int:
|
|
|
65
70
|
return restored
|
|
66
71
|
|
|
67
72
|
|
|
73
|
+
def school_login_hosts(config: dict[str, Any] | None) -> tuple[set[str], set[str]]:
|
|
74
|
+
"""The saved school's login hosts (its entityID's host, those its federation lists) and its
|
|
75
|
+
own domains (``schools/lookup.py``): where its sign-in keeps its cookies, whatever it runs
|
|
76
|
+
(Shibboleth, CAS, ADFS) and whatever it names them."""
|
|
77
|
+
from ..schools import lookup as schools
|
|
78
|
+
|
|
79
|
+
cfg = config or {}
|
|
80
|
+
return set(schools.login_hosts(cfg)), set(schools.domains(cfg))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def cross_site_login(context: Any, hosts: set[str], domains: set[str] = frozenset()) -> int:
|
|
84
|
+
"""The school's login cookies sent with a publisher's SAML POST too: those of its login
|
|
85
|
+
hosts (and of the hosts above them) and of its own domains, re-set as SameSite=None (and
|
|
86
|
+
Secure: these sites are https). A sign-in that sets them without SameSite gets Lax from the
|
|
87
|
+
browser, which leaves them out of the cross-site POST many publishers reach it with, and
|
|
88
|
+
the school then asked for the password again at each such publisher: Nature, Taylor &
|
|
89
|
+
Francis and Science did, ScienceDirect, JAMA and ACS (a redirect) did not (a school tested,
|
|
90
|
+
2026-11-19). Only this download browser's, and only the school's side. How many were re-set."""
|
|
91
|
+
hosts = {h.lower() for h in hosts if h}
|
|
92
|
+
domains = {d.lower().lstrip(".") for d in domains if d}
|
|
93
|
+
if not hosts and not domains:
|
|
94
|
+
return 0
|
|
95
|
+
try:
|
|
96
|
+
cookies = context.cookies()
|
|
97
|
+
except Exception:
|
|
98
|
+
return 0
|
|
99
|
+
|
|
100
|
+
def the_idps(cookie: dict[str, Any]) -> bool:
|
|
101
|
+
domain = str(cookie.get("domain") or "").lstrip(".").lower()
|
|
102
|
+
return bool(domain) and (any(host == domain or host.endswith("." + domain) for host in hosts)
|
|
103
|
+
or any(domain == d or domain.endswith("." + d) for d in domains))
|
|
104
|
+
|
|
105
|
+
changed = 0
|
|
106
|
+
for cookie in cookies:
|
|
107
|
+
if not the_idps(cookie) or cookie.get("sameSite") == "None":
|
|
108
|
+
continue
|
|
109
|
+
entry = {k: v for k, v in cookie.items() if k != "expires" or v not in (None, -1)}
|
|
110
|
+
entry.update(sameSite="None", secure=True)
|
|
111
|
+
try:
|
|
112
|
+
context.add_cookies([entry])
|
|
113
|
+
changed += 1
|
|
114
|
+
except Exception as exc:
|
|
115
|
+
logger.debug("browser_backend: login cookie %s not re-set: %s", cookie.get("name"), type(exc).__name__)
|
|
116
|
+
return changed
|
|
117
|
+
|
|
118
|
+
|
|
68
119
|
def _profile_owner_pid(user_data_dir: str) -> int | None:
|
|
69
120
|
"""PID of the browser holding this profile, if any: Chromium's
|
|
70
121
|
``SingletonLock`` symlink to ``<host>-<pid>`` (macOS and Linux)."""
|
|
@@ -149,6 +149,14 @@ def operation(seconds: float, label: str):
|
|
|
149
149
|
stack.pop()
|
|
150
150
|
|
|
151
151
|
|
|
152
|
+
def extend_operation(seconds: float) -> None:
|
|
153
|
+
"""Data still arriving (a large PDF read in pieces): every enclosing budget lasts at
|
|
154
|
+
least ``seconds`` more. Calls already sent keep the deadline they were sent with."""
|
|
155
|
+
until = time.monotonic() + seconds
|
|
156
|
+
for budget in getattr(_local, "budgets", []):
|
|
157
|
+
budget[0] = max(budget[0], until)
|
|
158
|
+
|
|
159
|
+
|
|
152
160
|
def operation_remaining() -> float | None:
|
|
153
161
|
"""Remaining automation time, so a human handoff can happen before expiry."""
|
|
154
162
|
budgets = getattr(_local, "budgets", [])
|