Add CanonicalizationPolicy, which encapsulates the combined hybrid simple/relaxed schemes.

This commit is contained in:
William Grant
2011-06-04 14:05:54 +10:00
parent 19b554212e
commit 7b1a3f70dc
2 changed files with 21 additions and 3 deletions
+14
View File
@@ -23,6 +23,7 @@ import re
__all__ = [
'algorithms',
'CanonicalizationPolicy',
]
@@ -83,4 +84,17 @@ class Relaxed:
compress_whitespace(strip_trailing_whitespace(body)))
class CanonicalizationPolicy:
def __init__(self, header_algorithm, body_algorithm):
self.header_algorithm = header_algorithm
self.body_algorithm = body_algorithm
def canonicalize_headers(self, headers):
return self.header_algorithm.canonicalize_headers(headers)
def canonicalize_body(self, body):
return self.body_algorithm.canonicalize_body(body)
algorithms = dict((c.name, c) for c in (Simple, Relaxed))