'Convert a splittable string back into an encoded string.
Uses the proper codec to try and convert the string from Unicode back
into an encoded format.  Return the string as-is if it is not Unicode,
or if it could not be converted from Unicode.
Characters that could not be converted from Unicode will be replaced
with an appropriate character (usually \'?\').
If to_output is True (the default), uses output_codec to convert to an
encoded format.  If to_output is False, uses input_codec.'

def from_splittable(self, ustr, to_output=True):

    if to_output:
        codec = self.output_codec
    else:
        codec = self.input_codec
    if ((not isinstance(ustr, unicode)) or (codec is None)):
        return ustr
    else:
        try:
            return ustr.encode(codec, 'replace')
        except LookupError:
            return ustr
        return
