Make convert_to_unicode handle bytearray.

Some SCM backends (notably Perforce), when dealing with files which are marked
as binary but aren't actually binary, will return a bytearray instead of bytes.
This wasn't properly handled in our unicode conversion step. I've fixed it to
check if the input is a bytearray, and convert it to bytes if needed.

Testing done:
Manually called convert_to_unicode with a bytearray and saw that it no longer
raised an error.

Reviewed at https://reviews.reviewboard.org/r/6679/
Fix call to sanitize_illegal_chars_for_xml.

The newly-added sanitize_illegal_chars_for_xml method was being called after we
had encoded the unicode string into bytes, and doing the regular expression
substitution would then try to coerce those bytes back to unicode using the
ascii codec. Doing the sanitization on the unicode object, and then encoding to
bytes works correctly.

Testing done:
Ran unit tests. Before the fix, this failed with the same error as the reported
issue. After, it runs successfully.

Reviewed at https://reviews.reviewboard.org/r/6678/
Sandbox reviewboard.reviews.ui.ReviewUI

Extensions that create a FileAttachmentReviewUI subclass (using the
ReviewUIHook) can throw exceptions inside Review Board. The parts of Review
Board that call those methods have been sandboxed.

Now when a FileAttachmentReviewUI subclass from an extension throws an
exception, Review Board logs the errors with enough information to find which
method in the FileAttachmentReviewUI subclass threw the exception.

Testing Done:
Unit tests have been written to make sure that functions from an
FileAttachmentReviewUI subclass have been called, and when an exception is
thrown it gets logged.

The tests fail without the sanboxing, and succeed with it.

Reviewed at https://reviews.reviewboard.org/r/6551/
Sandbox reviewboard.attachments.mimetypes.MimetypeHandler

Extensions that create a MimetypeHandler subclass can throw exceptions inside
Review Board. The sections of Review Board that call those methods have been
sandboxed.

Now when a MimetypeHandler subclass from an extension throws an exception,
Review Board logs the errors. The error logs give enough information to find
which method in the MimetypeHandler subclass threw the exception.

Testing Done:
Unit tests have been written to make sure that functions from an
MimetypeHandler subclass have been called, and when an exception is thrown it
gets logged.

The tests fail without the sandboxing, and succeed with it.

Reviewed at https://reviews.reviewboard.org/r/6532/