telepathy-gabble: tls/server-tls-channel: use with statement when reading certs
Will Thompson
wjt at kemper.freedesktop.org
Thu Dec 6 04:29:03 PST 2012
Module: telepathy-gabble
Branch: master
Commit: 5e5080f7cd7984fb4c62cee1a1856406dc210d0e
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=5e5080f7cd7984fb4c62cee1a1856406dc210d0e
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Nov 23 16:29:56 2012 +0000
tls/server-tls-channel: use with statement when reading certs
---
tests/twisted/tls/server-tls-channel.py | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/tests/twisted/tls/server-tls-channel.py b/tests/twisted/tls/server-tls-channel.py
index 3007d20..6528e69 100644
--- a/tests/twisted/tls/server-tls-channel.py
+++ b/tests/twisted/tls/server-tls-channel.py
@@ -62,19 +62,13 @@ class TlsAuthenticator(XmppAuthenticator):
self.streamTLS()
def tlsAuth(self, auth):
- try:
- file = open(CA_KEY, 'rb')
- pem_key = file.read()
+ with open(CA_KEY, 'rb') as f:
+ pem_key = f.read()
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, pem_key, "")
- finally:
- file.close()
- try:
- file = open(CA_CERT, 'rb')
- pem_cert = file.read()
+ with open(CA_CERT, 'rb') as f:
+ pem_cert = f.read()
cert = crypto.load_certificate(crypto.FILETYPE_PEM, pem_cert)
- finally:
- file.close()
tls_ctx = ssl.CertificateOptions(privateKey=pkey, certificate=cert)
More information about the telepathy-commits
mailing list