Files
felhom.eu/documentation/audits/rehearsal-2026-10-20/tools/nc_nfd.py
T

20 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/python3
"""nc_nfd.py put|list — put the NFD-named twin of „Ödön születésnapja – fénykép lista.txt" into Nextcloud by WebDAV
(as a Mac client would send it), then list the folder by PROPFIND and show each name's form (NFC/NFD) and bytes."""
import base64, os, sys, unicodedata, urllib.parse
sys.path.insert(0, "/root/work"); from apps import http
U = "odon"; H = {"Authorization": "Basic " + base64.b64encode(f"{U}:{os.environ['PW']}".encode()).decode()}
d = "/root/data/nextcloud/Csalad/Kulonleges_nevek"
B = f"https://cloud.tester4.test/remote.php/dav/files/{U}/Csalad/Kulonleges_nevek/"
nfd = unicodedata.normalize("NFD", "Ödön születésnapja – fénykép lista.txt")
if sys.argv[1] == "put":
body = open(os.path.join(d, nfd), "rb").read()
print("PUT NFD", http("PUT", B + urllib.parse.quote(nfd), body, H)[0])
st, out, _ = http("PROPFIND", B, None, dict(H, Depth="1"))
import re
for href in re.findall(rb"<d:href>([^<]+)</d:href>", out):
name = urllib.parse.unquote(href.decode().rstrip("/").split("/")[-1])
if "rk" in name or "dön" in unicodedata.normalize("NFC", name):
form = "NFC" if name == unicodedata.normalize("NFC", name) else "NFD" if name == unicodedata.normalize("NFD", name) else "mixed"
print(f" {form} {len(name.encode())} bytes: {name}")