-
Notifications
You must be signed in to change notification settings - Fork 23.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deprecated warnings #38388
Fix deprecated warnings #38388
Conversation
But that will explode on python 2.x since |
Is there a method to have it work on both versions? I don't think there is
any support on six for base64 migration between python2/3 :(
Le ven. 6 avr. 2018 à 11:27, Martin Krizek <notifications@github.com> a
écrit :
… But that will explode on python 2.x since base64.encodebytes is not
available there , no?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#38388 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASXIs2FirsASFhD0D-1JRgO-ppM4Qdeks5tlzTkgaJpZM4TJvfq>
.
|
@mkrizek is correct. You probably want to switch to b64encode instead.
Also, any deprecaution warning is probably less important than making sure
tthat we're only passing bytes into these functions. I'd use
ansible.module_utils._text.to_bytes("string", errors="surrogate_or_strict")
to make sure we're sending in be strings.
…On Fri, Apr 6, 2018, 3:15 AM Martin Krizek ***@***.***> wrote:
cc @abadger <https://github.com/abadger> @webknjaz
<https://github.com/webknjaz>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38388 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMxWkWmV8dhye6on3YbfuDQR7xmSFBTks5tl0A4gaJpZM4TJvfq>
.
|
It's also possible to shim it like: try:
from base64 import encodebytes
except ImportError:
from base64 import encodestring as encodebytes somewhere in compat module and use it from there. |
Alternatively, add moves to import six
for pf in 'de', 'en':
mv = six.MovedAttribute(
'base64_%scodebytes' % pf,
'base64', 'base64',
'%scodestring' % pf,
'%scodebytes' % pf
)
six.add_move(mv)
from six.moves import base64_encodebytes |
Both encodebytes and encodestring are part of the legacy/deprecated API.
That's why I recommend switching to b64encode.
… .
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
0b96b5d
to
b44786c
Compare
@abadger done I've changed it to use |
Oops, Sorry to have confused the matter. You'll still need to use
base64.b64encode() around the outside of the to_bytes() call.
In Python 3, b64encode only takes byte strings so the call to to_bytes
ensures that we are calling b64encode() on a bytes value. We still need to
call b64encode on those bytes in order to encode them in the base64
alphabet.
|
b44786c
to
35a3659
Compare
@abadger done |
@webknjaz are you satisfied with the current solution? |
35a3659
to
03da2d7
Compare
@mkrizek I misread :) Fixed |
Merged to devel and cherry-picked to stable-2.5 |
SUMMARY
base64.encodestring
is deprecated. https://docs.python.org/3/library/base64.html#base64.encodestringISSUE TYPE
ANSIBLE VERSION