
    q&i                         S r SSKJr  SSKrSSKrSSKJr  SS/r " S S\5      r	 " S	 S
\5      r
 " S S\R                  5      r " S S\R                  5      rg)a  
JPype Pickle Module
--------------------

This module contains overloaded Pickler and Unpickler classes that operate
on Java classes. Pickling of Java objects is restricted to classes
that implement Serializable.  Mixed pickle files containing both
Java and Python objects are allowed.  Only one copy of each Java object
will appear in the pickle file even it is appears multiple times in the
data structure.

JPicklers and JUnpickler use Java ObjectOutputStream and ObjectInputStream
to serialize objects. All of the usual Java serialization errors may be
thrown.

This is backed by the native cPickler implementation.

Example:

.. code-block:: python

  myobj = jpype.JClass('java.util.ArrayList')()
  myobj.add("test")

  from jpype.pickle import JPickler, JUnpickler
  with open("test.pic", "wb") as fd:
    JPickler(fd).dump(myobj)

  with open("test.pic", "rb") as fd:
    newobj = JUnpickler(fd).load()


Proxies and other JPype specific module resources cannot be pickled currently.

    )absolute_importNdispatch_tableJPickler
JUnpicklerc                       \ rS rSrS rSrg)JUnserializerD   c                 .    [         R                  " S5      e)Nz#Unpickling Java requires JUnpickler)pickleUnpicklingError)selfargss     L/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/jpype/pickle.py__call__JUnserializer.__call__E   s    $$%JKK     N__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r	   r	   D   s    Lr   r	   c                   0    \ rS rSrSrS rS rS rS rSr	g)	
_JDispatchI   zDispatch for Java classes and objects.

Python does not have a good way to register a reducer that applies to
many classes, thus we will substitute the usual dictionary with a
class that can produce reducers as needed.
c                     [         R                  " S5      " 5       U l        [        5       U l        Xl        U R                  U l        g )Nzorg.jpype.pickle.Encoder)_jpypeJClass_encoderr	   _builder	_dispatchreduce_call)r   dispatchs     r   __init___JDispatch.__init__Q   s1    &@AC%! [[
r   c                     [        U[        R                  [        R                  45      (       d  U R                  R                  U5      $ U R                  $ N)
issubclassr   r    JObjectr#   getr%   r   clss     r   r-   _JDispatch.getZ   s;    #v~~>??>>%%c**zzr   c                     [        U[        R                  [        R                  45      (       d  U R                  U   $ U R
                  $ r*   )r+   r   r    r,   r#   r%   r.   s     r   __getitem___JDispatch.__getitem__`   s5    #v~~>??>>#&&zzr   c                 h    [        U R                  R                  U5      5      nU R                  U44$ r*   )bytesr!   packr"   )r   objbytes      r   r$   _JDispatch.reducee   s,    T]]'',-x((r   )r"   r%   r#   r!   N)
r   r   r   r   __doc__r'   r-   r2   r$   r   r   r   r   r   r   I   s    !
)r   r   c                       \ rS rSrSrS rSrg)r   j   af  Pickler overloaded to support Java objects

Parameters:
    file: a file or other writeable object.
    *args: any arguments support by the native pickler.

Raises:
    java.io.NotSerializableException: if a class is not serializable or
        one of its members
    java.io.InvalidClassException: an error occures in constructing a
        serialization.

c                 t    [         R                  R                  " X/UQ70 UD6  [        [        5      U l        g r*   )r   Picklerr'   r   r   r   filer   kwargss       r   r'   JPickler.__init__y   s-    <T<V< )8r   r   N)r   r   r   r   r:   r'   r   r   r   r   r   r   j   s    9r   c                   $    \ rS rSrSrS rS rSrg)r      a	  Unpickler overloaded to support Java objects

Parameters:
    file: a file or other readable object.
    *args: any arguments support by the native unpickler.

Raises:
    java.lang.ClassNotFoundException: if a serialized class is not
        found by the current classloader.
    java.io.InvalidClassException: if the serialVersionUID for the
        class does not match, usually as a result of a new jar
        version.
    java.io.StreamCorruptedException: if the pickle file has been
        altered or corrupted.

c                     [         R                  " S5      " 5       U l        [        R                  R
                  " X/UQ70 UD6  g )Nzorg.jpype.pickle.Decoder)r   r    _decoderr   	Unpicklerr'   r?   s       r   r'   JUnpickler.__init__   s4    &@AC!!$>t>v>r   c                    ^ US:X  a   U R                   m " U4S jS[        5      nU$ [        R                  R	                  XU5      $ )zSpecialization for Java classes.

We just need to substitute the stub class for a real
one which points to our decoder instance.
r	   c                   "   > \ rS rSrU 4S jrSrg),JUnpickler.find_class.<locals>.JUnserializer   c                 ,   > TR                  US   5      $ )Nr   )unpack)r   r   decoders     r   r   5JUnpickler.find_class.<locals>.JUnserializer.__call__   s    ">>$q'22r   r   Nr   )rO   s   r   r	   rK      s    3 3r   )rF   objectr   rG   
find_class)r   moduler/   r	   rO   s       @r   rR   JUnpickler.find_class   sC     /!mmG3 3 ! **4==r   )rF   N)r   r   r   r   r:   r'   rR   r   r   r   r   r   r      s    "?>r   )r:   
__future__r   r   r   copyregr   __ALL__rQ   r	   r   r>   r   rG   r   r   r   r   <module>rX      sb   $"F '   " |
$
LF L
) )B9v~~ 9,#>!! #>r   