Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom namespaces definitions #329

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import importlib.metadata
import os
import sys

package_root = os.path.abspath("../..")
Expand Down
13 changes: 6 additions & 7 deletions setup_bdist_msi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# NOTE: isort must not change this import order:
# isort: skip_file

import os
import re
import sys

Expand All @@ -15,8 +14,8 @@
# Check for Windows MSI Setup
if "bdist_msi" not in sys.argv: # or len(sys.argv) != 2:
raise RuntimeError(
"This setup.py variant is only for creating 'bdist_msi' targets: {}\n"
"Example `{} bdist_msi`".format(sys.argv, sys.argv[0])
f"This setup.py variant is only for creating 'bdist_msi' targets: {sys.argv}\n"
f"Example `{sys.argv[0]} bdist_msi`"
)

org_version = __version__
Expand Down Expand Up @@ -54,12 +53,12 @@
patch = int(patch)
alpha = 0

version = "{}.{}.{}.{}".format(major, minor, patch, alpha)
print("Version {}, using {}".format(org_version, version))
version = f"{major}.{minor}.{patch}.{alpha}"
print(f"Version {org_version}, using {version}")

try:
readme = open("README.md", "rt").read()
except IOError:
readme = open("README.md").read()
except OSError:
readme = "(readme not found. Running from tox/setup.py test?)"

# These dependencies are for plain WsgiDAV:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import unittest
from io import StringIO

from wsgidav import xml_tools
from wsgidav.util import (
BASE_LOGGER_NAME,
add_property_response,
check_tags,
checked_etag,
deep_update,
Expand All @@ -25,8 +27,10 @@
pop_path,
removeprefix,
shift_path,
to_str,
update_headers_in_place,
)
from wsgidav.xml_tools import etree


class BasicTest(unittest.TestCase):
Expand Down Expand Up @@ -191,6 +195,19 @@ def testBasics(self):
assert get_dict_value(d, "x", as_dict=True) == {}
self.assertRaises(KeyError, get_dict_value, d, "x", as_dict=False)

multistatus_el = xml_tools.make_multistatus_el()
add_property_response(
multistatus_el,
"",
[("{custom}name", etree.Element("{custom}name", nsmap={"C": "custom"}))],
)
assert to_str(xml_tools.xml_to_bytes(multistatus_el, pretty=False)) == (
"<?xml version='1.0' encoding='UTF-8'?>\n"
'<D:multistatus xmlns:D="DAV:"><D:response>'
'<D:href></D:href><D:propstat><D:prop><C:name xmlns:C="custom"/></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat>'
"</D:response></D:multistatus>"
)


class LoggerTest(unittest.TestCase):
"""Test configurable logging."""
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ basepython = python3.12
envlist =
check
# mypy
py313 # EOL 2028-10-31
py313 # EOL 2029-10
py312 # EOL 2028-10-31
lxml
py311 # EOL 2027-10-24
py310 # EOL 2026-10-04
py39 # EOL 2025-10-05
py38 # EOL 2024-10-14
# Deprecated:
py38 # EOL 2024-10-14
# py37 # EOL 2023-06-27
# py36 # EOL 2021-12-21
# py35 # EOL 2020-09-13
Expand Down
11 changes: 6 additions & 5 deletions wsgidav/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ def add_property_response(multistatus_elem, href, prop_list):
"""
# Split prop_list by status code and build a unique list of namespaces
nsCount = 1
nsDict = {}
nsSet = set()
nsMap = {}
propDict = {}

Expand All @@ -1321,10 +1321,11 @@ def add_property_response(multistatus_elem, href, prop_list):
# Collect namespaces, so we can declare them in the <response> for
# compacter output
ns, _ = split_namespace(name)
if ns != "DAV:" and ns not in nsDict and ns != "":
nsDict[ns] = True
nsMap[f"NS{nsCount}"] = ns
nsCount += 1
if ns != "DAV:" and ns not in nsSet and ns != "":
if not is_etree_element(value) or ns not in value.nsmap.values():
nsMap[f"NS{nsCount}"] = ns
nsCount += 1
nsSet.add(ns)

propDict.setdefault(status, []).append((name, value))

Expand Down
Loading