Spaces:
Paused
Paused
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +33 -0
- README.md +2 -8
- app.py +89 -0
- icons/coda_bot_icon.png +0 -0
- icons/llama.png +0 -0
- icons/uk.png +0 -0
- icons/usa.png +0 -0
- icons/user_icon.png +0 -0
- start_ui.sh +24 -0
- venv/bin/Activate.ps1 +247 -0
- venv/bin/activate +70 -0
- venv/bin/activate.csh +27 -0
- venv/bin/activate.fish +69 -0
- venv/bin/dotenv +8 -0
- venv/bin/email_validator +8 -0
- venv/bin/f2py +8 -0
- venv/bin/fastapi +8 -0
- venv/bin/fonttools +8 -0
- venv/bin/gradio +8 -0
- venv/bin/httpx +8 -0
- venv/bin/huggingface-cli +8 -0
- venv/bin/jsonschema +8 -0
- venv/bin/markdown-it +8 -0
- venv/bin/normalizer +8 -0
- venv/bin/pip +8 -0
- venv/bin/pip3 +8 -0
- venv/bin/pip3.12 +8 -0
- venv/bin/pyftmerge +8 -0
- venv/bin/pyftsubset +8 -0
- venv/bin/pygmentize +8 -0
- venv/bin/python +3 -0
- venv/bin/python3 +3 -0
- venv/bin/python3.12 +3 -0
- venv/bin/ruff +3 -0
- venv/bin/tqdm +8 -0
- venv/bin/ttx +8 -0
- venv/bin/typer +8 -0
- venv/bin/upload_theme +8 -0
- venv/bin/uvicorn +8 -0
- venv/bin/watchfiles +8 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER +1 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst +28 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/METADATA +93 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/RECORD +14 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL +6 -0
- venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt +1 -0
- venv/lib/python3.12/site-packages/PIL/BdfFontFile.py +133 -0
- venv/lib/python3.12/site-packages/PIL/BlpImagePlugin.py +476 -0
- venv/lib/python3.12/site-packages/PIL/BmpImagePlugin.py +472 -0
- venv/lib/python3.12/site-packages/PIL/BufrStubImagePlugin.py +74 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,36 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
venv/bin/python filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
venv/bin/python3 filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
venv/bin/python3.12 filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
venv/bin/ruff filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
venv/lib/python3.12/site-packages/PIL/_imaging.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
venv/lib/python3.12/site-packages/altair/vegalite/v5/schema/__pycache__/channels.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
venv/lib/python3.12/site-packages/altair/vegalite/v5/schema/__pycache__/core.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
venv/lib/python3.12/site-packages/fontTools/cu2qu/cu2qu.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
venv/lib/python3.12/site-packages/fontTools/feaLib/lexer.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
venv/lib/python3.12/site-packages/fontTools/misc/bezierTools.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
venv/lib/python3.12/site-packages/fontTools/pens/momentsPen.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
venv/lib/python3.12/site-packages/fontTools/qu2cu/qu2cu.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
venv/lib/python3.12/site-packages/fontTools/varLib/iup.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
venv/lib/python3.12/site-packages/gradio/frpc_linux_amd64_v0.2 filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
venv/lib/python3.12/site-packages/gradio/templates/frontend/assets/Index-34zXpzH2.js.map filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
venv/lib/python3.12/site-packages/kiwisolver/_cext.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
venv/lib/python3.12/site-packages/numpy/core/_multiarray_umath.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
venv/lib/python3.12/site-packages/numpy/core/_simd.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
venv/lib/python3.12/site-packages/numpy.libs/libgfortran-040039e1.so.5.0.0 filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
venv/lib/python3.12/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
venv/lib/python3.12/site-packages/pandas/_libs/algos.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
venv/lib/python3.12/site-packages/pandas/_libs/groupby.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
venv/lib/python3.12/site-packages/pandas/_libs/hashtable.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
venv/lib/python3.12/site-packages/pandas/_libs/interval.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
venv/lib/python3.12/site-packages/pandas/_libs/join.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
venv/lib/python3.12/site-packages/pandas/_libs/tslibs/offsets.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
venv/lib/python3.12/site-packages/pillow.libs/libfreetype-1f2cdfbb.so.6.20.1 filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
venv/lib/python3.12/site-packages/pillow.libs/libharfbuzz-8b0b6641.so.0.60840.0 filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
venv/lib/python3.12/site-packages/pydantic_core/_pydantic_core.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
venv/lib/python3.12/site-packages/rpds/rpds.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
venv/lib/python3.12/site-packages/uvloop/loop.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
venv/lib/python3.12/site-packages/watchfiles/_rust_notify.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
venv/lib/python3.12/site-packages/yaml/_yaml.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: green
|
| 5 |
-
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.36.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: coda_alignment_ui
|
| 3 |
+
app_file: app.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
sdk_version: 4.36.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import time
|
| 3 |
+
import requests
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_response(endpoint, user_input, auth_token):
|
| 9 |
+
payload = json.dumps({"input": {"prompt": user_input}})
|
| 10 |
+
headers = {
|
| 11 |
+
'Content-Type': 'application/json',
|
| 12 |
+
'Authorization': f'Bearer {auth_token}',
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
response = requests.post(endpoint, headers=headers, data=payload)
|
| 16 |
+
response_data = response.json()
|
| 17 |
+
print(f"The response is {response_data}")
|
| 18 |
+
return response_data["output"]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def handle_user_input(user_input, untrained_history, usa_history, uk_history):
|
| 22 |
+
new_entry = [user_input, None]
|
| 23 |
+
return "", untrained_history + [new_entry], usa_history + [new_entry], uk_history + [new_entry]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def bot_response(bot_func, history):
|
| 27 |
+
bot_message = bot_func(history[-1][0])
|
| 28 |
+
history[-1][1] = ""
|
| 29 |
+
for character in bot_message:
|
| 30 |
+
history[-1][1] += character
|
| 31 |
+
time.sleep(0.05)
|
| 32 |
+
yield history
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def make_chatbot(label, bot_icon):
|
| 36 |
+
return gr.Chatbot([], elem_id="chatbot", bubble_full_width=False, label=label,
|
| 37 |
+
avatar_images=("./icons/user_icon.png", bot_icon))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def main(untrained_endpoint, us_endpoint, uk_endpoint, auth_token):
|
| 41 |
+
def untrained_bot(history):
|
| 42 |
+
return get_response(untrained_endpoint, history[-1][0], auth_token)
|
| 43 |
+
|
| 44 |
+
def usa_bot(history):
|
| 45 |
+
return get_response(us_endpoint, history[-1][0], auth_token)
|
| 46 |
+
|
| 47 |
+
def uk_bot(history):
|
| 48 |
+
return get_response(uk_endpoint, history[-1][0], auth_token)
|
| 49 |
+
|
| 50 |
+
with gr.Blocks(title="CODA Chatbots Interface") as demo:
|
| 51 |
+
gr.Markdown("<h1 style='text-align: center;'>CODA Model Demo</h1>")
|
| 52 |
+
|
| 53 |
+
with gr.Row():
|
| 54 |
+
with gr.Column():
|
| 55 |
+
gr.Markdown("## LLama3 Untrained Model")
|
| 56 |
+
untrained_chatbot = make_chatbot("Untrained Model", "./icons/llama.png")
|
| 57 |
+
|
| 58 |
+
with gr.Column():
|
| 59 |
+
gr.Markdown("## LLama3 CODA USA Model")
|
| 60 |
+
usa_chatbot = make_chatbot("USA Model", "./icons/usa.png")
|
| 61 |
+
|
| 62 |
+
with gr.Column():
|
| 63 |
+
gr.Markdown("## LLama3 CODA UK Model")
|
| 64 |
+
uk_chatbot = make_chatbot("UK Model", "./icons/uk.png")
|
| 65 |
+
|
| 66 |
+
with gr.Row():
|
| 67 |
+
user_input_box = gr.Textbox(show_label=False, placeholder="Enter your message here...")
|
| 68 |
+
user_input_box.submit(handle_user_input, [user_input_box, untrained_chatbot, usa_chatbot, uk_chatbot],
|
| 69 |
+
[user_input_box, untrained_chatbot, usa_chatbot, uk_chatbot], queue=False).then(
|
| 70 |
+
lambda h: bot_response(untrained_bot, h), untrained_chatbot, untrained_chatbot
|
| 71 |
+
).then(
|
| 72 |
+
lambda h: bot_response(usa_bot, h), usa_chatbot, usa_chatbot
|
| 73 |
+
).then(
|
| 74 |
+
lambda h: bot_response(uk_bot, h), uk_chatbot, uk_chatbot
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
demo.queue()
|
| 78 |
+
demo.launch(share=True)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
parser = argparse.ArgumentParser(description="CODA Chatbots Interface")
|
| 83 |
+
parser.add_argument("--untrained_endpoint", type=str, required=True, help="Endpoint for the untrained model")
|
| 84 |
+
parser.add_argument("--us_endpoint", type=str, required=True, help="Endpoint for the US model")
|
| 85 |
+
parser.add_argument("--uk_endpoint", type=str, required=True, help="Endpoint for the UK model")
|
| 86 |
+
parser.add_argument("--auth_token", type=str, required=True, help="Authorization token for the API")
|
| 87 |
+
|
| 88 |
+
args = parser.parse_args()
|
| 89 |
+
main(args.untrained_endpoint, args.us_endpoint, args.uk_endpoint, args.auth_token)
|
icons/coda_bot_icon.png
ADDED
|
|
icons/llama.png
ADDED
|
|
icons/uk.png
ADDED
|
|
icons/usa.png
ADDED
|
|
icons/user_icon.png
ADDED
|
|
start_ui.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Define API endpoints
|
| 4 |
+
UNTRAINED_ENDPOINT="https://api.runpod.ai/v2/xnlnpgafkof5nu/runsync"
|
| 5 |
+
US_ENDPOINT="https://api.runpod.ai/v2/xnlnpgafkof5nu/runsync"
|
| 6 |
+
UK_ENDPOINT="https://api.runpod.ai/v2/xnlnpgafkof5nu/runsync"
|
| 7 |
+
|
| 8 |
+
# Define authorization token
|
| 9 |
+
AUTH_TOKEN="xxx"
|
| 10 |
+
|
| 11 |
+
# Update and install necessary packages
|
| 12 |
+
apt-get update
|
| 13 |
+
apt-get install -y git-lfs vim wget htop python3-venv
|
| 14 |
+
|
| 15 |
+
# Create a virtual environment
|
| 16 |
+
python3 -m venv venv
|
| 17 |
+
source venv/bin/activate
|
| 18 |
+
|
| 19 |
+
# Upgrade pip and install required Python packages
|
| 20 |
+
pip3 install --upgrade pip
|
| 21 |
+
pip3 install gradio requests
|
| 22 |
+
|
| 23 |
+
# Run the Python script with the required arguments
|
| 24 |
+
python3 app.py --untrained_endpoint "$UNTRAINED_ENDPOINT" --us_endpoint "$US_ENDPOINT" --uk_endpoint "$UK_ENDPOINT" --auth_token "$AUTH_TOKEN"
|
venv/bin/Activate.ps1
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<#
|
| 2 |
+
.Synopsis
|
| 3 |
+
Activate a Python virtual environment for the current PowerShell session.
|
| 4 |
+
|
| 5 |
+
.Description
|
| 6 |
+
Pushes the python executable for a virtual environment to the front of the
|
| 7 |
+
$Env:PATH environment variable and sets the prompt to signify that you are
|
| 8 |
+
in a Python virtual environment. Makes use of the command line switches as
|
| 9 |
+
well as the `pyvenv.cfg` file values present in the virtual environment.
|
| 10 |
+
|
| 11 |
+
.Parameter VenvDir
|
| 12 |
+
Path to the directory that contains the virtual environment to activate. The
|
| 13 |
+
default value for this is the parent of the directory that the Activate.ps1
|
| 14 |
+
script is located within.
|
| 15 |
+
|
| 16 |
+
.Parameter Prompt
|
| 17 |
+
The prompt prefix to display when this virtual environment is activated. By
|
| 18 |
+
default, this prompt is the name of the virtual environment folder (VenvDir)
|
| 19 |
+
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
| 20 |
+
|
| 21 |
+
.Example
|
| 22 |
+
Activate.ps1
|
| 23 |
+
Activates the Python virtual environment that contains the Activate.ps1 script.
|
| 24 |
+
|
| 25 |
+
.Example
|
| 26 |
+
Activate.ps1 -Verbose
|
| 27 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 28 |
+
and shows extra information about the activation as it executes.
|
| 29 |
+
|
| 30 |
+
.Example
|
| 31 |
+
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
| 32 |
+
Activates the Python virtual environment located in the specified location.
|
| 33 |
+
|
| 34 |
+
.Example
|
| 35 |
+
Activate.ps1 -Prompt "MyPython"
|
| 36 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 37 |
+
and prefixes the current prompt with the specified string (surrounded in
|
| 38 |
+
parentheses) while the virtual environment is active.
|
| 39 |
+
|
| 40 |
+
.Notes
|
| 41 |
+
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
| 42 |
+
execution policy for the user. You can do this by issuing the following PowerShell
|
| 43 |
+
command:
|
| 44 |
+
|
| 45 |
+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
| 46 |
+
|
| 47 |
+
For more information on Execution Policies:
|
| 48 |
+
https://go.microsoft.com/fwlink/?LinkID=135170
|
| 49 |
+
|
| 50 |
+
#>
|
| 51 |
+
Param(
|
| 52 |
+
[Parameter(Mandatory = $false)]
|
| 53 |
+
[String]
|
| 54 |
+
$VenvDir,
|
| 55 |
+
[Parameter(Mandatory = $false)]
|
| 56 |
+
[String]
|
| 57 |
+
$Prompt
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
<# Function declarations --------------------------------------------------- #>
|
| 61 |
+
|
| 62 |
+
<#
|
| 63 |
+
.Synopsis
|
| 64 |
+
Remove all shell session elements added by the Activate script, including the
|
| 65 |
+
addition of the virtual environment's Python executable from the beginning of
|
| 66 |
+
the PATH variable.
|
| 67 |
+
|
| 68 |
+
.Parameter NonDestructive
|
| 69 |
+
If present, do not remove this function from the global namespace for the
|
| 70 |
+
session.
|
| 71 |
+
|
| 72 |
+
#>
|
| 73 |
+
function global:deactivate ([switch]$NonDestructive) {
|
| 74 |
+
# Revert to original values
|
| 75 |
+
|
| 76 |
+
# The prior prompt:
|
| 77 |
+
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
| 78 |
+
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
| 79 |
+
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# The prior PYTHONHOME:
|
| 83 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
| 84 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
| 85 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# The prior PATH:
|
| 89 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
| 90 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
| 91 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# Just remove the VIRTUAL_ENV altogether:
|
| 95 |
+
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
| 96 |
+
Remove-Item -Path env:VIRTUAL_ENV
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
| 100 |
+
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
| 101 |
+
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
| 105 |
+
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
| 106 |
+
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
# Leave deactivate function in the global namespace if requested:
|
| 110 |
+
if (-not $NonDestructive) {
|
| 111 |
+
Remove-Item -Path function:deactivate
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
<#
|
| 116 |
+
.Description
|
| 117 |
+
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
| 118 |
+
given folder, and returns them in a map.
|
| 119 |
+
|
| 120 |
+
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
| 121 |
+
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
| 122 |
+
then it is considered a `key = value` line. The left hand string is the key,
|
| 123 |
+
the right hand is the value.
|
| 124 |
+
|
| 125 |
+
If the value starts with a `'` or a `"` then the first and last character is
|
| 126 |
+
stripped from the value before being captured.
|
| 127 |
+
|
| 128 |
+
.Parameter ConfigDir
|
| 129 |
+
Path to the directory that contains the `pyvenv.cfg` file.
|
| 130 |
+
#>
|
| 131 |
+
function Get-PyVenvConfig(
|
| 132 |
+
[String]
|
| 133 |
+
$ConfigDir
|
| 134 |
+
) {
|
| 135 |
+
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
| 136 |
+
|
| 137 |
+
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
| 138 |
+
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
| 139 |
+
|
| 140 |
+
# An empty map will be returned if no config file is found.
|
| 141 |
+
$pyvenvConfig = @{ }
|
| 142 |
+
|
| 143 |
+
if ($pyvenvConfigPath) {
|
| 144 |
+
|
| 145 |
+
Write-Verbose "File exists, parse `key = value` lines"
|
| 146 |
+
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
| 147 |
+
|
| 148 |
+
$pyvenvConfigContent | ForEach-Object {
|
| 149 |
+
$keyval = $PSItem -split "\s*=\s*", 2
|
| 150 |
+
if ($keyval[0] -and $keyval[1]) {
|
| 151 |
+
$val = $keyval[1]
|
| 152 |
+
|
| 153 |
+
# Remove extraneous quotations around a string value.
|
| 154 |
+
if ("'""".Contains($val.Substring(0, 1))) {
|
| 155 |
+
$val = $val.Substring(1, $val.Length - 2)
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$pyvenvConfig[$keyval[0]] = $val
|
| 159 |
+
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
return $pyvenvConfig
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
<# Begin Activate script --------------------------------------------------- #>
|
| 168 |
+
|
| 169 |
+
# Determine the containing directory of this script
|
| 170 |
+
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
| 171 |
+
$VenvExecDir = Get-Item -Path $VenvExecPath
|
| 172 |
+
|
| 173 |
+
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
| 174 |
+
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
| 175 |
+
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
| 176 |
+
|
| 177 |
+
# Set values required in priority: CmdLine, ConfigFile, Default
|
| 178 |
+
# First, get the location of the virtual environment, it might not be
|
| 179 |
+
# VenvExecDir if specified on the command line.
|
| 180 |
+
if ($VenvDir) {
|
| 181 |
+
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
| 182 |
+
}
|
| 183 |
+
else {
|
| 184 |
+
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
| 185 |
+
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
| 186 |
+
Write-Verbose "VenvDir=$VenvDir"
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Next, read the `pyvenv.cfg` file to determine any required value such
|
| 190 |
+
# as `prompt`.
|
| 191 |
+
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
| 192 |
+
|
| 193 |
+
# Next, set the prompt from the command line, or the config file, or
|
| 194 |
+
# just use the name of the virtual environment folder.
|
| 195 |
+
if ($Prompt) {
|
| 196 |
+
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
| 197 |
+
}
|
| 198 |
+
else {
|
| 199 |
+
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
| 200 |
+
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
| 201 |
+
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
| 202 |
+
$Prompt = $pyvenvCfg['prompt'];
|
| 203 |
+
}
|
| 204 |
+
else {
|
| 205 |
+
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
| 206 |
+
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
| 207 |
+
$Prompt = Split-Path -Path $venvDir -Leaf
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
Write-Verbose "Prompt = '$Prompt'"
|
| 212 |
+
Write-Verbose "VenvDir='$VenvDir'"
|
| 213 |
+
|
| 214 |
+
# Deactivate any currently active virtual environment, but leave the
|
| 215 |
+
# deactivate function in place.
|
| 216 |
+
deactivate -nondestructive
|
| 217 |
+
|
| 218 |
+
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
| 219 |
+
# that there is an activated venv.
|
| 220 |
+
$env:VIRTUAL_ENV = $VenvDir
|
| 221 |
+
|
| 222 |
+
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
| 223 |
+
|
| 224 |
+
Write-Verbose "Setting prompt to '$Prompt'"
|
| 225 |
+
|
| 226 |
+
# Set the prompt to include the env name
|
| 227 |
+
# Make sure _OLD_VIRTUAL_PROMPT is global
|
| 228 |
+
function global:_OLD_VIRTUAL_PROMPT { "" }
|
| 229 |
+
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
| 230 |
+
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
| 231 |
+
|
| 232 |
+
function global:prompt {
|
| 233 |
+
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
| 234 |
+
_OLD_VIRTUAL_PROMPT
|
| 235 |
+
}
|
| 236 |
+
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
# Clear PYTHONHOME
|
| 240 |
+
if (Test-Path -Path Env:PYTHONHOME) {
|
| 241 |
+
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
| 242 |
+
Remove-Item -Path Env:PYTHONHOME
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
# Add the venv to the PATH
|
| 246 |
+
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
| 247 |
+
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
venv/bin/activate
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source bin/activate" *from bash*
|
| 2 |
+
# You cannot run it directly
|
| 3 |
+
|
| 4 |
+
deactivate () {
|
| 5 |
+
# reset old environment variables
|
| 6 |
+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
| 7 |
+
PATH="${_OLD_VIRTUAL_PATH:-}"
|
| 8 |
+
export PATH
|
| 9 |
+
unset _OLD_VIRTUAL_PATH
|
| 10 |
+
fi
|
| 11 |
+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
| 12 |
+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
| 13 |
+
export PYTHONHOME
|
| 14 |
+
unset _OLD_VIRTUAL_PYTHONHOME
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
# Call hash to forget past commands. Without forgetting
|
| 18 |
+
# past commands the $PATH changes we made may not be respected
|
| 19 |
+
hash -r 2> /dev/null
|
| 20 |
+
|
| 21 |
+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
| 22 |
+
PS1="${_OLD_VIRTUAL_PS1:-}"
|
| 23 |
+
export PS1
|
| 24 |
+
unset _OLD_VIRTUAL_PS1
|
| 25 |
+
fi
|
| 26 |
+
|
| 27 |
+
unset VIRTUAL_ENV
|
| 28 |
+
unset VIRTUAL_ENV_PROMPT
|
| 29 |
+
if [ ! "${1:-}" = "nondestructive" ] ; then
|
| 30 |
+
# Self destruct!
|
| 31 |
+
unset -f deactivate
|
| 32 |
+
fi
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# unset irrelevant variables
|
| 36 |
+
deactivate nondestructive
|
| 37 |
+
|
| 38 |
+
# on Windows, a path can contain colons and backslashes and has to be converted:
|
| 39 |
+
if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
|
| 40 |
+
# transform D:\path\to\venv to /d/path/to/venv on MSYS
|
| 41 |
+
# and to /cygdrive/d/path/to/venv on Cygwin
|
| 42 |
+
export VIRTUAL_ENV=$(cygpath "/home/dean/Documents/coda_deployment/ui/venv")
|
| 43 |
+
else
|
| 44 |
+
# use the path as-is
|
| 45 |
+
export VIRTUAL_ENV="/home/dean/Documents/coda_deployment/ui/venv"
|
| 46 |
+
fi
|
| 47 |
+
|
| 48 |
+
_OLD_VIRTUAL_PATH="$PATH"
|
| 49 |
+
PATH="$VIRTUAL_ENV/bin:$PATH"
|
| 50 |
+
export PATH
|
| 51 |
+
|
| 52 |
+
# unset PYTHONHOME if set
|
| 53 |
+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
| 54 |
+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
| 55 |
+
if [ -n "${PYTHONHOME:-}" ] ; then
|
| 56 |
+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
| 57 |
+
unset PYTHONHOME
|
| 58 |
+
fi
|
| 59 |
+
|
| 60 |
+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
| 61 |
+
_OLD_VIRTUAL_PS1="${PS1:-}"
|
| 62 |
+
PS1="(venv) ${PS1:-}"
|
| 63 |
+
export PS1
|
| 64 |
+
VIRTUAL_ENV_PROMPT="(venv) "
|
| 65 |
+
export VIRTUAL_ENV_PROMPT
|
| 66 |
+
fi
|
| 67 |
+
|
| 68 |
+
# Call hash to forget past commands. Without forgetting
|
| 69 |
+
# past commands the $PATH changes we made may not be respected
|
| 70 |
+
hash -r 2> /dev/null
|
venv/bin/activate.csh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source bin/activate.csh" *from csh*.
|
| 2 |
+
# You cannot run it directly.
|
| 3 |
+
|
| 4 |
+
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
| 5 |
+
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
| 6 |
+
|
| 7 |
+
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
| 8 |
+
|
| 9 |
+
# Unset irrelevant variables.
|
| 10 |
+
deactivate nondestructive
|
| 11 |
+
|
| 12 |
+
setenv VIRTUAL_ENV "/home/dean/Documents/coda_deployment/ui/venv"
|
| 13 |
+
|
| 14 |
+
set _OLD_VIRTUAL_PATH="$PATH"
|
| 15 |
+
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
set _OLD_VIRTUAL_PROMPT="$prompt"
|
| 19 |
+
|
| 20 |
+
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
| 21 |
+
set prompt = "(venv) $prompt"
|
| 22 |
+
setenv VIRTUAL_ENV_PROMPT "(venv) "
|
| 23 |
+
endif
|
| 24 |
+
|
| 25 |
+
alias pydoc python -m pydoc
|
| 26 |
+
|
| 27 |
+
rehash
|
venv/bin/activate.fish
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
| 2 |
+
# (https://fishshell.com/). You cannot run it directly.
|
| 3 |
+
|
| 4 |
+
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
| 5 |
+
# reset old environment variables
|
| 6 |
+
if test -n "$_OLD_VIRTUAL_PATH"
|
| 7 |
+
set -gx PATH $_OLD_VIRTUAL_PATH
|
| 8 |
+
set -e _OLD_VIRTUAL_PATH
|
| 9 |
+
end
|
| 10 |
+
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
| 11 |
+
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
| 12 |
+
set -e _OLD_VIRTUAL_PYTHONHOME
|
| 13 |
+
end
|
| 14 |
+
|
| 15 |
+
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
| 16 |
+
set -e _OLD_FISH_PROMPT_OVERRIDE
|
| 17 |
+
# prevents error when using nested fish instances (Issue #93858)
|
| 18 |
+
if functions -q _old_fish_prompt
|
| 19 |
+
functions -e fish_prompt
|
| 20 |
+
functions -c _old_fish_prompt fish_prompt
|
| 21 |
+
functions -e _old_fish_prompt
|
| 22 |
+
end
|
| 23 |
+
end
|
| 24 |
+
|
| 25 |
+
set -e VIRTUAL_ENV
|
| 26 |
+
set -e VIRTUAL_ENV_PROMPT
|
| 27 |
+
if test "$argv[1]" != "nondestructive"
|
| 28 |
+
# Self-destruct!
|
| 29 |
+
functions -e deactivate
|
| 30 |
+
end
|
| 31 |
+
end
|
| 32 |
+
|
| 33 |
+
# Unset irrelevant variables.
|
| 34 |
+
deactivate nondestructive
|
| 35 |
+
|
| 36 |
+
set -gx VIRTUAL_ENV "/home/dean/Documents/coda_deployment/ui/venv"
|
| 37 |
+
|
| 38 |
+
set -gx _OLD_VIRTUAL_PATH $PATH
|
| 39 |
+
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
|
| 40 |
+
|
| 41 |
+
# Unset PYTHONHOME if set.
|
| 42 |
+
if set -q PYTHONHOME
|
| 43 |
+
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
| 44 |
+
set -e PYTHONHOME
|
| 45 |
+
end
|
| 46 |
+
|
| 47 |
+
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
| 48 |
+
# fish uses a function instead of an env var to generate the prompt.
|
| 49 |
+
|
| 50 |
+
# Save the current fish_prompt function as the function _old_fish_prompt.
|
| 51 |
+
functions -c fish_prompt _old_fish_prompt
|
| 52 |
+
|
| 53 |
+
# With the original prompt function renamed, we can override with our own.
|
| 54 |
+
function fish_prompt
|
| 55 |
+
# Save the return status of the last command.
|
| 56 |
+
set -l old_status $status
|
| 57 |
+
|
| 58 |
+
# Output the venv prompt; color taken from the blue of the Python logo.
|
| 59 |
+
printf "%s%s%s" (set_color 4B8BBE) "(venv) " (set_color normal)
|
| 60 |
+
|
| 61 |
+
# Restore the return status of the previous command.
|
| 62 |
+
echo "exit $old_status" | .
|
| 63 |
+
# Output the original/"old" prompt.
|
| 64 |
+
_old_fish_prompt
|
| 65 |
+
end
|
| 66 |
+
|
| 67 |
+
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
| 68 |
+
set -gx VIRTUAL_ENV_PROMPT "(venv) "
|
| 69 |
+
end
|
venv/bin/dotenv
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from dotenv.__main__ import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
venv/bin/email_validator
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from email_validator.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/f2py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from numpy.f2py.f2py2e import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/fastapi
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fastapi_cli.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/fonttools
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.__main__ import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/gradio
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from gradio.cli import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
venv/bin/httpx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from httpx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/huggingface-cli
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from huggingface_hub.commands.huggingface_cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/jsonschema
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from jsonschema.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/markdown-it
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from markdown_it.cli.parse import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/normalizer
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from charset_normalizer.cli import cli_detect
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli_detect())
|
venv/bin/pip
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/pip3
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/pip3.12
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pip._internal.cli.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/pyftmerge
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.merge import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/pyftsubset
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.subset import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/pygmentize
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from pygments.cmdline import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/python
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:359ca926ba4596147d7d558c1e0cbf6a5784f5475d7e8bf0a55d9d7c4fa7106c
|
| 3 |
+
size 8019136
|
venv/bin/python3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:359ca926ba4596147d7d558c1e0cbf6a5784f5475d7e8bf0a55d9d7c4fa7106c
|
| 3 |
+
size 8019136
|
venv/bin/python3.12
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:359ca926ba4596147d7d558c1e0cbf6a5784f5475d7e8bf0a55d9d7c4fa7106c
|
| 3 |
+
size 8019136
|
venv/bin/ruff
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:909e158295812209eae0fdec2f8a55757bc1fb14982572b65b6e50ec48fa2169
|
| 3 |
+
size 23358480
|
venv/bin/tqdm
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from tqdm.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/ttx
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from fontTools.ttx import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/typer
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from typer.cli import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/upload_theme
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from gradio.themes.upload_theme import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/uvicorn
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from uvicorn.main import main
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(main())
|
venv/bin/watchfiles
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/home/dean/Documents/coda_deployment/ui/venv/bin/python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
import re
|
| 4 |
+
import sys
|
| 5 |
+
from watchfiles.cli import cli
|
| 6 |
+
if __name__ == '__main__':
|
| 7 |
+
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
| 8 |
+
sys.exit(cli())
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
pip
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright 2010 Pallets
|
| 2 |
+
|
| 3 |
+
Redistribution and use in source and binary forms, with or without
|
| 4 |
+
modification, are permitted provided that the following conditions are
|
| 5 |
+
met:
|
| 6 |
+
|
| 7 |
+
1. Redistributions of source code must retain the above copyright
|
| 8 |
+
notice, this list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 19 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 20 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
| 21 |
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 22 |
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 23 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
| 24 |
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
| 25 |
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
| 26 |
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
| 27 |
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 28 |
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/METADATA
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: MarkupSafe
|
| 3 |
+
Version: 2.1.5
|
| 4 |
+
Summary: Safely add untrusted strings to HTML/XML markup.
|
| 5 |
+
Home-page: https://palletsprojects.com/p/markupsafe/
|
| 6 |
+
Maintainer: Pallets
|
| 7 |
+
Maintainer-email: contact@palletsprojects.com
|
| 8 |
+
License: BSD-3-Clause
|
| 9 |
+
Project-URL: Donate, https://palletsprojects.com/donate
|
| 10 |
+
Project-URL: Documentation, https://markupsafe.palletsprojects.com/
|
| 11 |
+
Project-URL: Changes, https://markupsafe.palletsprojects.com/changes/
|
| 12 |
+
Project-URL: Source Code, https://github.com/pallets/markupsafe/
|
| 13 |
+
Project-URL: Issue Tracker, https://github.com/pallets/markupsafe/issues/
|
| 14 |
+
Project-URL: Chat, https://discord.gg/pallets
|
| 15 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 16 |
+
Classifier: Environment :: Web Environment
|
| 17 |
+
Classifier: Intended Audience :: Developers
|
| 18 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 19 |
+
Classifier: Operating System :: OS Independent
|
| 20 |
+
Classifier: Programming Language :: Python
|
| 21 |
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
| 22 |
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
| 23 |
+
Requires-Python: >=3.7
|
| 24 |
+
Description-Content-Type: text/x-rst
|
| 25 |
+
License-File: LICENSE.rst
|
| 26 |
+
|
| 27 |
+
MarkupSafe
|
| 28 |
+
==========
|
| 29 |
+
|
| 30 |
+
MarkupSafe implements a text object that escapes characters so it is
|
| 31 |
+
safe to use in HTML and XML. Characters that have special meanings are
|
| 32 |
+
replaced so that they display as the actual characters. This mitigates
|
| 33 |
+
injection attacks, meaning untrusted user input can safely be displayed
|
| 34 |
+
on a page.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
Installing
|
| 38 |
+
----------
|
| 39 |
+
|
| 40 |
+
Install and update using `pip`_:
|
| 41 |
+
|
| 42 |
+
.. code-block:: text
|
| 43 |
+
|
| 44 |
+
pip install -U MarkupSafe
|
| 45 |
+
|
| 46 |
+
.. _pip: https://pip.pypa.io/en/stable/getting-started/
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
Examples
|
| 50 |
+
--------
|
| 51 |
+
|
| 52 |
+
.. code-block:: pycon
|
| 53 |
+
|
| 54 |
+
>>> from markupsafe import Markup, escape
|
| 55 |
+
|
| 56 |
+
>>> # escape replaces special characters and wraps in Markup
|
| 57 |
+
>>> escape("<script>alert(document.cookie);</script>")
|
| 58 |
+
Markup('<script>alert(document.cookie);</script>')
|
| 59 |
+
|
| 60 |
+
>>> # wrap in Markup to mark text "safe" and prevent escaping
|
| 61 |
+
>>> Markup("<strong>Hello</strong>")
|
| 62 |
+
Markup('<strong>hello</strong>')
|
| 63 |
+
|
| 64 |
+
>>> escape(Markup("<strong>Hello</strong>"))
|
| 65 |
+
Markup('<strong>hello</strong>')
|
| 66 |
+
|
| 67 |
+
>>> # Markup is a str subclass
|
| 68 |
+
>>> # methods and operators escape their arguments
|
| 69 |
+
>>> template = Markup("Hello <em>{name}</em>")
|
| 70 |
+
>>> template.format(name='"World"')
|
| 71 |
+
Markup('Hello <em>"World"</em>')
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
Donate
|
| 75 |
+
------
|
| 76 |
+
|
| 77 |
+
The Pallets organization develops and supports MarkupSafe and other
|
| 78 |
+
popular packages. In order to grow the community of contributors and
|
| 79 |
+
users, and allow the maintainers to devote more time to the projects,
|
| 80 |
+
`please donate today`_.
|
| 81 |
+
|
| 82 |
+
.. _please donate today: https://palletsprojects.com/donate
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
Links
|
| 86 |
+
-----
|
| 87 |
+
|
| 88 |
+
- Documentation: https://markupsafe.palletsprojects.com/
|
| 89 |
+
- Changes: https://markupsafe.palletsprojects.com/changes/
|
| 90 |
+
- PyPI Releases: https://pypi.org/project/MarkupSafe/
|
| 91 |
+
- Source Code: https://github.com/pallets/markupsafe/
|
| 92 |
+
- Issue Tracker: https://github.com/pallets/markupsafe/issues/
|
| 93 |
+
- Chat: https://discord.gg/pallets
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/RECORD
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MarkupSafe-2.1.5.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 2 |
+
MarkupSafe-2.1.5.dist-info/LICENSE.rst,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
|
| 3 |
+
MarkupSafe-2.1.5.dist-info/METADATA,sha256=2dRDPam6OZLfpX0wg1JN5P3u9arqACxVSfdGmsJU7o8,3003
|
| 4 |
+
MarkupSafe-2.1.5.dist-info/RECORD,,
|
| 5 |
+
MarkupSafe-2.1.5.dist-info/WHEEL,sha256=vJMp7mUkE-fMIYyE5xJ9Q2cYPnWVgHf20clVdwMSXAg,152
|
| 6 |
+
MarkupSafe-2.1.5.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
|
| 7 |
+
markupsafe/__init__.py,sha256=r7VOTjUq7EMQ4v3p4R1LoVOGJg6ysfYRncLr34laRBs,10958
|
| 8 |
+
markupsafe/__pycache__/__init__.cpython-312.pyc,,
|
| 9 |
+
markupsafe/__pycache__/_native.cpython-312.pyc,,
|
| 10 |
+
markupsafe/_native.py,sha256=GR86Qvo_GcgKmKreA1WmYN9ud17OFwkww8E-fiW-57s,1713
|
| 11 |
+
markupsafe/_speedups.c,sha256=X2XvQVtIdcK4Usz70BvkzoOfjTCmQlDkkjYSn-swE0g,7083
|
| 12 |
+
markupsafe/_speedups.cpython-312-x86_64-linux-gnu.so,sha256=Y2jIPiSLPZlb82iRu9UUj27sbTui5o7SSoi-2SIXEUg,54072
|
| 13 |
+
markupsafe/_speedups.pyi,sha256=vfMCsOgbAXRNLUXkyuyonG8uEWKYU4PDqNuMaDELAYw,229
|
| 14 |
+
markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.42.0)
|
| 3 |
+
Root-Is-Purelib: false
|
| 4 |
+
Tag: cp312-cp312-manylinux_2_17_x86_64
|
| 5 |
+
Tag: cp312-cp312-manylinux2014_x86_64
|
| 6 |
+
|
venv/lib/python3.12/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
markupsafe
|
venv/lib/python3.12/site-packages/PIL/BdfFontFile.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# bitmap distribution font (bdf) file parser
|
| 6 |
+
#
|
| 7 |
+
# history:
|
| 8 |
+
# 1996-05-16 fl created (as bdf2pil)
|
| 9 |
+
# 1997-08-25 fl converted to FontFile driver
|
| 10 |
+
# 2001-05-25 fl removed bogus __init__ call
|
| 11 |
+
# 2002-11-20 fl robustification (from Kevin Cazabon, Dmitry Vasiliev)
|
| 12 |
+
# 2003-04-22 fl more robustification (from Graham Dumpleton)
|
| 13 |
+
#
|
| 14 |
+
# Copyright (c) 1997-2003 by Secret Labs AB.
|
| 15 |
+
# Copyright (c) 1997-2003 by Fredrik Lundh.
|
| 16 |
+
#
|
| 17 |
+
# See the README file for information on usage and redistribution.
|
| 18 |
+
#
|
| 19 |
+
|
| 20 |
+
"""
|
| 21 |
+
Parse X Bitmap Distribution Format (BDF)
|
| 22 |
+
"""
|
| 23 |
+
from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
from typing import BinaryIO
|
| 26 |
+
|
| 27 |
+
from . import FontFile, Image
|
| 28 |
+
|
| 29 |
+
bdf_slant = {
|
| 30 |
+
"R": "Roman",
|
| 31 |
+
"I": "Italic",
|
| 32 |
+
"O": "Oblique",
|
| 33 |
+
"RI": "Reverse Italic",
|
| 34 |
+
"RO": "Reverse Oblique",
|
| 35 |
+
"OT": "Other",
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def bdf_char(
|
| 42 |
+
f: BinaryIO,
|
| 43 |
+
) -> (
|
| 44 |
+
tuple[
|
| 45 |
+
str,
|
| 46 |
+
int,
|
| 47 |
+
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
|
| 48 |
+
Image.Image,
|
| 49 |
+
]
|
| 50 |
+
| None
|
| 51 |
+
):
|
| 52 |
+
# skip to STARTCHAR
|
| 53 |
+
while True:
|
| 54 |
+
s = f.readline()
|
| 55 |
+
if not s:
|
| 56 |
+
return None
|
| 57 |
+
if s[:9] == b"STARTCHAR":
|
| 58 |
+
break
|
| 59 |
+
id = s[9:].strip().decode("ascii")
|
| 60 |
+
|
| 61 |
+
# load symbol properties
|
| 62 |
+
props = {}
|
| 63 |
+
while True:
|
| 64 |
+
s = f.readline()
|
| 65 |
+
if not s or s[:6] == b"BITMAP":
|
| 66 |
+
break
|
| 67 |
+
i = s.find(b" ")
|
| 68 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 69 |
+
|
| 70 |
+
# load bitmap
|
| 71 |
+
bitmap = bytearray()
|
| 72 |
+
while True:
|
| 73 |
+
s = f.readline()
|
| 74 |
+
if not s or s[:7] == b"ENDCHAR":
|
| 75 |
+
break
|
| 76 |
+
bitmap += s[:-1]
|
| 77 |
+
|
| 78 |
+
# The word BBX
|
| 79 |
+
# followed by the width in x (BBw), height in y (BBh),
|
| 80 |
+
# and x and y displacement (BBxoff0, BByoff0)
|
| 81 |
+
# of the lower left corner from the origin of the character.
|
| 82 |
+
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())
|
| 83 |
+
|
| 84 |
+
# The word DWIDTH
|
| 85 |
+
# followed by the width in x and y of the character in device pixels.
|
| 86 |
+
dwx, dwy = (int(p) for p in props["DWIDTH"].split())
|
| 87 |
+
|
| 88 |
+
bbox = (
|
| 89 |
+
(dwx, dwy),
|
| 90 |
+
(x_disp, -y_disp - height, width + x_disp, -y_disp),
|
| 91 |
+
(0, 0, width, height),
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
im = Image.frombytes("1", (width, height), bitmap, "hex", "1")
|
| 96 |
+
except ValueError:
|
| 97 |
+
# deal with zero-width characters
|
| 98 |
+
im = Image.new("1", (width, height))
|
| 99 |
+
|
| 100 |
+
return id, int(props["ENCODING"]), bbox, im
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class BdfFontFile(FontFile.FontFile):
|
| 104 |
+
"""Font file plugin for the X11 BDF format."""
|
| 105 |
+
|
| 106 |
+
def __init__(self, fp: BinaryIO):
|
| 107 |
+
super().__init__()
|
| 108 |
+
|
| 109 |
+
s = fp.readline()
|
| 110 |
+
if s[:13] != b"STARTFONT 2.1":
|
| 111 |
+
msg = "not a valid BDF file"
|
| 112 |
+
raise SyntaxError(msg)
|
| 113 |
+
|
| 114 |
+
props = {}
|
| 115 |
+
comments = []
|
| 116 |
+
|
| 117 |
+
while True:
|
| 118 |
+
s = fp.readline()
|
| 119 |
+
if not s or s[:13] == b"ENDPROPERTIES":
|
| 120 |
+
break
|
| 121 |
+
i = s.find(b" ")
|
| 122 |
+
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
|
| 123 |
+
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
|
| 124 |
+
if s.find(b"LogicalFontDescription") < 0:
|
| 125 |
+
comments.append(s[i + 1 : -1].decode("ascii"))
|
| 126 |
+
|
| 127 |
+
while True:
|
| 128 |
+
c = bdf_char(fp)
|
| 129 |
+
if not c:
|
| 130 |
+
break
|
| 131 |
+
id, ch, (xy, dst, src), im = c
|
| 132 |
+
if 0 <= ch < len(self.glyph):
|
| 133 |
+
self.glyph[ch] = xy, dst, src, im
|
venv/lib/python3.12/site-packages/PIL/BlpImagePlugin.py
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Blizzard Mipmap Format (.blp)
|
| 3 |
+
Jerome Leclanche <jerome@leclan.ch>
|
| 4 |
+
|
| 5 |
+
The contents of this file are hereby released in the public domain (CC0)
|
| 6 |
+
Full text of the CC0 license:
|
| 7 |
+
https://creativecommons.org/publicdomain/zero/1.0/
|
| 8 |
+
|
| 9 |
+
BLP1 files, used mostly in Warcraft III, are not fully supported.
|
| 10 |
+
All types of BLP2 files used in World of Warcraft are supported.
|
| 11 |
+
|
| 12 |
+
The BLP file structure consists of a header, up to 16 mipmaps of the
|
| 13 |
+
texture
|
| 14 |
+
|
| 15 |
+
Texture sizes must be powers of two, though the two dimensions do
|
| 16 |
+
not have to be equal; 512x256 is valid, but 512x200 is not.
|
| 17 |
+
The first mipmap (mipmap #0) is the full size image; each subsequent
|
| 18 |
+
mipmap halves both dimensions. The final mipmap should be 1x1.
|
| 19 |
+
|
| 20 |
+
BLP files come in many different flavours:
|
| 21 |
+
* JPEG-compressed (type == 0) - only supported for BLP1.
|
| 22 |
+
* RAW images (type == 1, encoding == 1). Each mipmap is stored as an
|
| 23 |
+
array of 8-bit values, one per pixel, left to right, top to bottom.
|
| 24 |
+
Each value is an index to the palette.
|
| 25 |
+
* DXT-compressed (type == 1, encoding == 2):
|
| 26 |
+
- DXT1 compression is used if alpha_encoding == 0.
|
| 27 |
+
- An additional alpha bit is used if alpha_depth == 1.
|
| 28 |
+
- DXT3 compression is used if alpha_encoding == 1.
|
| 29 |
+
- DXT5 compression is used if alpha_encoding == 7.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
from __future__ import annotations
|
| 33 |
+
|
| 34 |
+
import os
|
| 35 |
+
import struct
|
| 36 |
+
from enum import IntEnum
|
| 37 |
+
from io import BytesIO
|
| 38 |
+
|
| 39 |
+
from . import Image, ImageFile
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
class Format(IntEnum):
|
| 43 |
+
JPEG = 0
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class Encoding(IntEnum):
|
| 47 |
+
UNCOMPRESSED = 1
|
| 48 |
+
DXT = 2
|
| 49 |
+
UNCOMPRESSED_RAW_BGRA = 3
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class AlphaEncoding(IntEnum):
|
| 53 |
+
DXT1 = 0
|
| 54 |
+
DXT3 = 1
|
| 55 |
+
DXT5 = 7
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def unpack_565(i):
|
| 59 |
+
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def decode_dxt1(data, alpha=False):
|
| 63 |
+
"""
|
| 64 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
blocks = len(data) // 8 # number of blocks in row
|
| 68 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 69 |
+
|
| 70 |
+
for block in range(blocks):
|
| 71 |
+
# Decode next 8-byte block.
|
| 72 |
+
idx = block * 8
|
| 73 |
+
color0, color1, bits = struct.unpack_from("<HHI", data, idx)
|
| 74 |
+
|
| 75 |
+
r0, g0, b0 = unpack_565(color0)
|
| 76 |
+
r1, g1, b1 = unpack_565(color1)
|
| 77 |
+
|
| 78 |
+
# Decode this block into 4x4 pixels
|
| 79 |
+
# Accumulate the results onto our 4 row accumulators
|
| 80 |
+
for j in range(4):
|
| 81 |
+
for i in range(4):
|
| 82 |
+
# get next control op and generate a pixel
|
| 83 |
+
|
| 84 |
+
control = bits & 3
|
| 85 |
+
bits = bits >> 2
|
| 86 |
+
|
| 87 |
+
a = 0xFF
|
| 88 |
+
if control == 0:
|
| 89 |
+
r, g, b = r0, g0, b0
|
| 90 |
+
elif control == 1:
|
| 91 |
+
r, g, b = r1, g1, b1
|
| 92 |
+
elif control == 2:
|
| 93 |
+
if color0 > color1:
|
| 94 |
+
r = (2 * r0 + r1) // 3
|
| 95 |
+
g = (2 * g0 + g1) // 3
|
| 96 |
+
b = (2 * b0 + b1) // 3
|
| 97 |
+
else:
|
| 98 |
+
r = (r0 + r1) // 2
|
| 99 |
+
g = (g0 + g1) // 2
|
| 100 |
+
b = (b0 + b1) // 2
|
| 101 |
+
elif control == 3:
|
| 102 |
+
if color0 > color1:
|
| 103 |
+
r = (2 * r1 + r0) // 3
|
| 104 |
+
g = (2 * g1 + g0) // 3
|
| 105 |
+
b = (2 * b1 + b0) // 3
|
| 106 |
+
else:
|
| 107 |
+
r, g, b, a = 0, 0, 0, 0
|
| 108 |
+
|
| 109 |
+
if alpha:
|
| 110 |
+
ret[j].extend([r, g, b, a])
|
| 111 |
+
else:
|
| 112 |
+
ret[j].extend([r, g, b])
|
| 113 |
+
|
| 114 |
+
return ret
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def decode_dxt3(data):
|
| 118 |
+
"""
|
| 119 |
+
input: one "row" of data (i.e. will produce 4*width pixels)
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 123 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 124 |
+
|
| 125 |
+
for block in range(blocks):
|
| 126 |
+
idx = block * 16
|
| 127 |
+
block = data[idx : idx + 16]
|
| 128 |
+
# Decode next 16-byte block.
|
| 129 |
+
bits = struct.unpack_from("<8B", block)
|
| 130 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 131 |
+
|
| 132 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 133 |
+
|
| 134 |
+
r0, g0, b0 = unpack_565(color0)
|
| 135 |
+
r1, g1, b1 = unpack_565(color1)
|
| 136 |
+
|
| 137 |
+
for j in range(4):
|
| 138 |
+
high = False # Do we want the higher bits?
|
| 139 |
+
for i in range(4):
|
| 140 |
+
alphacode_index = (4 * j + i) // 2
|
| 141 |
+
a = bits[alphacode_index]
|
| 142 |
+
if high:
|
| 143 |
+
high = False
|
| 144 |
+
a >>= 4
|
| 145 |
+
else:
|
| 146 |
+
high = True
|
| 147 |
+
a &= 0xF
|
| 148 |
+
a *= 17 # We get a value between 0 and 15
|
| 149 |
+
|
| 150 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 151 |
+
|
| 152 |
+
if color_code == 0:
|
| 153 |
+
r, g, b = r0, g0, b0
|
| 154 |
+
elif color_code == 1:
|
| 155 |
+
r, g, b = r1, g1, b1
|
| 156 |
+
elif color_code == 2:
|
| 157 |
+
r = (2 * r0 + r1) // 3
|
| 158 |
+
g = (2 * g0 + g1) // 3
|
| 159 |
+
b = (2 * b0 + b1) // 3
|
| 160 |
+
elif color_code == 3:
|
| 161 |
+
r = (2 * r1 + r0) // 3
|
| 162 |
+
g = (2 * g1 + g0) // 3
|
| 163 |
+
b = (2 * b1 + b0) // 3
|
| 164 |
+
|
| 165 |
+
ret[j].extend([r, g, b, a])
|
| 166 |
+
|
| 167 |
+
return ret
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def decode_dxt5(data):
|
| 171 |
+
"""
|
| 172 |
+
input: one "row" of data (i.e. will produce 4 * width pixels)
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
blocks = len(data) // 16 # number of blocks in row
|
| 176 |
+
ret = (bytearray(), bytearray(), bytearray(), bytearray())
|
| 177 |
+
|
| 178 |
+
for block in range(blocks):
|
| 179 |
+
idx = block * 16
|
| 180 |
+
block = data[idx : idx + 16]
|
| 181 |
+
# Decode next 16-byte block.
|
| 182 |
+
a0, a1 = struct.unpack_from("<BB", block)
|
| 183 |
+
|
| 184 |
+
bits = struct.unpack_from("<6B", block, 2)
|
| 185 |
+
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
|
| 186 |
+
alphacode2 = bits[0] | (bits[1] << 8)
|
| 187 |
+
|
| 188 |
+
color0, color1 = struct.unpack_from("<HH", block, 8)
|
| 189 |
+
|
| 190 |
+
(code,) = struct.unpack_from("<I", block, 12)
|
| 191 |
+
|
| 192 |
+
r0, g0, b0 = unpack_565(color0)
|
| 193 |
+
r1, g1, b1 = unpack_565(color1)
|
| 194 |
+
|
| 195 |
+
for j in range(4):
|
| 196 |
+
for i in range(4):
|
| 197 |
+
# get next control op and generate a pixel
|
| 198 |
+
alphacode_index = 3 * (4 * j + i)
|
| 199 |
+
|
| 200 |
+
if alphacode_index <= 12:
|
| 201 |
+
alphacode = (alphacode2 >> alphacode_index) & 0x07
|
| 202 |
+
elif alphacode_index == 15:
|
| 203 |
+
alphacode = (alphacode2 >> 15) | ((alphacode1 << 1) & 0x06)
|
| 204 |
+
else: # alphacode_index >= 18 and alphacode_index <= 45
|
| 205 |
+
alphacode = (alphacode1 >> (alphacode_index - 16)) & 0x07
|
| 206 |
+
|
| 207 |
+
if alphacode == 0:
|
| 208 |
+
a = a0
|
| 209 |
+
elif alphacode == 1:
|
| 210 |
+
a = a1
|
| 211 |
+
elif a0 > a1:
|
| 212 |
+
a = ((8 - alphacode) * a0 + (alphacode - 1) * a1) // 7
|
| 213 |
+
elif alphacode == 6:
|
| 214 |
+
a = 0
|
| 215 |
+
elif alphacode == 7:
|
| 216 |
+
a = 255
|
| 217 |
+
else:
|
| 218 |
+
a = ((6 - alphacode) * a0 + (alphacode - 1) * a1) // 5
|
| 219 |
+
|
| 220 |
+
color_code = (code >> 2 * (4 * j + i)) & 0x03
|
| 221 |
+
|
| 222 |
+
if color_code == 0:
|
| 223 |
+
r, g, b = r0, g0, b0
|
| 224 |
+
elif color_code == 1:
|
| 225 |
+
r, g, b = r1, g1, b1
|
| 226 |
+
elif color_code == 2:
|
| 227 |
+
r = (2 * r0 + r1) // 3
|
| 228 |
+
g = (2 * g0 + g1) // 3
|
| 229 |
+
b = (2 * b0 + b1) // 3
|
| 230 |
+
elif color_code == 3:
|
| 231 |
+
r = (2 * r1 + r0) // 3
|
| 232 |
+
g = (2 * g1 + g0) // 3
|
| 233 |
+
b = (2 * b1 + b0) // 3
|
| 234 |
+
|
| 235 |
+
ret[j].extend([r, g, b, a])
|
| 236 |
+
|
| 237 |
+
return ret
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
class BLPFormatError(NotImplementedError):
|
| 241 |
+
pass
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def _accept(prefix):
|
| 245 |
+
return prefix[:4] in (b"BLP1", b"BLP2")
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
class BlpImageFile(ImageFile.ImageFile):
|
| 249 |
+
"""
|
| 250 |
+
Blizzard Mipmap Format
|
| 251 |
+
"""
|
| 252 |
+
|
| 253 |
+
format = "BLP"
|
| 254 |
+
format_description = "Blizzard Mipmap Format"
|
| 255 |
+
|
| 256 |
+
def _open(self):
|
| 257 |
+
self.magic = self.fp.read(4)
|
| 258 |
+
|
| 259 |
+
self.fp.seek(5, os.SEEK_CUR)
|
| 260 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self.fp.read(1))
|
| 261 |
+
|
| 262 |
+
self.fp.seek(2, os.SEEK_CUR)
|
| 263 |
+
self._size = struct.unpack("<II", self.fp.read(8))
|
| 264 |
+
|
| 265 |
+
if self.magic in (b"BLP1", b"BLP2"):
|
| 266 |
+
decoder = self.magic.decode()
|
| 267 |
+
else:
|
| 268 |
+
msg = f"Bad BLP magic {repr(self.magic)}"
|
| 269 |
+
raise BLPFormatError(msg)
|
| 270 |
+
|
| 271 |
+
self._mode = "RGBA" if self._blp_alpha_depth else "RGB"
|
| 272 |
+
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
class _BLPBaseDecoder(ImageFile.PyDecoder):
|
| 276 |
+
_pulls_fd = True
|
| 277 |
+
|
| 278 |
+
def decode(self, buffer):
|
| 279 |
+
try:
|
| 280 |
+
self._read_blp_header()
|
| 281 |
+
self._load()
|
| 282 |
+
except struct.error as e:
|
| 283 |
+
msg = "Truncated BLP file"
|
| 284 |
+
raise OSError(msg) from e
|
| 285 |
+
return -1, 0
|
| 286 |
+
|
| 287 |
+
def _read_blp_header(self):
|
| 288 |
+
self.fd.seek(4)
|
| 289 |
+
(self._blp_compression,) = struct.unpack("<i", self._safe_read(4))
|
| 290 |
+
|
| 291 |
+
(self._blp_encoding,) = struct.unpack("<b", self._safe_read(1))
|
| 292 |
+
(self._blp_alpha_depth,) = struct.unpack("<b", self._safe_read(1))
|
| 293 |
+
(self._blp_alpha_encoding,) = struct.unpack("<b", self._safe_read(1))
|
| 294 |
+
self.fd.seek(1, os.SEEK_CUR) # mips
|
| 295 |
+
|
| 296 |
+
self.size = struct.unpack("<II", self._safe_read(8))
|
| 297 |
+
|
| 298 |
+
if isinstance(self, BLP1Decoder):
|
| 299 |
+
# Only present for BLP1
|
| 300 |
+
(self._blp_encoding,) = struct.unpack("<i", self._safe_read(4))
|
| 301 |
+
self.fd.seek(4, os.SEEK_CUR) # subtype
|
| 302 |
+
|
| 303 |
+
self._blp_offsets = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 304 |
+
self._blp_lengths = struct.unpack("<16I", self._safe_read(16 * 4))
|
| 305 |
+
|
| 306 |
+
def _safe_read(self, length):
|
| 307 |
+
return ImageFile._safe_read(self.fd, length)
|
| 308 |
+
|
| 309 |
+
def _read_palette(self):
|
| 310 |
+
ret = []
|
| 311 |
+
for i in range(256):
|
| 312 |
+
try:
|
| 313 |
+
b, g, r, a = struct.unpack("<4B", self._safe_read(4))
|
| 314 |
+
except struct.error:
|
| 315 |
+
break
|
| 316 |
+
ret.append((b, g, r, a))
|
| 317 |
+
return ret
|
| 318 |
+
|
| 319 |
+
def _read_bgra(self, palette):
|
| 320 |
+
data = bytearray()
|
| 321 |
+
_data = BytesIO(self._safe_read(self._blp_lengths[0]))
|
| 322 |
+
while True:
|
| 323 |
+
try:
|
| 324 |
+
(offset,) = struct.unpack("<B", _data.read(1))
|
| 325 |
+
except struct.error:
|
| 326 |
+
break
|
| 327 |
+
b, g, r, a = palette[offset]
|
| 328 |
+
d = (r, g, b)
|
| 329 |
+
if self._blp_alpha_depth:
|
| 330 |
+
d += (a,)
|
| 331 |
+
data.extend(d)
|
| 332 |
+
return data
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
class BLP1Decoder(_BLPBaseDecoder):
|
| 336 |
+
def _load(self):
|
| 337 |
+
if self._blp_compression == Format.JPEG:
|
| 338 |
+
self._decode_jpeg_stream()
|
| 339 |
+
|
| 340 |
+
elif self._blp_compression == 1:
|
| 341 |
+
if self._blp_encoding in (4, 5):
|
| 342 |
+
palette = self._read_palette()
|
| 343 |
+
data = self._read_bgra(palette)
|
| 344 |
+
self.set_as_raw(data)
|
| 345 |
+
else:
|
| 346 |
+
msg = f"Unsupported BLP encoding {repr(self._blp_encoding)}"
|
| 347 |
+
raise BLPFormatError(msg)
|
| 348 |
+
else:
|
| 349 |
+
msg = f"Unsupported BLP compression {repr(self._blp_encoding)}"
|
| 350 |
+
raise BLPFormatError(msg)
|
| 351 |
+
|
| 352 |
+
def _decode_jpeg_stream(self):
|
| 353 |
+
from .JpegImagePlugin import JpegImageFile
|
| 354 |
+
|
| 355 |
+
(jpeg_header_size,) = struct.unpack("<I", self._safe_read(4))
|
| 356 |
+
jpeg_header = self._safe_read(jpeg_header_size)
|
| 357 |
+
self._safe_read(self._blp_offsets[0] - self.fd.tell()) # What IS this?
|
| 358 |
+
data = self._safe_read(self._blp_lengths[0])
|
| 359 |
+
data = jpeg_header + data
|
| 360 |
+
data = BytesIO(data)
|
| 361 |
+
image = JpegImageFile(data)
|
| 362 |
+
Image._decompression_bomb_check(image.size)
|
| 363 |
+
if image.mode == "CMYK":
|
| 364 |
+
decoder_name, extents, offset, args = image.tile[0]
|
| 365 |
+
image.tile = [(decoder_name, extents, offset, (args[0], "CMYK"))]
|
| 366 |
+
r, g, b = image.convert("RGB").split()
|
| 367 |
+
image = Image.merge("RGB", (b, g, r))
|
| 368 |
+
self.set_as_raw(image.tobytes())
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class BLP2Decoder(_BLPBaseDecoder):
|
| 372 |
+
def _load(self):
|
| 373 |
+
palette = self._read_palette()
|
| 374 |
+
|
| 375 |
+
self.fd.seek(self._blp_offsets[0])
|
| 376 |
+
|
| 377 |
+
if self._blp_compression == 1:
|
| 378 |
+
# Uncompressed or DirectX compression
|
| 379 |
+
|
| 380 |
+
if self._blp_encoding == Encoding.UNCOMPRESSED:
|
| 381 |
+
data = self._read_bgra(palette)
|
| 382 |
+
|
| 383 |
+
elif self._blp_encoding == Encoding.DXT:
|
| 384 |
+
data = bytearray()
|
| 385 |
+
if self._blp_alpha_encoding == AlphaEncoding.DXT1:
|
| 386 |
+
linesize = (self.size[0] + 3) // 4 * 8
|
| 387 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 388 |
+
for d in decode_dxt1(
|
| 389 |
+
self._safe_read(linesize), alpha=bool(self._blp_alpha_depth)
|
| 390 |
+
):
|
| 391 |
+
data += d
|
| 392 |
+
|
| 393 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT3:
|
| 394 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
| 395 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 396 |
+
for d in decode_dxt3(self._safe_read(linesize)):
|
| 397 |
+
data += d
|
| 398 |
+
|
| 399 |
+
elif self._blp_alpha_encoding == AlphaEncoding.DXT5:
|
| 400 |
+
linesize = (self.size[0] + 3) // 4 * 16
|
| 401 |
+
for yb in range((self.size[1] + 3) // 4):
|
| 402 |
+
for d in decode_dxt5(self._safe_read(linesize)):
|
| 403 |
+
data += d
|
| 404 |
+
else:
|
| 405 |
+
msg = f"Unsupported alpha encoding {repr(self._blp_alpha_encoding)}"
|
| 406 |
+
raise BLPFormatError(msg)
|
| 407 |
+
else:
|
| 408 |
+
msg = f"Unknown BLP encoding {repr(self._blp_encoding)}"
|
| 409 |
+
raise BLPFormatError(msg)
|
| 410 |
+
|
| 411 |
+
else:
|
| 412 |
+
msg = f"Unknown BLP compression {repr(self._blp_compression)}"
|
| 413 |
+
raise BLPFormatError(msg)
|
| 414 |
+
|
| 415 |
+
self.set_as_raw(data)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
class BLPEncoder(ImageFile.PyEncoder):
|
| 419 |
+
_pushes_fd = True
|
| 420 |
+
|
| 421 |
+
def _write_palette(self):
|
| 422 |
+
data = b""
|
| 423 |
+
palette = self.im.getpalette("RGBA", "RGBA")
|
| 424 |
+
for i in range(len(palette) // 4):
|
| 425 |
+
r, g, b, a = palette[i * 4 : (i + 1) * 4]
|
| 426 |
+
data += struct.pack("<4B", b, g, r, a)
|
| 427 |
+
while len(data) < 256 * 4:
|
| 428 |
+
data += b"\x00" * 4
|
| 429 |
+
return data
|
| 430 |
+
|
| 431 |
+
def encode(self, bufsize):
|
| 432 |
+
palette_data = self._write_palette()
|
| 433 |
+
|
| 434 |
+
offset = 20 + 16 * 4 * 2 + len(palette_data)
|
| 435 |
+
data = struct.pack("<16I", offset, *((0,) * 15))
|
| 436 |
+
|
| 437 |
+
w, h = self.im.size
|
| 438 |
+
data += struct.pack("<16I", w * h, *((0,) * 15))
|
| 439 |
+
|
| 440 |
+
data += palette_data
|
| 441 |
+
|
| 442 |
+
for y in range(h):
|
| 443 |
+
for x in range(w):
|
| 444 |
+
data += struct.pack("<B", self.im.getpixel((x, y)))
|
| 445 |
+
|
| 446 |
+
return len(data), 0, data
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
def _save(im, fp, filename):
|
| 450 |
+
if im.mode != "P":
|
| 451 |
+
msg = "Unsupported BLP image mode"
|
| 452 |
+
raise ValueError(msg)
|
| 453 |
+
|
| 454 |
+
magic = b"BLP1" if im.encoderinfo.get("blp_version") == "BLP1" else b"BLP2"
|
| 455 |
+
fp.write(magic)
|
| 456 |
+
|
| 457 |
+
fp.write(struct.pack("<i", 1)) # Uncompressed or DirectX compression
|
| 458 |
+
fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
|
| 459 |
+
fp.write(struct.pack("<b", 1 if im.palette.mode == "RGBA" else 0))
|
| 460 |
+
fp.write(struct.pack("<b", 0)) # alpha encoding
|
| 461 |
+
fp.write(struct.pack("<b", 0)) # mips
|
| 462 |
+
fp.write(struct.pack("<II", *im.size))
|
| 463 |
+
if magic == b"BLP1":
|
| 464 |
+
fp.write(struct.pack("<i", 5))
|
| 465 |
+
fp.write(struct.pack("<i", 0))
|
| 466 |
+
|
| 467 |
+
ImageFile._save(im, fp, [("BLP", (0, 0) + im.size, 0, im.mode)])
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
|
| 471 |
+
Image.register_extension(BlpImageFile.format, ".blp")
|
| 472 |
+
Image.register_decoder("BLP1", BLP1Decoder)
|
| 473 |
+
Image.register_decoder("BLP2", BLP2Decoder)
|
| 474 |
+
|
| 475 |
+
Image.register_save(BlpImageFile.format, _save)
|
| 476 |
+
Image.register_encoder("BLP", BLPEncoder)
|
venv/lib/python3.12/site-packages/PIL/BmpImagePlugin.py
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library.
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# BMP file handler
|
| 6 |
+
#
|
| 7 |
+
# Windows (and OS/2) native bitmap storage format.
|
| 8 |
+
#
|
| 9 |
+
# history:
|
| 10 |
+
# 1995-09-01 fl Created
|
| 11 |
+
# 1996-04-30 fl Added save
|
| 12 |
+
# 1997-08-27 fl Fixed save of 1-bit images
|
| 13 |
+
# 1998-03-06 fl Load P images as L where possible
|
| 14 |
+
# 1998-07-03 fl Load P images as 1 where possible
|
| 15 |
+
# 1998-12-29 fl Handle small palettes
|
| 16 |
+
# 2002-12-30 fl Fixed load of 1-bit palette images
|
| 17 |
+
# 2003-04-21 fl Fixed load of 1-bit monochrome images
|
| 18 |
+
# 2003-04-23 fl Added limited support for BI_BITFIELDS compression
|
| 19 |
+
#
|
| 20 |
+
# Copyright (c) 1997-2003 by Secret Labs AB
|
| 21 |
+
# Copyright (c) 1995-2003 by Fredrik Lundh
|
| 22 |
+
#
|
| 23 |
+
# See the README file for information on usage and redistribution.
|
| 24 |
+
#
|
| 25 |
+
from __future__ import annotations
|
| 26 |
+
|
| 27 |
+
import os
|
| 28 |
+
|
| 29 |
+
from . import Image, ImageFile, ImagePalette
|
| 30 |
+
from ._binary import i16le as i16
|
| 31 |
+
from ._binary import i32le as i32
|
| 32 |
+
from ._binary import o8
|
| 33 |
+
from ._binary import o16le as o16
|
| 34 |
+
from ._binary import o32le as o32
|
| 35 |
+
|
| 36 |
+
#
|
| 37 |
+
# --------------------------------------------------------------------
|
| 38 |
+
# Read BMP file
|
| 39 |
+
|
| 40 |
+
BIT2MODE = {
|
| 41 |
+
# bits => mode, rawmode
|
| 42 |
+
1: ("P", "P;1"),
|
| 43 |
+
4: ("P", "P;4"),
|
| 44 |
+
8: ("P", "P"),
|
| 45 |
+
16: ("RGB", "BGR;15"),
|
| 46 |
+
24: ("RGB", "BGR"),
|
| 47 |
+
32: ("RGB", "BGRX"),
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _accept(prefix):
|
| 52 |
+
return prefix[:2] == b"BM"
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _dib_accept(prefix):
|
| 56 |
+
return i32(prefix) in [12, 40, 64, 108, 124]
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
# =============================================================================
|
| 60 |
+
# Image plugin for the Windows BMP format.
|
| 61 |
+
# =============================================================================
|
| 62 |
+
class BmpImageFile(ImageFile.ImageFile):
|
| 63 |
+
"""Image plugin for the Windows Bitmap format (BMP)"""
|
| 64 |
+
|
| 65 |
+
# ------------------------------------------------------------- Description
|
| 66 |
+
format_description = "Windows Bitmap"
|
| 67 |
+
format = "BMP"
|
| 68 |
+
|
| 69 |
+
# -------------------------------------------------- BMP Compression values
|
| 70 |
+
COMPRESSIONS = {"RAW": 0, "RLE8": 1, "RLE4": 2, "BITFIELDS": 3, "JPEG": 4, "PNG": 5}
|
| 71 |
+
for k, v in COMPRESSIONS.items():
|
| 72 |
+
vars()[k] = v
|
| 73 |
+
|
| 74 |
+
def _bitmap(self, header=0, offset=0):
|
| 75 |
+
"""Read relevant info about the BMP"""
|
| 76 |
+
read, seek = self.fp.read, self.fp.seek
|
| 77 |
+
if header:
|
| 78 |
+
seek(header)
|
| 79 |
+
# read bmp header size @offset 14 (this is part of the header size)
|
| 80 |
+
file_info = {"header_size": i32(read(4)), "direction": -1}
|
| 81 |
+
|
| 82 |
+
# -------------------- If requested, read header at a specific position
|
| 83 |
+
# read the rest of the bmp header, without its size
|
| 84 |
+
header_data = ImageFile._safe_read(self.fp, file_info["header_size"] - 4)
|
| 85 |
+
|
| 86 |
+
# -------------------------------------------------- IBM OS/2 Bitmap v1
|
| 87 |
+
# ----- This format has different offsets because of width/height types
|
| 88 |
+
if file_info["header_size"] == 12:
|
| 89 |
+
file_info["width"] = i16(header_data, 0)
|
| 90 |
+
file_info["height"] = i16(header_data, 2)
|
| 91 |
+
file_info["planes"] = i16(header_data, 4)
|
| 92 |
+
file_info["bits"] = i16(header_data, 6)
|
| 93 |
+
file_info["compression"] = self.RAW
|
| 94 |
+
file_info["palette_padding"] = 3
|
| 95 |
+
|
| 96 |
+
# --------------------------------------------- Windows Bitmap v2 to v5
|
| 97 |
+
# v3, OS/2 v2, v4, v5
|
| 98 |
+
elif file_info["header_size"] in (40, 64, 108, 124):
|
| 99 |
+
file_info["y_flip"] = header_data[7] == 0xFF
|
| 100 |
+
file_info["direction"] = 1 if file_info["y_flip"] else -1
|
| 101 |
+
file_info["width"] = i32(header_data, 0)
|
| 102 |
+
file_info["height"] = (
|
| 103 |
+
i32(header_data, 4)
|
| 104 |
+
if not file_info["y_flip"]
|
| 105 |
+
else 2**32 - i32(header_data, 4)
|
| 106 |
+
)
|
| 107 |
+
file_info["planes"] = i16(header_data, 8)
|
| 108 |
+
file_info["bits"] = i16(header_data, 10)
|
| 109 |
+
file_info["compression"] = i32(header_data, 12)
|
| 110 |
+
# byte size of pixel data
|
| 111 |
+
file_info["data_size"] = i32(header_data, 16)
|
| 112 |
+
file_info["pixels_per_meter"] = (
|
| 113 |
+
i32(header_data, 20),
|
| 114 |
+
i32(header_data, 24),
|
| 115 |
+
)
|
| 116 |
+
file_info["colors"] = i32(header_data, 28)
|
| 117 |
+
file_info["palette_padding"] = 4
|
| 118 |
+
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
| 119 |
+
if file_info["compression"] == self.BITFIELDS:
|
| 120 |
+
if len(header_data) >= 52:
|
| 121 |
+
for idx, mask in enumerate(
|
| 122 |
+
["r_mask", "g_mask", "b_mask", "a_mask"]
|
| 123 |
+
):
|
| 124 |
+
file_info[mask] = i32(header_data, 36 + idx * 4)
|
| 125 |
+
else:
|
| 126 |
+
# 40 byte headers only have the three components in the
|
| 127 |
+
# bitfields masks, ref:
|
| 128 |
+
# https://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
|
| 129 |
+
# See also
|
| 130 |
+
# https://github.com/python-pillow/Pillow/issues/1293
|
| 131 |
+
# There is a 4th component in the RGBQuad, in the alpha
|
| 132 |
+
# location, but it is listed as a reserved component,
|
| 133 |
+
# and it is not generally an alpha channel
|
| 134 |
+
file_info["a_mask"] = 0x0
|
| 135 |
+
for mask in ["r_mask", "g_mask", "b_mask"]:
|
| 136 |
+
file_info[mask] = i32(read(4))
|
| 137 |
+
file_info["rgb_mask"] = (
|
| 138 |
+
file_info["r_mask"],
|
| 139 |
+
file_info["g_mask"],
|
| 140 |
+
file_info["b_mask"],
|
| 141 |
+
)
|
| 142 |
+
file_info["rgba_mask"] = (
|
| 143 |
+
file_info["r_mask"],
|
| 144 |
+
file_info["g_mask"],
|
| 145 |
+
file_info["b_mask"],
|
| 146 |
+
file_info["a_mask"],
|
| 147 |
+
)
|
| 148 |
+
else:
|
| 149 |
+
msg = f"Unsupported BMP header type ({file_info['header_size']})"
|
| 150 |
+
raise OSError(msg)
|
| 151 |
+
|
| 152 |
+
# ------------------ Special case : header is reported 40, which
|
| 153 |
+
# ---------------------- is shorter than real size for bpp >= 16
|
| 154 |
+
self._size = file_info["width"], file_info["height"]
|
| 155 |
+
|
| 156 |
+
# ------- If color count was not found in the header, compute from bits
|
| 157 |
+
file_info["colors"] = (
|
| 158 |
+
file_info["colors"]
|
| 159 |
+
if file_info.get("colors", 0)
|
| 160 |
+
else (1 << file_info["bits"])
|
| 161 |
+
)
|
| 162 |
+
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
|
| 163 |
+
offset += 4 * file_info["colors"]
|
| 164 |
+
|
| 165 |
+
# ---------------------- Check bit depth for unusual unsupported values
|
| 166 |
+
self._mode, raw_mode = BIT2MODE.get(file_info["bits"], (None, None))
|
| 167 |
+
if self.mode is None:
|
| 168 |
+
msg = f"Unsupported BMP pixel depth ({file_info['bits']})"
|
| 169 |
+
raise OSError(msg)
|
| 170 |
+
|
| 171 |
+
# ---------------- Process BMP with Bitfields compression (not palette)
|
| 172 |
+
decoder_name = "raw"
|
| 173 |
+
if file_info["compression"] == self.BITFIELDS:
|
| 174 |
+
SUPPORTED = {
|
| 175 |
+
32: [
|
| 176 |
+
(0xFF0000, 0xFF00, 0xFF, 0x0),
|
| 177 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0x0),
|
| 178 |
+
(0xFF000000, 0xFF0000, 0xFF00, 0xFF),
|
| 179 |
+
(0xFF, 0xFF00, 0xFF0000, 0xFF000000),
|
| 180 |
+
(0xFF0000, 0xFF00, 0xFF, 0xFF000000),
|
| 181 |
+
(0x0, 0x0, 0x0, 0x0),
|
| 182 |
+
],
|
| 183 |
+
24: [(0xFF0000, 0xFF00, 0xFF)],
|
| 184 |
+
16: [(0xF800, 0x7E0, 0x1F), (0x7C00, 0x3E0, 0x1F)],
|
| 185 |
+
}
|
| 186 |
+
MASK_MODES = {
|
| 187 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0x0)): "BGRX",
|
| 188 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0x0)): "XBGR",
|
| 189 |
+
(32, (0xFF000000, 0xFF0000, 0xFF00, 0xFF)): "ABGR",
|
| 190 |
+
(32, (0xFF, 0xFF00, 0xFF0000, 0xFF000000)): "RGBA",
|
| 191 |
+
(32, (0xFF0000, 0xFF00, 0xFF, 0xFF000000)): "BGRA",
|
| 192 |
+
(32, (0x0, 0x0, 0x0, 0x0)): "BGRA",
|
| 193 |
+
(24, (0xFF0000, 0xFF00, 0xFF)): "BGR",
|
| 194 |
+
(16, (0xF800, 0x7E0, 0x1F)): "BGR;16",
|
| 195 |
+
(16, (0x7C00, 0x3E0, 0x1F)): "BGR;15",
|
| 196 |
+
}
|
| 197 |
+
if file_info["bits"] in SUPPORTED:
|
| 198 |
+
if (
|
| 199 |
+
file_info["bits"] == 32
|
| 200 |
+
and file_info["rgba_mask"] in SUPPORTED[file_info["bits"]]
|
| 201 |
+
):
|
| 202 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgba_mask"])]
|
| 203 |
+
self._mode = "RGBA" if "A" in raw_mode else self.mode
|
| 204 |
+
elif (
|
| 205 |
+
file_info["bits"] in (24, 16)
|
| 206 |
+
and file_info["rgb_mask"] in SUPPORTED[file_info["bits"]]
|
| 207 |
+
):
|
| 208 |
+
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgb_mask"])]
|
| 209 |
+
else:
|
| 210 |
+
msg = "Unsupported BMP bitfields layout"
|
| 211 |
+
raise OSError(msg)
|
| 212 |
+
else:
|
| 213 |
+
msg = "Unsupported BMP bitfields layout"
|
| 214 |
+
raise OSError(msg)
|
| 215 |
+
elif file_info["compression"] == self.RAW:
|
| 216 |
+
if file_info["bits"] == 32 and header == 22: # 32-bit .cur offset
|
| 217 |
+
raw_mode, self._mode = "BGRA", "RGBA"
|
| 218 |
+
elif file_info["compression"] in (self.RLE8, self.RLE4):
|
| 219 |
+
decoder_name = "bmp_rle"
|
| 220 |
+
else:
|
| 221 |
+
msg = f"Unsupported BMP compression ({file_info['compression']})"
|
| 222 |
+
raise OSError(msg)
|
| 223 |
+
|
| 224 |
+
# --------------- Once the header is processed, process the palette/LUT
|
| 225 |
+
if self.mode == "P": # Paletted for 1, 4 and 8 bit images
|
| 226 |
+
# ---------------------------------------------------- 1-bit images
|
| 227 |
+
if not (0 < file_info["colors"] <= 65536):
|
| 228 |
+
msg = f"Unsupported BMP Palette size ({file_info['colors']})"
|
| 229 |
+
raise OSError(msg)
|
| 230 |
+
else:
|
| 231 |
+
padding = file_info["palette_padding"]
|
| 232 |
+
palette = read(padding * file_info["colors"])
|
| 233 |
+
grayscale = True
|
| 234 |
+
indices = (
|
| 235 |
+
(0, 255)
|
| 236 |
+
if file_info["colors"] == 2
|
| 237 |
+
else list(range(file_info["colors"]))
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
# ----------------- Check if grayscale and ignore palette if so
|
| 241 |
+
for ind, val in enumerate(indices):
|
| 242 |
+
rgb = palette[ind * padding : ind * padding + 3]
|
| 243 |
+
if rgb != o8(val) * 3:
|
| 244 |
+
grayscale = False
|
| 245 |
+
|
| 246 |
+
# ------- If all colors are gray, white or black, ditch palette
|
| 247 |
+
if grayscale:
|
| 248 |
+
self._mode = "1" if file_info["colors"] == 2 else "L"
|
| 249 |
+
raw_mode = self.mode
|
| 250 |
+
else:
|
| 251 |
+
self._mode = "P"
|
| 252 |
+
self.palette = ImagePalette.raw(
|
| 253 |
+
"BGRX" if padding == 4 else "BGR", palette
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# ---------------------------- Finally set the tile data for the plugin
|
| 257 |
+
self.info["compression"] = file_info["compression"]
|
| 258 |
+
args = [raw_mode]
|
| 259 |
+
if decoder_name == "bmp_rle":
|
| 260 |
+
args.append(file_info["compression"] == self.RLE4)
|
| 261 |
+
else:
|
| 262 |
+
args.append(((file_info["width"] * file_info["bits"] + 31) >> 3) & (~3))
|
| 263 |
+
args.append(file_info["direction"])
|
| 264 |
+
self.tile = [
|
| 265 |
+
(
|
| 266 |
+
decoder_name,
|
| 267 |
+
(0, 0, file_info["width"], file_info["height"]),
|
| 268 |
+
offset or self.fp.tell(),
|
| 269 |
+
tuple(args),
|
| 270 |
+
)
|
| 271 |
+
]
|
| 272 |
+
|
| 273 |
+
def _open(self):
|
| 274 |
+
"""Open file, check magic number and read header"""
|
| 275 |
+
# read 14 bytes: magic number, filesize, reserved, header final offset
|
| 276 |
+
head_data = self.fp.read(14)
|
| 277 |
+
# choke if the file does not have the required magic bytes
|
| 278 |
+
if not _accept(head_data):
|
| 279 |
+
msg = "Not a BMP file"
|
| 280 |
+
raise SyntaxError(msg)
|
| 281 |
+
# read the start position of the BMP image data (u32)
|
| 282 |
+
offset = i32(head_data, 10)
|
| 283 |
+
# load bitmap information (offset=raster info)
|
| 284 |
+
self._bitmap(offset=offset)
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class BmpRleDecoder(ImageFile.PyDecoder):
|
| 288 |
+
_pulls_fd = True
|
| 289 |
+
|
| 290 |
+
def decode(self, buffer):
|
| 291 |
+
rle4 = self.args[1]
|
| 292 |
+
data = bytearray()
|
| 293 |
+
x = 0
|
| 294 |
+
dest_length = self.state.xsize * self.state.ysize
|
| 295 |
+
while len(data) < dest_length:
|
| 296 |
+
pixels = self.fd.read(1)
|
| 297 |
+
byte = self.fd.read(1)
|
| 298 |
+
if not pixels or not byte:
|
| 299 |
+
break
|
| 300 |
+
num_pixels = pixels[0]
|
| 301 |
+
if num_pixels:
|
| 302 |
+
# encoded mode
|
| 303 |
+
if x + num_pixels > self.state.xsize:
|
| 304 |
+
# Too much data for row
|
| 305 |
+
num_pixels = max(0, self.state.xsize - x)
|
| 306 |
+
if rle4:
|
| 307 |
+
first_pixel = o8(byte[0] >> 4)
|
| 308 |
+
second_pixel = o8(byte[0] & 0x0F)
|
| 309 |
+
for index in range(num_pixels):
|
| 310 |
+
if index % 2 == 0:
|
| 311 |
+
data += first_pixel
|
| 312 |
+
else:
|
| 313 |
+
data += second_pixel
|
| 314 |
+
else:
|
| 315 |
+
data += byte * num_pixels
|
| 316 |
+
x += num_pixels
|
| 317 |
+
else:
|
| 318 |
+
if byte[0] == 0:
|
| 319 |
+
# end of line
|
| 320 |
+
while len(data) % self.state.xsize != 0:
|
| 321 |
+
data += b"\x00"
|
| 322 |
+
x = 0
|
| 323 |
+
elif byte[0] == 1:
|
| 324 |
+
# end of bitmap
|
| 325 |
+
break
|
| 326 |
+
elif byte[0] == 2:
|
| 327 |
+
# delta
|
| 328 |
+
bytes_read = self.fd.read(2)
|
| 329 |
+
if len(bytes_read) < 2:
|
| 330 |
+
break
|
| 331 |
+
right, up = self.fd.read(2)
|
| 332 |
+
data += b"\x00" * (right + up * self.state.xsize)
|
| 333 |
+
x = len(data) % self.state.xsize
|
| 334 |
+
else:
|
| 335 |
+
# absolute mode
|
| 336 |
+
if rle4:
|
| 337 |
+
# 2 pixels per byte
|
| 338 |
+
byte_count = byte[0] // 2
|
| 339 |
+
bytes_read = self.fd.read(byte_count)
|
| 340 |
+
for byte_read in bytes_read:
|
| 341 |
+
data += o8(byte_read >> 4)
|
| 342 |
+
data += o8(byte_read & 0x0F)
|
| 343 |
+
else:
|
| 344 |
+
byte_count = byte[0]
|
| 345 |
+
bytes_read = self.fd.read(byte_count)
|
| 346 |
+
data += bytes_read
|
| 347 |
+
if len(bytes_read) < byte_count:
|
| 348 |
+
break
|
| 349 |
+
x += byte[0]
|
| 350 |
+
|
| 351 |
+
# align to 16-bit word boundary
|
| 352 |
+
if self.fd.tell() % 2 != 0:
|
| 353 |
+
self.fd.seek(1, os.SEEK_CUR)
|
| 354 |
+
rawmode = "L" if self.mode == "L" else "P"
|
| 355 |
+
self.set_as_raw(bytes(data), (rawmode, 0, self.args[-1]))
|
| 356 |
+
return -1, 0
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
# =============================================================================
|
| 360 |
+
# Image plugin for the DIB format (BMP alias)
|
| 361 |
+
# =============================================================================
|
| 362 |
+
class DibImageFile(BmpImageFile):
|
| 363 |
+
format = "DIB"
|
| 364 |
+
format_description = "Windows Bitmap"
|
| 365 |
+
|
| 366 |
+
def _open(self):
|
| 367 |
+
self._bitmap()
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
#
|
| 371 |
+
# --------------------------------------------------------------------
|
| 372 |
+
# Write BMP file
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
SAVE = {
|
| 376 |
+
"1": ("1", 1, 2),
|
| 377 |
+
"L": ("L", 8, 256),
|
| 378 |
+
"P": ("P", 8, 256),
|
| 379 |
+
"RGB": ("BGR", 24, 0),
|
| 380 |
+
"RGBA": ("BGRA", 32, 0),
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
def _dib_save(im, fp, filename):
|
| 385 |
+
_save(im, fp, filename, False)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def _save(im, fp, filename, bitmap_header=True):
|
| 389 |
+
try:
|
| 390 |
+
rawmode, bits, colors = SAVE[im.mode]
|
| 391 |
+
except KeyError as e:
|
| 392 |
+
msg = f"cannot write mode {im.mode} as BMP"
|
| 393 |
+
raise OSError(msg) from e
|
| 394 |
+
|
| 395 |
+
info = im.encoderinfo
|
| 396 |
+
|
| 397 |
+
dpi = info.get("dpi", (96, 96))
|
| 398 |
+
|
| 399 |
+
# 1 meter == 39.3701 inches
|
| 400 |
+
ppm = tuple(int(x * 39.3701 + 0.5) for x in dpi)
|
| 401 |
+
|
| 402 |
+
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
| 403 |
+
header = 40 # or 64 for OS/2 version 2
|
| 404 |
+
image = stride * im.size[1]
|
| 405 |
+
|
| 406 |
+
if im.mode == "1":
|
| 407 |
+
palette = b"".join(o8(i) * 4 for i in (0, 255))
|
| 408 |
+
elif im.mode == "L":
|
| 409 |
+
palette = b"".join(o8(i) * 4 for i in range(256))
|
| 410 |
+
elif im.mode == "P":
|
| 411 |
+
palette = im.im.getpalette("RGB", "BGRX")
|
| 412 |
+
colors = len(palette) // 4
|
| 413 |
+
else:
|
| 414 |
+
palette = None
|
| 415 |
+
|
| 416 |
+
# bitmap header
|
| 417 |
+
if bitmap_header:
|
| 418 |
+
offset = 14 + header + colors * 4
|
| 419 |
+
file_size = offset + image
|
| 420 |
+
if file_size > 2**32 - 1:
|
| 421 |
+
msg = "File size is too large for the BMP format"
|
| 422 |
+
raise ValueError(msg)
|
| 423 |
+
fp.write(
|
| 424 |
+
b"BM" # file type (magic)
|
| 425 |
+
+ o32(file_size) # file size
|
| 426 |
+
+ o32(0) # reserved
|
| 427 |
+
+ o32(offset) # image data offset
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
# bitmap info header
|
| 431 |
+
fp.write(
|
| 432 |
+
o32(header) # info header size
|
| 433 |
+
+ o32(im.size[0]) # width
|
| 434 |
+
+ o32(im.size[1]) # height
|
| 435 |
+
+ o16(1) # planes
|
| 436 |
+
+ o16(bits) # depth
|
| 437 |
+
+ o32(0) # compression (0=uncompressed)
|
| 438 |
+
+ o32(image) # size of bitmap
|
| 439 |
+
+ o32(ppm[0]) # resolution
|
| 440 |
+
+ o32(ppm[1]) # resolution
|
| 441 |
+
+ o32(colors) # colors used
|
| 442 |
+
+ o32(colors) # colors important
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
fp.write(b"\0" * (header - 40)) # padding (for OS/2 format)
|
| 446 |
+
|
| 447 |
+
if palette:
|
| 448 |
+
fp.write(palette)
|
| 449 |
+
|
| 450 |
+
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, stride, -1))])
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
#
|
| 454 |
+
# --------------------------------------------------------------------
|
| 455 |
+
# Registry
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
|
| 459 |
+
Image.register_save(BmpImageFile.format, _save)
|
| 460 |
+
|
| 461 |
+
Image.register_extension(BmpImageFile.format, ".bmp")
|
| 462 |
+
|
| 463 |
+
Image.register_mime(BmpImageFile.format, "image/bmp")
|
| 464 |
+
|
| 465 |
+
Image.register_decoder("bmp_rle", BmpRleDecoder)
|
| 466 |
+
|
| 467 |
+
Image.register_open(DibImageFile.format, DibImageFile, _dib_accept)
|
| 468 |
+
Image.register_save(DibImageFile.format, _dib_save)
|
| 469 |
+
|
| 470 |
+
Image.register_extension(DibImageFile.format, ".dib")
|
| 471 |
+
|
| 472 |
+
Image.register_mime(DibImageFile.format, "image/bmp")
|
venv/lib/python3.12/site-packages/PIL/BufrStubImagePlugin.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# The Python Imaging Library
|
| 3 |
+
# $Id$
|
| 4 |
+
#
|
| 5 |
+
# BUFR stub adapter
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 1996-2003 by Fredrik Lundh
|
| 8 |
+
#
|
| 9 |
+
# See the README file for information on usage and redistribution.
|
| 10 |
+
#
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
from . import Image, ImageFile
|
| 14 |
+
|
| 15 |
+
_handler = None
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def register_handler(handler):
|
| 19 |
+
"""
|
| 20 |
+
Install application-specific BUFR image handler.
|
| 21 |
+
|
| 22 |
+
:param handler: Handler object.
|
| 23 |
+
"""
|
| 24 |
+
global _handler
|
| 25 |
+
_handler = handler
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# --------------------------------------------------------------------
|
| 29 |
+
# Image adapter
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _accept(prefix):
|
| 33 |
+
return prefix[:4] == b"BUFR" or prefix[:4] == b"ZCZC"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class BufrStubImageFile(ImageFile.StubImageFile):
|
| 37 |
+
format = "BUFR"
|
| 38 |
+
format_description = "BUFR"
|
| 39 |
+
|
| 40 |
+
def _open(self):
|
| 41 |
+
offset = self.fp.tell()
|
| 42 |
+
|
| 43 |
+
if not _accept(self.fp.read(4)):
|
| 44 |
+
msg = "Not a BUFR file"
|
| 45 |
+
raise SyntaxError(msg)
|
| 46 |
+
|
| 47 |
+
self.fp.seek(offset)
|
| 48 |
+
|
| 49 |
+
# make something up
|
| 50 |
+
self._mode = "F"
|
| 51 |
+
self._size = 1, 1
|
| 52 |
+
|
| 53 |
+
loader = self._load()
|
| 54 |
+
if loader:
|
| 55 |
+
loader.open(self)
|
| 56 |
+
|
| 57 |
+
def _load(self):
|
| 58 |
+
return _handler
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _save(im, fp, filename):
|
| 62 |
+
if _handler is None or not hasattr(_handler, "save"):
|
| 63 |
+
msg = "BUFR save handler not installed"
|
| 64 |
+
raise OSError(msg)
|
| 65 |
+
_handler.save(im, fp, filename)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# --------------------------------------------------------------------
|
| 69 |
+
# Registry
|
| 70 |
+
|
| 71 |
+
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
|
| 72 |
+
Image.register_save(BufrStubImageFile.format, _save)
|
| 73 |
+
|
| 74 |
+
Image.register_extension(BufrStubImageFile.format, ".bufr")
|