summaryrefslogtreecommitdiff
path: root/src/wadllib
diff options
context:
space:
mode:
Diffstat (limited to 'src/wadllib')
-rw-r--r--src/wadllib/__init__.py9
-rw-r--r--src/wadllib/application.py5
-rw-r--r--src/wadllib/docs/Makefile20
-rw-r--r--src/wadllib/docs/NEWS.rst (renamed from src/wadllib/NEWS.txt)14
-rw-r--r--src/wadllib/docs/index.rst (renamed from src/wadllib/README.txt)34
-rw-r--r--src/wadllib/tests/test_docs.py6
-rw-r--r--src/wadllib/version.txt1
7 files changed, 70 insertions, 19 deletions
diff --git a/src/wadllib/__init__.py b/src/wadllib/__init__.py
index b50e2b6..3a9845c 100644
--- a/src/wadllib/__init__.py
+++ b/src/wadllib/__init__.py
@@ -17,9 +17,12 @@
import sys
-import pkg_resources
-__version__ = pkg_resources.resource_string(
- "wadllib", "version.txt").strip()
+try:
+ import importlib.metadata as importlib_metadata
+except ImportError:
+ import importlib_metadata
+
+__version__ = importlib_metadata.version("wadllib")
if sys.version_info[0] >= 3:
_string_types = str
diff --git a/src/wadllib/application.py b/src/wadllib/application.py
index 107d9e4..06a4398 100644
--- a/src/wadllib/application.py
+++ b/src/wadllib/application.py
@@ -880,8 +880,9 @@ class RepresentationDefinition(WADLResolvableDefinition, HasParametersMixin):
raise TypeError('bytes payload expected: %s' % type(value))
buf.write(value)
else:
- if not isinstance(value, str):
- raise TypeError('str payload expected: %s' % type(value))
+ if not isinstance(value, _string_types):
+ raise TypeError(
+ 'string payload expected: %s' % type(value))
lines = re.split(r'\r\n|\r|\n', value)
for line in lines[:-1]:
buf.write(line.encode('UTF-8'))
diff --git a/src/wadllib/docs/Makefile b/src/wadllib/docs/Makefile
new file mode 100644
index 0000000..8cbdfa0
--- /dev/null
+++ b/src/wadllib/docs/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+SPHINXPROJ = wadllib
+SOURCEDIR = .
+BUILDDIR = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/src/wadllib/NEWS.txt b/src/wadllib/docs/NEWS.rst
index 55aae4c..f619422 100644
--- a/src/wadllib/NEWS.txt
+++ b/src/wadllib/docs/NEWS.rst
@@ -2,6 +2,20 @@
NEWS for wadllib
================
+1.3.6 (2021-09-13)
+==================
+
+- Remove buildout support in favour of tox. [bug=922605]
+- Adjust versioning strategy to avoid importing pkg_resources, which is slow
+ in large environments.
+
+1.3.5 (2021-01-20)
+==================
+
+- Drop support for Python 3.2, 3.3, and 3.4.
+- Accept Unicode parameter values again when performing multipart/form-data
+ encoding on Python 2 (broken in 1.3.3).
+
1.3.4 (2020-04-29)
==================
diff --git a/src/wadllib/README.txt b/src/wadllib/docs/index.rst
index f4d7fd7..c86faca 100644
--- a/src/wadllib/README.txt
+++ b/src/wadllib/docs/index.rst
@@ -572,13 +572,6 @@ zope.publisher would.
>>> import cgi
>>> import io
>>> def assert_message_parts(media_type, doc, expected):
- ... if sys.version_info[0] == 3 and sys.version_info[1] < 3:
- ... # We can't do much due to https://bugs.python.org/issue18013.
- ... for value in expected:
- ... if not isinstance(value, bytes):
- ... value = value.encode('UTF-8')
- ... assert value in doc
- ... return
... environ = {
... 'REQUEST_METHOD': 'POST',
... 'CONTENT_TYPE': media_type,
@@ -609,6 +602,13 @@ zope.publisher would.
>>> method = service_root.get_method('post', 'multipart/form-data')
>>> media_type, doc = method.build_representation(
+ ... text_field=u"text", binary_field=b"\x01\x02\r\x81\r")
+ >>> print(media_type)
+ multipart/form-data; boundary=...
+ >>> assert_message_parts(media_type, doc, ['text', b'\x01\x02\r\x81\r'])
+
+ >>> method = service_root.get_method('post', 'multipart/form-data')
+ >>> media_type, doc = method.build_representation(
... text_field="text\n", binary_field=b"\x01\x02\r\x81\n\r")
>>> print(media_type)
multipart/form-data; boundary=...
@@ -617,6 +617,14 @@ zope.publisher would.
>>> method = service_root.get_method('post', 'multipart/form-data')
>>> media_type, doc = method.build_representation(
+ ... text_field=u"text\n", binary_field=b"\x01\x02\r\x81\n\r")
+ >>> print(media_type)
+ multipart/form-data; boundary=...
+ >>> assert_message_parts(
+ ... media_type, doc, ['text\r\n', b'\x01\x02\r\x81\n\r'])
+
+ >>> method = service_root.get_method('post', 'multipart/form-data')
+ >>> media_type, doc = method.build_representation(
... text_field="text\r\nmore\r\n",
... binary_field=b"\x01\x02\r\n\x81\r\x82\n")
>>> print(media_type)
@@ -624,6 +632,15 @@ zope.publisher would.
>>> assert_message_parts(
... media_type, doc, ['text\r\nmore\r\n', b'\x01\x02\r\n\x81\r\x82\n'])
+ >>> method = service_root.get_method('post', 'multipart/form-data')
+ >>> media_type, doc = method.build_representation(
+ ... text_field=u"text\r\nmore\r\n",
+ ... binary_field=b"\x01\x02\r\n\x81\r\x82\n")
+ >>> print(media_type)
+ multipart/form-data; boundary=...
+ >>> assert_message_parts(
+ ... media_type, doc, ['text\r\nmore\r\n', b'\x01\x02\r\n\x81\r\x82\n'])
+
>>> method = service_root.get_method('post', 'text/unknown')
>>> method.build_representation(field="value")
Traceback (most recent call last):
@@ -691,5 +708,4 @@ match any defined method.
.. toctree::
:glob:
- *
- docs/*
+ NEWS
diff --git a/src/wadllib/tests/test_docs.py b/src/wadllib/tests/test_docs.py
index 9cc7b89..b4f3a50 100644
--- a/src/wadllib/tests/test_docs.py
+++ b/src/wadllib/tests/test_docs.py
@@ -38,12 +38,10 @@ DOCTEST_FLAGS = (
def load_tests(loader, tests, pattern):
- doctest_files = [
- os.path.abspath(
- pkg_resources.resource_filename('wadllib', 'README.txt'))]
+ doctest_files = []
if pkg_resources.resource_exists('wadllib', 'docs'):
for name in pkg_resources.resource_listdir('wadllib', 'docs'):
- if name.endswith('.txt'):
+ if name.endswith('.rst'):
doctest_files.append(
os.path.abspath(
pkg_resources.resource_filename(
diff --git a/src/wadllib/version.txt b/src/wadllib/version.txt
deleted file mode 100644
index d0149fe..0000000
--- a/src/wadllib/version.txt
+++ /dev/null
@@ -1 +0,0 @@
-1.3.4