# Buggy code
def IsText(bytes_in, encoding=None):
    """Examine the bytes in and determine if they are indicative of a text.

    Parsers need quick and at least semi reliable method of discovering whether
    or not a particular byte stream is a text or resembles text or not. This can
    be used in text parsers to determine if a file is a text file or not for
    instance.

    The method assumes the byte sequence is either ASCII, UTF-8, UTF-16 or method
    supplied character encoding. Otherwise it will make the assumption the byte
    sequence is not text, but a byte sequence.

    Args:
      bytes_in (bytes): byte stream to examine.
      encoding (Optional[str]): encoding to test, if not defined ASCII and UTF-8
          are tried.

    Returns:
      bool: True if the bytes stream contains text.
    """
    # TODO: Improve speed and accuracy of this method.
    # Start with the assumption we are dealing with a text.
    is_ascii = True

    # Check if this is ASCII text string.
    for char in bytes_in:
        if not 31 < ord(char) < 128:
            is_ascii = False
            break

    # We have an ASCII string.
    if is_ascii:
        return is_ascii

    if isinstance(bytes_in, py2to3.UNICODE_TYPE):
        return True

    # Check if this is UTF-8
    try:
        bytes_in.decode("utf-8")
        return True

    except UnicodeDecodeError:
        pass

    if encoding:
        try:
            bytes_in.decode(encoding)
            return True

        except LookupError:
            logging.error("Unuppported encoding: {0:s}".format(encoding))
        except UnicodeDecodeError:
            pass

    return False


# Traceback (WindowsError)
(plaso) C:\dev\plaso>python tools\psort.py -o xlsx G:\test_data\set_1_output.zip -w G:\test_data\set_1_output.xlsx --status_view none -d --analysis browser_search
2016-08-30 12:37:21,882 [INFO] (MainProcess) PID:9376 <psort> Starting analysis plugins.
2016-08-30 12:37:21,888 [DEBUG] (MainProcess) PID:9376 <zeromq_queue> Creating socket for browser_search output event queue
2016-08-30 12:37:21,898 [DEBUG] (MainProcess) PID:9376 <zeromq_queue> browser_search output event queue bound to random port 61649
2016-08-30 12:37:22,417 [INFO] (MainProcess) PID:9376 <psort> Started analysis plugin: browser_search (PID: 14200).
2016-08-30 12:37:24,822 [INFO] (MainProcess) PID:9376 <psort> Analysis plugins running
Traceback (most recent call last):
File "tools\psort.py", line 867, in <module>
if not Main():
File "tools\psort.py", line 853, in Main
tool.ProcessStorage()
File "tools\psort.py", line 787, in ProcessStorage
status_update_callback=status_update_callback)
File "C:\dev\plaso\plaso\frontend\psort.py", line 103, in AnalyzeEvents
status_update_callback=status_update_callback)
File "C:\dev\plaso\plaso\multi_processing\psort.py", line 536, in AnalyzeEvents
storage_writer.Open()
File "C:\dev\plaso\plaso\storage\zip_file.py", line 3217, in Open
self._storage_file.Open(path=self._output_file, read_only=False)
File "C:\dev\plaso\plaso\storage\zip_file.py", line 2754, in Open
self._OpenZIPFile(path, read_only)
File "C:\dev\plaso\plaso\storage\zip_file.py", line 1740, in _OpenZIPFile
os.rename(path, zipfile_path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process

# Fixed code
def IsText(bytes_in, encoding=None):
    """Examine the bytes in and determine if they are indicative of a text.

    Parsers need quick and at least semi reliable method of discovering whether
    or not a particular byte stream is a text or resembles text or not. This can
    be used in text parsers to determine if a file is a text file or not for
    instance.

    The method assumes the byte sequence is either ASCII, UTF-8, UTF-16 or method
    supplied character encoding. Otherwise it will make the assumption the byte
    sequence is not text, but a byte sequence.

    Args:
      bytes_in (bytes): byte stream to examine.
      encoding (Optional[str]): encoding to test, if not defined ASCII and UTF-8
          are tried.

    Returns:
      bool: True if the bytes stream contains text.
    """
    # TODO: Improve speed and accuracy of this method.
    # Start with the assumption we are dealing with a text.
    is_ascii = True

    # Check if this is ASCII text string.
    for char in bytes_in:
        if not 31 < ord(char) < 128:
            is_ascii = False
            break

    # We have an ASCII string.
    if is_ascii:
        return is_ascii

    if isinstance(bytes_in, py2to3.UNICODE_TYPE):
        return True

    # Check if this is UTF-8
    try:
        bytes_in.decode("utf-8")
        return True

    except UnicodeDecodeError:
        pass

    if encoding:
        try:
            bytes_in.decode(encoding)
            return True

        except LookupError:
            logging.error("Unsupported encoding: {0:s}".format(encoding))
        except UnicodeDecodeError:
            pass

    return False