diff options
author | Louis Vézina <[email protected]> | 2020-04-15 00:02:44 -0400 |
---|---|---|
committer | Louis Vézina <[email protected]> | 2020-04-15 00:02:44 -0400 |
commit | 1b0e721a9d4b88bfbfea823798de92713d50826b (patch) | |
tree | 9139c5ca46fe1391f540a0190170edf08d30a588 /libs/waitress/rfc7230.py | |
parent | 02551f2486531cfdb83576ced380b72507fb2da0 (diff) | |
download | bazarr-1b0e721a9d4b88bfbfea823798de92713d50826b.tar.gz bazarr-1b0e721a9d4b88bfbfea823798de92713d50826b.zip |
WIP
Diffstat (limited to 'libs/waitress/rfc7230.py')
-rw-r--r-- | libs/waitress/rfc7230.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libs/waitress/rfc7230.py b/libs/waitress/rfc7230.py new file mode 100644 index 000000000..cd33c9064 --- /dev/null +++ b/libs/waitress/rfc7230.py @@ -0,0 +1,52 @@ +""" +This contains a bunch of RFC7230 definitions and regular expressions that are +needed to properly parse HTTP messages. +""" + +import re + +from .compat import tobytes + +WS = "[ \t]" +OWS = WS + "{0,}?" +RWS = WS + "{1,}?" +BWS = OWS + +# RFC 7230 Section 3.2.6 "Field Value Components": +# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" +# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" +# / DIGIT / ALPHA +# obs-text = %x80-FF +TCHAR = r"[!#$%&'*+\-.^_`|~0-9A-Za-z]" +OBS_TEXT = r"\x80-\xff" + +TOKEN = TCHAR + "{1,}" + +# RFC 5234 Appendix B.1 "Core Rules": +# VCHAR = %x21-7E +# ; visible (printing) characters +VCHAR = r"\x21-\x7e" + +# header-field = field-name ":" OWS field-value OWS +# field-name = token +# field-value = *( field-content / obs-fold ) +# field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] +# field-vchar = VCHAR / obs-text + +# Errata from: https://www.rfc-editor.org/errata_search.php?rfc=7230&eid=4189 +# changes field-content to: +# +# field-content = field-vchar [ 1*( SP / HTAB / field-vchar ) +# field-vchar ] + +FIELD_VCHAR = "[" + VCHAR + OBS_TEXT + "]" +# Field content is more greedy than the ABNF, in that it will match the whole value +FIELD_CONTENT = FIELD_VCHAR + "+(?:[ \t]+" + FIELD_VCHAR + "+)*" +# Which allows the field value here to just see if there is even a value in the first place +FIELD_VALUE = "(?:" + FIELD_CONTENT + ")?" + +HEADER_FIELD = re.compile( + tobytes( + "^(?P<name>" + TOKEN + "):" + OWS + "(?P<value>" + FIELD_VALUE + ")" + OWS + "$" + ) +) |