Re: [Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-02-17 Thread Jan Cholasta

On 17.2.2016 10:43, Jan Cholasta wrote:

On 9.2.2016 18:02, Petr Viktorin wrote:

On 01/29/2016 09:42 AM, Jan Cholasta wrote:

On 29.1.2016 09:25, Jan Cholasta wrote:

Hi,

On 27.1.2016 18:38, Petr Viktorin wrote:

Hello,

Here is a mixed bag of Python 3 fixes.
They fix some tests, and they should enable you to use `python3
/usr/bin/ipa`.


Patch 761:

1) The "invalid 'my_number': " bit comes from IPA itself, shouldn't we
check at least that?


Fixed


Patch 762:

1) We should handle UnicodeError here as well, in addition to
TypeError:

   if k.lower() == 'negotiate':
   try:
-token = base64.b64decode(v)
+token = base64.b64decode(v.encode('ascii'))
   break
   # b64decode raises TypeError on invalid input
   except TypeError:


Fixed


2) I would prefer if the encoding was specified explicitly here:

+response =
json_decode_binary(json.loads(response.decode()))


Fixed


Patch 763:

1)

+altname = altname


Fixed


2) Nitpick, but could you please:

-if isinstance(name_or_oid, unicode):
-name_or_oid = name_or_oid.encode('utf-8')
+if six.PY2:
+if isinstance(name_or_oid, unicode):
+name_or_oid = name_or_oid.encode('utf-8')

This way it's more visible that this is a py2-only thing.


Sure


Patch 764: LGTM


Patch 765:

1)

+import tempfile
+import tempfile


Fixed.


Patch 766-767: LGTM


Patch 768:

1) Only binascii.Error should be handled in int_to_bytes, the
try-except
block is there just to handle odd-length strings.


That's there for Python 2, where unhexlify raises TypeError.


2) I think you can just remove the library_path.encode(), it's there
because the original C code did the same thing, but don't think it's
necessary.


OK


Patch 769: LGTM


Also, could you please reference
 in the patches?


Sure.

Thanks for the review! Updated patches attached.


Thanks, ACK.

Pushed to:
master: d1252cfb8ef613e290a23e0e9cabd9d135a129ca
ipa-4-3: c8c2a6d33815b478c1d6ec402eaa2f56d0fe61b7


I screwed up. The attached patch fixes that.

Pushed under the one-liner rule to ipa-4-3: 
5ff41fa3091235aaf48e855b0c3ede0154a58dfc


--
Jan Cholasta
From 554d6d39d578375dc5990ea5b053736454a607e1 Mon Sep 17 00:00:00 2001
From: Jan Cholasta 
Date: Wed, 17 Feb 2016 10:49:45 +0100
Subject: [PATCH] test_ipagetkeytab: fix missing import

The import was accidentally removed in commit
9a3d5fdadd691df722b4a2ee29642a81a0035ad3.

https://fedorahosted.org/freeipa/ticket/5638
---
 ipatests/test_cmdline/test_ipagetkeytab.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ipatests/test_cmdline/test_ipagetkeytab.py b/ipatests/test_cmdline/test_ipagetkeytab.py
index 3c91f37..6153b9b 100644
--- a/ipatests/test_cmdline/test_ipagetkeytab.py
+++ b/ipatests/test_cmdline/test_ipagetkeytab.py
@@ -33,6 +33,7 @@ from ipalib import errors
 from ipapython import ipautil, ipaldap
 from ipaserver.plugins.ldap2 import ldap2
 from ipapython.dn import DN
+from ipatests.test_cmdline.cmdline import cmdline_test
 
 def use_keytab(principal, keytab):
 try:
