human
Complete this python program:
def _numa_get_pagesize_constraints(flavor, image_meta):
assistant
#Here is the Python code you requested.

    """Return the requested memory page size
    :param flavor: a Flavor object to read extra specs from
    :param image_meta: nova.objects.ImageMeta object instance
    :raises: MemoryPageSizeInvalid if flavor extra spec or image
    metadata provides an invalid hugepage value
    :raises: MemoryPageSizeForbidden if flavor extra spec request
    conflicts with image metadata request
    :returns: a page size requested or MEMPAGES_*
    """
    def check_and_return_pages_size(request):
        if (request == 'any'):
            return MEMPAGES_ANY
        elif (request == 'large'):
            return MEMPAGES_LARGE
        elif (request == 'small'):
            return MEMPAGES_SMALL
        else:
            try:
                request = int(request)
            except ValueError:
                try:
                    request = (strutils.string_to_bytes(request, return_int=True) / units.Ki)
                except ValueError:
                    request = 0
        if (request <= 0):
            raise exception.MemoryPageSizeInvalid(pagesize=request)
        return request
    (flavor_request, image_request) = _get_flavor_image_meta('mem_page_size', flavor, image_meta)
    if ((not flavor_request) and image_request):
        raise exception.MemoryPageSizeForbidden(pagesize=image_request, against='<empty>')
    if (not flavor_request):
        return None
    pagesize = check_and_return_pages_size(flavor_request)
    if (image_request and (pagesize in (MEMPAGES_ANY, MEMPAGES_LARGE))):
        return check_and_return_pages_size(image_request)
    elif image_request:
        raise exception.MemoryPageSizeForbidden(pagesize=image_request, against=flavor_request)
    return pagesize