summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2015-09-18 17:20:08 +0200
committerTomas Babej <tbabej@redhat.com>2015-10-13 14:16:32 +0200
commit929c3d1265dcb7af375d433a7e0b44193e19ed2f (patch)
treec7a7fe7b9d6cc0c0237b51acda513778ee25efcc /ipalib
parent59d87d53b10a201ef03077c96011523bdd1342e8 (diff)
downloadfreeipa-929c3d1265dcb7af375d433a7e0b44193e19ed2f.tar.gz
freeipa-929c3d1265dcb7af375d433a7e0b44193e19ed2f.tar.xz
freeipa-929c3d1265dcb7af375d433a7e0b44193e19ed2f.zip
x509: Port to Python 3
In python 3 , `bytes` has the buffer interface, and `buffer` was removed. Also, invalid padding in base64-encoded data raises a ValueError rather than TypeError. In tests, use pytest.assert_raises for more correct exception assertions. Also, get rid of unused imports in the tests Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/x509.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/ipalib/x509.py b/ipalib/x509.py
index e48d3edf7..037d6785c 100644
--- a/ipalib/x509.py
+++ b/ipalib/x509.py
@@ -37,10 +37,13 @@ import os
import sys
import base64
import re
+
import nss.nss as nss
from nss.error import NSPRError
from pyasn1.type import univ, namedtype, tag
from pyasn1.codec.der import decoder, encoder
+import six
+
from ipapython import ipautil
from ipalib import api
from ipalib import _
@@ -127,7 +130,11 @@ def load_certificate(data, datatype=PEM, dbdir=None):
initialize_nss_database(dbdir=dbdir)
- return nss.Certificate(buffer(data))
+ if six.PY2:
+ return nss.Certificate(buffer(data))
+ else:
+ # In python 3 , `bytes` has the buffer interface
+ return nss.Certificate(data)
def load_certificate_from_file(filename, dbdir=None):
"""