
    JՁjy                        d Z ddlZddlmZ ddlmZmZ ddl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mZ ej*                  d
k\  rddlmZ n G d dee      ZerddlmZ e G d de             Z G d dee      Z G d de      Zy)zAction types    N)ABC)Enumunique)TYPE_CHECKINGcast   )logger_warning)
ParseError)ArrayObjectDictionaryObject
NameObject
NullObjectTextStringObjectis_null_or_none)      )StrEnumc                       e Zd ZdefdZy)r   returnc                 ,    t        | j                        S )N)strvalue)selfs    =/tmp/pip-target-jj2dfcxx/lib/python/pypdf/actions/_actions.py__str__zStrEnum.__str__   s    tzz?"    N)__name__
__module____qualname__r   r    r   r   r   r      s    	#S 	#r   r   )
PageObjectc                   2    e Zd ZdZdZ	 dZ	 edefd       Zy)PageTriggerzGTrigger event entries in a page object's additional-actions dictionary.opencloser   c                 t    t         j                  t        d      t         j                  t        d      i}||    S )z5Returns the corresponding NameObject for the trigger.z/Oz/C)r#   OPENr   CLOSE)r   mappings     r   _name_objectzPageTrigger._name_object(   s7     j.z$/
 t}r   N)	r   r   r   __doc__r'   r(   propertyr   r*   r    r   r   r#   r#       s.    QD4E4j  r   r#   c            	       d     e Zd ZdZd fdZedddedd ddfd	       Zedddeddfd
       Z xZ	S )ActionzLAn action dictionary defines the characteristics and behaviour of an action.r   Nc                 |    t         |           t        d      | t        d      <   t               | t        d      <   y )Nz/Actionz/Type/Next)super__init__r   r   )r   	__class__s    r   r2   zAction.__init__4   s5    $.y$9Z ! %/LZ !r   pager!   triggeractionc                    |j                   }d|vrt        ||i      |t        d      <   yt        |d   t              rt               |t        d      <   t        |d   j                         t              s]t        |d         j                  }|j                  &t        |j                  dd      rt        d| d      t        dt        |       yt        t        |d         }t        |j                  |            r|j                  ||i       y|j                  |      x}}t        |t              s"t        dt        |      j                   d      t        t        |      }t!               }		 |j                  d	d      }
t        |
      rnt        |
t"        t        f      s"t%        d
t        |
      j                   d      t'        |
      }||	v rt        dt        |       n*|	j)                  |       t        |
t"              r|
d   }n|
}t        |j                  d	      x}
      st'        |
      |	v rt        dt        |       ||t        d	      <   |j                  ||i       y)z
        Create a new action and add it to the page.

        Args:
            page: The page to add the action to.
            trigger: An open or close trigger.
            action: The action to be done.
        /AANstrictFz]The type in a page object's additional-actions key must be a DictionaryObject: received type .zfThe type in a page object's additional-actions key must be a DictionaryObject: received type %(type)s.)sourcetyper0   us   An action dictionary’s Next entry must be an Action dictionary or an array of Action dictionaries: received type z1Detected cycle in the action tree for %(current)s)r;   current)r*   r   r   
isinstancer   
get_objectr<   r   pdfgetattrr
   r	   r   r   getupdatesetr   	TypeErroridadd)clsr4   r5   r6   trigger_namecurrent_typeadditional_actionsheadr=   visited	next_nodeid_nexts               r   _create_newzAction._create_new<   so    ++&6v&'DE"# d5k:.&6&8DE"#$u+0024DEU,55Lxx#(E(J %%1N!5  *!	 !"2DK@-11,?@%%|V&<= ,//==w$ 01!!%d!4!4 5Q8  '1%GT2Iy)i+7G)HIIIMiIaIaHbbce 
 mG'!R[cmtuKK )[1#B-#+ . GKK,@@yAbmW^F^NW_ipq'-
7#$!!<"67r   c                 h    d|vry|j                   }t        t        |d         }||vry||= |s|d= yy)z
        Delete an action from the page.

        Args:
            page: The page to delete the action.
            trigger: An open or close trigger.
        r8   N)r*   r   r   )rI   r4   r5   rJ   rL   s        r   _deletezAction._delete   sO     ++!"2DK@11|,!U "r   )r   N)
r   r   r   r+   r2   classmethodr#   rQ   rS   __classcell__r3   s   @r   r.   r.   2   sl    V1 U8| U8k U88 U8X\ U8 U8n < + $  r   r.   c                   ,     e Zd ZdZdeddf fdZ xZS )
JavaScriptaB  
    Upon invocation of an ECMAScript action, a PDF processor shall execute a
    script that is written in the ECMAScript programming language. ECMAScript
    extensions described in ISO/DIS 21757-1 shall also be allowed.

    Args:
        java_script: A text string containing the ECMAScript script to be executed.
    java_scriptr   Nc                 ~    t         |           t        d      | t        d      <   t        |      | t        d      <   y)z$Initialize JavaScript with a string.z/JavaScriptz/Sz/JSN)r1   r2   r   r   )r   rY   r3   s     r   r2   zJavaScript.__init__   s6    !+M!:Z"2;"?Zr   )r   r   r   r+   r   r2   rU   rV   s   @r   rX   rX      s$    @C @D @ @r   rX   )r+   sysabcr   enumr   r   typingr   r   _utilsr	   errorsr
   genericr   r   r   r   r   r   version_infor   r   _pager!   r#   r.   rX   r    r   r   <module>rd      s     
  
 $   w##t # " '  "xs xv@ @r   