

def _EncodeString(self, string):
    'Encodes a string in the preferred encoding.\n\n    Returns:\n      A byte string containing the encoded string.\n    '
    try:
        encoded_string = string.encode(self._preferred_encoding, errors=self._encode_errors)
    except UnicodeEncodeError:
        if (self._encode_errors == 'strict'):
            logging.error('Unable to properly write output due to encoding error. Switching to error tolerant encoding which can result in non Basic Latin (C0) characters being replaced with "?" or "\\ufffd".')
            self._encode_errors = 'replace'
        encoded_string = string.encode(self._preferred_encoding, errors=self._encode_errors)
    return encoded_string

dataset/ETHPy150Open log2timeline/dfvfs/examples/recursive_hasher.py RecursiveHasherVolumeScannerMediator._EncodeString/original