Path: blob/develop/awscli/customizations/emrcontainers/base36.py
1567 views
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.121314class Base36(object):15def str_to_int(self, request):16"""Method to convert given string into decimal representation"""17result = 018for char in request:19result = result * 256 + ord(char)2021return result2223def encode(self, request):24"""Method to return base36 encoded form of the input string"""25decimal_number = self.str_to_int(str(request))26alphabet, base36 = ['0123456789abcdefghijklmnopqrstuvwxyz', '']2728while decimal_number:29decimal_number, i = divmod(decimal_number, 36)30base36 = alphabet[i] + base363132return base36 or alphabet[0]333435