import base64

from .exceptions import InvalidArgumentError


def compose_new_shard_iterator(stream_name, shard, shard_iterator_type, starting_sequence_number,
                               at_timestamp):
    if shard_iterator_type == "AT_SEQUENCE_NUMBER":
        last_sequence_id = int(starting_sequence_number) - 1
    elif shard_iterator_type == "AFTER_SEQUENCE_NUMBER":
        last_sequence_id = int(starting_sequence_number)
    elif shard_iterator_type == "TRIM_HORIZON":
        last_sequence_id = 0
    elif shard_iterator_type == "LATEST":
        last_sequence_id = shard.get_max_sequence_number()
    elif shard_iterator_type == "AT_TIMESTAMP":
        last_sequence_id = shard.get_sequence_number_at(at_timestamp)
    else:
        raise InvalidArgumentError(
            "Invalid ShardIteratorType: {0}".format(shard_iterator_type))
    return compose_shard_iterator(stream_name, shard, last_sequence_id)


def compose_shard_iterator(stream_name, shard, last_sequence_id):
    return base64.encodestring(
        "{0}:{1}:{2}".format(
            stream_name,
            shard.shard_id,
            last_sequence_id,
        ).encode("utf-8")
    ).decode("utf-8")


def decompose_shard_iterator(shard_iterator):
    return base64.decodestring(shard_iterator.encode("utf-8")).decode("utf-8").split(":")

@@ -1,12 +1,23 @@
+import sys%0A
 import base6
@@ -66,16 +66,297 @@
 Error%0A%0A%0A
+if sys.version_info%5B0%5D == 2:%0A    encode_method = base64.encodestring%0A    decode_method = base64.decodestring%0Aelif sys.version_info%5B0%5D == 3:%0A    encode_method = base64.encodebytes%0A    decode_method = base64.decodebytes%0Aelse:%0A    raise Exception(%22Python version is not supported%22)%0A%0A%0A
 def comp
@@ -1285,35 +1285,29 @@
  return 
-base64.encodestring
+encode_method
 (%0A      
@@ -1520,35 +1520,29 @@
  return 
-base64.decodestring
+decode_method
 (shard_i

Fix base64 deprecated methods in kinesis.utils (#2209)