Files
zulip/zerver/lib/user_agent.py
Anders Kaseorg 96fbe060a6 python: Mark regexes as raw strings.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-04-26 12:30:31 -07:00

20 lines
490 B
Python

import re
from typing import Dict
# Warning: If you change this parsing, please test using
# zerver/tests/test_decorators.py
# And extend zerver/tests/fixtures/user_agents_unique with any new test cases
pattern = re.compile(
r"""^ (?P<name> [^/ ]* [^0-9/(]* )
(/ (?P<version> [^/ ]* ))?
([ /] .*)?
$""",
re.X,
)
def parse_user_agent(user_agent: str) -> Dict[str, str]:
match = pattern.match(user_agent)
assert match is not None
return match.groupdict()