From be7048844bfa7db7580eb7cd9cd64a6ef24b725f Mon Sep 17 00:00:00 2001 From: Vangelis Banos Date: Thu, 2 May 2019 07:11:24 +0000 Subject: [PATCH] Compile RecordedUrl regex to improve performance Minor optimisation. --- warcprox/warcproxy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/warcprox/warcproxy.py b/warcprox/warcproxy.py index 4a5312e..8898898 100644 --- a/warcprox/warcproxy.py +++ b/warcprox/warcproxy.py @@ -350,6 +350,7 @@ class WarcProxyHandler(warcprox.mitmproxy.MitmProxyHandler): # logging better handled elsewhere? pass +RE_MIMETYPE = re.compile(r'[;\s]') class RecordedUrl: logger = logging.getLogger("warcprox.warcproxy.RecordedUrl") @@ -389,7 +390,7 @@ class RecordedUrl: self.mimetype = content_type if self.mimetype: # chop off subtype, and ensure there's no whitespace - self.mimetype = re.split(r'[;\s]', self.mimetype, 2)[0] + self.mimetype = RE_MIMETYPE.split(self.mimetype, 2)[0] self.custom_type = custom_type self.status = status