@staticmethod
def _encode_to_bytes(string):
    """
        Tries to encode any string from bytes. Does not fail if gets already encoded string.
        :param string: string to encode
        :type string: basestring
        :return: encoded string
        :rtype: bytes
        """
    return string if isinstance(string, bytes) else string.encode('ascii',
        'ignore')
