Encodes an integer into a short Base64 string.

        Example:
            ``encode_int(123)`` returns ``'B7'``.
329874
def encode_int(self, n):
        
        str = []
        while True:
            n, r = divmod(n, self.BASE)
            str.append(self.ALPHABET[r])
            if n == 0: break
        return ''.join(reversed(str))
283516
def encode_value(value):
    # type: (bytes) -> bytes
    
    return struct.pack(">I{attr_len:d}s".format(attr_len=len(value)), len(value), value)
157285
def portable_b64encode(thing):
    """"""
    if is_py3():
        try:
            some_bits = bytes(thing, 'utf-8')
        except TypeError:
            some_bits = thing

        return polite_string(b64encode(some_bits).decode('utf-8'))

    return polite_string(b64encode(thing))
950185
def encode(self, value):
        '''
        
        '''
        encoded = strToBytes(value) + b'\x00'
        return Bits(bytes=encoded)
410603
private static String encodeBase64(final byte[] buffer) {
        final int l = buffer.length;
        final char[] out = new char[l << 1];
        int j = 0;
        for (int i = 0; i < l; i++) {
            out[j++] = DIGITS[(0xF0 & buffer[i]) >>> 4];
            out[j++] = DIGITS[0x0F & buffer[i]];
        }
        return String.copyValueOf(out);
    }
110774
def _encode_uvarint(data, n):
    ''' '''
    if n < 0:
        raise ValueError('only support positive integer')
    while True:
        this_byte = n & 0x7f
        n >>= 7
        if n == 0:
            data.append(this_byte)
            break
        data.append(this_byte | 0x80)
1341577
def str_encode(value, encoder='base64'):
    '''
    
    '''
    if six.PY2:
        try:
            out = value.encode(encoder)
        except LookupError:
            raise SaltInvocationError('You must specify a valid encoder')
        except AttributeError:
            raise SaltInvocationError('Value must be an encode-able string')
    else:
        if isinstance(value, six.string_types):
            value = value.encode(__salt_system_encoding__)
        if encoder == 'base64':
            try:
                out = base64.b64encode(value)
                out = out.decode(__salt_system_encoding__)
            except TypeError:
                raise SaltInvocationError('Value must be an encode-able string')
        else:
            try:
                out = value.encode(encoder)
            except LookupError:
                raise SaltInvocationError('You must specify a valid encoder')
            except AttributeError:
                raise SaltInvocationError('Value must be an encode-able string')
    return out
393967
def encode(self, b64=False, always_bytes=True):
        """"""
        if self.binary and not b64:
            encoded_packet = six.int2byte(self.packet_type)
        else:
            encoded_packet = six.text_type(self.packet_type)
            if self.binary and b64:
                encoded_packet = 'b' + encoded_packet
        if self.binary:
            if b64:
                encoded_packet += base64.b64encode(self.data).decode('utf-8')
            else:
                encoded_packet += self.data
        elif isinstance(self.data, six.string_types):
            encoded_packet += self.data
        elif isinstance(self.data, dict) or isinstance(self.data, list):
            encoded_packet += self.json.dumps(self.data,
                                              separators=(',', ':'))
        elif self.data is not None:
            encoded_packet += str(self.data)
        if always_bytes and not isinstance(encoded_packet, binary_types):
            encoded_packet = encoded_packet.encode('utf-8')
        return encoded_packet
417439
def _encode(self, value):
        ""
        if isinstance(value, bytes):
            return value
        elif isinstance(value, (int, long)):
            value = str(value).encode('utf-8')
        elif isinstance(value, float):
            value = repr(value).encode('utf-8')
        elif not isinstance(value, basestring):
            value = str(value).encode('utf-8')
        else:
            value = value.encode('utf-8', 'strict')
        return value
811781
def encode(self, uuid, pad_length=22):
        
        return self._num_to_string(uuid.int, pad_to_length=pad_length)
1046597
private String encodeBase64(byte[] bytes) {
        Objects.requireNonNull(bytes, Required.BYTES.toString());
        return org.apache.commons.codec.binary.Base64.encodeBase64String(bytes);
    }
1116414
def encode(self, value):
        """"""
        if isinstance(value, bytes):
            return value
        elif isinstance(value, int):
            value = b(str(value))
        elif isinstance(value, float):
            value = b(repr(value))
        elif not isinstance(value, str):
            value = str(value)
        if isinstance(value, str):
            value = value.encode()
        return value
599272
def base64decode(_input=None):
    """"""
    missing_padding = 4 - len(_input) % 4
    if missing_padding:
        _input += '=' * missing_padding
    if PY2:  # pragma: no cover
        return base64.decodestring(_input)
    elif PY3:  # pragma: no cover
        if isinstance(_input, bytes):
            return base64.b64decode(_input).decode('UTF-8')
        elif isinstance(_input, str):
            return base64.b64decode(bytearray(_input, encoding='UTF-8')).decode('UTF-8')
100203
def encode(number, alphabet):
    
    if not isinstance(number, (int, long)):
        raise TypeError("Number must be an integer.")

    base_n = ""
    sign = ""

    if number < 0:
        sign = "-"
        number = -number

    if 0 <= number < len(alphabet):
        return sign + alphabet[number]

    while number != 0:
        number, i = divmod(number, len(alphabet))
        base_n = alphabet[i] + base_n

    return sign + base_n
1238402
def base64_encodestring(instr):
    '''
    
    '''
    return salt.utils.stringutils.to_unicode(
        base64.encodestring(salt.utils.stringutils.to_bytes(instr)),
        encoding='utf8' if salt.utils.platform.is_windows() else None
    )
714312
def _encode_long(name, value, dummy0, dummy1):
    """"""
    try:
        return b"\x12" + name + _PACK_LONG(value)
    except struct.error:
        raise OverflowError("BSON can only handle up to 8-byte ints")
771621
def b58encode_int(i, default_one=True):
    ''''''
    if not i and default_one:
        return alphabet[0]
    string = ""
    while i:
        i, idx = divmod(i, 58)
        string = alphabet[idx] + string
    return string