
    |`                     f    d Z ddlmZmZmZmZ ddlmZ ddlm	Z	 ddlm
Z
mZmZmZ  G d de	      Zy)	zZ
This module provides the company class, used to store information about
a given company.
    )absolute_importdivisionprint_functionunicode_literals)deepcopy)
_Container)analyze_company_namebuild_company_namecmpCompaniesflattenc            	           e Zd ZdZdZdddddddddZdZeZd	 Z	d
 Z
d Zd Zd Zd Zd Zd Zd ZeZd Zd Zd Zd Zy)CompanyaF  A company.

    Every information about a company can be accessed as::

        companyObject['information']

    to get a list of the kind of information stored in a
    company object, use the keys() method; some useful aliases
    are defined (as "also known as" for the "akas" key);
    see the keys_alias dictionary.
    )maindistributorszspecial effects companieszmiscellaneous companieszproduction companies)distributorspecial effects companyzother companymiscellaneous companyzother companieszmisc companieszmisc companyproduction company c                     |j                  d      }|rd| j                  vr| j                  |       |j                  dd      | _        |j                  dd      | _        y)a  Initialize a company object.

        *companyID* -- the unique identifier for the company.
        *name* -- the name of the company, if not in the data dictionary.
        *myName* -- the nickname you use for this company.
        *myID* -- your personal id for this company.
        *data* -- a dictionary used to initialize the object.
        *notes* -- notes about the given company.
        *accessSystem* -- a string representing the data access system used.
        *titlesRefs* -- a dictionary with references to movies.
        *namesRefs* -- a dictionary with references to persons.
        *charactersRefs* -- a dictionary with references to companies.
        *modFunct* -- function called returning text fields.
        name	companyIDNmyName )getdataset_namer   r   )selfkwdsr   s      ./usr/lib/python3/dist-packages/imdb/Company.py_initzCompany._init=   sP     xxF$))+MM$+t4hhx,    c                      d| _         d| _        y)zReset the company object.Nr   )r   r   r   s    r    _resetzCompany._resetR   s    r"   c                 @   |j                         x}}d}|j                  d      r.|j                  d      }|dk7  r||d }|d| j                         }| j                  r|}t        |      }| j                  j                  |       |r| j                  s|| _        yyy)zSet the name of the company.r   )(N)stripendswithfindrstripnotesr	   r   update)r   r   onamer.   fparidxds         r    r   zCompany.set_nameW   s     zz|#==iinG"}WXHW~,,.::D &		DJ $5r"   c                 (    d| j                   v rdgS g S )z-Valid keys to append to the data.keys() list.r   long imdb name)r   r$   s    r    _additional_keyszCompany._additional_keysi   s    TYY$%%	r"   c                 T    d| j                   v r|dk(  rt        | j                         S y)zHandle special keys.r   r4   N)r   r
   )r   keys     r    _getitemzCompany._getitemo   s+     TYY&&)$))44r"   c                     | j                   S )zReturn the companyID.)r   r$   s    r    getIDzCompany.getIDw   s    ~~r"   c                 J    t        | j                  j                  d            S )z@The company is "false" if the self.data does not contain a name.r   )boolr   r   r$   s    r    __bool__zCompany.__bool__{   s     DIIMM&)**r"   c                     ddl m } t        ||      r1t        | j                  d|      D ]  }|j	                  |      s y yt        |t
              r|| j                  v S y)z<Return true if this company and the given Movie are related.   )MovieT)yieldDictKeysscalarF)r@   
isinstancer   r   isSamestr)r   itemr@   ms       r    __contains__zCompany.__contains__   s\     dE"TYYd5I  ;;q> 
  c"499$$r"   c                 @   t        || j                        syd| j                  v r:d|j                  v r,t        | j                        t        |j                        k(  ry| j                  |j                  k(  r&| j
                  | j
                  |j
                  k(  ryy)zGReturn true if two company have the same name
        and/or companyID.Fr   T)rC   	__class__r   r
   accessSystemr   )r   others     r    
isSameNamezCompany.isSameName   s     %0TYY%**$"499-"5::./ 2 22*%//1r"   c                    t        d| j                  | j                  | j                  t	        | j
                  |      | j                  | j                  t	        | j                  |      t	        | j                  |      t	        | j                  |      
      }t        | j                        |_        |j                  | j                         |S )z)Return a deep copy of a company instance.r   )
r   r   r   myIDr   r.   rK   
titlesRefs	namesRefscharactersRefs)r   r   r   rO   r   r   r.   rK   rP   rQ   rR   listcurrent_infoset_mod_functmodFunct)r   memocs      r    __deepcopy__zCompany.__deepcopy__   s    t~~;;TYY!$))T2**43D3D'>&t~~t<#+D,?,?#FH d//0	&r"   c                 `    d| j                   d| j                  d| j                  d      dS )z*String representation of a Company object.z<Company id:[z] name:_r4   z_>)r   rK   r   r$   s    r    __repr__zCompany.__repr__   s)     NND--txx8H/I
 	
r"   c                 &    | j                  dd      S )zSimply print the short name.r   r   )r   r$   s    r    __str__zCompany.__str__   s    xx##r"   c                     | syd| j                  dd      z  }dD ]S  }| j                  |g       dd }|s|d|dd	j                  |D cg c]  }|j                  d
d       c}      dz  }U |S c c}w )z>Return a string with a pretty-printed summary for the company.r   zCompany
=======
Name: %s
r   )r   r   r   r   N   zLast movies from this company (z): z; zlong imdb titlez.
)r   join)r   skr2   xs        r    summaryzCompany.summary   s    *TXXfb-AA- 	AB#A499AFqaee$5r:FG A	  Gs   
A3N)__name__
__module____qualname____doc__default_info
keys_aliaskeys_tomodify_listr   cmpFunctr!   r%   r   r5   r8   r:   r=   rH   rM   isSameCompanyrY   r\   r^   re   r   r"   r    r   r      s    
 L &#>2!:4314	J H-*
$+
	 M
$r"   r   N)ri   
__future__r   r   r   r   copyr   
imdb.utilsr   r	   r
   r   r   r   r   r"   r    <module>rr      s-   "
 S R  ! V Vbj br"   