2013-12-06 23:59:06 +01:00
|
|
|
import re
|
2016-06-03 23:32:55 +02:00
|
|
|
from typing import Optional, Dict
|
2013-12-06 23:59:06 +01:00
|
|
|
|
|
|
|
# Warning: If you change this parsing, please test using
|
2017-09-16 08:24:17 +02:00
|
|
|
# zerver/tests/test_decorators.py
|
|
|
|
# And extend zerver/fixtures/user_agents_unique with any new test cases
|
2013-12-06 23:59:06 +01:00
|
|
|
def parse_user_agent(user_agent):
|
2016-06-03 23:32:55 +02:00
|
|
|
# type: (str) -> Optional[Dict[str, str]]
|
2013-12-06 23:59:06 +01:00
|
|
|
match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent)
|
|
|
|
if match is None:
|
|
|
|
return None
|
|
|
|
return match.groupdict()
|