<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def data_uri(thumbnail):
 """ This filter will return the base64 encoded data URI for a given thumbnail object. Example usage:: {% thumbnail sample_image 25x25 crop as thumb %} <img src="{{ thumb|data_uri }}"> will for instance be rendered as: """

    try:
        thumbnail.open('rb')
        data = thumbnail.read()
    finally:
        thumbnail.close()
    mime_type = mimetypes.guess_type(str(thumbnail.file))[0] or 'application/octet-stream'
    data = b64encode(data).decode('utf-8')
    return 'data:{0};base64,{1}'.format(mime_type, data)