ó
O'—^c           @   s¿   d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z e  j d d k  rd e	 Z
 n e Z
 d Z i  Z e e d „ Z e d	 „ Z d
 „  Z d „  Z d „  Z e a d „  Z d S(   iÿÿÿÿN(   t   AutoFixture(   t   InvalidConstraint(   t   getargnamesi    i   s   0.12.1c         C   sŠ   d d l  m } t |  t ƒ r: | |  j d d ƒ Œ  }  n  | r| |  t k r| | rW d St d |  j j |  j j	 f ƒ ‚ n  | t |  <d S(   sß  
    Register a model with the registry.

    Arguments:

        *model* can be either a model class or a string that contains the model's
        app label and class name seperated by a dot, e.g. ``"app.ModelClass"``.

        *autofixture* is the :mod:`AutoFixture` subclass that shall be used to
        generated instances of *model*.

        By default :func:`register` will raise :exc:`ValueError` if the given
        *model* is already registered. You can overwrite the registered *model* if
        you pass ``True`` to the *overwrite* argument.

        The :exc:`ValueError` that is usually raised if a model is already
        registered can be suppressed by passing ``True`` to the *fail_silently*
        argument.
    i   (   t	   get_modelt   .Nup   %s.%s is already registered. You can overwrite the registered autofixture by providing the `overwrite` argument.(
   t   compatR   t
   isinstancet   string_typest   splitt   REGISTRYt
   ValueErrort   _metat	   app_labelt   object_name(   t   modelt   autofixturet	   overwritet   fail_silentlyR   (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyt   register   s    	c         C   sÊ   d d l  m } d d l m } t |  | j ƒ r> |  g }  n  x… |  D]} } t | t ƒ ru | | j d d ƒ Œ  } n  y t	 | =WqE t
 k
 rÁ | rœ qE n  t d | j j | j j f ƒ ‚ qE XqE Wd S(   sB   
    Remove one or more models from the autofixture registry.
    iÿÿÿÿ(   t   modelsi   (   R   R   u"   The model %s.%s is not registered.N(   t	   django.dbR   R   R   t
   issubclasst   ModelR   R   R   R	   t   KeyErrorR
   R   R   R   (   t   model_or_iterableR   R   R   R   (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyt
   unregister9   s     	c         O   sn   d d l  m } t |  t ƒ r: | |  j d d ƒ Œ  }  n  |  t k rZ t |  |  | | Ž St |  | | Ž Sd S(   s‚  
    Get an autofixture instance for the passed in *model* sing the either an
    appropiate autofixture that was :ref:`registry <registry>` or fall back
    to the default:class:`AutoFixture` class.  *model* can be a model class or
    its string representation (e.g.  ``"app.ModelClass"``).

    All positional and keyword arguments are passed to the autofixture
    constructor.
    i   (   R   R   N(   R   R   R   R   R   R	   R    (   R   t   argst   kwargsR   (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyt   getQ   s    
c   
      O   sÜ   d d l  m } t |  t ƒ r: | |  j d d ƒ Œ  }  n  |  t k rS t |  } n t } t t | j	 ƒ ƒ } | t d g ƒ 8} i  } x0 | D]( } | | k rŽ | j
 | ƒ | | <qŽ qŽ W| |  | | Ž }	 |	 j | |  S(   s¯  
    Create *count* instances of *model* using the either an appropiate
    autofixture that was :ref:`registry <registry>` or fall back to the
    default:class:`AutoFixture` class. *model* can be a model class or its
    string representation (e.g. ``"app.ModelClass"``).

    All positional and keyword arguments are passed to the autofixture
    constructor. It is demonstrated in the example below which will create ten
    superusers::

        import autofixture
        admins = autofixture.create('auth.User', 10, field_values={'is_superuser': True})

    .. note:: See :ref:`AutoFixture` for more information.

    :func:`create` will return a list of the created objects.
    i   (   R   R   t   self(   R   R   R   R   R   R	   R    t   setR   t
   create_onet   popt   create(
   R   t   countR   R   R   t   autofixture_classt   argnamest   create_kwargst   argnameR   (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyR!   e   s    c         O   s   t  |  d | | Ž d S(   sÀ   
    :func:`create_one` is exactly the as the :func:`create` function but a
    shortcut if you only want to generate one model instance.

    The function returns the instanciated model.
    i   i    (   R!   (   R   R   R   (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyR   ‹   s    c          C   s9  d d l  m }  t r d St a i  } d d l } y> d d l m } x' | j ƒ  D] } | j g | | j	 <qR WWnl t
 k
 rÞ d d l m } xL | j D]= } |  j | ƒ } y | j | | <Wqš t k
 rÖ qš qš Xqš Wn Xx¥ | j ƒ  D]— \ } } y | j d | ƒ \ }	 }
 }
 Wn t
 k
 r-qì n X|	 rA|	 j ƒ  n  y |  j d | ƒ Wqì t k
 r‚} t j d	 | | f ƒ qì Xqì Wx¥ | j ƒ  D]— \ } } y | j d
 | ƒ \ }	 }
 }
 Wn t
 k
 rÕq”n X|	 ré|	 j ƒ  n  y |  j d | ƒ Wq”t k
 r*} t j d | | f ƒ q”Xq”Wt a d S(   sÅ   
    Auto-discover INSTALLED_APPS autofixtures.py and tests.py modules and fail
    silently when not present. This forces an import on them to register any
    autofixture bits they may want.
    i   (   t	   importlibNiÿÿÿÿ(   t   apps(   t   settingst   autofixturess   %s.autofixturesu)   Error while importing %s.autofixtures: %rt   testss   %s.testsu"   Error while importing %s.tests: %r(   R   R'   t   LOADINGt   Truet   impt   django.appsR(   t   get_app_configst   patht   namet   ImportErrort   django.confR)   t   INSTALLED_APPSt   import_modulet   __path__t   AttributeErrort   itemst   find_modulet   closet	   Exceptiont   warningst   warnt   False(   R'   t	   app_pathsR.   R(   t
   app_configR)   t   appt   modt   app_patht   filet   _t   e(    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyt   autodiscover—   sV    		(   t   sysR=   t   autofixture.baseR    t   autofixture.constraintsR   t   autofixture.compatR   t   version_infot
   basestringR   t   strt   __version__R	   R?   R   R   R   R!   R   R,   RH   (    (    (    s6   /tmp/pip-unpacked-wheel-K50F1D/autofixture/__init__.pyt   <module>   s    	$		&	
