code: def _b32encode(alphabet, s):
      global _b32tab2
      # Delay the initialization of the table to not waste memory
      # if the function is never called
      if alphabet not in _b32tab2:
          b32tab = [bytes((i,)) for i in alphabet]
          _b32tab2[alphabet] = [a + b for a in b32tab for b in b32tab]
          b32tab = None
  
      if not isinstance(s, bytes_types):
          s = memoryview(s).tobytes()
      leftover = len(s) % 5
      # Pad the last quantum with zero bits if necessary
      if leftover:
          s = s + b"\0" * (5 - leftover)  # Don't use += !
      encoded = bytearray()
      from_bytes = int.from_bytes
      b32tab2 = _b32tab2[alphabet]
      for i in range(0, len(s), 5):
          c = from_bytes(s[i : i + 5])  # big endian
          encoded += (
              b32tab2[c >> 30]
              + b32tab2[(c >> 20) & 0x3FF]  # bits 1 - 10
              + b32tab2[(c >> 10) & 0x3FF]  # bits 11 - 20
              + b32tab2[c & 0x3FF]  # bits 21 - 30  # bits 31 - 40
          )
      # Adjust for any leftover partial quanta
      if leftover == 1:
          encoded[-6:] = b"======"
      elif leftover == 2:
          encoded[-4:] = b"===="
      elif leftover == 3:
          encoded[-3:] = b"==="
      elif leftover == 4:
          encoded[-1:] = b"="
      return bytes(encoded)
  
imports: import re
  import struct
  import binascii
label_desc: Use image node_id 8 for calling a global function with example usage: _b32encode(alphabet, s) and returns: bytes