'Get the spec to use for a query.'

def __query_spec(self):

    operators = self.__modifiers.copy()
    if self.__ordering:
        operators['$orderby'] = self.__ordering
    if self.__explain:
        operators['$explain'] = True
    if self.__hint:
        operators['$hint'] = self.__hint
    if self.__comment:
        operators['$comment'] = self.__comment
    if self.__max_scan:
        operators['$maxScan'] = self.__max_scan
    if (self.__max_time_ms is not None):
        operators['$maxTimeMS'] = self.__max_time_ms
    if self.__max:
        operators['$max'] = self.__max
    if self.__min:
        operators['$min'] = self.__min
    if self.__return_key:
        operators['$returnKey'] = self.__return_key
    if self.__show_record_id:
        operators['$showDiskLoc'] = self.__show_record_id
    if self.__snapshot:
        operators['$snapshot'] = self.__snapshot
    if operators:
        spec = self.__spec.copy()
        if ('$query' not in spec):
            spec = SON([('$query', spec)])
        if (not isinstance(spec, SON)):
            spec = SON(spec)
        spec.update(operators)
        return spec
    elif (('query' in self.__spec) and ((len(self.__spec) == 1) or (next(iter(self.__spec)) == 'query'))):
        return SON({'$query': self.__spec})
    return self.__spec
