
    |`                     j    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mZ  G d de      Zy)	z^
This module provides the Character class, used to store information about
a given character.
    )absolute_importdivisionprint_functionunicode_literals)deepcopy)IMDbParserError)
_Containeranalyze_name
build_name	cmpPeopleflattenc                       e Zd ZdZdZdddd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)	CharacteraN  A Character.

    Every information about a character can be accessed as::

        characterObject['information']

    to get a list of the kind of information stored in a
    Character object, use the keys() method; some useful aliases
    are defined (as "also known as" for the "akas" key);
    see the keys_alias dictionary.
    )mainfilmography	biographyr   akasquoteskeywords)zmini biographybiozcharacter biographyzcharacter biographiesbiographieszcharacter bioakazalso known aszalternate nameszpersonal quoteskeyskeyword)r   r   c                     |j                  d      }|rd| j                  vr| j                  |       |j                  dd      | _        |j                  dd      | _        y)a  Initialize a Character object.

        *characterID* -- the unique identifier for the character.
        *name* -- the name of the Character, if not in the data dictionary.
        *myName* -- the nickname you use for this character.
        *myID* -- your personal id for this character.
        *data* -- a dictionary used to initialize the object.
        *notes* -- notes about the given character.
        *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 characters.
        *modFunct* -- function called returning text fields.
        namecharacterIDNmyName )getdataset_namer   r   )selfkwdsr   s      0/usr/lib/python3/dist-packages/imdb/Character.py_initzCharacter._initA   sQ     xxF$))+MM$88M48hhx,    c                      d| _         d| _        y)zReset the Character object.Nr   )r   r   r#   s    r%   _resetzCharacter._resetV   s    r'   c                 p    	 t        |      }| j                  j                  |       y# t        $ r Y yw xY w)zSet the name of the character.N)r
   r!   updater   )r#   r   ds      r%   r"   zCharacter.set_name[   s5    	T"AIIQ 		s   &) 	55c                 Z    g }d| j                   v r|dgz  }d| j                   v r|dgz  }|S )z-Valid keys to append to the data.keys() list.r   long imdb nameheadshotzfull-size headshot)r!   )r#   addkeyss     r%   _additional_keyszCharacter._additional_keysc   s@    TYY())G",--Gr'   c                 T    d| j                   v r|dk(  rt        | j                         S y)zHandle special keys.r   r/   N)r!   r   )r#   keys     r%   _getitemzCharacter._getiteml   s+     TYY&&!$)),,r'   c                     | j                   S )zReturn the characterID.)r   r)   s    r%   getIDzCharacter.getIDt   s    r'   c                 J    t        | j                  j                  d            S )zBThe Character is "false" if the self.data does not contain a name.r   )boolr!   r    r)   s    r%   __bool__zCharacter.__bool__x   s     DIIMM&)**r'   c                 `   ddl m } ddlm} t        ||      r;t        | j                  d|      D ]  }|j                  |j                        s y yt        ||      r1t        | j                  d|      D ]  }|j                  |      s y yt        |t              r|| j                  v S y)zrReturn true if this Character was portrayed in the given Movie
        or it was impersonated by the given Person.   )Movie)PersonT)yieldDictKeysscalarF)r=   r>   
isinstancer   r!   isSamecurrentRolestr)r#   itemr=   r>   ms        r%   __contains__zCharacter.__contains__}   s     	!"dF#TYYd5I  ;;q}}-   e$TYYd5I  ;;q> 
  c"499$$r'   c                 H   t        || j                        syd| j                  v r>d|j                  v r0t        | j                  d      t        |j                  d      k(  ry| j                  |j                  k(  r&| j
                  | j
                  |j
                  k(  ryy)zKReturn true if two character have the same name
        and/or characterID.Fr   )	canonicalT)rA   	__class__r!   r   accessSystemr   )r#   others     r%   
isSameNamezCharacter.isSameName   s     %0TYY6UZZ#74996*UZZ[`:aa 2 22  ,  E$5$55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 Character instance.r   )
r   r   r   myIDr!   notesrK   
titlesRefs	namesRefscharactersRefs)r   r   r   rO   r   r!   rP   rK   rQ   rR   rS   listcurrent_infoset_mod_functmodFunct)r#   memocs      r%   __deepcopy__zCharacter.__deepcopy__   s    24+;+;![[tyy#DIIt4 JJT5F5F!)$//4!@ ( >%-d.A.A4%HJ d//0	&r'   c                 `    d| j                   d| j                  d| j                  d      dS )z,String representation of a Character object.z<Character id:[z] name:_r   z_>)r   rK   r    r)   s    r%   __repr__zCharacter.__repr__   s*     d//&1A
 	
r'   c                 &    | j                  dd      S )zSimply print the short name.r   r   )r    r)   s    r%   __str__zCharacter.__str__   s    xx##r'   c                    | syd| j                  dd      z  }| j                  d      }|r|d|d   z  z  }| j                  d      }|r9|dd	 D cg c]  }|j                  d
d       }}|ddj                  |      z  z  }|S c c}w )z@Return a string with a pretty-printed summary for the character.r   zCharacter
=====
Name: %s
r   r   zBiography: %s
r   r   N   zlong imdb canonical titlez%Last movies with this character: %s.
z; )r    join)r#   sr   filmoxa_lists         r%   summaryzCharacter.summary   s    *TXXfb-AAhh{#"SV++A'FKBQiPaee7<PFP9DIIf<MMMA Qs   BN)__name__
__module____qualname____doc__default_info
keys_aliaskeys_tomodify_listr   cmpFunctr&   r*   r"   r2   r5   r7   r:   rG   rM   isSameCharacterrZ   r]   r_   rg    r'   r%   r   r      s    
 8L &*!,"$!#J 1H-*
 +
" !O
$r'   r   N)rk   
__future__r   r   r   r   copyr   imdb._exceptionsr   
imdb.utilsr	   r
   r   r   r   r   rq   r'   r%   <module>rv      s-   "
 S R  , O Ob
 br'   