Fix missing variable declarations in auth backends.

The auth backends were attempting to decode UTF-8 username strings into
byte strings before operating on them, in order to convert them to a
format expected by the libraries providing authentication. If a byte
string is passed in, though, the variables are never declared, causing
errors.

This fixes this case, adding the missing variable declarations.

Reviewed at https://reviews.reviewboard.org/r/6672/
Add WebAPICapabilitiesHook, for adding capability listings to the API.

This introduces a new WebAPICapabilitiesHook that extensions can use to
register a set of custom web API capabilites, displaying in /api/ or
/api/info/.

This hook handles registering and unregistering the sets of web API
capabilities. Documentation and sample code was added, detailing the use
of the hook.

Reviewed at https://reviews.reviewboard.org/r/6613/
Fixed a very small typo in the Web API documentation.

In the documentation for Review Request Resource, the description of `approved`
should be "a review request is approved if it has at least one Ship It! and
*no* open issues."

Reviewed at https://reviews.reviewboard.org/r/6673/
Merge branch 'release-2.0.x'
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/
Merge branch 'release-2.0.x'
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/
Merge branch 'release-2.0.x'
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/
Merge branch 'release-2.0.x'