Use precompiled regexes
This commit is contained in:
parent
b52ef29ac3
commit
f13ecc5aca
2 changed files with 4 additions and 5 deletions
|
@ -1,5 +1,3 @@
|
|||
import re
|
||||
|
||||
from nntp.tiny.message import Message
|
||||
|
||||
class MBoxReaderError(Exception):
|
||||
|
@ -42,7 +40,7 @@ class MBoxReaderBuffer():
|
|||
return self.lines[line][0:5] == 'From '
|
||||
|
||||
def is_header_line(self, line):
|
||||
return re.match(Message.HEADER_REGEX, self.lines[line]) is not None
|
||||
return Message.RE_HEADER.match(self.lines[line]) is not None
|
||||
|
||||
def is_start(self):
|
||||
if self.lines[0] is None or self.lines[1] is None:
|
||||
|
|
|
@ -24,7 +24,8 @@ class MessageState(enum.Enum):
|
|||
class Message():
|
||||
__slots__ = 'state', 'headers', 'line', 'content', 'body', 'key',
|
||||
|
||||
HEADER_REGEX = '^([A-Za-z0-9\\-]+): (.*)$'
|
||||
RE_HEADER = re.compile(r'^([A-Za-z0-9\-]+): (.*)$')
|
||||
RE_MESSAGE_ID = re.compile(r'^<([^<>]+)>$')
|
||||
|
||||
def __init__(self):
|
||||
self.state = MessageState.EMPTY
|
||||
|
@ -47,7 +48,7 @@ class Message():
|
|||
elif line[0] == ' ' or line[0] == '\t':
|
||||
self.headers[self.key] += ' ' + decode(line.strip())
|
||||
else:
|
||||
match = re.match(self.HEADER_REGEX, line)
|
||||
match = self.RE_HEADER.match(line)
|
||||
|
||||
if match:
|
||||
self.key = match[1].lower()
|
||||
|
|
Loading…
Add table
Reference in a new issue