mirror of
https://github.com/zulip/zulip.git
synced 2026-06-21 21:32:29 +08:00
user_agent: Compile the regular expression.
We use this single regular expression for processing essentially every request, so it's definitely worth hinting to Python that we're going to do so by compiling it. Saves about 40us per request.
This commit is contained in:
parent
800312c976
commit
10e7e15088
@ -4,11 +4,13 @@ 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(
|
||||
"""^ (?P<name> [^/ ]* [^0-9/(]* )
|
||||
(/ (?P<version> [^/ ]* ))?
|
||||
([ /] .*)?
|
||||
$""", re.X)
|
||||
|
||||
def parse_user_agent(user_agent: str) -> Dict[str, str]:
|
||||
match = re.match(
|
||||
"""^ (?P<name> [^/ ]* [^0-9/(]* )
|
||||
(/ (?P<version> [^/ ]* ))?
|
||||
([ /] .*)?
|
||||
$""", user_agent, re.X)
|
||||
match = pattern.match(user_agent)
|
||||
assert match is not None
|
||||
return match.groupdict()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user