
    KJi                     Z    d 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dS )z^
This module provides the Character class, used to store information about
a given character.
    )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dS )	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                     |                     d          }|rd| j        vr|                     |           |                     dd          | _        |                     dd          | _        dS )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      N/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/imdb/Character.py_initzCharacter._init?   sj     xx 	 F$)++MM$88M488hhx,,    c                 "    d| _         d| _        dS )zReset the Character object.Nr   )r   r   r   s    r!   _resetzCharacter._resetT   s    r#   c                 |    	 t          |          }| j                            |           dS # t          $ r Y dS w xY w)zSet the name of the character.N)r   r   updater   )r   r   ds      r!   r   zCharacter.set_nameY   sR    	T""AIQ 	 	 	DD	s   )- 
;;c                 F    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_keysa   sB    TY())G"",--Gr#   c                 L    d| j         v r|dk    rt          | j                   S dS )zHandle special keys.r   r+   N)r   r   )r   keys     r!   _getitemzCharacter._getitemj   s2     TY&&&!$),,,tr#   c                     | j         S )zReturn the characterID.)r   r%   s    r!   getIDzCharacter.getIDr   s    r#   c                 P    t          | 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__v   s      DIMM&))***r#   c                 p   ddl m } ddlm} t          ||          r8t          | j        d|          D ]}|                    |j                  r dS  nat          ||          r3t          | j        d|          D ]}|                    |          r dS nt          |t                    r	|| j        v S dS )zrReturn true if this Character was portrayed in the given Movie
        or it was impersonated by the given Person.   )Movie)PersonT)yieldDictKeysscalarF)r9   r:   
isinstancer	   r   isSamecurrentRolestr)r   itemr9   r:   ms        r!   __contains__zCharacter.__contains__{   s     	!     """"""dF## 		%TYd5III    ;;q}--  44   e$$ 	%TYd5III    ;;q>>  44   c"" 	%49$$ur#   c                 
   t          || j                  sdS d| j        v r9d|j        v r0t          | j        d          t          |j        d          k    rdS | j        |j        k    r| j        | j        |j        k    rdS dS )zKReturn true if two character have the same name
        and/or characterID.Fr   )	canonicalT)r=   	__class__r   r   accessSystemr   )r   others     r!   
isSameNamezCharacter.isSameName   s     %00 	5TY6UZ#7#749666*UZ[`:a:a:aaa4 222 , E$5554ur#   c                 h   t          d| j        | j        | j        t	          | j        |          | j        | j        t	          | j        |          t	          | j	        |          t	          | j
        |          
  
        }t          | j                  |_        |                    | j                   |S )z+Return a deep copy of a Character instance.r   )
r   r   r   myIDr   notesrG   
titlesRefs	namesRefscharactersRefs)r   r   r   rK   r   r   rL   rG   rM   rN   rO   listcurrent_infoset_mod_functmodFunct)r   memocs      r!   __deepcopy__zCharacter.__deepcopy__   s    24+;![ty#DIt44 JT5F!)$/4!@!@ ( > >%-d.A4%H%HJ J J d/00	&&&r#   c                 T    d| j         d| j        d|                     d          dS )z,String representation of a Character object.z<Character id:[z] name:_r   z_>)r   rG   r   r%   s    r!   __repr__zCharacter.__repr__   s;      d///&1A1A1A1A
 	
r#   c                 .    |                      dd          S )zSimply print the short name.r   r   r   r%   s    r!   __str__zCharacter.__str__   s    xx###r#   c                    | sdS d|                      dd          z  }|                      d          }|r|d|d         z  z  }|                      d          }|r/d |d	d
         D             }|dd                    |          z  z  }|S )z@Return a string with a pretty-printed summary for the character.r   zCharacter
=====
Name: %s
r   r   zBiography: %s
r   r   c                 :    g | ]}|                     d d          S )zlong imdb canonical titler   r[   ).0xs     r!   
<listcomp>z%Character.summary.<locals>.<listcomp>   s'    PPPaee7<<PPPr#   N   z%Last movies with this character: %s.
z; )r   join)r   sr   filmoa_lists        r!   summaryzCharacter.summary   s     	2*TXXfb-A-AAhh{## 	,"SV++A'' 	NPPeBQBiPPPF9DIIf<M<MMMAr#   N)__name__
__module____qualname____doc__default_info
keys_aliaskeys_tomodify_listr   cmpFunctr"   r&   r   r.   r1   r3   r6   rC   rI   isSameCharacterrV   rY   r\   rg    r#   r!   r   r      s.       
 
 8L &*!,"$!# J 1H- - -*  
           + + +
  "   !O  
 
 
$ $ $    r#   r   N)rk   copyr   imdb._exceptionsr   
imdb.utilsr   r   r   r   r	   r   rq   r#   r!   <module>ru      s   " 
       , , , , , , O O O O O O O O O O O O O Ob b b b b
 b b b b br#   