-- 
2.5.0

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Re: [Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-02-17 Thread Jan Cholasta

On 9.2.2016 18:02, Petr Viktorin wrote:

On 01/29/2016 09:42 AM, Jan Cholasta wrote:

On 29.1.2016 09:25, Jan Cholasta wrote:

Hi,

On 27.1.2016 18:38, Petr Viktorin wrote:

Hello,

Here is a mixed bag of Python 3 fixes.
They fix some tests, and they should enable you to use `python3
/usr/bin/ipa`.


Patch 761:

1) The "invalid 'my_number': " bit comes from IPA itself, shouldn't we
check at least that?


Fixed


Patch 762:

1) We should handle UnicodeError here as well, in addition to TypeError:

   if k.lower() == 'negotiate':
   try:
-token = base64.b64decode(v)
+token = base64.b64decode(v.encode('ascii'))
   break
   # b64decode raises TypeError on invalid input
   except TypeError:


Fixed


2) I would prefer if the encoding was specified explicitly here:

+response = json_decode_binary(json.loads(response.decode()))


Fixed


Patch 763:

1)

+altname = altname


Fixed


2) Nitpick, but could you please:

-if isinstance(name_or_oid, unicode):
-name_or_oid = name_or_oid.encode('utf-8')
+if six.PY2:
+if isinstance(name_or_oid, unicode):
+name_or_oid = name_or_oid.encode('utf-8')

This way it's more visible that this is a py2-only thing.


Sure


Patch 764: LGTM


Patch 765:

1)

+import tempfile
+import tempfile


Fixed.


Patch 766-767: LGTM


Patch 768:

1) Only binascii.Error should be handled in int_to_bytes, the try-except
block is there just to handle odd-length strings.


That's there for Python 2, where unhexlify raises TypeError.


2) I think you can just remove the library_path.encode(), it's there
because the original C code did the same thing, but don't think it's
necessary.


OK


Patch 769: LGTM


Also, could you please reference
 in the patches?


Sure.

Thanks for the review! Updated patches attached.


Thanks, ACK.

Pushed to:
master: d1252cfb8ef613e290a23e0e9cabd9d135a129ca
ipa-4-3: c8c2a6d33815b478c1d6ec402eaa2f56d0fe61b7

--
Jan Cholasta

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-02-09 Thread Petr Viktorin
On 01/29/2016 09:42 AM, Jan Cholasta wrote:
> On 29.1.2016 09:25, Jan Cholasta wrote:
>> Hi,
>>
>> On 27.1.2016 18:38, Petr Viktorin wrote:
>>> Hello,
>>>
>>> Here is a mixed bag of Python 3 fixes.
>>> They fix some tests, and they should enable you to use `python3
>>> /usr/bin/ipa`.
>>
>> Patch 761:
>>
>> 1) The "invalid 'my_number': " bit comes from IPA itself, shouldn't we
>> check at least that?

Fixed

>> Patch 762:
>>
>> 1) We should handle UnicodeError here as well, in addition to TypeError:
>>
>>   if k.lower() == 'negotiate':
>>   try:
>> -token = base64.b64decode(v)
>> +token = base64.b64decode(v.encode('ascii'))
>>   break
>>   # b64decode raises TypeError on invalid input
>>   except TypeError:

Fixed

>> 2) I would prefer if the encoding was specified explicitly here:
>>
>> +response = json_decode_binary(json.loads(response.decode()))

Fixed

>> Patch 763:
>>
>> 1)
>>
>> +altname = altname

Fixed

>> 2) Nitpick, but could you please:
>>
>> -if isinstance(name_or_oid, unicode):
>> -name_or_oid = name_or_oid.encode('utf-8')
>> +if six.PY2:
>> +if isinstance(name_or_oid, unicode):
>> +name_or_oid = name_or_oid.encode('utf-8')
>>
>> This way it's more visible that this is a py2-only thing.

Sure

>> Patch 764: LGTM
>>
>>
>> Patch 765:
>>
>> 1)
>>
>> +import tempfile
>> +import tempfile

Fixed.

>> Patch 766-767: LGTM
>>
>>
>> Patch 768:
>>
>> 1) Only binascii.Error should be handled in int_to_bytes, the try-except
>> block is there just to handle odd-length strings.

