
]VMc           @   s  d  Z  d d k l Z d d k l Z l Z l Z l Z d d k l	 Z	 d d k
 l Z d d k l Z l Z l Z l Z d d k l Z d d k l Z l Z d d	 k l Z d
 Z e Z d Z e i Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ  d e f d     YZ! d d e" d e" e# d  Z$ d e f d     YZ% e# e# e" d  Z& d S(   sM   
The main QuerySet implementation. This provides the public API for the ORM.
i(   t   izip(   t   connectionst   routert   transactiont   IntegrityError(   t	   Aggregate(   t	   DateField(   t   Qt   select_related_descendt   deferred_class_factoryt   InvalidQuery(   t	   Collector(   t   signalst   sql(   t   deepcopyid   i   t   QuerySetc           B   sB  e  Z d  Z d6 d6 d6 d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d6 d  Z d   Z d   Z e e _ d   Z e e _ d   Z e e _ d   Z d   Z d   Z d d  Z  d   Z! d   Z" d   Z# d    Z$ d!   Z% d"   Z& d#   Z' d$   Z( d%   Z) d&   Z* e d'  Z+ d6 d6 d6 d6 d6 d6 d(  Z, d)   Z- d*   Z. d+   Z/ d,   Z0 d-   Z1 e2 e1  Z1 e2 d.    Z3 d6 e4 d/  Z5 d6 d0  Z6 d1   Z7 d2   Z8 d3   Z9 d4   Z: d5   Z; e Z< RS(7   sA   
    Represents a lazy database lookup for a set of objects.
    c         C   sV   | |  _  | |  _ | p t i |  i   |  _ d  |  _ d  |  _ t |  _	 t |  _
 d  S(   N(   t   modelt   _dbR   t   Queryt   queryt   Nonet   _result_cachet   _itert   Falset   _sticky_filtert
   _for_write(   t   selfR   R   t   using(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __init__   s    					c         C   sd   |  i    } xQ |  i i   D]@ \ } } | d j o d | i | <q t | |  | i | <q W| S(   sD   
        Deep copy of a QuerySet doesn't populate the cache
        R   R   (   s   _iters   _result_cacheN(   t	   __class__t   __dict__t   itemsR   R   (   R   t   memot   objt   kt   v(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __deepcopy__-   s     c         C   s'   t  |   |  i i   } d | d <| S(   s4   
        Allows the QuerySet to be pickled.
        R   N(   t   lenR   t   copyR   (   R   t   obj_dict(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __getstate__9   s    

c         C   s?   t  |  t d   } t |  t j o d | d <n t |  S(   Ni   s$   ...(remaining elements truncated)...i(   t   listt   REPR_OUTPUT_SIZER%   t   repr(   R   t   data(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __repr__D   s    c         C   sw   |  i  d  j o9 |  i o t |  i  |  _  qj t |  i    |  _  n" |  i o |  i  i |  i  n t |  i   S(   N(   R   R   R   R)   t   iteratort   extendR%   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __len__J   s    

c         C   sN   |  i  d  j o |  i   |  _ g  |  _  n |  i o |  i   St |  i   S(   N(   R   R   R.   R   t   _result_itert   iter(   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __iter__W   s    
c         c   s   d } xu t  |  i  } x( | | j  o |  i | V| d } q W|  i p
 t  n t  |  i  | j o |  i   q	 q	 d  S(   Ni    i   (   R%   R   R   t   StopIterationt   _fill_cache(   R   t   post   upper(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR1   a   s     

c         C   sM   |  i  d  j	 o t |  i   Sy t |   i   Wn t j
 o t SXt S(   N(   R   R   t   boolR2   t   nextR4   R   t   True(   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __nonzero__m   s    c         C   s   d } |  i  d  j	 o= | |  i  j o t S|  i d  j o t St |  i   } n t |   } xn t of t |  i   | j o |  i d d  n |  i d  j o t S|  i  | | j o t S| d 7} qb Wd  S(   Ni    t   numi   (   R   R   R:   R   R   R%   R2   R5   (   R   t   valR6   t   it(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __contains__v   s"     c         C   sY  t  | t t t f  p
 t  n t  | t  o | d j pZ t  | t  o@ | i d j p | i d j o  | i d j p | i d j p
 t d  |  i	 d j	 o |  i
 d j	 o t  | t  o- | i d j	 o t | i  } qd } n | d } t |  i	  | j  o |  i | t |  i	   q:n |  i	 | St  | t  o |  i   } | i d j	 o t | i  } n d } | i d j	 o t | i  } n d } | i i | |  | i o t |  d d | i  p | Sy5 |  i   } | i i | | d  t |  d SWn* |  i i j
 o } t | i   n Xd S(   sE   
        Retrieves an item or slice from the set of results.
        i    s#   Negative indexing is not supported.i   N(   t
   isinstancet   slicet   intt   longt	   TypeErrort   startR   t   stopt   AssertionErrorR   R   R%   R5   t   _cloneR   t
   set_limitst   stepR)   R   t   DoesNotExistt
   IndexErrort   args(   R   R"   t   boundt   qsRE   RF   t   e(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __getitem__   s@    
0#

",c         C   sQ   |  i  |  t | t  o | i   S|  i   } | i i | i t i  | S(   N(   t   _merge_sanity_checkR@   t   EmptyQuerySetRH   R   t   combineR   t   AND(   R   t   othert   combined(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __and__   s    c         C   sK   |  i  |  |  i   } t | t  o | S| i i | i t i  | S(   N(   RR   RH   R@   RS   R   RT   R   t   OR(   R   RV   RW   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   __or__   s    c         c   ss  |  i  i } t | t  o
 | } n d } |  i  i } |  i  i i   } |  i  i i   } |  i  i	   } | p% |  i
 i i } |  i
 i i   } n t |  }	 |	 t |  i
 i i  }
 g  } | o x |  i
 i i   D] \ } } | d j o |  i
 } n | |  i
 i i j o t |  } n y, | i | | j o | i | i  n Wq t j
 o | i | i  q Xq Wn d } | or | oj t   } g  } xB | D]: } | i | j o | i | i  q| i | i  qWt |  i
 |  } n |  i } |  i
 } |  i  i d |  } xD| i   D]6} | o@ t | | |	 d | d | d | d t |  d | \ } } ni | o6 | |	 |
 !} | | } | t t | |     } n | | |	 |
 !  } | | i _ t | i _ | o5 x2 t  |  D]  \ } } t! | | | |  qWn | o9 x6 t  |  D]$ \ } } t! | | | | |
  q:Wn | Vq5Wd S(   sc   
        An iterator over the results from applying this QuerySet to the
        database.
        R   t	   max_deptht	   requestedt   offsett	   only_loadN("   R   t   select_relatedR@   t   dictR   R[   t   extra_selectt   keyst   aggregate_selectt   get_loaded_field_namesR   t   _metat   fieldst   pk_indexR%   t   get_fields_with_modelt   pkt   namet   appendt   KeyErrort   sett   addt   attnameR	   t   dbt   get_compilert   results_itert   get_cached_rowt   zipt   _stateR   t   addingt	   enumeratet   setattr(   R   t
   fill_cacheR\   R[   Ra   Rc   R^   Rf   t   pk_idxt   index_startt   aggregate_startt   load_fieldst   fieldR   t   skipt	   init_listt	   model_clsRp   t   compilert   rowR!   t   _t   row_datat   pk_valt   iR"   t	   aggregate(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR.      s|    
 	 		 	
   c      	   O   sy   x | D] } | | | i  <q W|  i i   } x6 | i   D]( \ } } | i | |  i | d t q: W| i d |  i  S(   s   
        Returns a dictionary containing the calculations (aggregation)
        over the current queryset

        If args is present the expression is passed as a kwarg using
        the Aggregate object's default alias.
        t
   is_summaryR   (	   t   default_aliasR   t   cloneR   t   add_aggregateR   R:   t   get_aggregationRp   (   R   RM   t   kwargst   argR   t   aliast   aggregate_expr(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   0  s      c         C   s?   |  i  d j	 o |  i o t |  i   S|  i i d |  i  S(   s   
        Performs a SELECT COUNT() and returns the number of records as an
        integer.

        If the QuerySet is already fully cached this simply returns the length
        of the cached results set to avoid multiple SELECT COUNT(*) calls.
        R   N(   R   R   R   R%   R   t	   get_countRp   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   countC  s    c         O   s   |  i  | |   } |  i i   o | i   } n t |  } | d j o | i d S| p# |  i i d |  i i i	   n |  i i
 d |  i i i	 | | f   d S(   sn   
        Performs the query and returns a single object matching the given
        keyword arguments.
        i   i    s!   %s matching query does not exist.sL   get() returned more than one %s -- it returned %s! Lookup parameters were %sN(   t   filterR   t
   can_filtert   order_byR%   R   R   RK   Re   t   object_namet   MultipleObjectsReturned(   R   RM   R   R   R<   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   getP  s    c         K   s5   |  i  |   } t |  _ | i d t d |  i  | S(   s   
        Creates a new object with the given kwargs, saving it to the database
        and returning the created object.
        t   force_insertR   (   R   R:   R   t   saveRp   (   R   R   R!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   createa  s    	c         K   s  | p
 t  d  | i d h   } | i   } xD |  i i i D]3 } | i | j o | i | i  | | i <q? q? Wy  t |  _	 |  i
 |   t f SWn8|  i i j
 o&y t g  } | i   D]* \ } } d | j o | | | f q q ~  } | i |  |  i |   }	 t i d |  i  }
 |	 i d t d |  i  t i |
 d |  i |	 t f SWqt j
 oX } t i |
 d |  i y |  i
 |   t f SWq|  i i j
 o |  qXqXn Xd S(   s   
        Looks up an object with the given kwargs, creating one if necessary.
        Returns a tuple of (object, created), where created is a boolean
        specifying whether an object was created.
        s<   get_or_create() must be passed at least one keyword argumentt   defaultst   __R   R   N(   RG   t   popR&   R   Re   Rf   Ro   Rj   R:   R   R   R   RK   R`   R   t   updateR   t	   savepointRp   R   t   savepoint_commitR   t   savepoint_rollback(   R   R   R   t   lookupt   ft   _[1]R"   R#   t   paramsR!   t   sidRP   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   get_or_createk  s4    
 !	Jc         C   s   | p |  i  i i } t |  p
 t d  |  i i   p
 t d  |  i   } | i i d d  | i i	 d |  | i
   S(   s   
        Returns the latest object, according to the model's 'get_latest_by'
        option or optional given field_name.
        sO   latest() requires either a field_name parameter or 'get_latest_by' in the models2   Cannot change a query once a slice has been taken.t   highi   s   -%s(   R   Re   t   get_latest_byR8   RG   R   R   RH   RI   t   add_orderingR   (   R   t
   field_namet	   latest_byR!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   latest  s    c         C   s   |  i  i   p
 t d  t | t t t t f  p
 t d  | p h  S|  i   } | i  i	 d | f  | i  i
 d t  t g  } | i   D] } | | i   | f q ~  S(   sh   
        Returns a dictionary mapping each of the given IDs to the object with
        that ID.
        s+   Cannot use 'limit' or 'offset' with in_bulks.   in_bulk() must be provided with a list of IDs.t   pk__int   force_empty(   R   R   RG   R@   t   tupleR)   Rm   t	   frozensetRH   t
   add_filtert   clear_orderingR:   R`   R.   t   _get_pk_val(   R   t   id_listRO   R   R!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   in_bulk  s    c         C   s~   |  i  i   p
 t d  |  i   } t | _ t | i  _ | i  i   t	 d | i
  } | i |  | i   d |  _ d S(   s>   
        Deletes the records in the current QuerySet.
        s+   Cannot use 'limit' or 'offset' with delete.R   N(   R   R   RG   RH   R:   R   R   R_   R   R   Rp   t   collectt   deleteR   R   (   R   t	   del_queryt	   collector(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    	
c         K   s   |  i  i   p
 t d  t |  _ |  i  i t i  } | i |  t	 i
 d |  i  p t	 i d |  i  t } n t } zP | i |  i  i d  } | o t	 i d |  i  n t	 i d |  i  Wd | o t	 i d |  i  n Xd |  _ | S(   s   
        Updates all elements in the current QuerySet, setting all the given
        fields to the appropriate values.
        s2   Cannot update a query once a slice has been taken.R   N(   R   R   RG   R:   R   R   R   t   UpdateQueryt   add_update_valuesR   t
   is_managedRp   t   enter_transaction_managementR   Rq   t   execute_sqlR   t   committ   commit_unless_managedt   leave_transaction_managementR   (   R   R   R   t   forced_managedt   rows(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s$    	
	c         C   s^   |  i  i   p
 t d  |  i  i t i  } | i |  d |  _ | i	 |  i
  i d  S(   s  
        A version of update that accepts field objects instead of field names.
        Used primarily for model saving and not intended for use by general
        code (it requires too much poking around at model internals to be
        useful at that level).
        s2   Cannot update a query once a slice has been taken.N(   R   R   RG   R   R   R   t   add_update_fieldsR   R   Rq   Rp   R   (   R   t   valuesR   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   _update  s    	c         C   s4   |  i  d  j o |  i i d |  i  St |  i   S(   NR   (   R   R   R   t   has_resultsRp   R8   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   exists  s    c         G   s   |  i  d t d t d |  S(   Nt   klasst   setupt   _fields(   RH   t   ValuesQuerySetR:   (   R   Rf   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c      	   O   s   | i  d t  } | o t d | i   f   n | o# t |  d j o t d   n |  i d t d t d | d |  S(   Nt   flats/   Unexpected keyword arguments to values_list: %si   sH   'flat' is not valid when values_list is called with more than one field.R   R   R   (   R   R   RD   Rb   R%   RH   t   ValuesListQuerySetR:   (   R   Rf   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   values_list  s    t   ASCc         C   sV   | d j p
 t  d  | d j p
 t  d  |  i d t d	 t d
 | d | d |  S(   s   
        Returns a list of datetime objects representing all available dates for
        the given field_name, scoped to 'kind'.
        t   montht   yeart   days/   'kind' must be one of 'year', 'month' or 'day'.R   t   DESCs'   'order' must be either 'ASC' or 'DESC'.R   R   t   _field_namet   _kindt   _order(   R   R   R   (   R   R   (   RG   RH   t   DateQuerySetR:   (   R   R   t   kindt   order(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   dates  s    c         C   s   |  i  d t  S(   s,   
        Returns an empty QuerySet.
        R   (   RH   RS   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   none  s    c         C   s
   |  i    S(   s   
        Returns a new QuerySet that is a copy of the current one. This allows a
        QuerySet to proxy for a model manager in some cases.
        (   RH   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   all  s    c         O   s   |  i  t | |  S(   sb   
        Returns a new QuerySet instance with the args ANDed to the existing
        set.
        (   t   _filter_or_excludeR   (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   !  s    c         O   s   |  i  t | |  S(   sd   
        Returns a new QuerySet instance with NOT (args) ANDed to the existing
        set.
        (   R   R:   (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   exclude(  s    c         O   sz   | p | o |  i  i   p
 t d  n |  i   } | o | i  i t | |    n | i  i t | |    | S(   Ns2   Cannot filter a query once a slice has been taken.(   R   R   RG   RH   t   add_qR   (   R   t   negateRM   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   /  s    c         C   sU   t  | t  p t | d  o! |  i   } | i i |  | S|  i d |  Sd S(   so  
        Returns a new QuerySet instance with filter_obj added to the filters.

        filter_obj can be a Q object (or anything with an add_to_query()
        method) or a dictionary of keyword lookup arguments.

        This exists to support framework features such as 'limit_choices_to',
        and usually it will be more natural to use other methods.
        t   add_to_queryN(   R@   R   t   hasattrRH   R   R   R   R   (   R   t
   filter_objR   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   complex_filter;  s
    
 c         O   s   | i  d d  } | o t d | i   f   n |  i   } | o+ | o t d   n | i i |  n t | i _ | o | | i _ n | S(   s   
        Returns a new QuerySet instance that will select related objects.

        If fields are specified, they must be ForeignKey fields and only those
        related objects are included in the selection.
        t   depthi    s2   Unexpected keyword arguments to select_related: %ss7   Cannot pass both "depth" and fields to select_related()(	   R   RD   Rb   RH   R   t   add_select_relatedR:   R_   R[   (   R   Rf   R   R   R!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR_   L  s    c         C   s   | i  i |  i  _ d S(   sp   
        Copies the related selection status from the QuerySet 'other' to the
        current QuerySet.
        N(   R   R_   (   R   RV   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   dup_select_relatedb  s    c   	      O   s  xB | D]: } | i  | j o t d | i    n | | | i  <q Wt |  d d  } | d j o t |  i i i    } n x/ | D]' } | | j o t d |   q q W|  i   } | i	 | i
    x9 | i   D]+ \ } } | i i | |  i | d t q W| S(   s   
        Return a query set in which the returned objects have been annotated
        with data aggregated from related fields.
        sQ   The named annotation '%s' conflicts with the default name for another annotation.R   s8   The annotation '%s' conflicts with a field on the model.R   N(   R   t
   ValueErrort   getattrR   Rm   R   Re   t   get_all_field_namesRH   t   _setup_aggregate_queryRb   R   R   R   R   (	   R   RM   R   R   t   namesR   R!   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   annotatei  s*       c         G   sG   |  i  i   p
 t d  |  i   } | i  i   | i  i |   | S(   sL   
        Returns a new QuerySet instance with the ordering changed.
        s3   Cannot reorder a query once a slice has been taken.(   R   R   RG   RH   R   R   (   R   t   field_namesR!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         C   s   |  i    } | | i _ | S(   sY   
        Returns a new QuerySet instance that will select only distinct results.
        (   RH   R   t   distinct(   R   t   true_or_falseR!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         C   sI   |  i  i   p
 t d  |  i   } | i  i | | | | | |  | S(   s8   
        Adds extra SQL fragments to the query.
        s1   Cannot change a query once a slice has been taken(   R   R   RG   RH   t	   add_extra(   R   t   selectt   whereR   t   tablesR   t   select_paramsR   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   extra  s
    c         C   s#   |  i    } | i i | i _ | S(   s8   
        Reverses the ordering of the QuerySet.
        (   RH   R   t   standard_ordering(   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   reverse  s    c         G   s>   |  i    } | d j o | i i   n | i i |  | S(   sU  
        Defers the loading of data for certain fields until they are accessed.
        The set of fields to defer is added to any existing set of deferred
        fields. The only exception to this is if None is passed in as the only
        parameter, in which case all deferrals are removed (None acts as a
        reset option).
        N(   N(   RH   R   R   t   clear_deferred_loadingt   add_deferred_loading(   R   Rf   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   defer  s
    c         G   s=   | d j o t d   n |  i   } | i i |  | S(   s   
        Essentially, the opposite of defer. Only the fields passed into this
        method and that are not already specified as deferred are loaded
        immediately when the queryset is evaluated.
        s*   Cannot pass None as an argument to only().N(   N(   R   RD   RH   R   t   add_immediate_loading(   R   Rf   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   only  s
    c         C   s   |  i    } | | _ | S(   sZ   
        Selects which database this QuerySet should excecute it's query against.
        (   RH   R   (   R   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    	c         C   sL   |  i  i p |  i  i o t S|  i  i o |  i  i i i o t St Sd S(   s   
        Returns True if the QuerySet is ordered -- i.e. has an order_by()
        clause or a default ordering on the model.
        N(	   R   t   extra_order_byR   R:   t   default_orderingR   Re   t   orderingR   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   ordered  s
     c         C   s?   |  i  o |  i p t i |  i  S|  i p t i |  i  S(   sC   Return the database that will be used if this query is executed now(   R   R   R   t   db_for_writeR   t   db_for_read(   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRp     s    
c         K   s   | d  j o |  i } n |  i i   } |  i o t | _ n | d |  i d | d |  i  } |  i	 | _	 | i
 i |  | o t | d  o | i   n | S(   NR   R   R   t   _setup_query(   R   R   R   R   R   R:   t   filter_is_stickyR   R   R   R   R   R   R  (   R   R   R   R   R   t   c(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH     s    
!c         C   sl   |  i  o^ y; x4 t | p t  D] } |  i i |  i  i    q! WWqh t j
 o d |  _  qh Xn d S(   sv   
        Fills the result cache with 'num' more entries (or until the results
        iterator is exhausted).
        N(   R   t   ranget   ITER_CHUNK_SIZER   Rk   R9   R4   R   (   R   R<   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR5     s    
 !c         C   s   t  |  _ |  S(   s  
        Indicates that the next filter call and the one following that should
        be treated as a single filter. This is only important when it comes to
        determining when to reuse tables for many-to-many filters. Required so
        that we can filter naturally on the results of related managers.

        This doesn't return a clone of the current QuerySet (it returns
        "self"). The method is only used internally and should be immediately
        followed by a filter() that does create a clone.
        (   R:   R   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   _next_is_sticky  s    	c         C   s   d S(   s   
        Checks that we are merging two comparable QuerySet classes. By default
        this does nothing, but see the ValuesQuerySet for an example of where
        it's useful.
        N(    (   R   RV   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRR     s    c         C   sn   |  i  i } |  i i d j oK g  } | i D] } | | i q- ~ } |  i i | t  |  i i	   n d S(   s_   
        Prepare the query for computing a result that contains aggregate annotations.
        N(
   R   Re   R   t   group_byR   Rf   Ro   t
   add_fieldsR   t   set_group_by(   R   t
   aggregatest   optsR   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s
    'c         C   s   |  S(   N(    (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   _prepare(  s    c         C   s]   |  i  d  } | i d j p | t | i j o | i i d |  i   St d   d S(   sO   
        Returns the internal query's SQL and parameters (as a tuple).
        Ri   t
   connections2   Can't do subqueries with queries on different DBs.N(   R   R   R   R   R   Rq   t   as_nested_sqlR   (   R   R  R!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   _as_sql+  s    $N(=   t   __name__t
   __module__t   __doc__R   R   R$   R(   R-   R0   R3   R1   R;   R?   RQ   RX   RZ   R.   R   R   R   R   R   R   R   R   R:   t   alters_dataR   R   R   R   R   R   R   R   R   R   R   R   R_   R   R   R   R   R   R   R   R  R   R  t   propertyRp   R   RH   R5   R  RR   R   R  R  t   value_annotation(    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR      sv   					
					.			Z				
	 											
	
									
								
		R   c           B   sV   e  Z d    Z d   Z d   Z d e d  Z d   Z d   Z	 d   Z
 d   Z RS(	   c         O   s)   t  t |   i | |   t |  i _ d  S(   N(   t   superR   R   R   R   R_   (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   9  s    c         c   sy   |  i  i i   } |  i } |  i  i i   } | | | } x7 |  i  i |  i  i   D] } t t	 | |   VqW Wd  S(   N(
   R   Ra   Rb   R   Rc   Rq   Rp   Rr   R`   Rt   (   R   t   extra_namesR   t   aggregate_namesR   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR.   A  s    	 c         C   s  |  i  i   |  i  i   |  i o g  |  _ g  |  _ |  i  i o$ |  i  i o t |  i  |  _	 q5t
 |  i  _ g  |  _	 x |  i D]d } | |  i  i j o |  i i |  q | |  i  i j o |  i i |  q |  i	 i |  q WnC d |  _ g  } |  i i i D] } | | i q~ |  _	 d |  _ g  |  i  _ |  i d j	 o |  i  i |  i  n |  i  i |  i	 t  |  i d j	 o |  i  i |  i  n d S(   s   
        Constructs the field_names list that the values query will be
        retrieving.

        Called by the _clone() method after initializing the rest of the
        instance.
        N(   R   R   t   clear_select_fieldsR   R  R  R   R  R)   R   R   t   default_colsRk   Rc   R   R   Re   Rf   Ro   R   t   set_extra_maskR  R:   t   set_aggregate_mask(   R   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR  L  s2    
			
 	0	c         K   s   t  t |   i | |  } t | d  p |  i | _ n |  i | _ |  i | _ |  i | _ | o t | d  o | i   n | S(   sH   
        Cloning a ValuesQuerySet preserves the current fields.
        R   R  (	   R  R   RH   R   R   R   R  R  R  (   R   R   R   R   R
  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH   x  s    c         C   s   t  t |   i |  t |  i  t | i  j p2 t |  i  t | i  j p |  i | i j o t d |  i i	   n d  S(   Ns?   Merging '%s' classes must involve the same values in each case.(
   R  R   RR   Rm   R  R   R  RD   R   R  (   R   RV   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRR     s    c         C   s^   |  i  i   |  i d j	 o' |  i i |  |  i  i |  i  n t t |   i |  d S(   s_   
        Prepare the query for computing a result that contains aggregate annotations.
        N(	   R   R  R  R   R/   R#  R  R   R   (   R   R  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s
    c         C   s   |  i  o t |  i   d j p' |  i  o6 t |  i i i  d j o t d |  i i   n |  i   } | i	 d j p | t | i	 j o | i i d |  i   St d   d S(   s^  
        For ValueQuerySet (and subclasses like ValuesListQuerySet), they can
        only be used as nested queries if they're already set up to select only
        a single field (in which case, that is the field column that is
        returned). This differs from QuerySet.as_sql(), where the column to
        select is set up by Django.
        i   s.   Cannot use a multi-field %s as a filter value.R  s2   Can't do subqueries with queries on different DBs.N(   R   R%   R   Re   Rf   RD   R   R  RH   R   R   R   R   Rq   R  R   (   R   R  R!   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR    s     '$c         C   se   |  i  o t |  i   d j p' |  i  o6 t |  i i i  d j o t d |  i i   n |  S(   s   
        Validates that we aren't trying to do a query like
        value__in=qs.values('value1', 'value2'), which isn't valid.
        i   s.   Cannot use a multi-field %s as a filter value.(   R   R%   R   Re   Rf   RD   R   R  (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR    s
     'N(   R  R  R   R.   R  R   R   RH   RR   R   R  R  (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   8  s   			,			R   c           B   s   e  Z d    Z d   Z RS(   c   
      #   s    i  oI t   i  d j o3 xZ  i i   i  i   D] } | d Vq< Wn+  i i oC   i i o5 x  i i   i  i   D] } t	 |  Vq Wn   i i i
   }   i }   i i i
   } | | | }   i o) t   i  t   f d   |  } n | } xb   i i   i  i   D]E } t t | |   } t	 g  } | D] }	 | | |	 q]~  Vq4Wd  S(   Ni   i    c            s   |    i  j S(    (   R   (   R   (   R   (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   <lambda>  s    (   R   R%   R   R   Rq   Rp   Rr   Ra   Rc   R   Rb   R   R)   R   R`   Rt   (
   R   R   R  R   R  R   Rf   R,   R   R   (    (   R   s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR.     s&       	
) c         O   s?   t  t |   i | |   } t | d  p |  i | _ n | S(   NR   (   R  R   RH   R   R   (   R   RM   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH     s    (   R  R  R.   RH   (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s   	R   c           B   s)   e  Z d    Z d   Z d e d  Z RS(   c         C   s   |  i  i |  i  i   S(   N(   R   Rq   Rp   Rr   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR.     s    c         C   s]   |  i  i   |  i  i d t i d t  |  _  g  |  i  _ |  i  i |  i |  i	 |  i
  d S(   s   
        Sets up any special features of the query attribute.

        Called by the _clone() method after initializing the rest of the
        instance.
        R   R   N(   R   R   R   R   t	   DateQueryR:   R   t   add_date_selectR   R   R   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR    s    !c         K   s_   t  t |   i | t |  } |  i | _ |  i | _ | o t | d  o | i   n | S(   NR  (   R  R   RH   R   R   R   R   R  (   R   R   R   R   R
  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH     s    N(   R  R  R.   R  R   R   RH   (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s   		RS   c           B   s   e  Z d d d d   Z d   Z d   Z d   Z d   Z d e d  Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z e d  Z d d d d d d d  Z d   Z d   Z d   Z d   Z e Z RS(   c         C   s)   t  t |   i | | |  g  |  _ d  S(   N(   R  RS   R   R   (   R   R   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         C   s
   |  i    S(   N(   RH   (   R   RV   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRX     s    c         C   s
   | i    S(   N(   RH   (   R   RV   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRZ     s    c         C   s   d S(   Ni    (    (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         C   s   d  S(   N(    (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         K   s.   t  t |   i | d | | } g  | _ | S(   NR   (   R  RS   RH   R   (   R   R   R   R   R
  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH     s    !	c         c   s   t  g   i   Vd  S(   N(   R2   R9   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR.     s    c         C   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         O   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         O   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    c         C   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   $  s    c         O   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   Rf   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR_   *  s    c         O   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   RM   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   0  s    c         G   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   6  s    c         C   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   <  s    c         C   s   |  i  i   p
 t d  |  S(   s/   
        Always returns EmptyQuerySet.
        s1   Cannot change a query once a slice has been taken(   R   R   RG   (   R   R   R   R   R   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   B  s    c         C   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   K  s    c         G   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   Rf   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   Q  s    c         G   s   |  S(   s/   
        Always returns EmptyQuerySet.
        (    (   R   Rf   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR  W  s    c         K   s   d S(   s(   
        Don't update anything.
        i    (    (   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   ]  s    N(   R  R  R   R   RX   RZ   R   R   R   RH   R.   R   R   R   R   R_   R   R   R:   R   R   R   R   R  R   R  (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRS     s,   																i    c
   "      C   sC  | o | d j o | | j o d S| d j	 }
 | oT | i |   } xH |  i i   D]- } | i |  } | o | i |  qX qX Wn d } | o t   } g  } xl |  i i   D][ \ } } | i | j o | i | i  q |	 o | d j	 o q q | i	 | i
  q Wt |  } | | | | !} | d | j o
 d } qG| o. t |  |  }  |  t t | |     } qG|  |   } n |	 o. g  } |  i i D] } | | i
 q~ } n+ g  } |  i i D] } | | i
 q~ } t |  } | | | | !} | d | j o
 d } n |  t t | |     } | o | | i _ t | i _ n | | | } x |  i i D] } t | |
 |  p qn |
 o | | i } n d } t | i i | | | | | d | d | } | ok | \ } } | d j	 o t | | i   |  n | i o* | d j	 o t | | i i   |  qcqqW|
 og  } |  i i   D]* } | i i o | | i | i f qq~ } x| D]u\ } } t | |
 | d t  p qn | | i!   } t | | | | | | d | d | d t  } | o| \ } } | d j	 o t | | i i   |  n | d j	 o t | | i   |  x | i i   D] \ } }  |  d j	 ov t | | i
 t" | | i
   | i oI y/ t" | | i    }! t | | i   |!  Wq!t# j
 o q!Xq%qqWq1qqWn | | f S(   s  
    Helper function that recursively returns an object with the specified
    related attributes already populated.

    This method may be called recursively to populate deep select_related()
    clauses.

    Arguments:
     * klass - the class to retrieve (and instantiate)
     * row - the row of data returned by the database cursor
     * index_start - the index of the row at which data for this
       object is known to start
     * using - the database alias on which the query is being executed.
     * max_depth - the maximum depth to which a select_related()
       relationship should be explored.
     * cur_depth - the current depth in the select_related() tree.
       Used in recursive calls to determin if we should dig deeper.
     * requested - A dictionary describing the select_related() tree
       that is to be retrieved. keys are field names; values are
       dictionaries describing the keys on that related object that
       are themselves to be select_related().
     * offset - the number of additional fields that are known to
       exist in `row` for `klass`. This usually means the number of
       annotated results on `klass`.
     * only_load - if the query has had only() or defer() applied,
       this is the list of field names that will be returned. If None,
       the full field list for `klass` can be assumed.
     * local_only - Only populate local fields. This is used when building
       following reverse select-related relations
    i   R^   R   t
   local_onlyN(   N(   N($   R   R   Re   t   get_parent_listR   Rm   Rh   Rj   Rn   Rk   Ro   R%   R	   R`   Rt   t   local_fieldsRf   Ru   Rp   R   Rv   R   Rs   t   relt   toRx   t   get_cache_namet   uniquet   relatedt   get_all_related_objectsR~   R   R:   t   related_query_nameR   t   AttributeError("   R   R   R{   R   R[   t	   cur_depthR\   R]   R^   R'  t
   restrictedR}   t   parentRf   R   R   R~   R   t   field_countR!   R   R   R   t   _[2]t	   index_endR9   t
   cached_rowt   rel_objt   _[3]t   ot   related_fieldst	   rel_fieldt	   rel_modelt
   cached_obj(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRs   h  s     ! 	 
.*
 %-  
!t   RawQuerySetc           B   sw   e  Z d  Z d	 d	 d	 d	 d	 d  Z d   Z d   Z d   Z e d    Z	 d   Z
 e d    Z e d    Z RS(
   sp   
    Provides an iterator which converts the results of raw SQL queries into
    annotated model instances.
    c         C   sj   | |  _  | |  _ | |  _ | p t i d | d |  i d |  |  _ | p d |  _ | p h  |  _ d  S(   NR   R   R   (    (	   t	   raw_queryR   R   R   t   RawQueryRp   R   R   t   translations(   R   RA  R   R   R   RC  R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR     s    			+c         c   s  h  } g  } |  i  } t | i i d  |  i t | |  } t | d  } t |  i  } xX t |  i  D]G \ } } | |  i	 j o | | |  i	 | i
 <ql | i | | f  ql Wt   }	 x; |  i i i D]* }
 |
 i
 | j o |	 i |
 i
  q q W|	 o? |  i i i i
 |	 j o t d   n t |  i |	  } n> |  i } g  } x+ |  i i i D] }
 | i | |
 i
  qcW| o7 g  } |  i D] } | |  i	 i | d   q~ } n x | D] } | o | i | |  } n |	 oA h  } x( | i   D] \ } } | | | | <qW| |   } n2 g  } | D] } | | | q<~ } | |   } | o/ x, | D]  \ } } t | | | |  qpWn | | i _  t | i _ | VqWd  S(   Nt   SQLCompilert   resolve_columnss&   Raw query must include the primary key(   Rp   R   t   opsR   R   R   R2   Rw   t   columnst   model_fieldsRo   Rk   Rm   R   Re   Rf   Rn   Ri   R
   R	   R   R   RE  t	   iteritemsRx   Ru   R   Rv   (   R   t   model_init_field_namest   annotation_fieldsRp   R   t   need_resolv_columnsR   R6   t   columnR   R~   R   t   model_init_field_posR   R
  Rf   R   t   model_init_kwargsRo   t   instanceR6  t   model_init_args(    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR3     s^    	 	 	 7  % c         C   s   d |  i  |  i S(   Ns   <RawQuerySet: %r>(   RA  R   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR-   _  s    c         C   s   t  |   | S(   N(   R)   (   R   R"   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRQ   b  s    c         C   s   |  i  p t i |  i  S(   sC   Return the database that will be used if this query is executed now(   R   R   R  R   (   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRp   e  s    c         C   sC   t  |  i d |  i d |  i i d |  d |  i d |  i d | S(   s^   
        Selects which database this Raw QuerySet should excecute it's query against.
        R   R   R   R   RC  (   R@  RA  R   R   R   R   RC  (   R   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR   j  s    c         C   s   t  |  d  po |  i i   |  _ xZ |  i i   D]E \ } } y# |  i i |  } | |  i | <Wq2 t j
 o q2 Xq2 Wn |  i S(   sg   
        A list of model field names in the order they'll appear in the
        query results.
        t   _columns(   R   R   t   get_columnsRR  RC  R   t   indexR   (   R   t
   query_namet
   model_nameRT  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRG  s  s     c         C   sv   t  |  d  p_ t |  i i i } h  |  _ x@ |  i i i D]+ } | i	   \ } } | |  i | |  <q< Wn |  i S(   sC   
        A dict mapping column names to model field names.
        t   _model_fields(
   R   R   Rp   t   introspectiont   table_name_converterRW  R   Re   Rf   t   get_attname_column(   R   t	   converterR~   Rj   RM  (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyRH    s    	 N(   R  R  R  R   R   R3   R-   RQ   R  Rp   R   RG  RH  (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyR@    s   		C				c         C   s8   t  i |   } | i | |  | i d |  i |  S(   s   
    Inserts a new record for the given model. This provides an interface to
    the InsertQuery class and is how Model.save() is implemented. It is not
    part of the public API.
    R   (   R   t   InsertQueryt   insert_valuesRq   R   (   R   R   t	   return_idt
   raw_valuesR   R   (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   insert_query  s    N('   R  t	   itertoolsR    t	   django.dbR   R   R   R   t   django.db.models.aggregatesR   t   django.db.models.fieldsR   t   django.db.models.query_utilsR   R   R	   R
   t   django.db.models.deletionR   t   django.db.modelsR   R   t   django.utils.copycompatR   t
   CHUNK_SIZER  R*   t   EmptyResultSett   objectR   R   R   R   RS   R   R   Rs   R@  R`  (    (    (    s@   /usr/local/lib/python2.6/dist-packages/django/db/models/query.pyt   <module>   s0   ""	    %q