Jump to >

reviewboard.attachments.mimetypes

register_mimetype_handler(handler)[source]

Register a MimetypeHandler class.

This will register a Mimetype Handler used by Review Board to render thumbnails for the file attachements across different mimetypes.

Only MimetypeHandler subclasses are supported.

unregister_mimetype_handler(handler)[source]

Unregister a MimetypeHandler class.

This will unregister a previously registered mimetype handler.

Only MimetypeHandler subclasses are supported. The class must ahve been registered beforehand or a ValueError will be thrown.

score_match(pattern, mimetype)[source]

Return a score for how well the pattern matches the mimetype.

This is an ordered list of precedence (_ indicates non-match):

Format Precedence
Type/Vendor+Subtype 2
Type/_     +Subtype 1.9
Type/* 1.8
*/Vendor+Subtype 1.7
*/_     +Subtype 1.6
Type/_ 1
*/_ 0.7
class MimetypeHandler(attachment, mimetype)[source]

Bases: object

Handles mimetype-specific properties.

This class also acts as a generic handler for mimetypes not matched explicitly by any handler. Note that this is not the same as ‘/’.

MIMETYPES_DIR = u’rb/images/mimetypes’[source]
supported_mimetypes = [][source]
use_hd_thumbnails = True[source]

Subclasses (especially in extensions) can use this to introspect what size thumbnails they should generate.

__init__(attachment, mimetype)[source]

Initialize the handler.

classmethod get_best_handler(mimetype)[source]

Return the handler and score that that best fit the mimetype.

classmethod for_type(attachment)[source]

Return the handler that is the best fit for provided mimetype.

get_icon_url()[source]

Return the appropriate icon URL for this mimetype.

get_thumbnail()[source]

Return HTML that represents a preview of the attachment.

The outer-most object should have the class ‘file-thubmnail’.

set_thumbnail()[source]

Set the thumbnail data.

This should be implemented by subclasses if they need the thumbnail to be generated client-side.

class ImageMimetype(attachment, mimetype)[source]

Bases: reviewboard.attachments.mimetypes.MimetypeHandler

Handles image mimetypes.

supported_mimetypes = [u’image/*’][source]
get_thumbnail()[source]

Return a thumbnail of the image.

class TextMimetype(attachment, mimetype)[source]

Bases: reviewboard.attachments.mimetypes.MimetypeHandler

Handles text mimetypes.

supported_mimetypes = [u’text/*’][source]
FILE_CROP_CHAR_LIMIT = 1000[source]
TEXT_CROP_NUM_HEIGHT = 50[source]
get_thumbnail()[source]

Return the thumbnail of the text file as rendered as html.

class ReStructuredTextMimetype(attachment, mimetype)[source]

Bases: reviewboard.attachments.mimetypes.TextMimetype

Handles ReStructuredText (.rst) mimetypes.

supported_mimetypes = [u’text/x-rst’, u’text/rst’][source]
class MarkDownMimetype(attachment, mimetype)[source]

Bases: reviewboard.attachments.mimetypes.TextMimetype

Handle MarkDown (.md) mimetypes.

supported_mimetypes = [u’text/x-markdown’, u’text/markdown’][source]