That's there for Python 2, where unhexlify raises TypeError.

>> 2) I think you can just remove the library_path.encode(), it's there
>> because the original C code did the same thing, but don't think it's
>> necessary.

OK

>> Patch 769: LGTM
> 
> Also, could you please reference
>  in the patches?

Sure.

Thanks for the review! Updated patches attached.

-- 
Petr Viktorin
From e5cc6a408243454bd1e8ac5eae0af91d5138a3b0 Mon Sep 17 00:00:00 2001
From: Petr Viktorin 
Date: Mon, 21 Sep 2015 13:22:17 +0200
Subject: [PATCH] test_parameters: Ignore specific error message

In Python 3, the error message from the decimal module is
less clear than before.
(It's apparently the price to pay for speed -- Python3 uses
libmpdec as its Decimal implementation by default.)

Don't check for the exact error message.

https://fedorahosted.org/freeipa/ticket/5638
---
 ipatests/test_ipalib/test_parameters.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py
index b640f50dae4ebfb4f764e5ca9b2aa355fdfb6359..ea6b80ca859e16c91db4fad26aa8f484b34b6b15 100644
--- a/ipatests/test_ipalib/test_parameters.py
+++ b/ipatests/test_ipalib/test_parameters.py
@@ -1441,8 +1441,7 @@ class test_Decimal(ClassChecker):
 param = self.cls('my_number', precision=1)
 e = raises(ConversionError, param, '123456789012345678901234567890')
 
