From f82f0d7f0df9108f24942745b07926f81ef9f7bb Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 10 Jul 2014 14:31:05 -0700 Subject: [PATCH] flake8 and regexp cleanups --- flanker/dkim.py | 16 +++++++--------- tests/dkim_test.py | 3 +-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/flanker/dkim.py b/flanker/dkim.py index efdb78e..8702d5b 100644 --- a/flanker/dkim.py +++ b/flanker/dkim.py @@ -1,5 +1,4 @@ import base64 -import io import re import time @@ -7,8 +6,6 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import padding -from flanker.mime.message.headers import parsing - _BODY_LINES_RE = re.compile(r"\r?\n") @@ -24,8 +21,8 @@ class SimpleCanonicalization(object): class NoFWSCanonicalization(object): - _header_fws_re = re.compile(r"[\x09\x20\x0D\x0A]+") - _body_wsp_re = re.compile(r"[\x09\x20]+") + _header_fws_re = re.compile(r"[\t \r\n]+") + _body_wsp_re = re.compile(r"[\t ]+") _body_orphan_cr_re = re.compile(b"\r([^\n])") def canonicalize_header(self, header, value): @@ -70,7 +67,7 @@ class DomainKeySigner(object): canonicalization = NoFWSCanonicalization() signer = self._key.signer(padding.PKCS1v15(), hashes.SHA1()) - headers, body = rfc822_parse(message) + headers, body = _rfc822_parse(message) h_field = [] for header, value in headers: @@ -115,7 +112,7 @@ class DKIMSigner(object): signer = self._key.signer(padding.PKCS1v15(), hashes.SHA256()) - headers, body = rfc822_parse(message) + headers, body = _rfc822_parse(message) h_field = [] for header, value in headers: if self._signed_headers is None or header in self._signed_headers: @@ -155,10 +152,11 @@ class DKIMSigner(object): ) _RFC822_NEWLINE_RE = re.compile(r"\r?\n") -_RFC822_WS_RE = re.compile(r"[\x09\x20]") +_RFC822_WS_RE = re.compile(r"[\t ]") _RFC822_HEADER_RE = re.compile(r"([\x21-\x7e]+?):") -def rfc822_parse(message): + +def _rfc822_parse(message): headers = [] lines = _RFC822_NEWLINE_RE.split(message) i = 0 diff --git a/tests/dkim_test.py b/tests/dkim_test.py index 57b943f..9185d35 100644 --- a/tests/dkim_test.py +++ b/tests/dkim_test.py @@ -8,7 +8,6 @@ from cryptography.hazmat.primitives import serialization from nose.tools import assert_equal from flanker import dkim -from flanker.mime.message.headers import parsing DUMMY_EMAIL = b""" @@ -96,7 +95,7 @@ def test_canonicalization(): def canonicalize_contents(canonicalization_rule, contents): - headers, body = dkim.rfc822_parse(contents) + headers, body = dkim._rfc822_parse(contents) output = io.BytesIO() for header, value in headers: header, value = canonicalization_rule.canonicalize_header( -- 2.43.0