annotate sat/plugins/plugin_comp_ap_gateway/regex.py @ 3770:f31113777881

tests (unit/ap-gateway): tests for following/followers <=> PPS: AP following/followers collections to XMPP Public Pubsub Subscriptions conversion is checked in both directions. rel 365
author Goffi <goffi@goffi.org>
date Fri, 13 May 2022 19:29:17 +0200
parents eddab3798aca
children 381340b9a9ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3741
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia ActivityPub Gateway
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org)
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 """Regular Expression to parse "Signature" header"""
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 # those expression have been generated with abnf-to-regex
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 # (https://github.com/aas-core-works/abnf-to-regexp)
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # the base RFC 7320 ABNF rules come from https://github.com/EricGT/ABNF
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 # here is the ABNF file used:
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 # ---
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 # BWS = OWS
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 # OWS = *( SP / HTAB )
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 # tchar = "!" / "#" / "$" / "%" / "&" / "`" / "*" / "+" / "-" / "." / "^" / "_" / "\'" / "|" / "~" / DIGIT / ALPHA
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 # token = 1*tchar
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 # sig-param = token BWS "=" BWS ( token / quoted-string )
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 # quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 # qdtext = HTAB / SP / "!" / %x23-5B ; '#'-'['
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 # / %x5D-7E ; ']'-'~'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 # / obs-text
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 # quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 # obs-text = %x80-FF
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 # ---
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 import re
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 ows = '[ \t]*'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 bws = f'{ows}'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 obs_text = '[\\x80-\\xff]'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 qdtext = f'([\t !#-\\[\\]-~]|{obs_text})'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 quoted_pair = f'\\\\([\t !-~]|{obs_text})'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 quoted_string = f'"({qdtext}|{quoted_pair})*"'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 tchar = "([!#$%&`*+\\-.^_]|\\\\'|[|~0-9a-zA-Z])"
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 token = f'({tchar})+'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 RE_SIG_PARAM = re.compile(
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 f'(?P<key>{token}{bws})={bws}'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 f'((?P<uq_value>{token})|(?P<quoted_value>{quoted_string}))'
eddab3798aca comp AP gateway: regular expression to parse `Signature` header:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 )