def strip_surrogates(text, method='ignore'):
    """Strip surrogate escapes from the string

    This is useful if the text data is going to be processed by APIs
    which expect valid unicode and the text will not be passed to an
    API which will revert the surrogate escapes back to bytes.  Be
    aware then once stripped the original bytes can no longer be
    re-constructed.
    """
    assert method in ['ignore', 'replace'], 'Invalid strip method'
    return text.encode('utf-8', method).decode('utf-8')
