
    Mi                        S r SSKJr  SSKrSSKrSSKJrJr  Sr " S S\R                  5      r
 " S S	\R                  5      rSS
S.       SS jjrg)a>  
Helpers for safer and/or more explicit pickle usage in NLTK.

- RestrictedUnpickler: blocks unpickling of *any* globals (classes/functions).
  Intended for loading NLTK data packages where we control the serialization.
- WarningUnpickler: emits a security warning before unpickling (does not make
  unpickling safe).
    )annotationsN)AnyBinaryIOzSecurity warning: loading pickles can execute arbitrary code. Only load pickle files from trusted sources and never from untrusted or unauthenticated locations.c                  "    \ rS rSrSrSS jrSrg)RestrictedUnpickler   zO
Unpickler that prevents any class or function from being used during loading.
c                <    [         R                  " SU SU S35      e)Nzglobal '.z' is forbidden)pickleUnpicklingError)selfmodulenames      h/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/nltk/picklesec.py
find_classRestrictedUnpickler.find_class$   s"    $$xxqn%MNN     N)r   strr   r   returnr   )__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s    Or   r   c                  H   ^  \ rS rSrSrSS.SU 4S jjjrS	U 4S jjrSrU =r$ )
WarningUnpickler)   z6Unpickler that emits PICKLE_WARNING once per instance.Ncontextc               B   > [         TU ]  " U40 UD6  X l        SU l        g )NF)super__init___context_warned)r   filer!   kwargs	__class__s       r   r$   WarningUnpickler.__init__,   s!    ((r   c                   > U R                   (       dJ  U R                  c  [        O[         SU R                   S3n[        R                  " U[
        SS9  SU l         [        TU ]  5       $ )Nz ()   )
stacklevelT)r&   r%   PICKLE_WARNINGwarningswarnRuntimeWarningr#   load)r   msgr)   s     r   r3   WarningUnpickler.load1   sZ    || ==( &'r$--: 
 MM#~!<DLw|~r   )r%   r&   )r'   r   r!   
str | Noner(   r   )r   r   )	r   r   r   r   r   r$   r3   r   __classcell__)r)   s   @r   r   r   )   s    @@D  
	 	r   r   F)r!   
restrictedc               p    U(       a  [        U 5      R                  5       $ [        XS9R                  5       $ )z
Convenience wrapper similar to pickle.load(file).

- If restricted=True, uses RestrictedUnpickler (no warning by default).
- If restricted=False, uses WarningUnpickler and emits a warning.
r    )r   r3   r   )r'   r!   r8   s      r   pickle_loadr:   =   s/     "4(--//D27799r   )r'   r   r!   r6   r8   boolr   r   )r   
__future__r   r   r0   typingr   r   r/   	Unpicklerr   r   r:   r   r   r   <module>r?      st    #    $ O&** Ov'' * .2e:
: *:?C::r   