'Perform preliminary non-db specific lookup checks and conversions'

def get_prep_lookup(self, lookup_type, value):

    if hasattr(value, 'prepare'):
        return value.prepare()
    if hasattr(value, '_prepare'):
        return value._prepare()
    if (lookup_type in ('regex', 'iregex', 'month', 'day', 'week_day', 'search', 'contains', 'icontains', 'iexact', 'startswith', 'istartswith', 'endswith', 'iendswith', 'isnull')):
        return value
    elif (lookup_type in ('exact', 'gt', 'gte', 'lt', 'lte')):
        return self.get_prep_value(value)
    elif (lookup_type in ('range', 'in')):
        return [self.get_prep_value(v) for v in value]
    elif (lookup_type == 'year'):
        try:
            return int(value)
        except ValueError:
            raise ValueError('The    __year    lookup    type    requires    an    integer    argument')
    raise TypeError(('Field    has    invalid    lookup:    %s' % lookup_type))