-assert str(e) == \
-"invalid 'my_number': quantize result has too many digits for current context"
+assert str(e).startswith("invalid 'my_number': ")
 
 def test_exponential(self):
 """
-- 
2.5.0

From 3b957cdba60df736bed7fe562a352bc6b038e943 Mon Sep 17 00:00:00 2001
From: Michael Simacek 
Date: Tue, 22 Sep 2015 10:29:32 +0200
Subject: [PATCH] Fix bytes/string handling in rpc

https://fedorahosted.org/freeipa/ticket/5638
---
 ipalib/rpc.py | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index a165491adea5366a14a86d7c8bd6337e36fd1b44..c70b3a29fdc86ef10d9c0ce55a360233dbd8663e 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -349,7 +349,7 @@ def json_decode_binary(val):
 elif isinstance(val, list):
 return tuple(json_decode_binary(v) for v in val)
 else:
-if isinstance(val, six.string_types):
+if isinstance(val, bytes):
 try:
 return val.decode('utf-8')
 except UnicodeDecodeError:
@@ -400,7 +400,7 @@ def xml_loads(data, encoding='UTF-8'):
 
 class DummyParser(object):
 def __init__(self):
-self.data = ''
+self.data = b''
 
 def feed(self, data):
 self.data += data
@@ -575,7 +575,7 @@ class KerbTransport(SSLTransport):
 
 if token:
 extra_headers.append(
-('Authorization', 'negotiate %s' % base64.b64encode(token))
+('Authorization', 'negotiate %s' % base64.b64encode(token).decode('ascii'))
 )
 
 def _auth_complete(self, response):
@@ -586,10 +586,10 @@ class KerbTransport(SSLTransport):
 k, _, v = field.strip().partition(' ')
 if k.lower() == 'negotiate':
  

Re: [Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-01-29 Thread Jan Cholasta

On 29.1.2016 09:25, Jan Cholasta wrote:

Hi,

On 27.1.2016 18:38, Petr Viktorin wrote:

Hello,

Here is a mixed bag of Python 3 fixes.
They fix some tests, and they should enable you to use `python3
/usr/bin/ipa`.


Patch 761:

1) The "invalid 'my_number': " bit comes from IPA itself, shouldn't we
check at least that?


Patch 762:

1) We should handle UnicodeError here as well, in addition to TypeError:

  if k.lower() == 'negotiate':
  try:
-token = base64.b64decode(v)
+token = base64.b64decode(v.encode('ascii'))
  break
  # b64decode raises TypeError on invalid input
  except TypeError:

2) I would prefer if the encoding was specified explicitly here:

+response = json_decode_binary(json.loads(response.decode()))


Patch 763:

1)

+altname = altname

2) Nitpick, but could you please:

-if isinstance(name_or_oid, unicode):
-name_or_oid = name_or_oid.encode('utf-8')
+if six.PY2:
+if isinstance(name_or_oid, unicode):
+name_or_oid = name_or_oid.encode('utf-8')

This way it's more visible that this is a py2-only thing.


Patch 764: LGTM


Patch 765:

1)

+import tempfile
+import tempfile


Patch 766-767: LGTM


Patch 768:

1) Only binascii.Error should be handled in int_to_bytes, the try-except
block is there just to handle odd-length strings.

2) I think you can just remove the library_path.encode(), it's there
because the original C code did the same thing, but don't think it's
necessary.


Patch 769: LGTM


Also, could you please reference 
 in the patches?


--
Jan Cholasta

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


Re: [Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-01-29 Thread Jan Cholasta

Hi,

On 27.1.2016 18:38, Petr Viktorin wrote:

Hello,

Here is a mixed bag of Python 3 fixes.
They fix some tests, and they should enable you to use `python3
/usr/bin/ipa`.


Patch 761:

1) The "invalid 'my_number': " bit comes from IPA itself, shouldn't we 
check at least that?



Patch 762:

1) We should handle UnicodeError here as well, in addition to TypeError:

 if k.lower() == 'negotiate':
 try:
-token = base64.b64decode(v)
+token = base64.b64decode(v.encode('ascii'))
 break
 # b64decode raises TypeError on invalid input
 except TypeError:

2) I would prefer if the encoding was specified explicitly here:

+response = json_decode_binary(json.loads(response.decode()))


Patch 763:

1)

+altname = altname

2) Nitpick, but could you please:

-if isinstance(name_or_oid, unicode):
-name_or_oid = name_or_oid.encode('utf-8')
+if six.PY2:
+if isinstance(name_or_oid, unicode):
+name_or_oid = name_or_oid.encode('utf-8')

This way it's more visible that this is a py2-only thing.


Patch 764: LGTM


Patch 765:

1)

+import tempfile
+import tempfile


Patch 766-767: LGTM


Patch 768:

1) Only binascii.Error should be handled in int_to_bytes, the try-except 
block is there just to handle odd-length strings.


2) I think you can just remove the library_path.encode(), it's there 
because the original C code did the same thing, but don't think it's 
necessary.



Patch 769: LGTM


Honza

--
Jan Cholasta

--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code


[Freeipa-devel] [PATCHES] 0761-0769 More Python3 fixes

2016-01-27 Thread Petr Viktorin
Hello,

Here is a mixed bag of Python 3 fixes.
They fix some tests, and they should enable you to use `python3
/usr/bin/ipa`.


-- 
Petr Viktorin
From 7d6bb7fe8d548e564d7bd941439fa405f0f92742 Mon Sep 17 00:00:00 2001
From: Petr Viktorin 
Date: Mon, 21 Sep 2015 13:22:17 +0200
Subject: [PATCH] test_parameters: Ignore bad error message in Python 3

The decimal error message is less clear than before.
(It's apparently the price to pay for speed -- Python3 uses
libmpdec as its Decimal implementation by default.)

Don't check for the exact error message.
---
 ipatests/test_ipalib/test_parameters.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ipatests/test_ipalib/test_parameters.py b/ipatests/test_ipalib/test_parameters.py
index b640f50dae4ebfb4f764e5ca9b2aa355fdfb6359..90c92a933fd8a66945e6752c5eab6ceb5026e9d5 100644
--- a/ipatests/test_ipalib/test_parameters.py
+++ b/ipatests/test_ipalib/test_parameters.py
@@ -1441,8 +1441,9 @@ class test_Decimal(ClassChecker):
 param = self.cls('my_number', precision=1)
 e = raises(ConversionError, param, '123456789012345678901234567890')
 
-assert str(e) == \
-"invalid 'my_number': quantize result has too many digits for current context"
+if six.PY2:
+assert str(e) == \
+"invalid 'my_number': quantize result has too many digits for current context"
 
 def test_exponential(self):
 """
