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

def get_prep_lookup(self, lookup_type, value):

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