summaryrefslogtreecommitdiff
path: root/src/webob/acceptparse.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/webob/acceptparse.py')
-rw-r--r--src/webob/acceptparse.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/webob/acceptparse.py b/src/webob/acceptparse.py
index d2b6007..02c0cb6 100644
--- a/src/webob/acceptparse.py
+++ b/src/webob/acceptparse.py
@@ -1485,6 +1485,28 @@ class AcceptInvalidHeader(_AcceptInvalidOrNoHeader):
return AcceptNoHeader()
+def create_accept_header(header_value):
+ """
+ Create an object representing the ``Accept`` header in a request.
+
+ :param header_value: (``str``) header value
+ :return: If `header_value` is ``None``, an :class:`AcceptNoHeader`
+ instance.
+
+ | If `header_value` is a valid ``Accept`` header, an
+ :class:`AcceptValidHeader` instance.
+
+ | If `header_value` is an invalid ``Accept`` header, an
+ :class:`AcceptInvalidHeader` instance.
+ """
+ if header_value is None:
+ return AcceptNoHeader()
+ try:
+ return AcceptValidHeader(header_value=header_value)
+ except ValueError:
+ return AcceptInvalidHeader(header_value=header_value)
+
+
class NilAccept(object):
"""
Represents a generic ``Accept-*`` style header when it is not present in