'If the contents uses some known MIME types, check if it
conforms to the type. Throw a ValueError exception if not.
If the contents uses an uncheckable MIME type, don\'t check
it and don\'t throw an exception.
Returns True if the content was checked, False if it was not
checked.'

def check(self, contents):

    if (self.mimetype == 'application/xhtml+xml'):
        textoffset = 0
        stride = 1
        print u'Checking    text:{0}:'.format(contents[:10])
        if (contents[:3] == '\xef\xbb\xbf'):
            print u'Could    be    utf-8    with    BOM'
            textoffset = 3
        elif (contents[:2] == '\xfe\xff'):
            print u'Could    be        utf-16BE'
            textoffset = 3
            stride = 2
        elif (contents[:2] == '\xff\xfe'):
            print u'Could    be        utf-16LE'
            textoffset = 2
            stride = 2
        else:
            print u'Perhaps    utf-8    without    BOM'
        for i in xrange(textoffset, (textoffset + (5 * stride)), stride):
            if ((ord(contents[i]) < 32) or (ord(contents[i]) > 127)):
                print u'Bad    character    at    {0},    value    {1}'.format(i, ord(contents[i]))
                raise ValueError
        print u'Seems    to    be    good    text'
        return True
        if ((contents[:5] == '<?xml') or (contents[:8] == '\xef\xbb\xbf<?xml')):
            return True
        elif (contents[:14] == '\xfe\xff\x00<\x00?\x00x\x00m\x00l'):
            return True
        elif (contents[:14] == '\xff\xfe<\x00?\x00x\x00m\x00l\x00'):
            return True
        elif ((contents[:9] == '<!DOCTYPE') or (contents[:12] == '\xef\xbb\xbf<!DOCTYPE')):
            return True
        elif (contents[:22] == '\xfe\xff\x00<\x00!\x00D\x00O\x00C\x00T\x00Y\x00P\x00E'):
            return True
        elif (contents[:22] == '\xff\xfe<\x00!\x00D\x00O\x00C\x00T\x00Y\x00P\x00E\x00'):
            return True
        else:
            print u'Bad    XML:    {0}'.format(contents[:8])
            raise ValueError
    elif (self.mimetype == 'image/jpeg'):
        if (contents[:3] == '\xff\xd8\xff'):
            return True
        else:
            print u'Bad    JPEG:    {0}'.format(contents[:3].encode('hex'))
            raise ValueError()
    return False
