def encode(self, data, content_encoding="<STR_LIT>"):
<EOL>if not data:<EOL><INDENT>return<EOL><DEDENT>if not self.auth_key or not self.receiver_key:<EOL><INDENT>raise WebPushException("<STR_LIT>")<EOL><DEDENT>salt = None<EOL>if content_encoding not in self.valid_encodings:<EOL><INDENT>raise WebPushException("<STR_LIT>"<EOL>"<STR_LIT>" +<EOL>json.dumps(self.valid_encodings))<EOL><DEDENT>if content_encoding == "<STR_LIT>":<EOL><INDENT>salt = os.urandom(<NUM_LIT:16>)<EOL><DEDENT>server_key = ec.generate_private_key(ec.SECP256R1, default_backend())<EOL>crypto_key = server_key.public_key().public_bytes(<EOL>encoding=serialization.Encoding.X962,<EOL>format=serialization.PublicFormat.UncompressedPoint<EOL>)<EOL>if isinstance(data, six.string_types):<EOL><INDENT>data = bytes(data.encode('<STR_LIT:utf8>'))<EOL><DEDENT>if content_encoding == "<STR_LIT>":<EOL><INDENT>encrypted = http_ece.encrypt(<EOL>data,<EOL>salt=salt,<EOL>private_key=server_key,<EOL>dh=self.receiver_key,<EOL>auth_secret=self.auth_key,<EOL>version=content_encoding)<EOL>reply = CaseInsensitiveDict({<EOL>'<STR_LIT:body>': encrypted<EOL>})<EOL><DEDENT>else:<EOL><INDENT>crypto_key = base64.urlsafe_b64encode(crypto_key).strip(b'<STR_LIT:=>')<EOL>encrypted = http_ece.encrypt(<EOL>data,<EOL>salt=salt,<EOL>private_key=server_key,<EOL>keyid=crypto_key.decode(),<EOL>dh=self.receiver_key,<EOL>auth_secret=self.auth_key,<EOL>version=content_encoding)<EOL>reply = CaseInsensitiveDict({<EOL>'<STR_LIT>': crypto_key,<EOL>'<STR_LIT:body>': encrypted,<EOL>})<EOL>if salt:<EOL><INDENT>reply['<STR_LIT>'] = base64.urlsafe_b64encode(salt).strip(b'<STR_LIT:=>')<EOL><DEDENT><DEDENT>return reply<EOL>
Encrypt the data.

        :param data: A serialized block of byte data (String, JSON, bit array,
            etc.) Make sure that whatever you send, your client knows how
            to understand it.
        :type data: str
        :param content_encoding: The content_encoding type to use to encrypt
            the data. Defaults to RFC8188 "aes128gcm". The previous draft-01 is
            "aesgcm", however this format is now deprecated.
        :type content_encoding: enum("aesgcm", "aes128gcm")