How to use canonicalize_headers method in localstack

Best Python code snippet using localstack_python

canonicalization.py

Source:canonicalization.py Github

copy

Full Screen

...37class Simple:38 """Class that represents the "simple" canonicalization algorithm."""39 name = b"simple"40 @staticmethod41 def canonicalize_headers(headers):42 # No changes to headers.43 return headers44 @staticmethod45 def canonicalize_body(body):46 # Ignore all empty lines at the end of the message body.47 return strip_trailing_lines(body)48class Relaxed:49 """Class that represents the "relaxed" canonicalization algorithm."""50 name = b"relaxed"51 @staticmethod52 def canonicalize_headers(headers):53 # Convert all header field names to lowercase.54 # Unfold all header lines.55 # Compress WSP to single space.56 # Remove all WSP at the start or end of the field value (strip).57 return [58 (x[0].lower().rstrip(),59 compress_whitespace(unfold_header_value(x[1])).strip() + b"\r\n")60 for x in headers]61 @staticmethod62 def canonicalize_body(body):63 # Remove all trailing WSP at end of lines.64 # Compress non-line-ending WSP to single space.65 # Ignore all empty lines at the end of the message body.66 return strip_trailing_lines(67 compress_whitespace(strip_trailing_whitespace(body)))68class CanonicalizationPolicy:69 def __init__(self, header_algorithm, body_algorithm):70 self.header_algorithm = header_algorithm71 self.body_algorithm = body_algorithm72 @classmethod73 def from_c_value(cls, c):74 """Construct the canonicalization policy described by a c= value.75 May raise an C{InvalidCanonicalizationPolicyError} if the given76 value is invalid77 @param c: c= value from a DKIM-Signature header field78 @return: a C{CanonicalizationPolicy}79 """80 if c is None:81 c = b'simple/simple'82 m = c.split(b'/')83 if len(m) not in (1, 2):84 raise InvalidCanonicalizationPolicyError(c)85 if len(m) == 1:86 m.append(b'simple')87 can_headers, can_body = m88 try:89 header_algorithm = ALGORITHMS[can_headers]90 body_algorithm = ALGORITHMS[can_body]91 except KeyError as e:92 raise InvalidCanonicalizationPolicyError(e.args[0])93 return cls(header_algorithm, body_algorithm)94 def to_c_value(self):95 return b'/'.join(96 (self.header_algorithm.name, self.body_algorithm.name))97 def canonicalize_headers(self, headers):98 return self.header_algorithm.canonicalize_headers(headers)99 def canonicalize_body(self, body):100 return self.body_algorithm.canonicalize_body(body)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful