From: W. Trevor King Date: Sun, 21 Oct 2012 20:05:16 +0000 (-0400) Subject: pgp: force protocol/micalg ordering in doctest output. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=HEAD;p=pgp-mime.git pgp: force protocol/micalg ordering in doctest output. The Content-Type header is eventually set by Message.add_header(), which gets extra parameters from **_params and iterates over them with _params.items(). _params is a dict, so .items() is not sorted. Rather than using ELLIPSIS, I thought it was clearer if we explicitly force our expected ordering in doctest output. --- diff --git a/pgp_mime/pgp.py b/pgp_mime/pgp.py index d709cfb..8adb808 100644 --- a/pgp_mime/pgp.py +++ b/pgp_mime/pgp.py @@ -54,7 +54,10 @@ def sign(message, **kwargs): >>> message = encodedMIMEText('Hi\nBye') >>> signed = sign(message, signers=['pgp-mime@invalid.com']) >>> signed.set_boundary('boundsep') - >>> print(signed.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(signed.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-signature"', + ... 'protocol="application/pgp-signature"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline @@ -85,7 +88,10 @@ def sign(message, **kwargs): >>> message.attach(encodedMIMEText('Part B')) >>> signed = sign(message, signers=['pgp-mime@invalid.com']) >>> signed.set_boundary('boundsep') - >>> print(signed.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(signed.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-signature"', + ... 'protocol="application/pgp-signature"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline @@ -149,7 +155,10 @@ def encrypt(message, recipients=None, **kwargs): >>> message['To'] = 'pgp-mime-test ' >>> encrypted = encrypt(message, always_trust=True) >>> encrypted.set_boundary('boundsep') - >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(encrypted.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-encrypted"', + ... 'protocol="application/pgp-encrypted"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline @@ -180,7 +189,10 @@ def encrypt(message, recipients=None, **kwargs): >>> encrypted = encrypt( ... message, recipients=['pgp-mime@invalid.com'], always_trust=True) >>> encrypted.set_boundary('boundsep') - >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(encrypted.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-encrypted"', + ... 'protocol="application/pgp-encrypted"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline @@ -243,7 +255,10 @@ def sign_and_encrypt(message, signers=None, recipients=None, **kwargs): >>> encrypted = sign_and_encrypt( ... message, signers=['pgp-mime@invalid.com'], always_trust=True) >>> encrypted.set_boundary('boundsep') - >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(encrypted.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-encrypted"', + ... 'protocol="application/pgp-encrypted"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline @@ -275,7 +290,10 @@ def sign_and_encrypt(message, signers=None, recipients=None, **kwargs): ... message, signers=['pgp-mime@invalid.com'], ... recipients=['pgp-mime@invalid.com'], always_trust=True) >>> encrypted.set_boundary('boundsep') - >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + >>> print(encrypted.as_string().replace( + ... 'micalg="pgp-sha1"; protocol="application/pgp-encrypted"', + ... 'protocol="application/pgp-encrypted"; micalg="pgp-sha1"')) + ... # doctest: +ELLIPSIS, +REPORT_UDIFF Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep" MIME-Version: 1.0 Content-Disposition: inline