from __future__ import unicode_literals, absolute_import


def encode_bytes(*args):
    """
    Encodes values into a byte string
    strings are left as-is
    integer values are encoded into their char values
    :return: bytestring representing all arguments joined together
    """
    result = b''
    for arg in args:
        if isinstance(arg, basestring):
            result += str(arg)
        elif isinstance(arg, int):
            result += chr(arg)
    return result


def decode_int(string):
    """
    Decodes integer from byte string
    """
    result = 0
    for n, c in enumerate(string):
        result |= ord(c) << (8 * n)
    return result


def decode_string(string, len_pos, len_bytes=4):
    """
    Decodes string from a string
    :param string: bytestring with the response
    :param len_pos: position of the integer expressing the length
    :param len_bytes: number of bytes used for string length
    :return: substring of string starting at len_pos + len_bytes and ending at position indicated in length value at position len_pos
    """
    assert isinstance(len_pos, int)
    len_end = len_pos + len_bytes
    length = decode_int(string[len_pos:len_end])
    return string[len_end:len_end + length]


def build_rcon_command(command, args=None):
    """
    Appends args to the command
    :param command: the command string
    :param args: list of arguments or a single argument (bool, string or int)
    """
    if args is not None:
        # Bool check must come first because bool extends int
        if isinstance(args, bool):
            args = str(int(args)),
        elif isinstance(args, (basestring, int)):
            args = str(args),
        command += ' ' + ' '.join(args)
    return command
@@ -1579,20 +1579,16 @@
  args = 
-str(
 int(args
@@ -1588,17 +1588,16 @@
 nt(args)
-)
 ,%0A      
@@ -1663,27 +1663,45 @@
 s = 
-str
+args,%0A        if len
 (args)
-,%0A
+:%0A 
         
 comm
@@ -1696,16 +1696,19 @@
         
+   
 command 
@@ -1725,16 +1725,36 @@
  '.join(
+str(arg) for arg in 
 args)%0A  

Fix parsing args