Replace deprecated "decodestring"

decodestring() is a deprecated alias, use decodebytes()
https://docs.python.org/3.1/library/base64.html#base64.decodestring

This patch helps to remove this deprecation alias by
replacing "base64.decodestring" with "oslo_serialization.base64.decode_as_bytes".
The same has been done for nova:
https://review.openstack.org/#/c/610401/

Change-Id: Ibba785b8f9b27a74344c27dc952a8782f10fa697
This commit is contained in:
Vu Cong Tuan 2018-11-02 15:07:05 +07:00
parent da8aec9aed
commit d13622f274
1 changed files with 2 additions and 5 deletions

View File

@ -12,9 +12,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import base64
import jsonschema
from oslo_serialization import base64
from oslo_utils import timeutils
import six
@ -46,9 +45,7 @@ def _validate_base64_format(instance):
try:
if isinstance(instance, six.text_type):
instance = instance.encode('utf-8')
base64.decodestring(instance)
except base64.binascii.Error:
return False
base64.decode_as_bytes(instance)
except TypeError:
# The name must be string type. If instance isn't string type, the
# TypeError will be raised at here.