Fix project isolation: Make loadChatHistory respect active project sessions
- Modified loadChatHistory() to check for active project before fetching all sessions - When active project exists, use project.sessions instead of fetching from API - Added detailed console logging to debug session filtering - This prevents ALL sessions from appearing in every project's sidebar Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
43
.agent/metrics/metrics_20260122_120416.json
Normal file
43
.agent/metrics/metrics_20260122_120416.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 286.2897081375122,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:04:16.962058",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you create a SuperCharged Claude Code package. Let me start by checking the scratchpad and then exploring the current setup.Let me continue exploring the customizations and check the Ralph wrapper script:Now let me create a workspace and start building the package. First, let me create the scratchpad to track progress:Now let me start building the package structure. I'll create the packaging directory and start copying files:Now let me create a sanitized settings.json template and star",
|
||||
"tokens_used": 77686,
|
||||
"cost": 0.41950200000000004,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.41950200000000004,
|
||||
"by_tool": {
|
||||
"claude": 0.41950200000000004
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769083456.9416454,
|
||||
"tool": "claude",
|
||||
"input_tokens": 62149,
|
||||
"output_tokens": 15537,
|
||||
"cost": 0.41950200000000004
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 286.2897081375122,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_121823.json
Normal file
43
.agent/metrics/metrics_20260122_121823.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 411.8341362476349,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:18:23.593223",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you update the WordPress blog post to showcase the new SuperCharged Claude Code Upgrade repository. Let me start by checking for a scratchpad and then begin the work.Good! I can see from the scratchpad that the SuperCharged Claude Code package has been created with all the customizations. Now I need to update the WordPress blog post. Let me start by fetching the current blog post content to understand its structure.Perfect! I can see the current blog post structure. Now let me fetch in",
|
||||
"tokens_used": 87596,
|
||||
"cost": 0.473016,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.473016,
|
||||
"by_tool": {
|
||||
"claude": 0.473016
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769084303.5776978,
|
||||
"tool": "claude",
|
||||
"input_tokens": 70077,
|
||||
"output_tokens": 17519,
|
||||
"cost": 0.473016
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 411.8341362476349,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_122834.json
Normal file
43
.agent/metrics/metrics_20260122_122834.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 60.5629768371582,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:28:34.360554",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you fix the missing close buttons on the session/project tabs. Let me start by checking the scratchpad and exploring the codebase.Good! I found the files. The scratchpad shows previous work on a different task, so I'll start fresh on this close button task. Let me explore these files to understand the current implementation.Perfect! I can see the issue now. Let me analyze what I found:\n\n**Analysis:**\n1. **Session tabs (Level 2)**: Already have close buttons! Line 100 in `session-tabs.j",
|
||||
"tokens_used": 63630,
|
||||
"cost": 0.343602,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.343602,
|
||||
"by_tool": {
|
||||
"claude": 0.343602
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769084914.3426394,
|
||||
"tool": "claude",
|
||||
"input_tokens": 50904,
|
||||
"output_tokens": 12726,
|
||||
"cost": 0.343602
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 60.5629768371582,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_123611.json
Normal file
43
.agent/metrics/metrics_20260122_123611.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 120.01204371452332,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:36:11.499904",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you fix the session close button issue by replacing the blocking `confirm()` dialog with a non-blocking custom modal. Let me start by checking the scratchpad and then exploring the codebase.I can see from the scratchpad that previous work was done on adding close buttons to project tabs. However, the current task is specifically about fixing the **session close button** that's broken because the browser blocked the `confirm()` dialog. Let me explore the session-tabs.js file to understa",
|
||||
"tokens_used": 81501,
|
||||
"cost": 0.44010299999999997,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.44010299999999997,
|
||||
"by_tool": {
|
||||
"claude": 0.44010299999999997
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085371.4782748,
|
||||
"tool": "claude",
|
||||
"input_tokens": 65201,
|
||||
"output_tokens": 16300,
|
||||
"cost": 0.44010299999999997
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 120.01204371452332,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_123628.json
Normal file
43
.agent/metrics/metrics_20260122_123628.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 234.6205906867981,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:36:28.303076",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you fix the WordPress blog post issues. Let me start by checking the scratchpad and then examining the current state of the files.Good! I can see the scratchpad contains a different task (Claude IDE tab close buttons), so this is a fresh start. Now let me check the actual blog post to understand the issues:Let me get more details about the actual CTA buttons and check the full HTML:Now let me check for all the CTA buttons and potential contrast issues:Now let me check the actual render",
|
||||
"tokens_used": 71132,
|
||||
"cost": 0.384108,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.384108,
|
||||
"by_tool": {
|
||||
"claude": 0.384108
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085388.286653,
|
||||
"tool": "claude",
|
||||
"input_tokens": 56906,
|
||||
"output_tokens": 14226,
|
||||
"cost": 0.384108
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 234.6205906867981,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_123704.json
Normal file
43
.agent/metrics/metrics_20260122_123704.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 82.89949440956116,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:37:04.146861",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll start by reading the prompt file and checking for any scratchpad to understand the current state.I see the scratchpad contains information about a different task (Claude IDE session close button). This is a new task about fixing WordPress blog post CTA buttons. Let me start fresh for this new task.\n\nLet me first explore the WordPress installation and understand the post structure.I can see the post content. Looking at the final CTA section, I need to:\n1. Change the \"Get Free Suite\" button l",
|
||||
"tokens_used": 51576,
|
||||
"cost": 0.278508,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.278508,
|
||||
"by_tool": {
|
||||
"claude": 0.278508
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085424.1294374,
|
||||
"tool": "claude",
|
||||
"input_tokens": 41261,
|
||||
"output_tokens": 10315,
|
||||
"cost": 0.278508
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 82.89949440956116,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_123858.json
Normal file
43
.agent/metrics/metrics_20260122_123858.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 92.9218270778656,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:38:58.712792",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll start by checking the scratchpad to see if there's any previous progress, then begin working on this task.I can see from the scratchpad that a previous task was completed (CTA button fixes), but the current task is different. Let me read the PROMPT.md file to understand the current task:Let me check the actual task context and read the scratchpad more carefully. The current task is about fixing installation instructions in the WordPress blog post:Now let me understand the current task. The ",
|
||||
"tokens_used": 50880,
|
||||
"cost": 0.274752,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.274752,
|
||||
"by_tool": {
|
||||
"claude": 0.274752
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085538.6974664,
|
||||
"tool": "claude",
|
||||
"input_tokens": 40704,
|
||||
"output_tokens": 10176,
|
||||
"cost": 0.274752
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 92.9218270778656,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_124104.json
Normal file
43
.agent/metrics/metrics_20260122_124104.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 130.0527069568634,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:41:04.926101",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you fix the tab persistence issue in the Claude IDE. Let me start by reading the prompt file and checking for any existing scratchpad.I can see there's an old scratchpad from a previous task. Let me create a new scratchpad for this task and start exploring the codebase to understand the tab persistence issue.Perfect! Let me read the relevant files to understand the current implementation:Now I understand the issue. The closed tabs are not persisted to localStorage, so when the page ref",
|
||||
"tokens_used": 84911,
|
||||
"cost": 0.45851699999999995,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.45851699999999995,
|
||||
"by_tool": {
|
||||
"claude": 0.45851699999999995
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085664.9097311,
|
||||
"tool": "claude",
|
||||
"input_tokens": 67929,
|
||||
"output_tokens": 16982,
|
||||
"cost": 0.45851699999999995
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 130.0527069568634,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_124418.json
Normal file
43
.agent/metrics/metrics_20260122_124418.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 158.59392142295837,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:44:18.011239",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you review and improve the 'Alternative: Ralph Global CLI' section in the WordPress blog post. Let me start by checking the scratchpad and then examining the current content.I can see this is a different task. Let me check the WordPress database to get the post content for Post ID 19.Let me try using WP-CLI instead:Let me try accessing the blog post directly via the web:**\ud83c\udf10 Z.ai Built-in Tool: webReader**\n\n**Input:**\n```json\n{\"url\":\"https://www.rommark.dev/blog/2026/01/15/ultimate-clau",
|
||||
"tokens_used": 70358,
|
||||
"cost": 0.379926,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.379926,
|
||||
"by_tool": {
|
||||
"claude": 0.379926
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769085857.9904943,
|
||||
"tool": "claude",
|
||||
"input_tokens": 56287,
|
||||
"output_tokens": 14071,
|
||||
"cost": 0.379926
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 158.59392142295837,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_124818.json
Normal file
43
.agent/metrics/metrics_20260122_124818.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 290.6224524974823,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:48:18.654912",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll help you fix the text contrast issues on the WordPress blog post. Let me start by checking the scratchpad and understanding the current state.I can see the scratchpad contains a previous task. Let me now focus on the current task - fixing text contrast issues on the WordPress blog post. The main issue mentioned is the 'Ready to Transform Your Development Workflow' heading not being visible.\n\nLet me analyze the current styles and fetch the actual post content to identify ALL text with poor c",
|
||||
"tokens_used": 74312,
|
||||
"cost": 0.40127999999999997,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.40127999999999997,
|
||||
"by_tool": {
|
||||
"claude": 0.40127999999999997
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769086098.6375349,
|
||||
"tool": "claude",
|
||||
"input_tokens": 59450,
|
||||
"output_tokens": 14862,
|
||||
"cost": 0.40127999999999997
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 290.6224524974823,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
43
.agent/metrics/metrics_20260122_125000.json
Normal file
43
.agent/metrics/metrics_20260122_125000.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 1,
|
||||
"successful": 1,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"duration": 24.534838438034058,
|
||||
"success": true,
|
||||
"error": "",
|
||||
"timestamp": "2026-01-22T12:50:00.098429",
|
||||
"trigger_reason": "initial",
|
||||
"output_preview": "I'll start by reading the scratchpad to see what's already been accomplished, then verify the current state of the work.Based on the scratchpad and current styles file, I can see that all the text contrast fixes have already been implemented. Let me verify the current state by fetching the live page to confirm all changes are working:The page content shows the blog post is rendering. Looking at the scratchpad, I can see that:\n\n1. **Iteration 1** - Analysis was completed \u2705\n2. **Iteration 2** - Im",
|
||||
"tokens_used": 47241,
|
||||
"cost": 0.255099,
|
||||
"tools_used": []
|
||||
}
|
||||
],
|
||||
"cost": {
|
||||
"total": 0.255099,
|
||||
"by_tool": {
|
||||
"claude": 0.255099
|
||||
},
|
||||
"history": [
|
||||
{
|
||||
"timestamp": 1769086200.0856762,
|
||||
"tool": "claude",
|
||||
"input_tokens": 37793,
|
||||
"output_tokens": 9448,
|
||||
"cost": 0.255099
|
||||
}
|
||||
]
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 24.534838438034058,
|
||||
"success_rate": 100.0
|
||||
}
|
||||
}
|
||||
20
.agent/metrics/metrics_20260122_125036.json
Normal file
20
.agent/metrics/metrics_20260122_125036.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 0,
|
||||
"successful": 0,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [],
|
||||
"cost": {
|
||||
"total": 0.0,
|
||||
"by_tool": {},
|
||||
"history": []
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 0.0,
|
||||
"success_rate": 0.0
|
||||
}
|
||||
}
|
||||
20
.agent/metrics/metrics_20260122_125049.json
Normal file
20
.agent/metrics/metrics_20260122_125049.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 0,
|
||||
"successful": 0,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [],
|
||||
"cost": {
|
||||
"total": 0.0,
|
||||
"by_tool": {},
|
||||
"history": []
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 0.0,
|
||||
"success_rate": 0.0
|
||||
}
|
||||
}
|
||||
20
.agent/metrics/metrics_20260122_125103.json
Normal file
20
.agent/metrics/metrics_20260122_125103.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"summary": {
|
||||
"iterations": 0,
|
||||
"successful": 0,
|
||||
"failed": 0,
|
||||
"errors": 0,
|
||||
"checkpoints": 0,
|
||||
"rollbacks": 0
|
||||
},
|
||||
"iterations": [],
|
||||
"cost": {
|
||||
"total": 0.0,
|
||||
"by_tool": {},
|
||||
"history": []
|
||||
},
|
||||
"analysis": {
|
||||
"avg_iteration_duration": 0.0,
|
||||
"success_rate": 0.0
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,60 @@
|
||||
# Claude IDE Tab Close Buttons - Scratchpad
|
||||
# Project Isolation Bug - Scratchpad
|
||||
|
||||
## Task Overview
|
||||
Fix the missing 'x' close button on session/project tabs in the Claude IDE.
|
||||
Issue URL: https://rommark.dev/claude/ide/session/session-1769083280612-mdof554ot
|
||||
Fix project isolation bug where ALL sessions appear in every project's left sidebar instead of only that project's sessions.
|
||||
|
||||
## Files to Modify
|
||||
- /home/uroma/obsidian-web-interface/public/claude-ide/project-manager.js (main logic)
|
||||
- /home/uroma/obsidian-web-interface/public/claude-ide/chat-enhanced.js (left sidebar)
|
||||
|
||||
## Root Cause Analysis
|
||||
|
||||
After analyzing the code:
|
||||
|
||||
1. **project-manager.js line 365**: `switchProject()` calls `loadChatHistory(project.sessions)` - this passes the correct sessions
|
||||
2. **chat-enhanced.js line 52**: `loadChatHistory()` accepts `sessionsToRender` parameter
|
||||
3. **BUT** - When `loadChatHistory()` is called without parameters (initial load), it fetches ALL sessions from API
|
||||
|
||||
The issue: The left sidebar `loadChatHistory` function is being called in multiple places:
|
||||
1. Initial page load (no filter) - loads ALL sessions
|
||||
2. When switching projects (with filter) - should load only project sessions
|
||||
3. When sessions are created/updated
|
||||
|
||||
The problem is that `loadChatHistory` caches and reuses all sessions, and the filtering mechanism isn't working correctly.
|
||||
|
||||
## Progress
|
||||
|
||||
### Iteration 1 - Add Close Buttons to Project Tabs - COMPLETED
|
||||
### Iteration 1 - Analysis - COMPLETED ✅
|
||||
- Read all relevant files
|
||||
- Identified the root cause
|
||||
- Created fix plan
|
||||
|
||||
**Discovery:**
|
||||
- Session tabs (Level 2) already had close buttons implemented in session-tabs.js line 100
|
||||
- Project tabs (Level 1) were missing close buttons entirely
|
||||
### Next Steps
|
||||
1. Fix `loadChatHistory` to properly filter by project
|
||||
2. Ensure sessions are tracked per project correctly
|
||||
3. Test the fix
|
||||
|
||||
**Changes Made:**
|
||||
## Detailed Root Cause
|
||||
|
||||
1. **project-manager.js** - Added close button to project tabs:
|
||||
- Modified `renderProjectTab()` to include close button element (line 192)
|
||||
- Added `closeProject()` method with confirmation dialog
|
||||
- Added `getSessionName()` helper method for displaying session names in confirmation
|
||||
- Close button removes project tab but keeps sessions accessible
|
||||
- Auto-switches to next available project when active project is closed
|
||||
Looking at `chat-enhanced.js` lines 64-81:
|
||||
```javascript
|
||||
if (sessionsToRender) {
|
||||
// Use provided sessions (for project filtering)
|
||||
allSessions = sessionsToRender;
|
||||
} else {
|
||||
// Fetch all sessions from API
|
||||
const res = await fetch('/claude/api/claude/sessions');
|
||||
// ... loads ALL sessions
|
||||
}
|
||||
```
|
||||
|
||||
2. **project-tabs.css** - Added styling for project tab close buttons:
|
||||
- Added `.project-tab .tab-close` styles (lines 101-122)
|
||||
- Close button hidden by default, shows on hover
|
||||
- Red highlight on hover with rotation effect
|
||||
- Added mobile responsive styles to always show close button on small screens
|
||||
The problem: When `loadChatHistory()` is called from `switchProject()` with `project.sessions`, it correctly uses those sessions. BUT there are other calls to `loadChatHistory()` throughout the code that don't pass the filter parameter, causing all sessions to load.
|
||||
|
||||
**Implementation Details:**
|
||||
- Close button uses × (multiplication sign) character
|
||||
- Click event stops propagation to prevent triggering project switch
|
||||
- Confirmation dialog shows session count and list for non-empty projects
|
||||
- Graceful handling when last project is closed (shows empty state)
|
||||
Also, the session tabs (`window.sessionTabs.setSessions`) are correctly updated but the left sidebar isn't properly isolated.
|
||||
|
||||
## Next Steps
|
||||
- Test the implementation in browser
|
||||
- Verify close buttons work on both project and session tabs
|
||||
- Ensure responsive behavior on mobile devices
|
||||
## Solution
|
||||
|
||||
## Files Modified
|
||||
- /home/uroma/obsidian-web-interface/public/claude-ide/project-manager.js
|
||||
- /home/uroma/obsidian-web-interface/public/claude-ide/project-tabs.css
|
||||
|
||||
## Files Verified (No Changes Needed)
|
||||
- /home/uroma/obsidian-web-interface/public/claude-ide/session-tabs.js (already had close buttons)
|
||||
The fix needs to:
|
||||
1. Make `loadChatHistory` always respect the current project's sessions
|
||||
2. Track which project is active globally
|
||||
3. Filter sessions by the active project's workingDir or project ID
|
||||
|
||||
215
.ralph/PROMPT.md
Normal file
215
.ralph/PROMPT.md
Normal file
@@ -0,0 +1,215 @@
|
||||
# Task: Fix ALL Color Contrast Issues on WordPress Blog Post with UX Expertise
|
||||
|
||||
## Context
|
||||
|
||||
User reports there are STILL contrast issues on the WordPress blog post:
|
||||
https://www.rommark.dev/blog/2026/01/15/ultimate-claude-code-glm-suite-40-agents-mcp-tools-complete-automation/
|
||||
|
||||
Previous attempt fixed some issues but user says "still contrasting issue" - meaning there are MORE problems that weren't caught.
|
||||
|
||||
### What Was Fixed Previously
|
||||
|
||||
1. `.claude-hero p` - Changed opacity to explicit white
|
||||
2. `.claude-badge` - Added explicit white color
|
||||
3. `.claude-stat-number` - Added explicit white color
|
||||
4. `.claude-stat-label` - Changed opacity to explicit white
|
||||
5. `.final-cta p` - Added !important flags
|
||||
|
||||
### Issues That May Remain
|
||||
|
||||
- Inline styles in HTML content that override CSS
|
||||
- Other elements with opacity values not caught
|
||||
- Gradient backgrounds with poor text contrast
|
||||
- Link colors on colored backgrounds
|
||||
- Code blocks with poor contrast
|
||||
- Button hover states
|
||||
- Mobile responsive styles
|
||||
- Elements not covered by the existing CSS
|
||||
|
||||
## Your Role
|
||||
|
||||
You are a **UX Design Specialist** who will:
|
||||
1. **Analyze the entire page** for ALL contrast issues
|
||||
2. **Use UX expertise** to identify elements humans would miss
|
||||
3. **Test every text element** against its background
|
||||
4. **Fix both CSS AND HTML** (inline styles)
|
||||
5. **Verify live on the site** after fixes
|
||||
6. **Use WCAG AA standards** (4.5:1 for normal text, 3:1 for large text)
|
||||
|
||||
## Success Criteria
|
||||
|
||||
The task is complete when:
|
||||
- [ ] ALL text elements meet WCAG AA contrast standards
|
||||
- [ ] No inline opacity styles remain in HTML
|
||||
- [ ] All gradients have sufficient contrast with text
|
||||
- [ ] Links are readable on all backgrounds
|
||||
- [ ] Buttons have proper contrast in all states
|
||||
- [ ] Mobile responsive styles have proper contrast
|
||||
- [ ] User confirms no more contrast issues
|
||||
- [ ] Changes verified live on the website
|
||||
|
||||
## Investigation Process
|
||||
|
||||
### Step 1: Fetch Live Page Content
|
||||
|
||||
```bash
|
||||
# Get the full HTML of the live page
|
||||
curl -s "https://www.rommark.dev/blog/2026/01/15/ultimate-claude-code-glm-suite-40-agents-mcp-tools-complete-automation/" > /tmp/live_page.html
|
||||
|
||||
# Search for ALL inline styles with opacity/color
|
||||
grep -o 'style="[^"]*opacity[^"]*"' /tmp/live_page.html
|
||||
grep -o 'style="[^"]*color[^"]*"' /tmp/live_page.html
|
||||
```
|
||||
|
||||
### Step 2: Analyze CSS File
|
||||
|
||||
```bash
|
||||
# Current styles location
|
||||
CSS_FILE="/var/www/blog/wp-content/themes/rommark-v2/post-19-styles.php"
|
||||
|
||||
# Find ALL color/opacity declarations
|
||||
grep -n "color:\|opacity:" $CSS_FILE
|
||||
|
||||
# Find ALL background declarations
|
||||
grep -n "background:" $CSS_FILE
|
||||
```
|
||||
|
||||
### Step 3: Use UX/Design Agent for Analysis
|
||||
|
||||
Use the Task tool with `ui-ux-pro-max` agent to:
|
||||
1. Analyze the page visually
|
||||
2. Identify ALL contrast issues
|
||||
3. Suggest proper color combinations
|
||||
4. Ensure accessibility compliance
|
||||
|
||||
### Step 4: Fix Issues Systematically
|
||||
|
||||
For each contrast issue:
|
||||
1. Identify the element
|
||||
2. Calculate contrast ratio
|
||||
3. Fix in CSS file (or HTML if inline)
|
||||
4. Test on live site
|
||||
5. Move to next issue
|
||||
|
||||
## Common Contrast Issues to Check
|
||||
|
||||
### 1. White/Light Text on Light Backgrounds
|
||||
```css
|
||||
/* BAD */
|
||||
background: #f0f0f0;
|
||||
color: #ffffff; /* Contrast too low */
|
||||
|
||||
/* GOOD */
|
||||
background: #1a1a1a;
|
||||
color: #ffffff; /* High contrast */
|
||||
```
|
||||
|
||||
### 2. Opacity Values
|
||||
```css
|
||||
/* BAD */
|
||||
color: rgba(255, 255, 255, 0.7); /* Too transparent */
|
||||
|
||||
/* GOOD */
|
||||
color: #ffffff; /* Full opacity */
|
||||
```
|
||||
|
||||
### 3. Links on Colored Backgrounds
|
||||
```css
|
||||
/* BAD */
|
||||
background: linear-gradient(#667eea, #764ba2);
|
||||
color: white;
|
||||
a { color: #a78bfa; /* Too light on purple */ }
|
||||
|
||||
/* GOOD */
|
||||
background: linear-gradient(#667eea, #764ba2);
|
||||
color: white;
|
||||
a { color: #ffffff; font-weight: 700; text-decoration: underline; }
|
||||
```
|
||||
|
||||
### 4. Code Blocks
|
||||
```css
|
||||
/* BAD */
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
|
||||
/* GOOD */
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
color: #ffffff;
|
||||
```
|
||||
|
||||
## Commands You Can Use
|
||||
|
||||
```bash
|
||||
# Get WordPress post content via PHP
|
||||
php -r "
|
||||
require_once '/var/www/blog/wp-load.php';
|
||||
\$post = get_post(19);
|
||||
echo \$post->post_content;
|
||||
" > /tmp/post_content.html
|
||||
|
||||
# Update WordPress post via PHP
|
||||
php -r "
|
||||
require_once '/var/www/blog/wp-load.php';
|
||||
\$post = array(
|
||||
'ID' => 19,
|
||||
'post_content' => file_get_contents('/tmp/fixed_content.html')
|
||||
);
|
||||
wp_update_post(\$post);
|
||||
"
|
||||
|
||||
# Edit CSS file with sudo
|
||||
sudo nano /var/www/blog/wp-content/themes/rommark-v2/post-19-styles.php
|
||||
|
||||
# Verify changes are live
|
||||
curl -s "https://www.rommark.dev/blog/2026/01/15/ultimate-claude-code-glm-suite-40-agents-mcp-tools-complete-automation/" | grep -A5 "element-in-question"
|
||||
```
|
||||
|
||||
## WordPress Credentials
|
||||
|
||||
- URL: https://www.rommark.dev/blog/
|
||||
- Path: /var/www/blog/
|
||||
- Post ID: 19
|
||||
- CSS: /var/www/blog/wp-content/themes/rommark-v2/post-19-styles.php
|
||||
- Backup exists at: /var/www/blog/wp-content/themes/rommark-v2/post-19-styles.php.backup
|
||||
|
||||
## Instructions for YOU
|
||||
|
||||
1. **Start by fetching live page** - see what's actually rendered
|
||||
2. **Use ui-ux-pro-max agent** - get expert analysis
|
||||
3. **Find ALL contrast issues** - not just the obvious ones
|
||||
4. **Fix CSS first** - update the stylesheet
|
||||
5. **Fix HTML inline styles** - update post content if needed
|
||||
6. **Verify live on site** - check actual rendered page
|
||||
7. **Ask user to confirm** - they have final say
|
||||
8. **Repeat until satisfied** - don't stop until user says it's good
|
||||
|
||||
## Important Notes
|
||||
|
||||
- **Previous fix was incomplete** - user says issues remain
|
||||
- **Look EVERYWHERE** - inline styles, responsive breakpoints, hover states
|
||||
- **Use UX agent** - don't rely on manual inspection alone
|
||||
- **Test with tools** - use contrast checker if available
|
||||
- **Background gradients** - check text against ALL gradient colors
|
||||
- **Mobile views** - responsive styles may have different colors
|
||||
|
||||
## User Communication
|
||||
|
||||
Be thorough and systematic:
|
||||
- "I'm analyzing the entire page for ALL contrast issues..."
|
||||
- "Found X more elements with poor contrast..."
|
||||
- "Using UX agent to verify all color combinations..."
|
||||
- "Fixed issue with [element], testing live now..."
|
||||
- "Please verify the changes at [URL]..."
|
||||
|
||||
Don't ask "is it good?" - be proactive and find issues yourself.
|
||||
|
||||
---
|
||||
|
||||
## Completion
|
||||
|
||||
When ALL contrast issues are fixed and user confirms no more problems:
|
||||
- Document all changes made
|
||||
- Create summary of elements fixed
|
||||
- Mark task complete
|
||||
|
||||
<!-- Ralph will continue iterating until task is complete -->
|
||||
7
.venv/bin/dotenv
Executable file
7
.venv/bin/dotenv
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from dotenv.__main__ import cli
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(cli())
|
||||
7
.venv/bin/fastapi
Executable file
7
.venv/bin/fastapi
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from fastapi.cli import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/httpx
Executable file
7
.venv/bin/httpx
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from httpx import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/jsonschema
Executable file
7
.venv/bin/jsonschema
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from jsonschema.cli import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/markdown-it
Executable file
7
.venv/bin/markdown-it
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from markdown_it.cli.parse import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/mcp
Executable file
7
.venv/bin/mcp
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from mcp.cli import app
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(app())
|
||||
7
.venv/bin/pip
Executable file
7
.venv/bin/pip
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/pip3
Executable file
7
.venv/bin/pip3
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/pip3.11
Executable file
7
.venv/bin/pip3.11
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from pip._internal.cli.main import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/pygmentize
Executable file
7
.venv/bin/pygmentize
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from pygments.cmdline import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
1
.venv/bin/python
Symbolic link
1
.venv/bin/python
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
1
.venv/bin/python3
Symbolic link
1
.venv/bin/python3
Symbolic link
@@ -0,0 +1 @@
|
||||
/usr/bin/python3
|
||||
1
.venv/bin/python3.11
Symbolic link
1
.venv/bin/python3.11
Symbolic link
@@ -0,0 +1 @@
|
||||
python3
|
||||
7
.venv/bin/ralph
Executable file
7
.venv/bin/ralph
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from ralph_orchestrator.__main__ import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/uvicorn
Executable file
7
.venv/bin/uvicorn
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from uvicorn.main import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/watchfiles
Executable file
7
.venv/bin/watchfiles
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from watchfiles.cli import cli
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(cli())
|
||||
7
.venv/bin/websockets
Executable file
7
.venv/bin/websockets
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from websockets.cli import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
7
.venv/bin/wheel
Executable file
7
.venv/bin/wheel
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/home/uroma/obsidian-web-interface/.venv/bin/python3
|
||||
import sys
|
||||
from wheel._commands import main
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
sys.argv[0] = sys.argv[0][:-4]
|
||||
sys.exit(main())
|
||||
27368
.venv/get-pip.py
Normal file
27368
.venv/get-pip.py
Normal file
File diff suppressed because it is too large
Load Diff
164
.venv/include/site/python3.11/greenlet/greenlet.h
Normal file
164
.venv/include/site/python3.11/greenlet/greenlet.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/* -*- indent-tabs-mode: nil; tab-width: 4; -*- */
|
||||
|
||||
/* Greenlet object interface */
|
||||
|
||||
#ifndef Py_GREENLETOBJECT_H
|
||||
#define Py_GREENLETOBJECT_H
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* This is deprecated and undocumented. It does not change. */
|
||||
#define GREENLET_VERSION "1.0.0"
|
||||
|
||||
#ifndef GREENLET_MODULE
|
||||
#define implementation_ptr_t void*
|
||||
#endif
|
||||
|
||||
typedef struct _greenlet {
|
||||
PyObject_HEAD
|
||||
PyObject* weakreflist;
|
||||
PyObject* dict;
|
||||
implementation_ptr_t pimpl;
|
||||
} PyGreenlet;
|
||||
|
||||
#define PyGreenlet_Check(op) (op && PyObject_TypeCheck(op, &PyGreenlet_Type))
|
||||
|
||||
|
||||
/* C API functions */
|
||||
|
||||
/* Total number of symbols that are exported */
|
||||
#define PyGreenlet_API_pointers 12
|
||||
|
||||
#define PyGreenlet_Type_NUM 0
|
||||
#define PyExc_GreenletError_NUM 1
|
||||
#define PyExc_GreenletExit_NUM 2
|
||||
|
||||
#define PyGreenlet_New_NUM 3
|
||||
#define PyGreenlet_GetCurrent_NUM 4
|
||||
#define PyGreenlet_Throw_NUM 5
|
||||
#define PyGreenlet_Switch_NUM 6
|
||||
#define PyGreenlet_SetParent_NUM 7
|
||||
|
||||
#define PyGreenlet_MAIN_NUM 8
|
||||
#define PyGreenlet_STARTED_NUM 9
|
||||
#define PyGreenlet_ACTIVE_NUM 10
|
||||
#define PyGreenlet_GET_PARENT_NUM 11
|
||||
|
||||
#ifndef GREENLET_MODULE
|
||||
/* This section is used by modules that uses the greenlet C API */
|
||||
static void** _PyGreenlet_API = NULL;
|
||||
|
||||
# define PyGreenlet_Type \
|
||||
(*(PyTypeObject*)_PyGreenlet_API[PyGreenlet_Type_NUM])
|
||||
|
||||
# define PyExc_GreenletError \
|
||||
((PyObject*)_PyGreenlet_API[PyExc_GreenletError_NUM])
|
||||
|
||||
# define PyExc_GreenletExit \
|
||||
((PyObject*)_PyGreenlet_API[PyExc_GreenletExit_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_New(PyObject *args)
|
||||
*
|
||||
* greenlet.greenlet(run, parent=None)
|
||||
*/
|
||||
# define PyGreenlet_New \
|
||||
(*(PyGreenlet * (*)(PyObject * run, PyGreenlet * parent)) \
|
||||
_PyGreenlet_API[PyGreenlet_New_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_GetCurrent(void)
|
||||
*
|
||||
* greenlet.getcurrent()
|
||||
*/
|
||||
# define PyGreenlet_GetCurrent \
|
||||
(*(PyGreenlet * (*)(void)) _PyGreenlet_API[PyGreenlet_GetCurrent_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_Throw(
|
||||
* PyGreenlet *greenlet,
|
||||
* PyObject *typ,
|
||||
* PyObject *val,
|
||||
* PyObject *tb)
|
||||
*
|
||||
* g.throw(...)
|
||||
*/
|
||||
# define PyGreenlet_Throw \
|
||||
(*(PyObject * (*)(PyGreenlet * self, \
|
||||
PyObject * typ, \
|
||||
PyObject * val, \
|
||||
PyObject * tb)) \
|
||||
_PyGreenlet_API[PyGreenlet_Throw_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_Switch(PyGreenlet *greenlet, PyObject *args)
|
||||
*
|
||||
* g.switch(*args, **kwargs)
|
||||
*/
|
||||
# define PyGreenlet_Switch \
|
||||
(*(PyObject * \
|
||||
(*)(PyGreenlet * greenlet, PyObject * args, PyObject * kwargs)) \
|
||||
_PyGreenlet_API[PyGreenlet_Switch_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_SetParent(PyObject *greenlet, PyObject *new_parent)
|
||||
*
|
||||
* g.parent = new_parent
|
||||
*/
|
||||
# define PyGreenlet_SetParent \
|
||||
(*(int (*)(PyGreenlet * greenlet, PyGreenlet * nparent)) \
|
||||
_PyGreenlet_API[PyGreenlet_SetParent_NUM])
|
||||
|
||||
/*
|
||||
* PyGreenlet_GetParent(PyObject* greenlet)
|
||||
*
|
||||
* return greenlet.parent;
|
||||
*
|
||||
* This could return NULL even if there is no exception active.
|
||||
* If it does not return NULL, you are responsible for decrementing the
|
||||
* reference count.
|
||||
*/
|
||||
# define PyGreenlet_GetParent \
|
||||
(*(PyGreenlet* (*)(PyGreenlet*)) \
|
||||
_PyGreenlet_API[PyGreenlet_GET_PARENT_NUM])
|
||||
|
||||
/*
|
||||
* deprecated, undocumented alias.
|
||||
*/
|
||||
# define PyGreenlet_GET_PARENT PyGreenlet_GetParent
|
||||
|
||||
# define PyGreenlet_MAIN \
|
||||
(*(int (*)(PyGreenlet*)) \
|
||||
_PyGreenlet_API[PyGreenlet_MAIN_NUM])
|
||||
|
||||
# define PyGreenlet_STARTED \
|
||||
(*(int (*)(PyGreenlet*)) \
|
||||
_PyGreenlet_API[PyGreenlet_STARTED_NUM])
|
||||
|
||||
# define PyGreenlet_ACTIVE \
|
||||
(*(int (*)(PyGreenlet*)) \
|
||||
_PyGreenlet_API[PyGreenlet_ACTIVE_NUM])
|
||||
|
||||
|
||||
|
||||
|
||||
/* Macro that imports greenlet and initializes C API */
|
||||
/* NOTE: This has actually moved to ``greenlet._greenlet._C_API``, but we
|
||||
keep the older definition to be sure older code that might have a copy of
|
||||
the header still works. */
|
||||
# define PyGreenlet_Import() \
|
||||
{ \
|
||||
_PyGreenlet_API = (void**)PyCapsule_Import("greenlet._C_API", 0); \
|
||||
}
|
||||
|
||||
#endif /* GREENLET_MODULE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !Py_GREENLETOBJECT_H */
|
||||
@@ -0,0 +1,7 @@
|
||||
Authors
|
||||
=======
|
||||
|
||||
``pyjwt`` is currently written and maintained by `Jose Padilla <https://github.com/jpadilla>`_.
|
||||
Originally written and maintained by `Jeff Lindsay <https://github.com/progrium>`_.
|
||||
|
||||
A full list of contributors can be found on GitHub’s `overview <https://github.com/jpadilla/pyjwt/graphs/contributors>`_.
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2022 José Padilla
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,106 @@
|
||||
Metadata-Version: 2.1
|
||||
Name: PyJWT
|
||||
Version: 2.10.1
|
||||
Summary: JSON Web Token implementation in Python
|
||||
Author-email: Jose Padilla <hello@jpadilla.com>
|
||||
License: MIT
|
||||
Project-URL: Homepage, https://github.com/jpadilla/pyjwt
|
||||
Keywords: json,jwt,security,signing,token,web
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Natural Language :: English
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3 :: Only
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Topic :: Utilities
|
||||
Requires-Python: >=3.9
|
||||
Description-Content-Type: text/x-rst
|
||||
License-File: LICENSE
|
||||
License-File: AUTHORS.rst
|
||||
Provides-Extra: crypto
|
||||
Requires-Dist: cryptography>=3.4.0; extra == "crypto"
|
||||
Provides-Extra: dev
|
||||
Requires-Dist: coverage[toml]==5.0.4; extra == "dev"
|
||||
Requires-Dist: cryptography>=3.4.0; extra == "dev"
|
||||
Requires-Dist: pre-commit; extra == "dev"
|
||||
Requires-Dist: pytest<7.0.0,>=6.0.0; extra == "dev"
|
||||
Requires-Dist: sphinx; extra == "dev"
|
||||
Requires-Dist: sphinx-rtd-theme; extra == "dev"
|
||||
Requires-Dist: zope.interface; extra == "dev"
|
||||
Provides-Extra: docs
|
||||
Requires-Dist: sphinx; extra == "docs"
|
||||
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
||||
Requires-Dist: zope.interface; extra == "docs"
|
||||
Provides-Extra: tests
|
||||
Requires-Dist: coverage[toml]==5.0.4; extra == "tests"
|
||||
Requires-Dist: pytest<7.0.0,>=6.0.0; extra == "tests"
|
||||
|
||||
PyJWT
|
||||
=====
|
||||
|
||||
.. image:: https://github.com/jpadilla/pyjwt/workflows/CI/badge.svg
|
||||
:target: https://github.com/jpadilla/pyjwt/actions?query=workflow%3ACI
|
||||
|
||||
.. image:: https://img.shields.io/pypi/v/pyjwt.svg
|
||||
:target: https://pypi.python.org/pypi/pyjwt
|
||||
|
||||
.. image:: https://codecov.io/gh/jpadilla/pyjwt/branch/master/graph/badge.svg
|
||||
:target: https://codecov.io/gh/jpadilla/pyjwt
|
||||
|
||||
.. image:: https://readthedocs.org/projects/pyjwt/badge/?version=stable
|
||||
:target: https://pyjwt.readthedocs.io/en/stable/
|
||||
|
||||
A Python implementation of `RFC 7519 <https://tools.ietf.org/html/rfc7519>`_. Original implementation was written by `@progrium <https://github.com/progrium>`_.
|
||||
|
||||
Sponsor
|
||||
-------
|
||||
|
||||
.. |auth0-logo| image:: https://github.com/user-attachments/assets/ee98379e-ee76-4bcb-943a-e25c4ea6d174
|
||||
:width: 160px
|
||||
|
||||
+--------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
| |auth0-logo| | If you want to quickly add secure token-based authentication to Python projects, feel free to check Auth0's Python SDK and free plan at `auth0.com/signup <https://auth0.com/signup?utm_source=external_sites&utm_medium=pyjwt&utm_campaign=devn_signup>`_. |
|
||||
+--------------+-----------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
Install with **pip**:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install PyJWT
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
>>> import jwt
|
||||
>>> encoded = jwt.encode({"some": "payload"}, "secret", algorithm="HS256")
|
||||
>>> print(encoded)
|
||||
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg
|
||||
>>> jwt.decode(encoded, "secret", algorithms=["HS256"])
|
||||
{'some': 'payload'}
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
View the full docs online at https://pyjwt.readthedocs.io/en/stable/
|
||||
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
You can run tests from the project root after cloning with:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ tox
|
||||
@@ -0,0 +1,32 @@
|
||||
PyJWT-2.10.1.dist-info/AUTHORS.rst,sha256=klzkNGECnu2_VY7At89_xLBF3vUSDruXk3xwgUBxzwc,322
|
||||
PyJWT-2.10.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
PyJWT-2.10.1.dist-info/LICENSE,sha256=eXp6ICMdTEM-nxkR2xcx0GtYKLmPSZgZoDT3wPVvXOU,1085
|
||||
PyJWT-2.10.1.dist-info/METADATA,sha256=EkewF6D6KU8SGaaQzVYfxUUU1P_gs_dp1pYTkoYvAx8,3990
|
||||
PyJWT-2.10.1.dist-info/RECORD,,
|
||||
PyJWT-2.10.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
||||
PyJWT-2.10.1.dist-info/top_level.txt,sha256=RP5DHNyJbMq2ka0FmfTgoSaQzh7e3r5XuCWCO8a00k8,4
|
||||
jwt/__init__.py,sha256=VB2vFKuboTjcDGeZ8r-UqK_dz3NsQSQEqySSICby8Xg,1711
|
||||
jwt/__pycache__/__init__.cpython-311.pyc,,
|
||||
jwt/__pycache__/algorithms.cpython-311.pyc,,
|
||||
jwt/__pycache__/api_jwk.cpython-311.pyc,,
|
||||
jwt/__pycache__/api_jws.cpython-311.pyc,,
|
||||
jwt/__pycache__/api_jwt.cpython-311.pyc,,
|
||||
jwt/__pycache__/exceptions.cpython-311.pyc,,
|
||||
jwt/__pycache__/help.cpython-311.pyc,,
|
||||
jwt/__pycache__/jwk_set_cache.cpython-311.pyc,,
|
||||
jwt/__pycache__/jwks_client.cpython-311.pyc,,
|
||||
jwt/__pycache__/types.cpython-311.pyc,,
|
||||
jwt/__pycache__/utils.cpython-311.pyc,,
|
||||
jwt/__pycache__/warnings.cpython-311.pyc,,
|
||||
jwt/algorithms.py,sha256=cKr-XEioe0mBtqJMCaHEswqVOA1Z8Purt5Sb3Bi-5BE,30409
|
||||
jwt/api_jwk.py,sha256=6F1r7rmm8V5qEnBKA_xMjS9R7VoANe1_BL1oD2FrAjE,4451
|
||||
jwt/api_jws.py,sha256=aM8vzqQf6mRrAw7bRy-Moj_pjWsKSVQyYK896AfMjJU,11762
|
||||
jwt/api_jwt.py,sha256=OGT4hok1l5A6FH_KdcrU5g6u6EQ8B7em0r9kGM9SYgA,14512
|
||||
jwt/exceptions.py,sha256=bUIOJ-v9tjopTLS-FYOTc3kFx5WP5IZt7ksN_HE1G9Q,1211
|
||||
jwt/help.py,sha256=vFdNzjQoAch04XCMYpCkyB2blaqHAGAqQrtf9nSPkdk,1808
|
||||
jwt/jwk_set_cache.py,sha256=hBKmN-giU7-G37L_XKgc_OZu2ah4wdbj1ZNG_GkoSE8,959
|
||||
jwt/jwks_client.py,sha256=p9b-IbQqo2tEge9Zit3oSPBFNePqwho96VLbnUrHUWs,4259
|
||||
jwt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
jwt/types.py,sha256=VnhGv_VFu5a7_mrPoSCB7HaNLrJdhM8Sq1sSfEg0gLU,99
|
||||
jwt/utils.py,sha256=hxOjvDBheBYhz-RIPiEz7Q88dSUSTMzEdKE_Ww2VdJw,3640
|
||||
jwt/warnings.py,sha256=50XWOnyNsIaqzUJTk6XHNiIDykiL763GYA92MjTKmok,59
|
||||
@@ -0,0 +1,5 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: setuptools (75.6.0)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
jwt
|
||||
Binary file not shown.
BIN
.venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-x86_64-linux-gnu.so
Executable file
BIN
.venv/lib/python3.11/site-packages/_cffi_backend.cpython-311-x86_64-linux-gnu.so
Executable file
Binary file not shown.
239
.venv/lib/python3.11/site-packages/_distutils_hack/__init__.py
Normal file
239
.venv/lib/python3.11/site-packages/_distutils_hack/__init__.py
Normal file
@@ -0,0 +1,239 @@
|
||||
# don't import any costly modules
|
||||
import os
|
||||
import sys
|
||||
|
||||
report_url = (
|
||||
"https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml"
|
||||
)
|
||||
|
||||
|
||||
def warn_distutils_present():
|
||||
if 'distutils' not in sys.modules:
|
||||
return
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
"Distutils was imported before Setuptools, but importing Setuptools "
|
||||
"also replaces the `distutils` module in `sys.modules`. This may lead "
|
||||
"to undesirable behaviors or errors. To avoid these issues, avoid "
|
||||
"using distutils directly, ensure that setuptools is installed in the "
|
||||
"traditional way (e.g. not an editable install), and/or make sure "
|
||||
"that setuptools is always imported before distutils."
|
||||
)
|
||||
|
||||
|
||||
def clear_distutils():
|
||||
if 'distutils' not in sys.modules:
|
||||
return
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
"Setuptools is replacing distutils. Support for replacing "
|
||||
"an already imported distutils is deprecated. In the future, "
|
||||
"this condition will fail. "
|
||||
f"Register concerns at {report_url}"
|
||||
)
|
||||
mods = [
|
||||
name
|
||||
for name in sys.modules
|
||||
if name == "distutils" or name.startswith("distutils.")
|
||||
]
|
||||
for name in mods:
|
||||
del sys.modules[name]
|
||||
|
||||
|
||||
def enabled():
|
||||
"""
|
||||
Allow selection of distutils by environment variable.
|
||||
"""
|
||||
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
|
||||
if which == 'stdlib':
|
||||
import warnings
|
||||
|
||||
warnings.warn(
|
||||
"Reliance on distutils from stdlib is deprecated. Users "
|
||||
"must rely on setuptools to provide the distutils module. "
|
||||
"Avoid importing distutils or import setuptools first, "
|
||||
"and avoid setting SETUPTOOLS_USE_DISTUTILS=stdlib. "
|
||||
f"Register concerns at {report_url}"
|
||||
)
|
||||
return which == 'local'
|
||||
|
||||
|
||||
def ensure_local_distutils():
|
||||
import importlib
|
||||
|
||||
clear_distutils()
|
||||
|
||||
# With the DistutilsMetaFinder in place,
|
||||
# perform an import to cause distutils to be
|
||||
# loaded from setuptools._distutils. Ref #2906.
|
||||
with shim():
|
||||
importlib.import_module('distutils')
|
||||
|
||||
# check that submodules load as expected
|
||||
core = importlib.import_module('distutils.core')
|
||||
assert '_distutils' in core.__file__, core.__file__
|
||||
assert 'setuptools._distutils.log' not in sys.modules
|
||||
|
||||
|
||||
def do_override():
|
||||
"""
|
||||
Ensure that the local copy of distutils is preferred over stdlib.
|
||||
|
||||
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
|
||||
for more motivation.
|
||||
"""
|
||||
if enabled():
|
||||
warn_distutils_present()
|
||||
ensure_local_distutils()
|
||||
|
||||
|
||||
class _TrivialRe:
|
||||
def __init__(self, *patterns) -> None:
|
||||
self._patterns = patterns
|
||||
|
||||
def match(self, string):
|
||||
return all(pat in string for pat in self._patterns)
|
||||
|
||||
|
||||
class DistutilsMetaFinder:
|
||||
def find_spec(self, fullname, path, target=None):
|
||||
# optimization: only consider top level modules and those
|
||||
# found in the CPython test suite.
|
||||
if path is not None and not fullname.startswith('test.'):
|
||||
return None
|
||||
|
||||
method_name = 'spec_for_{fullname}'.format(**locals())
|
||||
method = getattr(self, method_name, lambda: None)
|
||||
return method()
|
||||
|
||||
def spec_for_distutils(self):
|
||||
if self.is_cpython():
|
||||
return None
|
||||
|
||||
import importlib
|
||||
import importlib.abc
|
||||
import importlib.util
|
||||
|
||||
try:
|
||||
mod = importlib.import_module('setuptools._distutils')
|
||||
except Exception:
|
||||
# There are a couple of cases where setuptools._distutils
|
||||
# may not be present:
|
||||
# - An older Setuptools without a local distutils is
|
||||
# taking precedence. Ref #2957.
|
||||
# - Path manipulation during sitecustomize removes
|
||||
# setuptools from the path but only after the hook
|
||||
# has been loaded. Ref #2980.
|
||||
# In either case, fall back to stdlib behavior.
|
||||
return None
|
||||
|
||||
class DistutilsLoader(importlib.abc.Loader):
|
||||
def create_module(self, spec):
|
||||
mod.__name__ = 'distutils'
|
||||
return mod
|
||||
|
||||
def exec_module(self, module):
|
||||
pass
|
||||
|
||||
return importlib.util.spec_from_loader(
|
||||
'distutils', DistutilsLoader(), origin=mod.__file__
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_cpython():
|
||||
"""
|
||||
Suppress supplying distutils for CPython (build and tests).
|
||||
Ref #2965 and #3007.
|
||||
"""
|
||||
return os.path.isfile('pybuilddir.txt')
|
||||
|
||||
def spec_for_pip(self):
|
||||
"""
|
||||
Ensure stdlib distutils when running under pip.
|
||||
See pypa/pip#8761 for rationale.
|
||||
"""
|
||||
if sys.version_info >= (3, 12) or self.pip_imported_during_build():
|
||||
return
|
||||
clear_distutils()
|
||||
self.spec_for_distutils = lambda: None
|
||||
|
||||
@classmethod
|
||||
def pip_imported_during_build(cls):
|
||||
"""
|
||||
Detect if pip is being imported in a build script. Ref #2355.
|
||||
"""
|
||||
import traceback
|
||||
|
||||
return any(
|
||||
cls.frame_file_is_setup(frame) for frame, line in traceback.walk_stack(None)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def frame_file_is_setup(frame):
|
||||
"""
|
||||
Return True if the indicated frame suggests a setup.py file.
|
||||
"""
|
||||
# some frames may not have __file__ (#2940)
|
||||
return frame.f_globals.get('__file__', '').endswith('setup.py')
|
||||
|
||||
def spec_for_sensitive_tests(self):
|
||||
"""
|
||||
Ensure stdlib distutils when running select tests under CPython.
|
||||
|
||||
python/cpython#91169
|
||||
"""
|
||||
clear_distutils()
|
||||
self.spec_for_distutils = lambda: None
|
||||
|
||||
sensitive_tests = (
|
||||
[
|
||||
'test.test_distutils',
|
||||
'test.test_peg_generator',
|
||||
'test.test_importlib',
|
||||
]
|
||||
if sys.version_info < (3, 10)
|
||||
else [
|
||||
'test.test_distutils',
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
for name in DistutilsMetaFinder.sensitive_tests:
|
||||
setattr(
|
||||
DistutilsMetaFinder,
|
||||
f'spec_for_{name}',
|
||||
DistutilsMetaFinder.spec_for_sensitive_tests,
|
||||
)
|
||||
|
||||
|
||||
DISTUTILS_FINDER = DistutilsMetaFinder()
|
||||
|
||||
|
||||
def add_shim():
|
||||
DISTUTILS_FINDER in sys.meta_path or insert_shim()
|
||||
|
||||
|
||||
class shim:
|
||||
def __enter__(self) -> None:
|
||||
insert_shim()
|
||||
|
||||
def __exit__(self, exc: object, value: object, tb: object) -> None:
|
||||
_remove_shim()
|
||||
|
||||
|
||||
def insert_shim():
|
||||
sys.meta_path.insert(0, DISTUTILS_FINDER)
|
||||
|
||||
|
||||
def _remove_shim():
|
||||
try:
|
||||
sys.meta_path.remove(DISTUTILS_FINDER)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
if sys.version_info < (3, 12):
|
||||
# DistutilsMetaFinder can only be disabled in Python < 3.12 (PEP 632)
|
||||
remove_shim = _remove_shim
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
__import__('_distutils_hack').do_override()
|
||||
33
.venv/lib/python3.11/site-packages/_yaml/__init__.py
Normal file
33
.venv/lib/python3.11/site-packages/_yaml/__init__.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# This is a stub package designed to roughly emulate the _yaml
|
||||
# extension module, which previously existed as a standalone module
|
||||
# and has been moved into the `yaml` package namespace.
|
||||
# It does not perfectly mimic its old counterpart, but should get
|
||||
# close enough for anyone who's relying on it even when they shouldn't.
|
||||
import yaml
|
||||
|
||||
# in some circumstances, the yaml module we imoprted may be from a different version, so we need
|
||||
# to tread carefully when poking at it here (it may not have the attributes we expect)
|
||||
if not getattr(yaml, '__with_libyaml__', False):
|
||||
from sys import version_info
|
||||
|
||||
exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError
|
||||
raise exc("No module named '_yaml'")
|
||||
else:
|
||||
from yaml._yaml import *
|
||||
import warnings
|
||||
warnings.warn(
|
||||
'The _yaml extension module is now located at yaml._yaml'
|
||||
' and its location is subject to change. To use the'
|
||||
' LibYAML-based parser and emitter, import from `yaml`:'
|
||||
' `from yaml import CLoader as Loader, CDumper as Dumper`.',
|
||||
DeprecationWarning
|
||||
)
|
||||
del warnings
|
||||
# Don't `del yaml` here because yaml is actually an existing
|
||||
# namespace member of _yaml.
|
||||
|
||||
__name__ = '_yaml'
|
||||
# If the module is top-level (i.e. not a part of any specific package)
|
||||
# then the attribute should be set to ''.
|
||||
# https://docs.python.org/3.8/library/types.html
|
||||
__package__ = ''
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,209 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: aiofiles
|
||||
Version: 25.1.0
|
||||
Summary: File support for asyncio.
|
||||
Project-URL: Changelog, https://github.com/Tinche/aiofiles#history
|
||||
Project-URL: Bug Tracker, https://github.com/Tinche/aiofiles/issues
|
||||
Project-URL: Repository, https://github.com/Tinche/aiofiles
|
||||
Author-email: Tin Tvrtkovic <tinchester@gmail.com>
|
||||
License: Apache-2.0
|
||||
License-File: LICENSE
|
||||
License-File: NOTICE
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Framework :: AsyncIO
|
||||
Classifier: License :: OSI Approved :: Apache Software License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||
Requires-Python: >=3.9
|
||||
Description-Content-Type: text/markdown
|
||||
|
||||
# aiofiles: file support for asyncio
|
||||
|
||||
[](https://pypi.python.org/pypi/aiofiles)
|
||||
[](https://github.com/Tinche/aiofiles/actions)
|
||||
[](https://github.com/Tinche/aiofiles/actions/workflows/main.yml)
|
||||
[](https://github.com/Tinche/aiofiles)
|
||||
[](https://github.com/astral-sh/ruff)
|
||||
|
||||
**aiofiles** is an Apache2 licensed library, written in Python, for handling local
|
||||
disk files in asyncio applications.
|
||||
|
||||
Ordinary local file IO is blocking, and cannot easily and portably be made
|
||||
asynchronous. This means doing file IO may interfere with asyncio applications,
|
||||
which shouldn't block the executing thread. aiofiles helps with this by
|
||||
introducing asynchronous versions of files that support delegating operations to
|
||||
a separate thread pool.
|
||||
|
||||
```python
|
||||
async with aiofiles.open('filename', mode='r') as f:
|
||||
contents = await f.read()
|
||||
print(contents)
|
||||
'My file contents'
|
||||
```
|
||||
|
||||
Asynchronous iteration is also supported.
|
||||
|
||||
```python
|
||||
async with aiofiles.open('filename') as f:
|
||||
async for line in f:
|
||||
...
|
||||
```
|
||||
|
||||
Asynchronous interface to tempfile module.
|
||||
|
||||
```python
|
||||
async with aiofiles.tempfile.TemporaryFile('wb') as f:
|
||||
await f.write(b'Hello, World!')
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- a file API very similar to Python's standard, blocking API
|
||||
- support for buffered and unbuffered binary files, and buffered text files
|
||||
- support for `async`/`await` ([PEP 492](https://peps.python.org/pep-0492/)) constructs
|
||||
- async interface to tempfile module
|
||||
|
||||
## Installation
|
||||
|
||||
To install aiofiles, simply:
|
||||
|
||||
```shell
|
||||
pip install aiofiles
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Files are opened using the `aiofiles.open()` coroutine, which in addition to
|
||||
mirroring the builtin `open` accepts optional `loop` and `executor`
|
||||
arguments. If `loop` is absent, the default loop will be used, as per the
|
||||
set asyncio policy. If `executor` is not specified, the default event loop
|
||||
executor will be used.
|
||||
|
||||
In case of success, an asynchronous file object is returned with an
|
||||
API identical to an ordinary file, except the following methods are coroutines
|
||||
and delegate to an executor:
|
||||
|
||||
- `close`
|
||||
- `flush`
|
||||
- `isatty`
|
||||
- `read`
|
||||
- `readall`
|
||||
- `read1`
|
||||
- `readinto`
|
||||
- `readline`
|
||||
- `readlines`
|
||||
- `seek`
|
||||
- `seekable`
|
||||
- `tell`
|
||||
- `truncate`
|
||||
- `writable`
|
||||
- `write`
|
||||
- `writelines`
|
||||
|
||||
In case of failure, one of the usual exceptions will be raised.
|
||||
|
||||
`aiofiles.stdin`, `aiofiles.stdout`, `aiofiles.stderr`,
|
||||
`aiofiles.stdin_bytes`, `aiofiles.stdout_bytes`, and
|
||||
`aiofiles.stderr_bytes` provide async access to `sys.stdin`,
|
||||
`sys.stdout`, `sys.stderr`, and their corresponding `.buffer` properties.
|
||||
|
||||
The `aiofiles.os` module contains executor-enabled coroutine versions of
|
||||
several useful `os` functions that deal with files:
|
||||
|
||||
- `stat`
|
||||
- `statvfs`
|
||||
- `sendfile`
|
||||
- `rename`
|
||||
- `renames`
|
||||
- `replace`
|
||||
- `remove`
|
||||
- `unlink`
|
||||
- `mkdir`
|
||||
- `makedirs`
|
||||
- `rmdir`
|
||||
- `removedirs`
|
||||
- `link`
|
||||
- `symlink`
|
||||
- `readlink`
|
||||
- `listdir`
|
||||
- `scandir`
|
||||
- `access`
|
||||
- `getcwd`
|
||||
- `path.abspath`
|
||||
- `path.exists`
|
||||
- `path.isfile`
|
||||
- `path.isdir`
|
||||
- `path.islink`
|
||||
- `path.ismount`
|
||||
- `path.getsize`
|
||||
- `path.getatime`
|
||||
- `path.getctime`
|
||||
- `path.samefile`
|
||||
- `path.sameopenfile`
|
||||
|
||||
### Tempfile
|
||||
|
||||
**aiofiles.tempfile** implements the following interfaces:
|
||||
|
||||
- TemporaryFile
|
||||
- NamedTemporaryFile
|
||||
- SpooledTemporaryFile
|
||||
- TemporaryDirectory
|
||||
|
||||
Results return wrapped with a context manager allowing use with async with and async for.
|
||||
|
||||
```python
|
||||
async with aiofiles.tempfile.NamedTemporaryFile('wb+') as f:
|
||||
await f.write(b'Line1\n Line2')
|
||||
await f.seek(0)
|
||||
async for line in f:
|
||||
print(line)
|
||||
|
||||
async with aiofiles.tempfile.TemporaryDirectory() as d:
|
||||
filename = os.path.join(d, "file.ext")
|
||||
```
|
||||
|
||||
### Writing tests for aiofiles
|
||||
|
||||
Real file IO can be mocked by patching `aiofiles.threadpool.sync_open`
|
||||
as desired. The return type also needs to be registered with the
|
||||
`aiofiles.threadpool.wrap` dispatcher:
|
||||
|
||||
```python
|
||||
aiofiles.threadpool.wrap.register(mock.MagicMock)(
|
||||
lambda *args, **kwargs: aiofiles.threadpool.AsyncBufferedIOBase(*args, **kwargs)
|
||||
)
|
||||
|
||||
async def test_stuff():
|
||||
write_data = 'data'
|
||||
read_file_chunks = [
|
||||
b'file chunks 1',
|
||||
b'file chunks 2',
|
||||
b'file chunks 3',
|
||||
b'',
|
||||
]
|
||||
file_chunks_iter = iter(read_file_chunks)
|
||||
|
||||
mock_file_stream = mock.MagicMock(
|
||||
read=lambda *args, **kwargs: next(file_chunks_iter)
|
||||
)
|
||||
|
||||
with mock.patch('aiofiles.threadpool.sync_open', return_value=mock_file_stream) as mock_open:
|
||||
async with aiofiles.open('filename', 'w') as f:
|
||||
await f.write(write_data)
|
||||
assert await f.read() == b'file chunks 1'
|
||||
|
||||
mock_file_stream.write.assert_called_once_with(write_data)
|
||||
```
|
||||
|
||||
### Contributing
|
||||
|
||||
Contributions are very welcome. Tests can be run with `tox`, please ensure
|
||||
the coverage at least stays the same before you submit a pull request.
|
||||
@@ -0,0 +1,26 @@
|
||||
aiofiles-25.1.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
aiofiles-25.1.0.dist-info/METADATA,sha256=a5a5kHMVigDdsBKlFINLSMPsX3Ms4Fn_zecASBdZqLU,6291
|
||||
aiofiles-25.1.0.dist-info/RECORD,,
|
||||
aiofiles-25.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
||||
aiofiles-25.1.0.dist-info/licenses/LICENSE,sha256=y16Ofl9KOYjhBjwULGDcLfdWBfTEZRXnduOspt-XbhQ,11325
|
||||
aiofiles-25.1.0.dist-info/licenses/NOTICE,sha256=EExY0dRQvWR0wJ2LZLwBgnM6YKw9jCU-M0zegpRSD_E,55
|
||||
aiofiles/__init__.py,sha256=DYqUwak6MVosBjbAsgyEnFFP-HUZCG5h7X4owoeyYHw,345
|
||||
aiofiles/__pycache__/__init__.cpython-311.pyc,,
|
||||
aiofiles/__pycache__/base.cpython-311.pyc,,
|
||||
aiofiles/__pycache__/os.cpython-311.pyc,,
|
||||
aiofiles/__pycache__/ospath.cpython-311.pyc,,
|
||||
aiofiles/base.py,sha256=-fvh41PnictTZL3cg98HoN4h6jdebi5d7Mfh81zOBOc,2046
|
||||
aiofiles/os.py,sha256=slJ5oUNHVW1xWVuuIWQiYjw30n3L48H7oX4CJvD_1d4,1078
|
||||
aiofiles/ospath.py,sha256=c-Kqw4wMCZ-YRt8Jleb697cANwJQM9qux6lq97949C8,678
|
||||
aiofiles/tempfile/__init__.py,sha256=twoC7vaQ-JjFzh2Bbd-3-o0hmExH3CYJUmQcuiVwZfg,10207
|
||||
aiofiles/tempfile/__pycache__/__init__.cpython-311.pyc,,
|
||||
aiofiles/tempfile/__pycache__/temptypes.cpython-311.pyc,,
|
||||
aiofiles/tempfile/temptypes.py,sha256=3_hlc6l9r5wmino1fDrt4TpFlX4IKoR5IP_bBYVVuHg,2037
|
||||
aiofiles/threadpool/__init__.py,sha256=-65UURmzUHsGTXUz0TARdSzyXIfkCFtbczAQLEPpEcU,3140
|
||||
aiofiles/threadpool/__pycache__/__init__.cpython-311.pyc,,
|
||||
aiofiles/threadpool/__pycache__/binary.cpython-311.pyc,,
|
||||
aiofiles/threadpool/__pycache__/text.cpython-311.pyc,,
|
||||
aiofiles/threadpool/__pycache__/utils.cpython-311.pyc,,
|
||||
aiofiles/threadpool/binary.py,sha256=hp-km9VCRu0MLz_wAEUfbCz7OL7xtn9iGAawabpnp5U,2315
|
||||
aiofiles/threadpool/text.py,sha256=fNmpw2PEkj0BZSldipJXAgZqVGLxALcfOMiuDQ54Eas,1223
|
||||
aiofiles/threadpool/utils.py,sha256=VtIJ9KErbcIT9_Yz4V4rZgNEUjBH3cAYxzKQBMpEzik,1850
|
||||
@@ -0,0 +1,4 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: hatchling 1.27.0
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
@@ -0,0 +1,202 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Asyncio support for files
|
||||
Copyright 2016 Tin Tvrtkovic
|
||||
23
.venv/lib/python3.11/site-packages/aiofiles/__init__.py
Normal file
23
.venv/lib/python3.11/site-packages/aiofiles/__init__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
"""Utilities for asyncio-friendly file handling."""
|
||||
|
||||
from . import tempfile
|
||||
from .threadpool import (
|
||||
open,
|
||||
stderr,
|
||||
stderr_bytes,
|
||||
stdin,
|
||||
stdin_bytes,
|
||||
stdout,
|
||||
stdout_bytes,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"open",
|
||||
"tempfile",
|
||||
"stdin",
|
||||
"stdout",
|
||||
"stderr",
|
||||
"stdin_bytes",
|
||||
"stdout_bytes",
|
||||
"stderr_bytes",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
79
.venv/lib/python3.11/site-packages/aiofiles/base.py
Normal file
79
.venv/lib/python3.11/site-packages/aiofiles/base.py
Normal file
@@ -0,0 +1,79 @@
|
||||
from asyncio import get_running_loop
|
||||
from collections.abc import Awaitable
|
||||
from contextlib import AbstractAsyncContextManager
|
||||
from functools import partial, wraps
|
||||
|
||||
|
||||
def wrap(func):
|
||||
@wraps(func)
|
||||
async def run(*args, loop=None, executor=None, **kwargs):
|
||||
if loop is None:
|
||||
loop = get_running_loop()
|
||||
pfunc = partial(func, *args, **kwargs)
|
||||
return await loop.run_in_executor(executor, pfunc)
|
||||
|
||||
return run
|
||||
|
||||
|
||||
class AsyncBase:
|
||||
def __init__(self, file, loop, executor):
|
||||
self._file = file
|
||||
self._executor = executor
|
||||
self._ref_loop = loop
|
||||
|
||||
@property
|
||||
def _loop(self):
|
||||
return self._ref_loop or get_running_loop()
|
||||
|
||||
def __aiter__(self):
|
||||
"""We are our own iterator."""
|
||||
return self
|
||||
|
||||
def __repr__(self):
|
||||
return super().__repr__() + " wrapping " + repr(self._file)
|
||||
|
||||
async def __anext__(self):
|
||||
"""Simulate normal file iteration."""
|
||||
|
||||
if line := await self.readline():
|
||||
return line
|
||||
raise StopAsyncIteration
|
||||
|
||||
|
||||
class AsyncIndirectBase(AsyncBase):
|
||||
def __init__(self, name, loop, executor, indirect):
|
||||
self._indirect = indirect
|
||||
self._name = name
|
||||
super().__init__(None, loop, executor)
|
||||
|
||||
@property
|
||||
def _file(self):
|
||||
return self._indirect()
|
||||
|
||||
@_file.setter
|
||||
def _file(self, v):
|
||||
pass # discard writes
|
||||
|
||||
|
||||
class AiofilesContextManager(Awaitable, AbstractAsyncContextManager):
|
||||
"""An adjusted async context manager for aiofiles."""
|
||||
|
||||
__slots__ = ("_coro", "_obj")
|
||||
|
||||
def __init__(self, coro):
|
||||
self._coro = coro
|
||||
self._obj = None
|
||||
|
||||
def __await__(self):
|
||||
if self._obj is None:
|
||||
self._obj = yield from self._coro.__await__()
|
||||
return self._obj
|
||||
|
||||
async def __aenter__(self):
|
||||
return await self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
await get_running_loop().run_in_executor(
|
||||
None, self._obj._file.__exit__, exc_type, exc_val, exc_tb
|
||||
)
|
||||
self._obj = None
|
||||
61
.venv/lib/python3.11/site-packages/aiofiles/os.py
Normal file
61
.venv/lib/python3.11/site-packages/aiofiles/os.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Async executor versions of file functions from the os module."""
|
||||
|
||||
import os
|
||||
|
||||
from . import ospath as path
|
||||
from .base import wrap
|
||||
|
||||
__all__ = [
|
||||
"path",
|
||||
"stat",
|
||||
"rename",
|
||||
"renames",
|
||||
"replace",
|
||||
"remove",
|
||||
"unlink",
|
||||
"mkdir",
|
||||
"makedirs",
|
||||
"rmdir",
|
||||
"removedirs",
|
||||
"symlink",
|
||||
"readlink",
|
||||
"listdir",
|
||||
"scandir",
|
||||
"access",
|
||||
"wrap",
|
||||
"getcwd",
|
||||
]
|
||||
|
||||
access = wrap(os.access)
|
||||
|
||||
getcwd = wrap(os.getcwd)
|
||||
|
||||
listdir = wrap(os.listdir)
|
||||
|
||||
makedirs = wrap(os.makedirs)
|
||||
mkdir = wrap(os.mkdir)
|
||||
|
||||
readlink = wrap(os.readlink)
|
||||
remove = wrap(os.remove)
|
||||
removedirs = wrap(os.removedirs)
|
||||
rename = wrap(os.rename)
|
||||
renames = wrap(os.renames)
|
||||
replace = wrap(os.replace)
|
||||
rmdir = wrap(os.rmdir)
|
||||
|
||||
scandir = wrap(os.scandir)
|
||||
stat = wrap(os.stat)
|
||||
symlink = wrap(os.symlink)
|
||||
|
||||
unlink = wrap(os.unlink)
|
||||
|
||||
|
||||
if hasattr(os, "link"):
|
||||
__all__ += ["link"]
|
||||
link = wrap(os.link)
|
||||
if hasattr(os, "sendfile"):
|
||||
__all__ += ["sendfile"]
|
||||
sendfile = wrap(os.sendfile)
|
||||
if hasattr(os, "statvfs"):
|
||||
__all__ += ["statvfs"]
|
||||
statvfs = wrap(os.statvfs)
|
||||
37
.venv/lib/python3.11/site-packages/aiofiles/ospath.py
Normal file
37
.venv/lib/python3.11/site-packages/aiofiles/ospath.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Async executor versions of file functions from the os.path module."""
|
||||
|
||||
from os import path
|
||||
|
||||
from .base import wrap
|
||||
|
||||
__all__ = [
|
||||
"abspath",
|
||||
"getatime",
|
||||
"getctime",
|
||||
"getmtime",
|
||||
"getsize",
|
||||
"exists",
|
||||
"isdir",
|
||||
"isfile",
|
||||
"islink",
|
||||
"ismount",
|
||||
"samefile",
|
||||
"sameopenfile",
|
||||
]
|
||||
|
||||
abspath = wrap(path.abspath)
|
||||
|
||||
getatime = wrap(path.getatime)
|
||||
getctime = wrap(path.getctime)
|
||||
getmtime = wrap(path.getmtime)
|
||||
getsize = wrap(path.getsize)
|
||||
|
||||
exists = wrap(path.exists)
|
||||
|
||||
isdir = wrap(path.isdir)
|
||||
isfile = wrap(path.isfile)
|
||||
islink = wrap(path.islink)
|
||||
ismount = wrap(path.ismount)
|
||||
|
||||
samefile = wrap(path.samefile)
|
||||
sameopenfile = wrap(path.sameopenfile)
|
||||
357
.venv/lib/python3.11/site-packages/aiofiles/tempfile/__init__.py
Normal file
357
.venv/lib/python3.11/site-packages/aiofiles/tempfile/__init__.py
Normal file
@@ -0,0 +1,357 @@
|
||||
import asyncio
|
||||
import sys
|
||||
from functools import partial, singledispatch
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOBase
|
||||
from tempfile import NamedTemporaryFile as syncNamedTemporaryFile
|
||||
from tempfile import SpooledTemporaryFile as syncSpooledTemporaryFile
|
||||
from tempfile import TemporaryDirectory as syncTemporaryDirectory
|
||||
from tempfile import TemporaryFile as syncTemporaryFile
|
||||
from tempfile import _TemporaryFileWrapper as syncTemporaryFileWrapper
|
||||
|
||||
from ..base import AiofilesContextManager
|
||||
from ..threadpool.binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO
|
||||
from ..threadpool.text import AsyncTextIOWrapper
|
||||
from .temptypes import AsyncSpooledTemporaryFile, AsyncTemporaryDirectory
|
||||
|
||||
__all__ = [
|
||||
"NamedTemporaryFile",
|
||||
"TemporaryFile",
|
||||
"SpooledTemporaryFile",
|
||||
"TemporaryDirectory",
|
||||
]
|
||||
|
||||
|
||||
# ================================================================
|
||||
# Public methods for async open and return of temp file/directory
|
||||
# objects with async interface
|
||||
# ================================================================
|
||||
if sys.version_info >= (3, 12):
|
||||
|
||||
def NamedTemporaryFile(
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
delete=True,
|
||||
delete_on_close=True,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Async open a named temporary file"""
|
||||
return AiofilesContextManager(
|
||||
_temporary_file(
|
||||
named=True,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
delete=delete,
|
||||
delete_on_close=delete_on_close,
|
||||
loop=loop,
|
||||
executor=executor,
|
||||
)
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
def NamedTemporaryFile(
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
delete=True,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Async open a named temporary file"""
|
||||
return AiofilesContextManager(
|
||||
_temporary_file(
|
||||
named=True,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
delete=delete,
|
||||
loop=loop,
|
||||
executor=executor,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def TemporaryFile(
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Async open an unnamed temporary file"""
|
||||
return AiofilesContextManager(
|
||||
_temporary_file(
|
||||
named=False,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
loop=loop,
|
||||
executor=executor,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def SpooledTemporaryFile(
|
||||
max_size=0,
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Async open a spooled temporary file"""
|
||||
return AiofilesContextManager(
|
||||
_spooled_temporary_file(
|
||||
max_size=max_size,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
loop=loop,
|
||||
executor=executor,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def TemporaryDirectory(suffix=None, prefix=None, dir=None, loop=None, executor=None):
|
||||
"""Async open a temporary directory"""
|
||||
return AiofilesContextManagerTempDir(
|
||||
_temporary_directory(
|
||||
suffix=suffix, prefix=prefix, dir=dir, loop=loop, executor=executor
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# =========================================================
|
||||
# Internal coroutines to open new temp files/directories
|
||||
# =========================================================
|
||||
if sys.version_info >= (3, 12):
|
||||
|
||||
async def _temporary_file(
|
||||
named=True,
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
delete=True,
|
||||
delete_on_close=True,
|
||||
loop=None,
|
||||
executor=None,
|
||||
max_size=0,
|
||||
):
|
||||
"""Async method to open a temporary file with async interface"""
|
||||
if loop is None:
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
if named:
|
||||
cb = partial(
|
||||
syncNamedTemporaryFile,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
delete=delete,
|
||||
delete_on_close=delete_on_close,
|
||||
)
|
||||
else:
|
||||
cb = partial(
|
||||
syncTemporaryFile,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
)
|
||||
|
||||
f = await loop.run_in_executor(executor, cb)
|
||||
|
||||
# Wrap based on type of underlying IO object
|
||||
if type(f) is syncTemporaryFileWrapper:
|
||||
# _TemporaryFileWrapper was used (named files)
|
||||
result = wrap(f.file, f, loop=loop, executor=executor)
|
||||
result._closer = f._closer
|
||||
return result
|
||||
# IO object was returned directly without wrapper
|
||||
return wrap(f, f, loop=loop, executor=executor)
|
||||
|
||||
else:
|
||||
|
||||
async def _temporary_file(
|
||||
named=True,
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
delete=True,
|
||||
loop=None,
|
||||
executor=None,
|
||||
max_size=0,
|
||||
):
|
||||
"""Async method to open a temporary file with async interface"""
|
||||
if loop is None:
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
if named:
|
||||
cb = partial(
|
||||
syncNamedTemporaryFile,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
delete=delete,
|
||||
)
|
||||
else:
|
||||
cb = partial(
|
||||
syncTemporaryFile,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
)
|
||||
|
||||
f = await loop.run_in_executor(executor, cb)
|
||||
|
||||
# Wrap based on type of underlying IO object
|
||||
if type(f) is syncTemporaryFileWrapper:
|
||||
# _TemporaryFileWrapper was used (named files)
|
||||
result = wrap(f.file, f, loop=loop, executor=executor)
|
||||
# add delete property
|
||||
result.delete = f.delete
|
||||
return result
|
||||
# IO object was returned directly without wrapper
|
||||
return wrap(f, f, loop=loop, executor=executor)
|
||||
|
||||
|
||||
async def _spooled_temporary_file(
|
||||
max_size=0,
|
||||
mode="w+b",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
newline=None,
|
||||
suffix=None,
|
||||
prefix=None,
|
||||
dir=None,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Open a spooled temporary file with async interface"""
|
||||
if loop is None:
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
cb = partial(
|
||||
syncSpooledTemporaryFile,
|
||||
max_size=max_size,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
newline=newline,
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
dir=dir,
|
||||
)
|
||||
|
||||
f = await loop.run_in_executor(executor, cb)
|
||||
|
||||
# Single interface provided by SpooledTemporaryFile for all modes
|
||||
return AsyncSpooledTemporaryFile(f, loop=loop, executor=executor)
|
||||
|
||||
|
||||
async def _temporary_directory(
|
||||
suffix=None, prefix=None, dir=None, loop=None, executor=None
|
||||
):
|
||||
"""Async method to open a temporary directory with async interface"""
|
||||
if loop is None:
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
cb = partial(syncTemporaryDirectory, suffix, prefix, dir)
|
||||
f = await loop.run_in_executor(executor, cb)
|
||||
|
||||
return AsyncTemporaryDirectory(f, loop=loop, executor=executor)
|
||||
|
||||
|
||||
class AiofilesContextManagerTempDir(AiofilesContextManager):
|
||||
"""With returns the directory location, not the object (matching sync lib)"""
|
||||
|
||||
async def __aenter__(self):
|
||||
self._obj = await self._coro
|
||||
return self._obj.name
|
||||
|
||||
|
||||
@singledispatch
|
||||
def wrap(base_io_obj, file, *, loop=None, executor=None):
|
||||
"""Wrap the object with interface based on type of underlying IO"""
|
||||
|
||||
msg = f"Unsupported IO type: {base_io_obj}"
|
||||
raise TypeError(msg)
|
||||
|
||||
|
||||
@wrap.register(TextIOBase)
|
||||
def _(base_io_obj, file, *, loop=None, executor=None):
|
||||
return AsyncTextIOWrapper(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(BufferedWriter)
|
||||
def _(base_io_obj, file, *, loop=None, executor=None):
|
||||
return AsyncBufferedIOBase(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(BufferedReader)
|
||||
@wrap.register(BufferedRandom)
|
||||
def _(base_io_obj, file, *, loop=None, executor=None):
|
||||
return AsyncBufferedReader(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(FileIO)
|
||||
def _(base_io_obj, file, *, loop=None, executor=None):
|
||||
return AsyncFileIO(file, loop=loop, executor=executor)
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
"""Async wrappers for spooled temp files and temp directory objects"""
|
||||
|
||||
from functools import partial
|
||||
|
||||
from ..base import AsyncBase
|
||||
from ..threadpool.utils import (
|
||||
cond_delegate_to_executor,
|
||||
delegate_to_executor,
|
||||
proxy_property_directly,
|
||||
)
|
||||
|
||||
|
||||
@delegate_to_executor("fileno", "rollover")
|
||||
@cond_delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"tell",
|
||||
"truncate",
|
||||
)
|
||||
@proxy_property_directly("closed", "encoding", "mode", "name", "newlines")
|
||||
class AsyncSpooledTemporaryFile(AsyncBase):
|
||||
"""Async wrapper for SpooledTemporaryFile class"""
|
||||
|
||||
async def _check(self):
|
||||
if self._file._rolled:
|
||||
return
|
||||
max_size = self._file._max_size
|
||||
if max_size and self._file.tell() > max_size:
|
||||
await self.rollover()
|
||||
|
||||
async def write(self, s):
|
||||
"""Implementation to anticipate rollover"""
|
||||
if self._file._rolled:
|
||||
cb = partial(self._file.write, s)
|
||||
return await self._loop.run_in_executor(self._executor, cb)
|
||||
|
||||
file = self._file._file # reference underlying base IO object
|
||||
rv = file.write(s)
|
||||
await self._check()
|
||||
return rv
|
||||
|
||||
async def writelines(self, iterable):
|
||||
"""Implementation to anticipate rollover"""
|
||||
if self._file._rolled:
|
||||
cb = partial(self._file.writelines, iterable)
|
||||
return await self._loop.run_in_executor(self._executor, cb)
|
||||
|
||||
file = self._file._file # reference underlying base IO object
|
||||
rv = file.writelines(iterable)
|
||||
await self._check()
|
||||
return rv
|
||||
|
||||
|
||||
@delegate_to_executor("cleanup")
|
||||
@proxy_property_directly("name")
|
||||
class AsyncTemporaryDirectory:
|
||||
"""Async wrapper for TemporaryDirectory class"""
|
||||
|
||||
def __init__(self, file, loop, executor):
|
||||
self._file = file
|
||||
self._loop = loop
|
||||
self._executor = executor
|
||||
|
||||
async def close(self):
|
||||
await self.cleanup()
|
||||
@@ -0,0 +1,141 @@
|
||||
"""Handle files using a thread pool executor."""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from functools import partial, singledispatch
|
||||
from io import (
|
||||
BufferedIOBase,
|
||||
BufferedRandom,
|
||||
BufferedReader,
|
||||
BufferedWriter,
|
||||
FileIO,
|
||||
TextIOBase,
|
||||
)
|
||||
|
||||
from ..base import AiofilesContextManager
|
||||
from .binary import (
|
||||
AsyncBufferedIOBase,
|
||||
AsyncBufferedReader,
|
||||
AsyncFileIO,
|
||||
AsyncIndirectBufferedIOBase,
|
||||
)
|
||||
from .text import AsyncTextIndirectIOWrapper, AsyncTextIOWrapper
|
||||
|
||||
sync_open = open
|
||||
|
||||
__all__ = (
|
||||
"open",
|
||||
"stdin",
|
||||
"stdout",
|
||||
"stderr",
|
||||
"stdin_bytes",
|
||||
"stdout_bytes",
|
||||
"stderr_bytes",
|
||||
)
|
||||
|
||||
|
||||
def open(
|
||||
file,
|
||||
mode="r",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
errors=None,
|
||||
newline=None,
|
||||
closefd=True,
|
||||
opener=None,
|
||||
*,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
return AiofilesContextManager(
|
||||
_open(
|
||||
file,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
errors=errors,
|
||||
newline=newline,
|
||||
closefd=closefd,
|
||||
opener=opener,
|
||||
loop=loop,
|
||||
executor=executor,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def _open(
|
||||
file,
|
||||
mode="r",
|
||||
buffering=-1,
|
||||
encoding=None,
|
||||
errors=None,
|
||||
newline=None,
|
||||
closefd=True,
|
||||
opener=None,
|
||||
*,
|
||||
loop=None,
|
||||
executor=None,
|
||||
):
|
||||
"""Open an asyncio file."""
|
||||
if loop is None:
|
||||
loop = asyncio.get_running_loop()
|
||||
cb = partial(
|
||||
sync_open,
|
||||
file,
|
||||
mode=mode,
|
||||
buffering=buffering,
|
||||
encoding=encoding,
|
||||
errors=errors,
|
||||
newline=newline,
|
||||
closefd=closefd,
|
||||
opener=opener,
|
||||
)
|
||||
f = await loop.run_in_executor(executor, cb)
|
||||
|
||||
return wrap(f, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@singledispatch
|
||||
def wrap(file, *, loop=None, executor=None):
|
||||
msg = f"Unsupported io type: {file}."
|
||||
raise TypeError(msg)
|
||||
|
||||
|
||||
@wrap.register(TextIOBase)
|
||||
def _(file, *, loop=None, executor=None):
|
||||
return AsyncTextIOWrapper(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(BufferedWriter)
|
||||
@wrap.register(BufferedIOBase)
|
||||
def _(file, *, loop=None, executor=None):
|
||||
return AsyncBufferedIOBase(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(BufferedReader)
|
||||
@wrap.register(BufferedRandom)
|
||||
def _(file, *, loop=None, executor=None):
|
||||
return AsyncBufferedReader(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
@wrap.register(FileIO)
|
||||
def _(file, *, loop=None, executor=None):
|
||||
return AsyncFileIO(file, loop=loop, executor=executor)
|
||||
|
||||
|
||||
stdin = AsyncTextIndirectIOWrapper("sys.stdin", None, None, indirect=lambda: sys.stdin)
|
||||
stdout = AsyncTextIndirectIOWrapper(
|
||||
"sys.stdout", None, None, indirect=lambda: sys.stdout
|
||||
)
|
||||
stderr = AsyncTextIndirectIOWrapper(
|
||||
"sys.stderr", None, None, indirect=lambda: sys.stderr
|
||||
)
|
||||
stdin_bytes = AsyncIndirectBufferedIOBase(
|
||||
"sys.stdin.buffer", None, None, indirect=lambda: sys.stdin.buffer
|
||||
)
|
||||
stdout_bytes = AsyncIndirectBufferedIOBase(
|
||||
"sys.stdout.buffer", None, None, indirect=lambda: sys.stdout.buffer
|
||||
)
|
||||
stderr_bytes = AsyncIndirectBufferedIOBase(
|
||||
"sys.stderr.buffer", None, None, indirect=lambda: sys.stderr.buffer
|
||||
)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
104
.venv/lib/python3.11/site-packages/aiofiles/threadpool/binary.py
Normal file
104
.venv/lib/python3.11/site-packages/aiofiles/threadpool/binary.py
Normal file
@@ -0,0 +1,104 @@
|
||||
from ..base import AsyncBase, AsyncIndirectBase
|
||||
from .utils import delegate_to_executor, proxy_method_directly, proxy_property_directly
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"read1",
|
||||
"readinto",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"writable",
|
||||
"write",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("detach", "fileno", "readable")
|
||||
@proxy_property_directly("closed", "raw", "name", "mode")
|
||||
class AsyncBufferedIOBase(AsyncBase):
|
||||
"""The asyncio executor version of io.BufferedWriter and BufferedIOBase."""
|
||||
|
||||
|
||||
@delegate_to_executor("peek")
|
||||
class AsyncBufferedReader(AsyncBufferedIOBase):
|
||||
"""The asyncio executor version of io.BufferedReader and Random."""
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"readall",
|
||||
"readinto",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"writable",
|
||||
"write",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("fileno", "readable")
|
||||
@proxy_property_directly("closed", "name", "mode")
|
||||
class AsyncFileIO(AsyncBase):
|
||||
"""The asyncio executor version of io.FileIO."""
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"read1",
|
||||
"readinto",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"writable",
|
||||
"write",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("detach", "fileno", "readable")
|
||||
@proxy_property_directly("closed", "raw", "name", "mode")
|
||||
class AsyncIndirectBufferedIOBase(AsyncIndirectBase):
|
||||
"""The indirect asyncio executor version of io.BufferedWriter and BufferedIOBase."""
|
||||
|
||||
|
||||
@delegate_to_executor("peek")
|
||||
class AsyncIndirectBufferedReader(AsyncIndirectBufferedIOBase):
|
||||
"""The indirect asyncio executor version of io.BufferedReader and Random."""
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"readall",
|
||||
"readinto",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"writable",
|
||||
"write",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("fileno", "readable")
|
||||
@proxy_property_directly("closed", "name", "mode")
|
||||
class AsyncIndirectFileIO(AsyncIndirectBase):
|
||||
"""The indirect asyncio executor version of io.FileIO."""
|
||||
@@ -0,0 +1,64 @@
|
||||
from ..base import AsyncBase, AsyncIndirectBase
|
||||
from .utils import delegate_to_executor, proxy_method_directly, proxy_property_directly
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"readable",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"write",
|
||||
"writable",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("detach", "fileno", "readable")
|
||||
@proxy_property_directly(
|
||||
"buffer",
|
||||
"closed",
|
||||
"encoding",
|
||||
"errors",
|
||||
"line_buffering",
|
||||
"newlines",
|
||||
"name",
|
||||
"mode",
|
||||
)
|
||||
class AsyncTextIOWrapper(AsyncBase):
|
||||
"""The asyncio executor version of io.TextIOWrapper."""
|
||||
|
||||
|
||||
@delegate_to_executor(
|
||||
"close",
|
||||
"flush",
|
||||
"isatty",
|
||||
"read",
|
||||
"readable",
|
||||
"readline",
|
||||
"readlines",
|
||||
"seek",
|
||||
"seekable",
|
||||
"tell",
|
||||
"truncate",
|
||||
"write",
|
||||
"writable",
|
||||
"writelines",
|
||||
)
|
||||
@proxy_method_directly("detach", "fileno", "readable")
|
||||
@proxy_property_directly(
|
||||
"buffer",
|
||||
"closed",
|
||||
"encoding",
|
||||
"errors",
|
||||
"line_buffering",
|
||||
"newlines",
|
||||
"name",
|
||||
"mode",
|
||||
)
|
||||
class AsyncTextIndirectIOWrapper(AsyncIndirectBase):
|
||||
"""The indirect asyncio executor version of io.TextIOWrapper."""
|
||||
@@ -0,0 +1,71 @@
|
||||
import functools
|
||||
|
||||
|
||||
def delegate_to_executor(*attrs):
|
||||
def cls_builder(cls):
|
||||
for attr_name in attrs:
|
||||
setattr(cls, attr_name, _make_delegate_method(attr_name))
|
||||
return cls
|
||||
|
||||
return cls_builder
|
||||
|
||||
|
||||
def proxy_method_directly(*attrs):
|
||||
def cls_builder(cls):
|
||||
for attr_name in attrs:
|
||||
setattr(cls, attr_name, _make_proxy_method(attr_name))
|
||||
return cls
|
||||
|
||||
return cls_builder
|
||||
|
||||
|
||||
def proxy_property_directly(*attrs):
|
||||
def cls_builder(cls):
|
||||
for attr_name in attrs:
|
||||
setattr(cls, attr_name, _make_proxy_property(attr_name))
|
||||
return cls
|
||||
|
||||
return cls_builder
|
||||
|
||||
|
||||
def cond_delegate_to_executor(*attrs):
|
||||
def cls_builder(cls):
|
||||
for attr_name in attrs:
|
||||
setattr(cls, attr_name, _make_cond_delegate_method(attr_name))
|
||||
return cls
|
||||
|
||||
return cls_builder
|
||||
|
||||
|
||||
def _make_delegate_method(attr_name):
|
||||
async def method(self, *args, **kwargs):
|
||||
cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs)
|
||||
return await self._loop.run_in_executor(self._executor, cb)
|
||||
|
||||
return method
|
||||
|
||||
|
||||
def _make_proxy_method(attr_name):
|
||||
def method(self, *args, **kwargs):
|
||||
return getattr(self._file, attr_name)(*args, **kwargs)
|
||||
|
||||
return method
|
||||
|
||||
|
||||
def _make_proxy_property(attr_name):
|
||||
def proxy_property(self):
|
||||
return getattr(self._file, attr_name)
|
||||
|
||||
return property(proxy_property)
|
||||
|
||||
|
||||
def _make_cond_delegate_method(attr_name):
|
||||
"""For spooled temp files, delegate only if rolled to file object"""
|
||||
|
||||
async def method(self, *args, **kwargs):
|
||||
if self._file._rolled:
|
||||
cb = functools.partial(getattr(self._file, attr_name), *args, **kwargs)
|
||||
return await self._loop.run_in_executor(self._executor, cb)
|
||||
return getattr(self._file, attr_name)(*args, **kwargs)
|
||||
|
||||
return method
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,145 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: annotated-doc
|
||||
Version: 0.0.4
|
||||
Summary: Document parameters, class attributes, return types, and variables inline, with Annotated.
|
||||
Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
|
||||
License-Expression: MIT
|
||||
License-File: LICENSE
|
||||
Classifier: Intended Audience :: Information Technology
|
||||
Classifier: Intended Audience :: System Administrators
|
||||
Classifier: Operating System :: OS Independent
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Topic :: Internet
|
||||
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Classifier: Topic :: Software Development :: Libraries
|
||||
Classifier: Topic :: Software Development
|
||||
Classifier: Typing :: Typed
|
||||
Classifier: Development Status :: 4 - Beta
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: Programming Language :: Python :: 3 :: Only
|
||||
Classifier: Programming Language :: Python :: 3.8
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Project-URL: Homepage, https://github.com/fastapi/annotated-doc
|
||||
Project-URL: Documentation, https://github.com/fastapi/annotated-doc
|
||||
Project-URL: Repository, https://github.com/fastapi/annotated-doc
|
||||
Project-URL: Issues, https://github.com/fastapi/annotated-doc/issues
|
||||
Project-URL: Changelog, https://github.com/fastapi/annotated-doc/release-notes.md
|
||||
Requires-Python: >=3.8
|
||||
Description-Content-Type: text/markdown
|
||||
|
||||
# Annotated Doc
|
||||
|
||||
Document parameters, class attributes, return types, and variables inline, with `Annotated`.
|
||||
|
||||
<a href="https://github.com/fastapi/annotated-doc/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
|
||||
<img src="https://github.com/fastapi/annotated-doc/actions/workflows/test.yml/badge.svg?event=push&branch=main" alt="Test">
|
||||
</a>
|
||||
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/annotated-doc" target="_blank">
|
||||
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/annotated-doc.svg" alt="Coverage">
|
||||
</a>
|
||||
<a href="https://pypi.org/project/annotated-doc" target="_blank">
|
||||
<img src="https://img.shields.io/pypi/v/annotated-doc?color=%2334D058&label=pypi%20package" alt="Package version">
|
||||
</a>
|
||||
<a href="https://pypi.org/project/annotated-doc" target="_blank">
|
||||
<img src="https://img.shields.io/pypi/pyversions/annotated-doc.svg?color=%2334D058" alt="Supported Python versions">
|
||||
</a>
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install annotated-doc
|
||||
```
|
||||
|
||||
Or with `uv`:
|
||||
|
||||
```Python
|
||||
uv add annotated-doc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Import `Doc` and pass a single literal string with the documentation for the specific parameter, class attribute, return type, or variable.
|
||||
|
||||
For example, to document a parameter `name` in a function `hi` you could do:
|
||||
|
||||
```Python
|
||||
from typing import Annotated
|
||||
|
||||
from annotated_doc import Doc
|
||||
|
||||
def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None:
|
||||
print(f"Hi, {name}!")
|
||||
```
|
||||
|
||||
You can also use it to document class attributes:
|
||||
|
||||
```Python
|
||||
from typing import Annotated
|
||||
|
||||
from annotated_doc import Doc
|
||||
|
||||
class User:
|
||||
name: Annotated[str, Doc("The user's name")]
|
||||
age: Annotated[int, Doc("The user's age")]
|
||||
```
|
||||
|
||||
The same way, you could document return types and variables, or anything that could have a type annotation with `Annotated`.
|
||||
|
||||
## Who Uses This
|
||||
|
||||
`annotated-doc` was made for:
|
||||
|
||||
* [FastAPI](https://fastapi.tiangolo.com/)
|
||||
* [Typer](https://typer.tiangolo.com/)
|
||||
* [SQLModel](https://sqlmodel.tiangolo.com/)
|
||||
* [Asyncer](https://asyncer.tiangolo.com/)
|
||||
|
||||
`annotated-doc` is supported by [griffe-typingdoc](https://github.com/mkdocstrings/griffe-typingdoc), which powers reference documentation like the one in the [FastAPI Reference](https://fastapi.tiangolo.com/reference/).
|
||||
|
||||
## Reasons not to use `annotated-doc`
|
||||
|
||||
You are already comfortable with one of the existing docstring formats, like:
|
||||
|
||||
* Sphinx
|
||||
* numpydoc
|
||||
* Google
|
||||
* Keras
|
||||
|
||||
Your team is already comfortable using them.
|
||||
|
||||
You prefer having the documentation about parameters all together in a docstring, separated from the code defining them.
|
||||
|
||||
You care about a specific set of users, using one specific editor, and that editor already has support for the specific docstring format you use.
|
||||
|
||||
## Reasons to use `annotated-doc`
|
||||
|
||||
* No micro-syntax to learn for newcomers, it’s **just Python** syntax.
|
||||
* **Editing** would be already fully supported by default by any editor (current or future) supporting Python syntax, including syntax errors, syntax highlighting, etc.
|
||||
* **Rendering** would be relatively straightforward to implement by static tools (tools that don't need runtime execution), as the information can be extracted from the AST they normally already create.
|
||||
* **Deduplication of information**: the name of a parameter would be defined in a single place, not duplicated inside of a docstring.
|
||||
* **Elimination** of the possibility of having **inconsistencies** when removing a parameter or class variable and **forgetting to remove** its documentation.
|
||||
* **Minimization** of the probability of adding a new parameter or class variable and **forgetting to add its documentation**.
|
||||
* **Elimination** of the possibility of having **inconsistencies** between the **name** of a parameter in the **signature** and the name in the docstring when it is renamed.
|
||||
* **Access** to the documentation string for each symbol at **runtime**, including existing (older) Python versions.
|
||||
* A more formalized way to document other symbols, like type aliases, that could use Annotated.
|
||||
* **Support** for apps using FastAPI, Typer and others.
|
||||
* **AI Accessibility**: AI tools will have an easier way understanding each parameter as the distance from documentation to parameter is much closer.
|
||||
|
||||
## History
|
||||
|
||||
I ([@tiangolo](https://github.com/tiangolo)) originally wanted for this to be part of the Python standard library (in [PEP 727](https://peps.python.org/pep-0727/)), but the proposal was withdrawn as there was a fair amount of negative feedback and opposition.
|
||||
|
||||
The conclusion was that this was better done as an external effort, in a third-party library.
|
||||
|
||||
So, here it is, with a simpler approach, as a third-party library, in a way that can be used by others, starting with FastAPI and friends.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the terms of the MIT license.
|
||||
@@ -0,0 +1,11 @@
|
||||
annotated_doc-0.0.4.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
annotated_doc-0.0.4.dist-info/METADATA,sha256=Irm5KJua33dY2qKKAjJ-OhKaVBVIfwFGej_dSe3Z1TU,6566
|
||||
annotated_doc-0.0.4.dist-info/RECORD,,
|
||||
annotated_doc-0.0.4.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
|
||||
annotated_doc-0.0.4.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
||||
annotated_doc-0.0.4.dist-info/licenses/LICENSE,sha256=__Fwd5pqy_ZavbQFwIfxzuF4ZpHkqWpANFF-SlBKDN8,1086
|
||||
annotated_doc/__init__.py,sha256=VuyxxUe80kfEyWnOrCx_Bk8hybo3aKo6RYBlkBBYW8k,52
|
||||
annotated_doc/__pycache__/__init__.cpython-311.pyc,,
|
||||
annotated_doc/__pycache__/main.cpython-311.pyc,,
|
||||
annotated_doc/main.py,sha256=5Zfvxv80SwwLqpRW73AZyZyiM4bWma9QWRbp_cgD20s,1075
|
||||
annotated_doc/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
@@ -0,0 +1,4 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: pdm-backend (2.4.5)
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
@@ -0,0 +1,4 @@
|
||||
[console_scripts]
|
||||
|
||||
[gui_scripts]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2025 Sebastián Ramírez
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -0,0 +1,3 @@
|
||||
from .main import Doc as Doc
|
||||
|
||||
__version__ = "0.0.4"
|
||||
Binary file not shown.
Binary file not shown.
36
.venv/lib/python3.11/site-packages/annotated_doc/main.py
Normal file
36
.venv/lib/python3.11/site-packages/annotated_doc/main.py
Normal file
@@ -0,0 +1,36 @@
|
||||
class Doc:
|
||||
"""Define the documentation of a type annotation using `Annotated`, to be
|
||||
used in class attributes, function and method parameters, return values,
|
||||
and variables.
|
||||
|
||||
The value should be a positional-only string literal to allow static tools
|
||||
like editors and documentation generators to use it.
|
||||
|
||||
This complements docstrings.
|
||||
|
||||
The string value passed is available in the attribute `documentation`.
|
||||
|
||||
Example:
|
||||
|
||||
```Python
|
||||
from typing import Annotated
|
||||
from annotated_doc import Doc
|
||||
|
||||
def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None:
|
||||
print(f"Hi, {name}!")
|
||||
```
|
||||
"""
|
||||
|
||||
def __init__(self, documentation: str, /) -> None:
|
||||
self.documentation = documentation
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Doc({self.documentation!r})"
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(self.documentation)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, Doc):
|
||||
return NotImplemented
|
||||
return self.documentation == other.documentation
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,295 @@
|
||||
Metadata-Version: 2.3
|
||||
Name: annotated-types
|
||||
Version: 0.7.0
|
||||
Summary: Reusable constraint types to use with typing.Annotated
|
||||
Project-URL: Homepage, https://github.com/annotated-types/annotated-types
|
||||
Project-URL: Source, https://github.com/annotated-types/annotated-types
|
||||
Project-URL: Changelog, https://github.com/annotated-types/annotated-types/releases
|
||||
Author-email: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>, Samuel Colvin <s@muelcolvin.com>, Zac Hatfield-Dodds <zac@zhd.dev>
|
||||
License-File: LICENSE
|
||||
Classifier: Development Status :: 4 - Beta
|
||||
Classifier: Environment :: Console
|
||||
Classifier: Environment :: MacOS X
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: Intended Audience :: Information Technology
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Operating System :: POSIX :: Linux
|
||||
Classifier: Operating System :: Unix
|
||||
Classifier: Programming Language :: Python :: 3 :: Only
|
||||
Classifier: Programming Language :: Python :: 3.8
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
||||
Classifier: Typing :: Typed
|
||||
Requires-Python: >=3.8
|
||||
Requires-Dist: typing-extensions>=4.0.0; python_version < '3.9'
|
||||
Description-Content-Type: text/markdown
|
||||
|
||||
# annotated-types
|
||||
|
||||
[](https://github.com/annotated-types/annotated-types/actions?query=event%3Apush+branch%3Amain+workflow%3ACI)
|
||||
[](https://pypi.python.org/pypi/annotated-types)
|
||||
[](https://github.com/annotated-types/annotated-types)
|
||||
[](https://github.com/annotated-types/annotated-types/blob/main/LICENSE)
|
||||
|
||||
[PEP-593](https://peps.python.org/pep-0593/) added `typing.Annotated` as a way of
|
||||
adding context-specific metadata to existing types, and specifies that
|
||||
`Annotated[T, x]` _should_ be treated as `T` by any tool or library without special
|
||||
logic for `x`.
|
||||
|
||||
This package provides metadata objects which can be used to represent common
|
||||
constraints such as upper and lower bounds on scalar values and collection sizes,
|
||||
a `Predicate` marker for runtime checks, and
|
||||
descriptions of how we intend these metadata to be interpreted. In some cases,
|
||||
we also note alternative representations which do not require this package.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pip install annotated-types
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```python
|
||||
from typing import Annotated
|
||||
from annotated_types import Gt, Len, Predicate
|
||||
|
||||
class MyClass:
|
||||
age: Annotated[int, Gt(18)] # Valid: 19, 20, ...
|
||||
# Invalid: 17, 18, "19", 19.0, ...
|
||||
factors: list[Annotated[int, Predicate(is_prime)]] # Valid: 2, 3, 5, 7, 11, ...
|
||||
# Invalid: 4, 8, -2, 5.0, "prime", ...
|
||||
|
||||
my_list: Annotated[list[int], Len(0, 10)] # Valid: [], [10, 20, 30, 40, 50]
|
||||
# Invalid: (1, 2), ["abc"], [0] * 20
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
_While `annotated-types` avoids runtime checks for performance, users should not
|
||||
construct invalid combinations such as `MultipleOf("non-numeric")` or `Annotated[int, Len(3)]`.
|
||||
Downstream implementors may choose to raise an error, emit a warning, silently ignore
|
||||
a metadata item, etc., if the metadata objects described below are used with an
|
||||
incompatible type - or for any other reason!_
|
||||
|
||||
### Gt, Ge, Lt, Le
|
||||
|
||||
Express inclusive and/or exclusive bounds on orderable values - which may be numbers,
|
||||
dates, times, strings, sets, etc. Note that the boundary value need not be of the
|
||||
same type that was annotated, so long as they can be compared: `Annotated[int, Gt(1.5)]`
|
||||
is fine, for example, and implies that the value is an integer x such that `x > 1.5`.
|
||||
|
||||
We suggest that implementors may also interpret `functools.partial(operator.le, 1.5)`
|
||||
as being equivalent to `Gt(1.5)`, for users who wish to avoid a runtime dependency on
|
||||
the `annotated-types` package.
|
||||
|
||||
To be explicit, these types have the following meanings:
|
||||
|
||||
* `Gt(x)` - value must be "Greater Than" `x` - equivalent to exclusive minimum
|
||||
* `Ge(x)` - value must be "Greater than or Equal" to `x` - equivalent to inclusive minimum
|
||||
* `Lt(x)` - value must be "Less Than" `x` - equivalent to exclusive maximum
|
||||
* `Le(x)` - value must be "Less than or Equal" to `x` - equivalent to inclusive maximum
|
||||
|
||||
### Interval
|
||||
|
||||
`Interval(gt, ge, lt, le)` allows you to specify an upper and lower bound with a single
|
||||
metadata object. `None` attributes should be ignored, and non-`None` attributes
|
||||
treated as per the single bounds above.
|
||||
|
||||
### MultipleOf
|
||||
|
||||
`MultipleOf(multiple_of=x)` might be interpreted in two ways:
|
||||
|
||||
1. Python semantics, implying `value % multiple_of == 0`, or
|
||||
2. [JSONschema semantics](https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.2.1),
|
||||
where `int(value / multiple_of) == value / multiple_of`.
|
||||
|
||||
We encourage users to be aware of these two common interpretations and their
|
||||
distinct behaviours, especially since very large or non-integer numbers make
|
||||
it easy to cause silent data corruption due to floating-point imprecision.
|
||||
|
||||
We encourage libraries to carefully document which interpretation they implement.
|
||||
|
||||
### MinLen, MaxLen, Len
|
||||
|
||||
`Len()` implies that `min_length <= len(value) <= max_length` - lower and upper bounds are inclusive.
|
||||
|
||||
As well as `Len()` which can optionally include upper and lower bounds, we also
|
||||
provide `MinLen(x)` and `MaxLen(y)` which are equivalent to `Len(min_length=x)`
|
||||
and `Len(max_length=y)` respectively.
|
||||
|
||||
`Len`, `MinLen`, and `MaxLen` may be used with any type which supports `len(value)`.
|
||||
|
||||
Examples of usage:
|
||||
|
||||
* `Annotated[list, MaxLen(10)]` (or `Annotated[list, Len(max_length=10))`) - list must have a length of 10 or less
|
||||
* `Annotated[str, MaxLen(10)]` - string must have a length of 10 or less
|
||||
* `Annotated[list, MinLen(3))` (or `Annotated[list, Len(min_length=3))`) - list must have a length of 3 or more
|
||||
* `Annotated[list, Len(4, 6)]` - list must have a length of 4, 5, or 6
|
||||
* `Annotated[list, Len(8, 8)]` - list must have a length of exactly 8
|
||||
|
||||
#### Changed in v0.4.0
|
||||
|
||||
* `min_inclusive` has been renamed to `min_length`, no change in meaning
|
||||
* `max_exclusive` has been renamed to `max_length`, upper bound is now **inclusive** instead of **exclusive**
|
||||
* The recommendation that slices are interpreted as `Len` has been removed due to ambiguity and different semantic
|
||||
meaning of the upper bound in slices vs. `Len`
|
||||
|
||||
See [issue #23](https://github.com/annotated-types/annotated-types/issues/23) for discussion.
|
||||
|
||||
### Timezone
|
||||
|
||||
`Timezone` can be used with a `datetime` or a `time` to express which timezones
|
||||
are allowed. `Annotated[datetime, Timezone(None)]` must be a naive datetime.
|
||||
`Timezone[...]` ([literal ellipsis](https://docs.python.org/3/library/constants.html#Ellipsis))
|
||||
expresses that any timezone-aware datetime is allowed. You may also pass a specific
|
||||
timezone string or [`tzinfo`](https://docs.python.org/3/library/datetime.html#tzinfo-objects)
|
||||
object such as `Timezone(timezone.utc)` or `Timezone("Africa/Abidjan")` to express that you only
|
||||
allow a specific timezone, though we note that this is often a symptom of fragile design.
|
||||
|
||||
#### Changed in v0.x.x
|
||||
|
||||
* `Timezone` accepts [`tzinfo`](https://docs.python.org/3/library/datetime.html#tzinfo-objects) objects instead of
|
||||
`timezone`, extending compatibility to [`zoneinfo`](https://docs.python.org/3/library/zoneinfo.html) and third party libraries.
|
||||
|
||||
### Unit
|
||||
|
||||
`Unit(unit: str)` expresses that the annotated numeric value is the magnitude of
|
||||
a quantity with the specified unit. For example, `Annotated[float, Unit("m/s")]`
|
||||
would be a float representing a velocity in meters per second.
|
||||
|
||||
Please note that `annotated_types` itself makes no attempt to parse or validate
|
||||
the unit string in any way. That is left entirely to downstream libraries,
|
||||
such as [`pint`](https://pint.readthedocs.io) or
|
||||
[`astropy.units`](https://docs.astropy.org/en/stable/units/).
|
||||
|
||||
An example of how a library might use this metadata:
|
||||
|
||||
```python
|
||||
from annotated_types import Unit
|
||||
from typing import Annotated, TypeVar, Callable, Any, get_origin, get_args
|
||||
|
||||
# given a type annotated with a unit:
|
||||
Meters = Annotated[float, Unit("m")]
|
||||
|
||||
|
||||
# you can cast the annotation to a specific unit type with any
|
||||
# callable that accepts a string and returns the desired type
|
||||
T = TypeVar("T")
|
||||
def cast_unit(tp: Any, unit_cls: Callable[[str], T]) -> T | None:
|
||||
if get_origin(tp) is Annotated:
|
||||
for arg in get_args(tp):
|
||||
if isinstance(arg, Unit):
|
||||
return unit_cls(arg.unit)
|
||||
return None
|
||||
|
||||
|
||||
# using `pint`
|
||||
import pint
|
||||
pint_unit = cast_unit(Meters, pint.Unit)
|
||||
|
||||
|
||||
# using `astropy.units`
|
||||
import astropy.units as u
|
||||
astropy_unit = cast_unit(Meters, u.Unit)
|
||||
```
|
||||
|
||||
### Predicate
|
||||
|
||||
`Predicate(func: Callable)` expresses that `func(value)` is truthy for valid values.
|
||||
Users should prefer the statically inspectable metadata above, but if you need
|
||||
the full power and flexibility of arbitrary runtime predicates... here it is.
|
||||
|
||||
For some common constraints, we provide generic types:
|
||||
|
||||
* `IsLower = Annotated[T, Predicate(str.islower)]`
|
||||
* `IsUpper = Annotated[T, Predicate(str.isupper)]`
|
||||
* `IsDigit = Annotated[T, Predicate(str.isdigit)]`
|
||||
* `IsFinite = Annotated[T, Predicate(math.isfinite)]`
|
||||
* `IsNotFinite = Annotated[T, Predicate(Not(math.isfinite))]`
|
||||
* `IsNan = Annotated[T, Predicate(math.isnan)]`
|
||||
* `IsNotNan = Annotated[T, Predicate(Not(math.isnan))]`
|
||||
* `IsInfinite = Annotated[T, Predicate(math.isinf)]`
|
||||
* `IsNotInfinite = Annotated[T, Predicate(Not(math.isinf))]`
|
||||
|
||||
so that you can write e.g. `x: IsFinite[float] = 2.0` instead of the longer
|
||||
(but exactly equivalent) `x: Annotated[float, Predicate(math.isfinite)] = 2.0`.
|
||||
|
||||
Some libraries might have special logic to handle known or understandable predicates,
|
||||
for example by checking for `str.isdigit` and using its presence to both call custom
|
||||
logic to enforce digit-only strings, and customise some generated external schema.
|
||||
Users are therefore encouraged to avoid indirection like `lambda s: s.lower()`, in
|
||||
favor of introspectable methods such as `str.lower` or `re.compile("pattern").search`.
|
||||
|
||||
To enable basic negation of commonly used predicates like `math.isnan` without introducing introspection that makes it impossible for implementers to introspect the predicate we provide a `Not` wrapper that simply negates the predicate in an introspectable manner. Several of the predicates listed above are created in this manner.
|
||||
|
||||
We do not specify what behaviour should be expected for predicates that raise
|
||||
an exception. For example `Annotated[int, Predicate(str.isdigit)]` might silently
|
||||
skip invalid constraints, or statically raise an error; or it might try calling it
|
||||
and then propagate or discard the resulting
|
||||
`TypeError: descriptor 'isdigit' for 'str' objects doesn't apply to a 'int' object`
|
||||
exception. We encourage libraries to document the behaviour they choose.
|
||||
|
||||
### Doc
|
||||
|
||||
`doc()` can be used to add documentation information in `Annotated`, for function and method parameters, variables, class attributes, return types, and any place where `Annotated` can be used.
|
||||
|
||||
It expects a value that can be statically analyzed, as the main use case is for static analysis, editors, documentation generators, and similar tools.
|
||||
|
||||
It returns a `DocInfo` class with a single attribute `documentation` containing the value passed to `doc()`.
|
||||
|
||||
This is the early adopter's alternative form of the [`typing-doc` proposal](https://github.com/tiangolo/fastapi/blob/typing-doc/typing_doc.md).
|
||||
|
||||
### Integrating downstream types with `GroupedMetadata`
|
||||
|
||||
Implementers may choose to provide a convenience wrapper that groups multiple pieces of metadata.
|
||||
This can help reduce verbosity and cognitive overhead for users.
|
||||
For example, an implementer like Pydantic might provide a `Field` or `Meta` type that accepts keyword arguments and transforms these into low-level metadata:
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
from typing import Iterator
|
||||
from annotated_types import GroupedMetadata, Ge
|
||||
|
||||
@dataclass
|
||||
class Field(GroupedMetadata):
|
||||
ge: int | None = None
|
||||
description: str | None = None
|
||||
|
||||
def __iter__(self) -> Iterator[object]:
|
||||
# Iterating over a GroupedMetadata object should yield annotated-types
|
||||
# constraint metadata objects which describe it as fully as possible,
|
||||
# and may include other unknown objects too.
|
||||
if self.ge is not None:
|
||||
yield Ge(self.ge)
|
||||
if self.description is not None:
|
||||
yield Description(self.description)
|
||||
```
|
||||
|
||||
Libraries consuming annotated-types constraints should check for `GroupedMetadata` and unpack it by iterating over the object and treating the results as if they had been "unpacked" in the `Annotated` type. The same logic should be applied to the [PEP 646 `Unpack` type](https://peps.python.org/pep-0646/), so that `Annotated[T, Field(...)]`, `Annotated[T, Unpack[Field(...)]]` and `Annotated[T, *Field(...)]` are all treated consistently.
|
||||
|
||||
Libraries consuming annotated-types should also ignore any metadata they do not recongize that came from unpacking a `GroupedMetadata`, just like they ignore unrecognized metadata in `Annotated` itself.
|
||||
|
||||
Our own `annotated_types.Interval` class is a `GroupedMetadata` which unpacks itself into `Gt`, `Lt`, etc., so this is not an abstract concern. Similarly, `annotated_types.Len` is a `GroupedMetadata` which unpacks itself into `MinLen` (optionally) and `MaxLen`.
|
||||
|
||||
### Consuming metadata
|
||||
|
||||
We intend to not be prescriptive as to _how_ the metadata and constraints are used, but as an example of how one might parse constraints from types annotations see our [implementation in `test_main.py`](https://github.com/annotated-types/annotated-types/blob/f59cf6d1b5255a0fe359b93896759a180bec30ae/tests/test_main.py#L94-L103).
|
||||
|
||||
It is up to the implementer to determine how this metadata is used.
|
||||
You could use the metadata for runtime type checking, for generating schemas or to generate example data, amongst other use cases.
|
||||
|
||||
## Design & History
|
||||
|
||||
This package was designed at the PyCon 2022 sprints by the maintainers of Pydantic
|
||||
and Hypothesis, with the goal of making it as easy as possible for end-users to
|
||||
provide more informative annotations for use by runtime libraries.
|
||||
|
||||
It is deliberately minimal, and following PEP-593 allows considerable downstream
|
||||
discretion in what (if anything!) they choose to support. Nonetheless, we expect
|
||||
that staying simple and covering _only_ the most common use-cases will give users
|
||||
and maintainers the best experience we can. If you'd like more constraints for your
|
||||
types - follow our lead, by defining them and documenting them downstream!
|
||||
@@ -0,0 +1,10 @@
|
||||
annotated_types-0.7.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||
annotated_types-0.7.0.dist-info/METADATA,sha256=7ltqxksJJ0wCYFGBNIQCWTlWQGeAH0hRFdnK3CB895E,15046
|
||||
annotated_types-0.7.0.dist-info/RECORD,,
|
||||
annotated_types-0.7.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
||||
annotated_types-0.7.0.dist-info/licenses/LICENSE,sha256=_hBJiEsaDZNCkB6I4H8ykl0ksxIdmXK2poBfuYJLCV0,1083
|
||||
annotated_types/__init__.py,sha256=RynLsRKUEGI0KimXydlD1fZEfEzWwDo0Uon3zOKhG1Q,13819
|
||||
annotated_types/__pycache__/__init__.cpython-311.pyc,,
|
||||
annotated_types/__pycache__/test_cases.cpython-311.pyc,,
|
||||
annotated_types/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||
annotated_types/test_cases.py,sha256=zHFX6EpcMbGJ8FzBYDbO56bPwx_DYIVSKbZM-4B3_lg,6421
|
||||
@@ -0,0 +1,4 @@
|
||||
Wheel-Version: 1.0
|
||||
Generator: hatchling 1.24.2
|
||||
Root-Is-Purelib: true
|
||||
Tag: py3-none-any
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2022 the contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
432
.venv/lib/python3.11/site-packages/annotated_types/__init__.py
Normal file
432
.venv/lib/python3.11/site-packages/annotated_types/__init__.py
Normal file
@@ -0,0 +1,432 @@
|
||||
import math
|
||||
import sys
|
||||
import types
|
||||
from dataclasses import dataclass
|
||||
from datetime import tzinfo
|
||||
from typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, SupportsFloat, SupportsIndex, TypeVar, Union
|
||||
|
||||
if sys.version_info < (3, 8):
|
||||
from typing_extensions import Protocol, runtime_checkable
|
||||
else:
|
||||
from typing import Protocol, runtime_checkable
|
||||
|
||||
if sys.version_info < (3, 9):
|
||||
from typing_extensions import Annotated, Literal
|
||||
else:
|
||||
from typing import Annotated, Literal
|
||||
|
||||
if sys.version_info < (3, 10):
|
||||
EllipsisType = type(Ellipsis)
|
||||
KW_ONLY = {}
|
||||
SLOTS = {}
|
||||
else:
|
||||
from types import EllipsisType
|
||||
|
||||
KW_ONLY = {"kw_only": True}
|
||||
SLOTS = {"slots": True}
|
||||
|
||||
|
||||
__all__ = (
|
||||
'BaseMetadata',
|
||||
'GroupedMetadata',
|
||||
'Gt',
|
||||
'Ge',
|
||||
'Lt',
|
||||
'Le',
|
||||
'Interval',
|
||||
'MultipleOf',
|
||||
'MinLen',
|
||||
'MaxLen',
|
||||
'Len',
|
||||
'Timezone',
|
||||
'Predicate',
|
||||
'LowerCase',
|
||||
'UpperCase',
|
||||
'IsDigits',
|
||||
'IsFinite',
|
||||
'IsNotFinite',
|
||||
'IsNan',
|
||||
'IsNotNan',
|
||||
'IsInfinite',
|
||||
'IsNotInfinite',
|
||||
'doc',
|
||||
'DocInfo',
|
||||
'__version__',
|
||||
)
|
||||
|
||||
__version__ = '0.7.0'
|
||||
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
|
||||
# arguments that start with __ are considered
|
||||
# positional only
|
||||
# see https://peps.python.org/pep-0484/#positional-only-arguments
|
||||
|
||||
|
||||
class SupportsGt(Protocol):
|
||||
def __gt__(self: T, __other: T) -> bool:
|
||||
...
|
||||
|
||||
|
||||
class SupportsGe(Protocol):
|
||||
def __ge__(self: T, __other: T) -> bool:
|
||||
...
|
||||
|
||||
|
||||
class SupportsLt(Protocol):
|
||||
def __lt__(self: T, __other: T) -> bool:
|
||||
...
|
||||
|
||||
|
||||
class SupportsLe(Protocol):
|
||||
def __le__(self: T, __other: T) -> bool:
|
||||
...
|
||||
|
||||
|
||||
class SupportsMod(Protocol):
|
||||
def __mod__(self: T, __other: T) -> T:
|
||||
...
|
||||
|
||||
|
||||
class SupportsDiv(Protocol):
|
||||
def __div__(self: T, __other: T) -> T:
|
||||
...
|
||||
|
||||
|
||||
class BaseMetadata:
|
||||
"""Base class for all metadata.
|
||||
|
||||
This exists mainly so that implementers
|
||||
can do `isinstance(..., BaseMetadata)` while traversing field annotations.
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Gt(BaseMetadata):
|
||||
"""Gt(gt=x) implies that the value must be greater than x.
|
||||
|
||||
It can be used with any type that supports the ``>`` operator,
|
||||
including numbers, dates and times, strings, sets, and so on.
|
||||
"""
|
||||
|
||||
gt: SupportsGt
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Ge(BaseMetadata):
|
||||
"""Ge(ge=x) implies that the value must be greater than or equal to x.
|
||||
|
||||
It can be used with any type that supports the ``>=`` operator,
|
||||
including numbers, dates and times, strings, sets, and so on.
|
||||
"""
|
||||
|
||||
ge: SupportsGe
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Lt(BaseMetadata):
|
||||
"""Lt(lt=x) implies that the value must be less than x.
|
||||
|
||||
It can be used with any type that supports the ``<`` operator,
|
||||
including numbers, dates and times, strings, sets, and so on.
|
||||
"""
|
||||
|
||||
lt: SupportsLt
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Le(BaseMetadata):
|
||||
"""Le(le=x) implies that the value must be less than or equal to x.
|
||||
|
||||
It can be used with any type that supports the ``<=`` operator,
|
||||
including numbers, dates and times, strings, sets, and so on.
|
||||
"""
|
||||
|
||||
le: SupportsLe
|
||||
|
||||
|
||||
@runtime_checkable
|
||||
class GroupedMetadata(Protocol):
|
||||
"""A grouping of multiple objects, like typing.Unpack.
|
||||
|
||||
`GroupedMetadata` on its own is not metadata and has no meaning.
|
||||
All of the constraints and metadata should be fully expressable
|
||||
in terms of the `BaseMetadata`'s returned by `GroupedMetadata.__iter__()`.
|
||||
|
||||
Concrete implementations should override `GroupedMetadata.__iter__()`
|
||||
to add their own metadata.
|
||||
For example:
|
||||
|
||||
>>> @dataclass
|
||||
>>> class Field(GroupedMetadata):
|
||||
>>> gt: float | None = None
|
||||
>>> description: str | None = None
|
||||
...
|
||||
>>> def __iter__(self) -> Iterable[object]:
|
||||
>>> if self.gt is not None:
|
||||
>>> yield Gt(self.gt)
|
||||
>>> if self.description is not None:
|
||||
>>> yield Description(self.gt)
|
||||
|
||||
Also see the implementation of `Interval` below for an example.
|
||||
|
||||
Parsers should recognize this and unpack it so that it can be used
|
||||
both with and without unpacking:
|
||||
|
||||
- `Annotated[int, Field(...)]` (parser must unpack Field)
|
||||
- `Annotated[int, *Field(...)]` (PEP-646)
|
||||
""" # noqa: trailing-whitespace
|
||||
|
||||
@property
|
||||
def __is_annotated_types_grouped_metadata__(self) -> Literal[True]:
|
||||
return True
|
||||
|
||||
def __iter__(self) -> Iterator[object]:
|
||||
...
|
||||
|
||||
if not TYPE_CHECKING:
|
||||
__slots__ = () # allow subclasses to use slots
|
||||
|
||||
def __init_subclass__(cls, *args: Any, **kwargs: Any) -> None:
|
||||
# Basic ABC like functionality without the complexity of an ABC
|
||||
super().__init_subclass__(*args, **kwargs)
|
||||
if cls.__iter__ is GroupedMetadata.__iter__:
|
||||
raise TypeError("Can't subclass GroupedMetadata without implementing __iter__")
|
||||
|
||||
def __iter__(self) -> Iterator[object]: # noqa: F811
|
||||
raise NotImplementedError # more helpful than "None has no attribute..." type errors
|
||||
|
||||
|
||||
@dataclass(frozen=True, **KW_ONLY, **SLOTS)
|
||||
class Interval(GroupedMetadata):
|
||||
"""Interval can express inclusive or exclusive bounds with a single object.
|
||||
|
||||
It accepts keyword arguments ``gt``, ``ge``, ``lt``, and/or ``le``, which
|
||||
are interpreted the same way as the single-bound constraints.
|
||||
"""
|
||||
|
||||
gt: Union[SupportsGt, None] = None
|
||||
ge: Union[SupportsGe, None] = None
|
||||
lt: Union[SupportsLt, None] = None
|
||||
le: Union[SupportsLe, None] = None
|
||||
|
||||
def __iter__(self) -> Iterator[BaseMetadata]:
|
||||
"""Unpack an Interval into zero or more single-bounds."""
|
||||
if self.gt is not None:
|
||||
yield Gt(self.gt)
|
||||
if self.ge is not None:
|
||||
yield Ge(self.ge)
|
||||
if self.lt is not None:
|
||||
yield Lt(self.lt)
|
||||
if self.le is not None:
|
||||
yield Le(self.le)
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class MultipleOf(BaseMetadata):
|
||||
"""MultipleOf(multiple_of=x) might be interpreted in two ways:
|
||||
|
||||
1. Python semantics, implying ``value % multiple_of == 0``, or
|
||||
2. JSONschema semantics, where ``int(value / multiple_of) == value / multiple_of``
|
||||
|
||||
We encourage users to be aware of these two common interpretations,
|
||||
and libraries to carefully document which they implement.
|
||||
"""
|
||||
|
||||
multiple_of: Union[SupportsDiv, SupportsMod]
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class MinLen(BaseMetadata):
|
||||
"""
|
||||
MinLen() implies minimum inclusive length,
|
||||
e.g. ``len(value) >= min_length``.
|
||||
"""
|
||||
|
||||
min_length: Annotated[int, Ge(0)]
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class MaxLen(BaseMetadata):
|
||||
"""
|
||||
MaxLen() implies maximum inclusive length,
|
||||
e.g. ``len(value) <= max_length``.
|
||||
"""
|
||||
|
||||
max_length: Annotated[int, Ge(0)]
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Len(GroupedMetadata):
|
||||
"""
|
||||
Len() implies that ``min_length <= len(value) <= max_length``.
|
||||
|
||||
Upper bound may be omitted or ``None`` to indicate no upper length bound.
|
||||
"""
|
||||
|
||||
min_length: Annotated[int, Ge(0)] = 0
|
||||
max_length: Optional[Annotated[int, Ge(0)]] = None
|
||||
|
||||
def __iter__(self) -> Iterator[BaseMetadata]:
|
||||
"""Unpack a Len into zone or more single-bounds."""
|
||||
if self.min_length > 0:
|
||||
yield MinLen(self.min_length)
|
||||
if self.max_length is not None:
|
||||
yield MaxLen(self.max_length)
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Timezone(BaseMetadata):
|
||||
"""Timezone(tz=...) requires a datetime to be aware (or ``tz=None``, naive).
|
||||
|
||||
``Annotated[datetime, Timezone(None)]`` must be a naive datetime.
|
||||
``Timezone[...]`` (the ellipsis literal) expresses that the datetime must be
|
||||
tz-aware but any timezone is allowed.
|
||||
|
||||
You may also pass a specific timezone string or tzinfo object such as
|
||||
``Timezone(timezone.utc)`` or ``Timezone("Africa/Abidjan")`` to express that
|
||||
you only allow a specific timezone, though we note that this is often
|
||||
a symptom of poor design.
|
||||
"""
|
||||
|
||||
tz: Union[str, tzinfo, EllipsisType, None]
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Unit(BaseMetadata):
|
||||
"""Indicates that the value is a physical quantity with the specified unit.
|
||||
|
||||
It is intended for usage with numeric types, where the value represents the
|
||||
magnitude of the quantity. For example, ``distance: Annotated[float, Unit('m')]``
|
||||
or ``speed: Annotated[float, Unit('m/s')]``.
|
||||
|
||||
Interpretation of the unit string is left to the discretion of the consumer.
|
||||
It is suggested to follow conventions established by python libraries that work
|
||||
with physical quantities, such as
|
||||
|
||||
- ``pint`` : <https://pint.readthedocs.io/en/stable/>
|
||||
- ``astropy.units``: <https://docs.astropy.org/en/stable/units/>
|
||||
|
||||
For indicating a quantity with a certain dimensionality but without a specific unit
|
||||
it is recommended to use square brackets, e.g. `Annotated[float, Unit('[time]')]`.
|
||||
Note, however, ``annotated_types`` itself makes no use of the unit string.
|
||||
"""
|
||||
|
||||
unit: str
|
||||
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class Predicate(BaseMetadata):
|
||||
"""``Predicate(func: Callable)`` implies `func(value)` is truthy for valid values.
|
||||
|
||||
Users should prefer statically inspectable metadata, but if you need the full
|
||||
power and flexibility of arbitrary runtime predicates... here it is.
|
||||
|
||||
We provide a few predefined predicates for common string constraints:
|
||||
``IsLower = Predicate(str.islower)``, ``IsUpper = Predicate(str.isupper)``, and
|
||||
``IsDigits = Predicate(str.isdigit)``. Users are encouraged to use methods which
|
||||
can be given special handling, and avoid indirection like ``lambda s: s.lower()``.
|
||||
|
||||
Some libraries might have special logic to handle certain predicates, e.g. by
|
||||
checking for `str.isdigit` and using its presence to both call custom logic to
|
||||
enforce digit-only strings, and customise some generated external schema.
|
||||
|
||||
We do not specify what behaviour should be expected for predicates that raise
|
||||
an exception. For example `Annotated[int, Predicate(str.isdigit)]` might silently
|
||||
skip invalid constraints, or statically raise an error; or it might try calling it
|
||||
and then propagate or discard the resulting exception.
|
||||
"""
|
||||
|
||||
func: Callable[[Any], bool]
|
||||
|
||||
def __repr__(self) -> str:
|
||||
if getattr(self.func, "__name__", "<lambda>") == "<lambda>":
|
||||
return f"{self.__class__.__name__}({self.func!r})"
|
||||
if isinstance(self.func, (types.MethodType, types.BuiltinMethodType)) and (
|
||||
namespace := getattr(self.func.__self__, "__name__", None)
|
||||
):
|
||||
return f"{self.__class__.__name__}({namespace}.{self.func.__name__})"
|
||||
if isinstance(self.func, type(str.isascii)): # method descriptor
|
||||
return f"{self.__class__.__name__}({self.func.__qualname__})"
|
||||
return f"{self.__class__.__name__}({self.func.__name__})"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Not:
|
||||
func: Callable[[Any], bool]
|
||||
|
||||
def __call__(self, __v: Any) -> bool:
|
||||
return not self.func(__v)
|
||||
|
||||
|
||||
_StrType = TypeVar("_StrType", bound=str)
|
||||
|
||||
LowerCase = Annotated[_StrType, Predicate(str.islower)]
|
||||
"""
|
||||
Return True if the string is a lowercase string, False otherwise.
|
||||
|
||||
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
|
||||
""" # noqa: E501
|
||||
UpperCase = Annotated[_StrType, Predicate(str.isupper)]
|
||||
"""
|
||||
Return True if the string is an uppercase string, False otherwise.
|
||||
|
||||
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
|
||||
""" # noqa: E501
|
||||
IsDigit = Annotated[_StrType, Predicate(str.isdigit)]
|
||||
IsDigits = IsDigit # type: ignore # plural for backwards compatibility, see #63
|
||||
"""
|
||||
Return True if the string is a digit string, False otherwise.
|
||||
|
||||
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
|
||||
""" # noqa: E501
|
||||
IsAscii = Annotated[_StrType, Predicate(str.isascii)]
|
||||
"""
|
||||
Return True if all characters in the string are ASCII, False otherwise.
|
||||
|
||||
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
|
||||
"""
|
||||
|
||||
_NumericType = TypeVar('_NumericType', bound=Union[SupportsFloat, SupportsIndex])
|
||||
IsFinite = Annotated[_NumericType, Predicate(math.isfinite)]
|
||||
"""Return True if x is neither an infinity nor a NaN, and False otherwise."""
|
||||
IsNotFinite = Annotated[_NumericType, Predicate(Not(math.isfinite))]
|
||||
"""Return True if x is one of infinity or NaN, and False otherwise"""
|
||||
IsNan = Annotated[_NumericType, Predicate(math.isnan)]
|
||||
"""Return True if x is a NaN (not a number), and False otherwise."""
|
||||
IsNotNan = Annotated[_NumericType, Predicate(Not(math.isnan))]
|
||||
"""Return True if x is anything but NaN (not a number), and False otherwise."""
|
||||
IsInfinite = Annotated[_NumericType, Predicate(math.isinf)]
|
||||
"""Return True if x is a positive or negative infinity, and False otherwise."""
|
||||
IsNotInfinite = Annotated[_NumericType, Predicate(Not(math.isinf))]
|
||||
"""Return True if x is neither a positive or negative infinity, and False otherwise."""
|
||||
|
||||
try:
|
||||
from typing_extensions import DocInfo, doc # type: ignore [attr-defined]
|
||||
except ImportError:
|
||||
|
||||
@dataclass(frozen=True, **SLOTS)
|
||||
class DocInfo: # type: ignore [no-redef]
|
||||
""" "
|
||||
The return value of doc(), mainly to be used by tools that want to extract the
|
||||
Annotated documentation at runtime.
|
||||
"""
|
||||
|
||||
documentation: str
|
||||
"""The documentation string passed to doc()."""
|
||||
|
||||
def doc(
|
||||
documentation: str,
|
||||
) -> DocInfo:
|
||||
"""
|
||||
Add documentation to a type annotation inside of Annotated.
|
||||
|
||||
For example:
|
||||
|
||||
>>> def hi(name: Annotated[int, doc("The name of the user")]) -> None: ...
|
||||
"""
|
||||
return DocInfo(documentation)
|
||||
Binary file not shown.
Binary file not shown.
151
.venv/lib/python3.11/site-packages/annotated_types/test_cases.py
Normal file
151
.venv/lib/python3.11/site-packages/annotated_types/test_cases.py
Normal file
@@ -0,0 +1,151 @@
|
||||
import math
|
||||
import sys
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from decimal import Decimal
|
||||
from typing import Any, Dict, Iterable, Iterator, List, NamedTuple, Set, Tuple
|
||||
|
||||
if sys.version_info < (3, 9):
|
||||
from typing_extensions import Annotated
|
||||
else:
|
||||
from typing import Annotated
|
||||
|
||||
import annotated_types as at
|
||||
|
||||
|
||||
class Case(NamedTuple):
|
||||
"""
|
||||
A test case for `annotated_types`.
|
||||
"""
|
||||
|
||||
annotation: Any
|
||||
valid_cases: Iterable[Any]
|
||||
invalid_cases: Iterable[Any]
|
||||
|
||||
|
||||
def cases() -> Iterable[Case]:
|
||||
# Gt, Ge, Lt, Le
|
||||
yield Case(Annotated[int, at.Gt(4)], (5, 6, 1000), (4, 0, -1))
|
||||
yield Case(Annotated[float, at.Gt(0.5)], (0.6, 0.7, 0.8, 0.9), (0.5, 0.0, -0.1))
|
||||
yield Case(
|
||||
Annotated[datetime, at.Gt(datetime(2000, 1, 1))],
|
||||
[datetime(2000, 1, 2), datetime(2000, 1, 3)],
|
||||
[datetime(2000, 1, 1), datetime(1999, 12, 31)],
|
||||
)
|
||||
yield Case(
|
||||
Annotated[datetime, at.Gt(date(2000, 1, 1))],
|
||||
[date(2000, 1, 2), date(2000, 1, 3)],
|
||||
[date(2000, 1, 1), date(1999, 12, 31)],
|
||||
)
|
||||
yield Case(
|
||||
Annotated[datetime, at.Gt(Decimal('1.123'))],
|
||||
[Decimal('1.1231'), Decimal('123')],
|
||||
[Decimal('1.123'), Decimal('0')],
|
||||
)
|
||||
|
||||
yield Case(Annotated[int, at.Ge(4)], (4, 5, 6, 1000, 4), (0, -1))
|
||||
yield Case(Annotated[float, at.Ge(0.5)], (0.5, 0.6, 0.7, 0.8, 0.9), (0.4, 0.0, -0.1))
|
||||
yield Case(
|
||||
Annotated[datetime, at.Ge(datetime(2000, 1, 1))],
|
||||
[datetime(2000, 1, 2), datetime(2000, 1, 3)],
|
||||
[datetime(1998, 1, 1), datetime(1999, 12, 31)],
|
||||
)
|
||||
|
||||
yield Case(Annotated[int, at.Lt(4)], (0, -1), (4, 5, 6, 1000, 4))
|
||||
yield Case(Annotated[float, at.Lt(0.5)], (0.4, 0.0, -0.1), (0.5, 0.6, 0.7, 0.8, 0.9))
|
||||
yield Case(
|
||||
Annotated[datetime, at.Lt(datetime(2000, 1, 1))],
|
||||
[datetime(1999, 12, 31), datetime(1999, 12, 31)],
|
||||
[datetime(2000, 1, 2), datetime(2000, 1, 3)],
|
||||
)
|
||||
|
||||
yield Case(Annotated[int, at.Le(4)], (4, 0, -1), (5, 6, 1000))
|
||||
yield Case(Annotated[float, at.Le(0.5)], (0.5, 0.0, -0.1), (0.6, 0.7, 0.8, 0.9))
|
||||
yield Case(
|
||||
Annotated[datetime, at.Le(datetime(2000, 1, 1))],
|
||||
[datetime(2000, 1, 1), datetime(1999, 12, 31)],
|
||||
[datetime(2000, 1, 2), datetime(2000, 1, 3)],
|
||||
)
|
||||
|
||||
# Interval
|
||||
yield Case(Annotated[int, at.Interval(gt=4)], (5, 6, 1000), (4, 0, -1))
|
||||
yield Case(Annotated[int, at.Interval(gt=4, lt=10)], (5, 6), (4, 10, 1000, 0, -1))
|
||||
yield Case(Annotated[float, at.Interval(ge=0.5, le=1)], (0.5, 0.9, 1), (0.49, 1.1))
|
||||
yield Case(
|
||||
Annotated[datetime, at.Interval(gt=datetime(2000, 1, 1), le=datetime(2000, 1, 3))],
|
||||
[datetime(2000, 1, 2), datetime(2000, 1, 3)],
|
||||
[datetime(2000, 1, 1), datetime(2000, 1, 4)],
|
||||
)
|
||||
|
||||
yield Case(Annotated[int, at.MultipleOf(multiple_of=3)], (0, 3, 9), (1, 2, 4))
|
||||
yield Case(Annotated[float, at.MultipleOf(multiple_of=0.5)], (0, 0.5, 1, 1.5), (0.4, 1.1))
|
||||
|
||||
# lengths
|
||||
|
||||
yield Case(Annotated[str, at.MinLen(3)], ('123', '1234', 'x' * 10), ('', '1', '12'))
|
||||
yield Case(Annotated[str, at.Len(3)], ('123', '1234', 'x' * 10), ('', '1', '12'))
|
||||
yield Case(Annotated[List[int], at.MinLen(3)], ([1, 2, 3], [1, 2, 3, 4], [1] * 10), ([], [1], [1, 2]))
|
||||
yield Case(Annotated[List[int], at.Len(3)], ([1, 2, 3], [1, 2, 3, 4], [1] * 10), ([], [1], [1, 2]))
|
||||
|
||||
yield Case(Annotated[str, at.MaxLen(4)], ('', '1234'), ('12345', 'x' * 10))
|
||||
yield Case(Annotated[str, at.Len(0, 4)], ('', '1234'), ('12345', 'x' * 10))
|
||||
yield Case(Annotated[List[str], at.MaxLen(4)], ([], ['a', 'bcdef'], ['a', 'b', 'c']), (['a'] * 5, ['b'] * 10))
|
||||
yield Case(Annotated[List[str], at.Len(0, 4)], ([], ['a', 'bcdef'], ['a', 'b', 'c']), (['a'] * 5, ['b'] * 10))
|
||||
|
||||
yield Case(Annotated[str, at.Len(3, 5)], ('123', '12345'), ('', '1', '12', '123456', 'x' * 10))
|
||||
yield Case(Annotated[str, at.Len(3, 3)], ('123',), ('12', '1234'))
|
||||
|
||||
yield Case(Annotated[Dict[int, int], at.Len(2, 3)], [{1: 1, 2: 2}], [{}, {1: 1}, {1: 1, 2: 2, 3: 3, 4: 4}])
|
||||
yield Case(Annotated[Set[int], at.Len(2, 3)], ({1, 2}, {1, 2, 3}), (set(), {1}, {1, 2, 3, 4}))
|
||||
yield Case(Annotated[Tuple[int, ...], at.Len(2, 3)], ((1, 2), (1, 2, 3)), ((), (1,), (1, 2, 3, 4)))
|
||||
|
||||
# Timezone
|
||||
|
||||
yield Case(
|
||||
Annotated[datetime, at.Timezone(None)], [datetime(2000, 1, 1)], [datetime(2000, 1, 1, tzinfo=timezone.utc)]
|
||||
)
|
||||
yield Case(
|
||||
Annotated[datetime, at.Timezone(...)], [datetime(2000, 1, 1, tzinfo=timezone.utc)], [datetime(2000, 1, 1)]
|
||||
)
|
||||
yield Case(
|
||||
Annotated[datetime, at.Timezone(timezone.utc)],
|
||||
[datetime(2000, 1, 1, tzinfo=timezone.utc)],
|
||||
[datetime(2000, 1, 1), datetime(2000, 1, 1, tzinfo=timezone(timedelta(hours=6)))],
|
||||
)
|
||||
yield Case(
|
||||
Annotated[datetime, at.Timezone('Europe/London')],
|
||||
[datetime(2000, 1, 1, tzinfo=timezone(timedelta(0), name='Europe/London'))],
|
||||
[datetime(2000, 1, 1), datetime(2000, 1, 1, tzinfo=timezone(timedelta(hours=6)))],
|
||||
)
|
||||
|
||||
# Quantity
|
||||
|
||||
yield Case(Annotated[float, at.Unit(unit='m')], (5, 4.2), ('5m', '4.2m'))
|
||||
|
||||
# predicate types
|
||||
|
||||
yield Case(at.LowerCase[str], ['abc', 'foobar'], ['', 'A', 'Boom'])
|
||||
yield Case(at.UpperCase[str], ['ABC', 'DEFO'], ['', 'a', 'abc', 'AbC'])
|
||||
yield Case(at.IsDigit[str], ['123'], ['', 'ab', 'a1b2'])
|
||||
yield Case(at.IsAscii[str], ['123', 'foo bar'], ['£100', '😊', 'whatever 👀'])
|
||||
|
||||
yield Case(Annotated[int, at.Predicate(lambda x: x % 2 == 0)], [0, 2, 4], [1, 3, 5])
|
||||
|
||||
yield Case(at.IsFinite[float], [1.23], [math.nan, math.inf, -math.inf])
|
||||
yield Case(at.IsNotFinite[float], [math.nan, math.inf], [1.23])
|
||||
yield Case(at.IsNan[float], [math.nan], [1.23, math.inf])
|
||||
yield Case(at.IsNotNan[float], [1.23, math.inf], [math.nan])
|
||||
yield Case(at.IsInfinite[float], [math.inf], [math.nan, 1.23])
|
||||
yield Case(at.IsNotInfinite[float], [math.nan, 1.23], [math.inf])
|
||||
|
||||
# check stacked predicates
|
||||
yield Case(at.IsInfinite[Annotated[float, at.Predicate(lambda x: x > 0)]], [math.inf], [-math.inf, 1.23, math.nan])
|
||||
|
||||
# doc
|
||||
yield Case(Annotated[int, at.doc("A number")], [1, 2], [])
|
||||
|
||||
# custom GroupedMetadata
|
||||
class MyCustomGroupedMetadata(at.GroupedMetadata):
|
||||
def __iter__(self) -> Iterator[at.Predicate]:
|
||||
yield at.Predicate(lambda x: float(x).is_integer())
|
||||
|
||||
yield Case(Annotated[float, MyCustomGroupedMetadata()], [0, 2.0], [0.01, 1.5])
|
||||
@@ -0,0 +1 @@
|
||||
pip
|
||||
@@ -0,0 +1,96 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: anyio
|
||||
Version: 4.12.1
|
||||
Summary: High-level concurrency and networking framework on top of asyncio or Trio
|
||||
Author-email: Alex Grönholm <alex.gronholm@nextday.fi>
|
||||
License-Expression: MIT
|
||||
Project-URL: Documentation, https://anyio.readthedocs.io/en/latest/
|
||||
Project-URL: Changelog, https://anyio.readthedocs.io/en/stable/versionhistory.html
|
||||
Project-URL: Source code, https://github.com/agronholm/anyio
|
||||
Project-URL: Issue tracker, https://github.com/agronholm/anyio/issues
|
||||
Classifier: Development Status :: 5 - Production/Stable
|
||||
Classifier: Intended Audience :: Developers
|
||||
Classifier: Framework :: AnyIO
|
||||
Classifier: Typing :: Typed
|
||||
Classifier: Programming Language :: Python
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: Programming Language :: Python :: 3.9
|
||||
Classifier: Programming Language :: Python :: 3.10
|
||||
Classifier: Programming Language :: Python :: 3.11
|
||||
Classifier: Programming Language :: Python :: 3.12
|
||||
Classifier: Programming Language :: Python :: 3.13
|
||||
Classifier: Programming Language :: Python :: 3.14
|
||||
Requires-Python: >=3.9
|
||||
Description-Content-Type: text/x-rst
|
||||
License-File: LICENSE
|
||||
Requires-Dist: exceptiongroup>=1.0.2; python_version < "3.11"
|
||||
Requires-Dist: idna>=2.8
|
||||
Requires-Dist: typing_extensions>=4.5; python_version < "3.13"
|
||||
Provides-Extra: trio
|
||||
Requires-Dist: trio>=0.32.0; python_version >= "3.10" and extra == "trio"
|
||||
Requires-Dist: trio>=0.31.0; python_version < "3.10" and extra == "trio"
|
||||
Dynamic: license-file
|
||||
|
||||
.. image:: https://github.com/agronholm/anyio/actions/workflows/test.yml/badge.svg
|
||||
:target: https://github.com/agronholm/anyio/actions/workflows/test.yml
|
||||
:alt: Build Status
|
||||
.. image:: https://coveralls.io/repos/github/agronholm/anyio/badge.svg?branch=master
|
||||
:target: https://coveralls.io/github/agronholm/anyio?branch=master
|
||||
:alt: Code Coverage
|
||||
.. image:: https://readthedocs.org/projects/anyio/badge/?version=latest
|
||||
:target: https://anyio.readthedocs.io/en/latest/?badge=latest
|
||||
:alt: Documentation
|
||||
.. image:: https://badges.gitter.im/gitterHQ/gitter.svg
|
||||
:target: https://gitter.im/python-trio/AnyIO
|
||||
:alt: Gitter chat
|
||||
|
||||
AnyIO is an asynchronous networking and concurrency library that works on top of either asyncio_ or
|
||||
Trio_. It implements Trio-like `structured concurrency`_ (SC) on top of asyncio and works in harmony
|
||||
with the native SC of Trio itself.
|
||||
|
||||
Applications and libraries written against AnyIO's API will run unmodified on either asyncio_ or
|
||||
Trio_. AnyIO can also be adopted into a library or application incrementally – bit by bit, no full
|
||||
refactoring necessary. It will blend in with the native libraries of your chosen backend.
|
||||
|
||||
To find out why you might want to use AnyIO's APIs instead of asyncio's, you can read about it
|
||||
`here <https://anyio.readthedocs.io/en/stable/why.html>`_.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
View full documentation at: https://anyio.readthedocs.io/
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
AnyIO offers the following functionality:
|
||||
|
||||
* Task groups (nurseries_ in trio terminology)
|
||||
* High-level networking (TCP, UDP and UNIX sockets)
|
||||
|
||||
* `Happy eyeballs`_ algorithm for TCP connections (more robust than that of asyncio on Python
|
||||
3.8)
|
||||
* async/await style UDP sockets (unlike asyncio where you still have to use Transports and
|
||||
Protocols)
|
||||
|
||||
* A versatile API for byte streams and object streams
|
||||
* Inter-task synchronization and communication (locks, conditions, events, semaphores, object
|
||||
streams)
|
||||
* Worker threads
|
||||
* Subprocesses
|
||||
* Subinterpreter support for code parallelization (on Python 3.13 and later)
|
||||
* Asynchronous file I/O (using worker threads)
|
||||
* Signal handling
|
||||
* Asynchronous version of the functools_ module
|
||||
|
||||
AnyIO also comes with its own pytest_ plugin which also supports asynchronous fixtures.
|
||||
It even works with the popular Hypothesis_ library.
|
||||
|
||||
.. _asyncio: https://docs.python.org/3/library/asyncio.html
|
||||
.. _Trio: https://github.com/python-trio/trio
|
||||
.. _structured concurrency: https://en.wikipedia.org/wiki/Structured_concurrency
|
||||
.. _nurseries: https://trio.readthedocs.io/en/stable/reference-core.html#nurseries-and-spawning
|
||||
.. _Happy eyeballs: https://en.wikipedia.org/wiki/Happy_Eyeballs
|
||||
.. _pytest: https://docs.pytest.org/en/latest/
|
||||
.. _functools: https://docs.python.org/3/library/functools.html
|
||||
.. _Hypothesis: https://hypothesis.works/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user