2013-12-06 23:59:06 +01:00
|
|
|
import re
|
|
|
|
|
|
|
|
# Warning: If you change this parsing, please test using
|
2017-09-16 08:24:17 +02:00
|
|
|
# zerver/tests/test_decorators.py
|
2018-04-19 20:17:24 +02:00
|
|
|
# And extend zerver/tests/fixtures/user_agents_unique with any new test cases
|
2020-02-14 19:20:54 +01:00
|
|
|
pattern = re.compile(
|
2024-04-26 20:30:22 +02:00
|
|
|
r"""^ (?P<name> [^/ ]* [^0-9/(]* )
|
2020-02-14 19:20:54 +01:00
|
|
|
(/ (?P<version> [^/ ]* ))?
|
|
|
|
([ /] .*)?
|
2021-02-12 08:19:30 +01:00
|
|
|
$""",
|
2024-06-30 20:29:07 +02:00
|
|
|
re.VERBOSE,
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
|
|
|
|
2020-02-14 19:20:54 +01:00
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
def parse_user_agent(user_agent: str) -> dict[str, str]:
|
2020-02-14 19:20:54 +01:00
|
|
|
match = pattern.match(user_agent)
|
2018-03-22 20:02:15 +01:00
|
|
|
assert match is not None
|
2013-12-06 23:59:06 +01:00
|
|
|
return match.groupdict()
|