user_agent: Use re.X to make the regex a little more readable.

This commit is contained in:
Greg Price
2018-12-04 13:00:40 -08:00
committed by Tim Abbott
parent cfeb87c1c9
commit 60de598cb5

View File

@@ -5,6 +5,10 @@ from typing import Dict
# zerver/tests/test_decorators.py
# And extend zerver/tests/fixtures/user_agents_unique with any new test cases
def parse_user_agent(user_agent: str) -> Dict[str, str]:
match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent)
match = re.match(
"""^ (?P<name> [^/ ]* [^0-9/(]* )
(/ (?P<version> [^/ ]* ))?
([ /] .*)?
$""", user_agent, re.X)
assert match is not None
return match.groupdict()