(domain, case_id, attachment_id, filesize_limit=0, width_limit=0, height_limit=0, fixed_size=None)
return meta, stream
Return (metadata, stream) information of best matching image attachment.

    :param attachment_id: the identifier of the attachment to fetch
Return (metadata, stream) information of best matching image attachment.
Return ( metadata stream ) information of best matching image attachment .
def fetch_case_image(domain, case_id, attachment_id, filesize_limit=0, width_limit=0, height_limit=0, fixed_size=None):
    """
    Return (metadata, stream) information of best matching image attachment.

    :param attachment_id: the identifier of the attachment to fetch
    """
    if fixed_size is not None:
        size_key = fixed_size
    else:
        size_key = OBJECT_ORIGINAL

    constraint_dict = {}
    if filesize_limit:
        constraint_dict['content_length'] = filesize_limit

    if height_limit:
        constraint_dict['height'] = height_limit

    if width_limit:
        constraint_dict['width'] = width_limit
    do_constrain = bool(constraint_dict)

    cached_image = get_cached_case_attachment(domain, case_id, attachment_id, is_image=True)
    meta, stream = cached_image.get(size_key=size_key)

    if do_constrain:
        def meets_constraint(constraints, meta):
            for c, limit in constraints.items():
                if meta[c] > limit:
                    return False
            return True

        if not meets_constraint(constraint_dict, meta):
            # this meta is no good, find another one
            lesser_keys = IMAGE_SIZE_ORDERING[0:IMAGE_SIZE_ORDERING.index(size_key)]
            lesser_keys.reverse()
            is_met = False
            for lesser_size in lesser_keys:
                less_meta, less_stream = cached_image.get_size(lesser_size)
                if meets_constraint(constraint_dict, less_meta):
                    meta = less_meta
                    stream = less_stream
                    is_met = True
                    break
            if not is_met:
                meta = None
                stream = None

    return meta, stream
def fetch_case_image ( domain , case_id , attachment_id , filesize_limit = 0 , width_limit = 0 , height_limit = 0 , fixed_size = None ) : if fixed_size is not None : size_key = fixed_size else : size_key = OBJECT_ORIGINAL constraint_dict = { } if filesize_limit : constraint_dict [ 'content_length' ] = filesize_limit if height_limit : constraint_dict [ 'height' ] = height_limit if width_limit : constraint_dict [ 'width' ] = width_limit do_constrain = bool ( constraint_dict ) cached_image = get_cached_case_attachment ( domain , case_id , attachment_id , is_image = True ) meta , stream = cached_image . get ( size_key = size_key ) if do_constrain : def meets_constraint ( constraints , meta ) : for c , limit in constraints . items ( ) : if meta [ c ] > limit : return False return True if not meets_constraint ( constraint_dict , meta ) : # this meta is no good, find another one lesser_keys = IMAGE_SIZE_ORDERING [ 0 : IMAGE_SIZE_ORDERING . index ( size_key ) ] lesser_keys . reverse ( ) is_met = False for lesser_size in lesser_keys : less_meta , less_stream = cached_image . get_size ( lesser_size ) if meets_constraint ( constraint_dict , less_meta ) : meta = less_meta stream = less_stream is_met = True break if not is_met : meta = None stream = None return meta , stream