-- 
2.5.0

From 5201e2c9cd56b9be3f5dfe9f2e7c6e251ba3931e Mon Sep 17 00:00:00 2001
From: Michael Simacek 
Date: Tue, 22 Sep 2015 10:29:32 +0200
Subject: [PATCH] Fix bytes/string handling in rpc

---
 ipalib/rpc.py | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index a165491adea5366a14a86d7c8bd6337e36fd1b44..56f20512dbe83646923537117e589d5b895fe9c4 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -349,7 +349,7 @@ def json_decode_binary(val):
 elif isinstance(val, list):
 return tuple(json_decode_binary(v) for v in val)
 else:
-if isinstance(val, six.string_types):
+if isinstance(val, bytes):
 try:
 return val.decode('utf-8')
 except UnicodeDecodeError:
@@ -400,7 +400,7 @@ def xml_loads(data, encoding='UTF-8'):
 
 class DummyParser(object):
 def __init__(self):
-self.data = ''
+self.data = b''
 
 def feed(self, data):
 self.data += data
@@ -575,7 +575,7 @@ class KerbTransport(SSLTransport):
 
 if token:
 extra_headers.append(
-('Authorization', 'negotiate %s' % base64.b64encode(token))
+('Authorization', 'negotiate %s' % base64.b64encode(token).decode('ascii'))
 )
 
 def _auth_complete(self, response):
@@ -586,7 +586,7 @@ class KerbTransport(SSLTransport):
 k, _, v = field.strip().partition(' ')
 if k.lower() == 'negotiate':
 try:
-token = base64.b64decode(v)
+token = base64.b64decode(v.encode('ascii'))
 break
 # b64decode raises TypeError on invalid input
 except TypeError:
@@ -1068,12 +1068,12 @@ class JSONServerProxy(object):
 response = self.__transport.request(
 self.__host,
 self.__handler,
-json.dumps(payload),
+json.dumps(payload).encode('utf-8'),
 verbose=self.__verbose >= 3,
 )
 
 try:
-response = json_decode_binary(json.loads(response))
+response = json_decode_binary(json.loads(response.decode()))
 except ValueError as e:
 raise JSONError(str(e))
 
-- 
2.5.0

From a7ea3fa1096c5ef53564b0f28ad5d6e85f8a8f64 Mon Sep 17 00:00:00 2001
From: Petr Viktorin 
Date: Wed, 14 Oct 2015 15:02:51 +0200
Subject: [PATCH] ipaldap, ldapupdate: Encoding fixes for Python 3

---
 ipapython/ipaldap.py| 12 +---
 ipaserver/install/ldapupdate.py |  8 
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py
index 28bfcb5c2ee2140d38f17248fc9c90861cd251e4..45ab15bd4a0c3fefa17604419ef73a7d5eb3f77c 100644
--- a/ipapython/ipaldap.py
+++ b/ipapython/ipaldap.py
@@ -346,11 +346,17 @@ class LDAPEntry(collections.MutableMapping):
 return self._names[name]
 
 if self._conn.schema is not None:
+if six.PY2:
+encoded_name = name.encode('utf-8')
+else:
+encoded_name = name
 attrtype = self._conn.schema.get_obj(
-ldap.schema.AttributeType, name.encode('utf-8'))
+ldap.schema.AttributeType, encoded_name)
 if attrtype is not None:
 for altname in attrtype.names:
-altname = altname.decode('utf-8')
+if six.PY2:
+altname = altnam