
    <h                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJr  SSKJrJr  SSKJr  SSKrSSKJr  SSKJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#  SS	K$J%r%J&r&  SS
K'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0  SSK1J2r2J3r3J4r4J5r5  \Rl                  r7\Rp                  r8S.S jr9Sr:Sr;S/S jr<S0S jr=S1S jr>\R~                  r@\<rA\=rBSrC\R                  " 5       rES2S jrFS3S jrGSSSS.rHS\G" 5       SS .0S!4SS"SS .0S#4S$.rIS4S% jrJS5S& jrK " S' S(\&5      rL " S) S*5      rM          S6S+ jrNS7S, jrO " S- S\%5      rPg)8a  Session object for building, serializing, sending, and receiving messages.

The Session object supports serialization, HMAC signatures,
and metadata on messages.

Also defined here are utilities for working with Sessions:
* A SessionFactory to be used as a base class for configurables that work with
Sessions.
* A Message object for convenience that allows attribute-access to the msg dict.
    )annotationsN)b2a_hex)datetimetimezone)compare_digest)IOLoop)AnyBoolCBytesCUnicodeDictDottedObjectNameInstanceIntegerSet
TraitErrorUnicodeobserve)ConfigurableLoggingConfigurable)
get_logger)import_item)	ZMQStream   )protocol_version)adapt)extract_dates
json_cleanjson_defaultsquash_datesc                   [        U [        5      (       ae  [        U R                  5       5       HF  n[	        X   5      X'   [        U[
        5      (       d  M)  U R                  U5      U [	        U5      '   MH     U $ [        U [        5      (       a#  [        U 5       H  u  p#[	        U5      X'   M     U $ [        U [
        5      (       a  U R                  S5      n U $ )z#coerce unicode back to bytestrings.utf8)	
isinstancedictlistkeyssquash_unicodestrpop	enumerateencode)objkeyivs       iC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\jupyter_client/session.pyr'   r'   @   s    #t
#C%ch/CH#s##+.773<N3'( $ J 
C		cNDA#A&CF # J 
C		jj J    @   i   c                *    [         R                  " U [        SSS9R                  SSS9$ ! [        [
        4 aW  n[         R                  " [        U 5      [        SSS9R                  SSS9n[        R                  " SU S3SS	9  Us S
nA$ S
nAff = f)z!Convert a json object to a bytes.F)defaultensure_ascii	allow_nanr"   surrogateescape)errorsz#Message serialization failed with:
zk
Supporting this message is deprecated in jupyter-client 7, please make sure your message is JSON-compliant   
stacklevelN)	jsondumpsr   r+   	TypeError
ValueErrorr   warningswarn)r,   epackeds      r0   json_packerrD   \   s    zz 	

 & 1&
2	3 z" sO 	

 & 1&
2 	 	21# 62 2 		
 !s   (+ BABBBc                |    [        U [        5      (       a  U R                  SS5      n [        R                  " U 5      $ )z,Convert a json bytes or string to an object.r"   replace)r#   bytesdecoder<   loads)ss    r0   json_unpackerrK   x   s-    !UHHVY'::a=r1   c                J    [         R                  " [        U 5      [        5      $ )z'Pack an object using the pickle module.)pickler=   r    PICKLE_PROTOCOL)os    r0   pickle_packerrP      s    <<Q99r1   s	   <IDS|MSG>c                 n    [         R                  " S5      n SR                  S U SS U SS 4 5       5      $ )zGenerate a new random id.

Avoids problematic runtime import in stdlib uuid on Python 2.

Returns
-------

id string (16 random bytes as hex-encoded text, chunks separated by '-')
   -c              3  V   #    U  H  n[        U5      R                  S 5      v   M!     g7f)asciiN)r   rH   ).0xs     r0   	<genexpr>new_id.<locals>.<genexpr>   s$     K8J1GAJ%%g..8Js   ')N   )osurandomjoin)bufs    r0   new_idr_      s7     **R.C88KRa#ab'8JKKKr1   c                 4    [        5       R                  S5      $ )zReturn new_id as ascii bytesrU   )r_   r+    r1   r0   new_id_bytesrb      s    8??7##r1   zSession.sessionzSession.usernamezSession.keyfile)identuserkeyfileSession )r-   re   zUse HMAC digests for authentication of messages.
        Setting this flag will generate a new UUID to use as the HMAC key.
        r1   zDon't authenticate messages.)securez	no-securec                    [         R                  " S[        SS9  SU ;   a!  SU R                  ;   d  SU R                  ;   a  g[	        5       U R                  l        g)zSet the default behavior for a config environment to be secure.

If Session.key/keyfile have not been set, set Session.key to
a new random UUID.
zdefault_secure is deprecatedr9   r:   rf   r-   re   N)r@   rA   DeprecationWarningrf   rb   r-   )cfgs    r0   default_securerl      sE     MM02DQRSCUckk1Y#++5M"nCKKOr1   c                 6    [         R                  " [        5      $ )z#Return timezone-aware UTC timestamp)r   nowutcra   r1   r0   utcnowrp      s    <<r1   c                     ^  \ rS rSrSr\" S5      r\" S5      SS j5       r\	" S5      r
SS jr\	" SS	S
9r\	" S5      rSS jrSU 4S jjrSrU =r$ )SessionFactory   zSThe Base class for configurables that have a Session, Context, logger,
and IOLoop.
rg   lognamec                @    [         R                  " US   5      U l        g )Nnew)logging	getLoggerlogselfchanges     r0   _logname_changedSessionFactory._logname_changed   s    $$VE]3r1   zmq.Contextc                ,    [         R                  " 5       $ N)zmqContextr{   s    r0   _context_defaultSessionFactory._context_default   s    {{}r1   zjupyter_client.session.SessionT
allow_noneztornado.ioloop.IOLoopc                ,    [         R                  " 5       $ r   )r   currentr   s    r0   _loop_defaultSessionFactory._loop_default   s    ~~r1   c                b   > [         TU ]  " S0 UD6  U R                  c  [        S0 UD6U l        gg)zInitialize a session factory.Nra   )super__init__sessionrf   r{   kwargs	__class__s     r0   r   SessionFactory.__init__   s1    "6"<<",V,DL  r1   )ry   r   r|   t.AnyreturnNone)r   r   )r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   rt   r   r}   r   contextr   r   loopr   r   __static_attributes____classcell__r   s   @r0   rr   rr      sd     bkGY4 4 }%G 7DIG+,D - -r1   rr   c                  T    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
S	rg
)Message   zA simple message object that maps dict keys to attributes.

A Message can be created from a dict and a dict from a Message instance
simply by calling dict(msg_obj).c                    U R                   n[        U5      R                  5        H)  u  p4[        U[        5      (       a  [	        U5      nXBU'   M+     g)zInitialize a message.N)__dict__r$   itemsr#   r   )r{   msg_dictdctkr/   s        r0   r   Message.__init__   sA    mmN((*DA!T""AJF +r1   c                H    [        U R                  R                  5       5      $ r   )iterr   r   r   s    r0   __iter__Message.__iter__   s    DMM'')**r1   c                ,    [        U R                  5      $ r   )reprr   r   s    r0   __repr__Message.__repr__  s    DMM""r1   c                B    [         R                  " U R                  5      $ r   )pprintpformatr   r   s    r0   __str__Message.__str__  s    ~~dmm,,r1   c                    XR                   ;   $ r   r   r{   r   s     r0   __contains__Message.__contains__	  s    MM!!r1   c                     U R                   U   $ r   r   r   s     r0   __getitem__Message.__getitem__  s    }}Qr1   ra   N)r   dict[str, t.Any]r   r   )r   zt.ItemsView[str, t.Any]r   r(   )r   objectr   bool)r   r(   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   ra   r1   r0   r   r      s%    (
+#-" r1   r   c                6    [        5       n[        n[        5       $ )zCreate a new message header)rp   r   locals)msg_idmsg_typeusernamer   dateversions         r0   
msg_headerr     s     8DG8Or1   c                    U (       d  0 $  U S   n[        U[        5      (       d  [        U5      nU$ ! [          a     U S   nU n N6! [          a    e f = ff = f)z-Given a message or header, return the header.headerr   )KeyErrorr#   r$   )msg_or_headerhs     r0   extract_headerr     sq    	
(# aGH  	h'A A  			s    2 
AAAAAc                  z  ^  \ rS rSrSr\" SSSS9r\" SSSS9r\" SSS	S9r	\
" S
5      SCS j5       r\" SSSS9r\
" S5      SCS j5       r\" SSSS9rSDS jr\
" S5      SCS j5       r\" S5      r\" \R,                  R/                  SS5      SSS9r\" 0 SSS9r\" S5      r\" SSS9rSES jr\
" S5      SCS j5       r\" SSS S9r \
" S!5      SCS" j5       r!\"" 5       r#SFS# jr$\%" \&RN                  SS$9r(SGS% jr)\*" 5       r+\" S&SS'S9r,\" SSS(S9r-\
" S)5      SCS* j5       r.\" 5       r/\"" \05      r1\
" S+5      SCS, j5       r2\"" \35      r4\
" S-5      SCS. j5       r5\" S&SS/S9r6\" \7SS0S9r8\" \9SS1S9r:SHU 4S2 jjr;SIS3 jr<Sr=\>SDS4 j5       r?SGS5 jr@SJS6 jrA    SK           SLS7 jjrBSMS8 jrC SN     SOS9 jjrD       SP                   SQS: jjrE   SR           SSS; jjrF\GR                  SS4         STS< jjrI SU     SVS= jjrJSWS> jrKSGS? jrL  SX       SYS@ jjrMSZSA jrNSBrOU =rP$ )[rf   i-  a  Object for handling serialization and sending of messages.

The Session object handles building messages and sending them
with ZMQ sockets or ZMQStream objects.  Objects can communicate with each
other over the network via Session objects, and only need to work with the
dict-based IPython message spec. The Session will handle
serialization/deserialization, security, and metadata.

Sessions support configurable serialization via packer/unpacker traits,
and signing with HMAC digests via the key/keyfile traits.

Parameters
----------

debug : bool
    whether to trigger extra debugging statements
packer/unpacker : str : 'json', 'pickle' or import_string
    importstrings for methods to serialize message parts.  If just
    'json' or 'pickle', predefined JSON and pickle packers will be used.
    Otherwise, the entire importstring must be used.

    The functions must accept at least valid JSON input, and output *bytes*.

    For example, to use msgpack:
    packer = 'msgpack.packb', unpacker='msgpack.unpackb'
pack/unpack : callables
    You can also set the pack/unpack callables for serialization directly.
session : bytes
    the ID of this Session object.  The default is to generate a new UUID.
username : unicode
    username added to message headers.  The default is to ask the OS.
key : bytes
    The key used to initialize an HMAC signature.  If unset, messages
    will not be signed or checked.
keyfile : filepath
    The file containing a key.  If this is set, `key` will be initialized
    to the contents of the file.

FTzDebug output in the Session)confighelpzWhether to check PID to protect against calls after fork.

        This check can be disabled if fork-safety is handled elsewhere.
        r<   zThe name of the packer for serializing messages.
            Should be one of 'json', 'pickle', or an import name
            for a custom callable serializer.packerc                   US   nUR                  5       S:X  a  [        U l        [        U l        X l        g UR                  5       S:X  a  [        U l        [        U l        X l        g [        [        U5      5      U l        g Nrv   r<   rM   )
lowerrD   packrK   unpackunpackerrP   pickle_unpackerr   r(   r{   r|   rv   s      r0   _packer_changedSession._packer_changedi  s]    Um99;& #DI'DKMYY[H$%DI)DKM#CH-DIr1   zjThe name of the unpacker for unserializing messages.
        Only used with custom functions for `packer`.r   c                   US   nUR                  5       S:X  a  [        U l        [        U l        X l        g UR                  5       S:X  a  [        U l        [        U l        X l        g [        [        U5      5      U l        g r   )
r   rD   r   rK   r   r   rP   r   r   r(   r   s      r0   _unpacker_changedSession._unpacker_changed~  s]    Um99;& #DI'DKKYY[H$%DI)DKK%c#h/DKr1   rg   z"The UUID identifying this session.c                F    [        5       nUR                  S5      U l        U$ NrU   )r_   r+   bsession)r{   us     r0   _session_defaultSession._session_default  s    H)r1   r   c                D    U R                   R                  S5      U l        g r   )r   r+   r   rz   s     r0   _session_changedSession._session_changed  s    ++G4r1   r1   USERr   z:Username for the Session. Default is your system username.)r   r   zZMetadata dictionary, which serves as the default top-level metadata dict for each message.r   z$execution key, for signing messages.c                    [        5       $ r   )rb   r   s    r0   _key_defaultSession._key_default  s
    ~r1   r-   c                $    U R                  5         g r   )	_new_authrz   s     r0   _key_changedSession._key_changed  s    r1   zhmac-sha256zcThe digest scheme used to construct the message signatures.
        Must have the form 'hmac-HASH'.signature_schemec                   US   nUR                  S5      (       d  [        SU-  5      eUR                  SS5      S   n [        [        U5      U l        U R                  5         g ! [         a  n[        SU-  5      UeS nAff = f)Nrv   zhmac-z0signature_scheme must start with 'hmac-', got %rrS   r   z!hashlib has no such attribute: %s)
startswithr   splitgetattrhashlib
digest_modAttributeErrorr   )r{   r|   rv   	hash_namerB   s        r0   _signature_scheme_changed!Session._signature_scheme_changed  s    Um~~g&&ORUUVVIIc1%a(		U%gy9DO 	  	U@9LMSTT	Us    A& &
B0A??Bc                "    [         R                  $ r   )r   sha256r   s    r0   _digest_mod_defaultSession._digest_mod_default  s    ~~r1   r   c                    U R                   (       a/  [        R                  " U R                   U R                  S9U l        g S U l        g )N)	digestmod)r-   hmacHMACr   authr   s    r0   r   Session._new_auth  s*    88		$((dooFDIDIr1   i   zzThe maximum number of digests to remember.

        The digest history will be culled when it exceeds this value.
        z&path to file containing execution key.re   c                    [        US   S5       nUR                  5       R                  5       U l        S S S 5        g ! , (       d  f       g = f)Nrv   rb)openreadstripr-   )r{   r|   fs      r0   _keyfile_changedSession._keyfile_changed  s2    &-&!vvx~~'DH '&&s	   $=
Ar   c                \    US   n[        U5      (       d  [        S[        U5      -  5      eg )Nrv   zpacker must be callable, not %scallabler>   typer   s      r0   _pack_changedSession._pack_changed  s.    Um}}=S	IJJ r1   r   c                \    US   n[        U5      (       d  [        S[        U5      -  5      eg )Nrv   z!unpacker must be callable, not %sr  r   s      r0   _unpack_changedSession._unpack_changed  s0     Um}}?$s)KLL r1   zJThreshold (in bytes) beyond which a buffer should be sent without copying.z[Threshold (in bytes) beyond which an object's buffer should be extracted to avoid pickling.zThe maximum number of items for a container to be introspected for custom serialization.
        Containers larger than this are pickled outright.
        c                4  > [         TU ]  " S0 UD6  U R                  5         U R                  0 5      U l        U R
                    [        R                  " 5       U l        U R                  5         U R                  (       d  [        5       R                  S5        gg)aU  create a Session object

Parameters
----------

debug : bool
    whether to trigger extra debugging statements
packer/unpacker : str : 'json', 'pickle' or import_string
    importstrings for methods to serialize message parts.  If just
    'json' or 'pickle', predefined JSON and pickle packers will be used.
    Otherwise, the entire importstring must be used.

    The functions must accept at least valid JSON input, and output
    *bytes*.

    For example, to use msgpack:
    packer = 'msgpack.packb', unpacker='msgpack.unpackb'
pack/unpack : callables
    You can also set the pack/unpack callables for serialization
    directly.
session : unicode (must be ascii)
    the ID of this Session object.  The default is to generate a new
    UUID.
bsession : bytes
    The session as bytes
username : unicode
    username added to message headers.  The default is to ask the OS.
key : bytes
    The key used to initialize an HMAC signature.  If unset, messages
    will not be signed or checked.
signature_scheme : str
    The message digest scheme. Currently must be of the form 'hmac-HASH',
    where 'HASH' is a hashing function available in Python's hashlib.
    The default is 'hmac-sha256'.
    This is ignored if 'key' is empty.
keyfile : filepath
    The file containing a key.  If this is set, `key` will be
    initialized to the contents of the file.
zCMessage signing is disabled.  This is insecure and not recommended!Nra   )r   r   _check_packersr   noner   r[   getpidpidr   r-   r   warningr   s     r0   r   Session.__init__  sn    P 	"6"IIbM	99;xxL  U r1   c           	         [        U 5      " 5       nU R                  5        H  n[        X[        X5      5        M     [	        5       Ul        UR
                  R                  U R
                  5        U$ )zCreate a copy of this Session

Useful when connecting multiple times to a given kernel.
This prevents a shared digest_history warning about duplicate digests
due to multiple connections to IOPub in the same process.

.. versionadded:: 5.1
)r  traitssetattrr   setdigest_historyupdate)r{   new_sessionnames      r0   cloneSession.cloneD  sZ     4jlKKMDKwt':; " &)U"""))$*=*=>r1   c                    U R                   nU =R                   S-  sl         U R                   S[        R                  " 5        SU 3$ )Nr   _)message_countr   r[   r   )r{   message_numbers     r0   r   Session.msg_idX  s@    ++a,,qQ~.>??r1   c                v  ^^ U R                   mU R                  mSSS/0n T" U5      n[        U[        5      (       d  [	        S[        U5      -  5      e T" U5      nXQ:X  d   e S[        5       0n T" T" U5      5      n[        US   [        5      (       a  Sn[	        U5      eg! [         a#  nSU R                   SU 3n[	        U5      UeSnAff = f! [         a0  nSU R                   S	U R                   S
U 3n[	        U5      UeSnAff = f! [         a    U4S jU l         U4S jU l         gf = f)z#check packers for datetime support.ar   hizpacker 'z(' could not serialize a simple message: Nz,message packed to %r, but bytes are requiredz
unpacker 'z'' could not handle output from packer 'z': tz!Shouldn't deserialize to datetimec                &   > T" [        U 5      5      $ r   )r    )rO   r   s    r0   <lambda>(Session._check_packers.<locals>.<lambda>  s    $|A"7r1   c                   > T" U 5      $ r   ra   )rJ   r   s    r0   r8  r9    s	    F1Ir1   )r   r   	Exceptionr   r?   r#   rG   r  r   rp   r   )	r{   msg_listrC   rB   msgunpackedmsg_datetimer   r   s	          @@r0   r  Session._check_packers^  sU   yy !T#	)(^F &%((KdSYlZ[[	)f~H''' VX	.d<01H(3-229 o% 3/  	)T[[M)QRSQTUCS/q(	)  	)T]]O ,[[MQC)  S/q(	)  	.7DI-DK	.sA   B( C 43D (
C2CC
D"+DD D87D8c                X    [        U R                  XR                  U R                  5      $ )z#Create a header for a message type.)r   r   r   r   )r{   r   s     r0   r   Session.msg_header  s    $++xMMr1   c                    0 nUc  U R                  U5      OUnXFS'   US   US'   US   US'   Uc  0 O
[        U5      US'   Uc  0 OUUS'   U R                  R                  5       US'   Ub  US   R	                  U5        U$ )zReturn the nested message dict.

This format is different from what is sent over the wire. The
serialize/deserialize methods converts this nested message dict to the wire
format, which is a list of message parts.
r   r   r   parent_headercontentmetadata)r   r   rF  copyr)  )r{   r   rE  parentr   rF  r=  s          r0   r=  Session.msg  s     .4n*&Hx(H ,J%+^r9OO&GI--,,.J
O""8,
r1   c                    U R                   c  gU R                   R                  5       nU H  nUR                  U5        M     UR                  5       R	                  5       $ )zSign a message with HMAC digest. If no auth, return b''.

Parameters
----------
msg_list : list
    The [p_header,p_parent,p_content] part of the message list.
r1   )r
  rG  r)  	hexdigestr+   )r{   r<  r   ms       r0   signSession.sign  sK     99IINNAHHQK {{}##%%r1   c                   UR                  S0 5      nUc  U R                  nO{[        U[        5      (       a  U R	                  U5      nOT[        U[
        5      (       a  O>[        U[        5      (       a  UR                  S5      nO[        S[        U5      -  5      eU R	                  US   5      U R	                  US   5      U R	                  US   5      U/n/ n[        U[        5      (       a  UR                  U5        OUb  UR                  U5        UR                  [        5        U R                  U5      nUR                  U5        UR                  U5        U$ )a  Serialize the message components to bytes.

This is roughly the inverse of deserialize. The serialize/deserialize
methods work with full message lists, whereas pack/unpack work with
the individual message parts in the message list.

Parameters
----------
msg : dict or Message
    The next message dict as returned by the self.msg method.

Returns
-------
msg_list : list
    The list of bytes objects to be sent with the format::

        [ident1, ident2, ..., DELIM, HMAC, p_header, p_parent,
         p_metadata, p_content, buffer1, buffer2, ...]

    In this list, the ``p_*`` entities are the packed or serialized
    versions, so if JSON is used, these are utf8 encoded JSON strings.
rE  r"   zContent incorrect type: %sr   rD  rF  )getr  r#   r$   r   rG   r(   r+   r>   r  r%   extendappendDELIMrM  )r{   r=  rc   rE  real_messageto_send	signatures          r0   	serializeSession.serialize  s#   6 '')R(?iiG&&ii(G''%%nnV,G84=HII IIc(m$IIc/*+IIc*o&	
 eT""NN5!NN5!uIIl+	y!|$r1   c
                   [        U[        R                  5      (       d  Sn[        U[        R                  R                  5      (       a.  Uc   e[        R                  R	                  UR
                  5      n[        U[        [        45      (       a  Un
U=(       d    U
R                  S/ 5      nOU R                  UUUUU	S9n
U R                  (       a>  [        R                  " 5       U R                  :w  a  [        5       R                  SU
5        gUc  / OUn[!        U5       H\  u  p[        U["        5      (       a  UnO [#        U5      n['        US5      (       d  M<  UR(                  (       a  MO  [+        SX4-  5      e   U R,                  (       a  [/        XR,                  5      n
U R1                  X5      nUR3                  U5        [5        U Vs/ s H  n[7        U5      PM     sn5      nUU R8                  :  nU(       a'  U(       a   U(       a  U(       d  UR;                  USS	S
9nO$U(       a  [<        nUR;                  UUS9  O[<        nU R>                  (       aB  [@        R@                  " U
5        [@        R@                  " U5        [@        R@                  " U5        UU
S'   U
$ ! [$         a  nSn[%        U5      UeSnAff = fs  snf )aG  Build and send a message via stream or socket.

The message format used by this function internally is as follows:

[ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content,
 buffer1,buffer2,...]

The serialize/deserialize methods convert the nested message dict into this
format.

Parameters
----------

stream : zmq.Socket or ZMQStream
    The socket-like object used to send the data.
msg_or_type : str or Message/dict
    Normally, msg_or_type will be a msg_type unless a message is being
    sent more than once. If a header is supplied, this can be set to
    None and the msg_type will be pulled from the header.

content : dict or None
    The content of the message (ignored if msg_or_type is a message).
header : dict or None
    The header dict for the message (ignored if msg_to_type is a message).
parent : Message or dict or None
    The parent or parent header describing the parent of this message
    (ignored if msg_or_type is a message).
ident : bytes or list of bytes
    The zmq.IDENTITY routing path.
metadata : dict or None
    The metadata describing the message
buffers : list or None
    The already-serialized buffers to be appended to the message.
track : bool
    Whether to track.  Only for use with Sockets, because ZMQStream
    objects cannot track messages.


Returns
-------
msg : dict
    The constructed message.
FNbuffers)rE  rH  r   rF  z/WARNING: attempted to send message from fork
%sz0Buffer objects must support the buffer protocol.
contiguousz Buffer %i (%r) is not contiguousT)rG  trackrG  tracker)!r#   r   Socketasyncioshadow
underlyingr   r$   rP  r=  	check_pidr[   r   r!  r   r"  r*   
memoryviewr>   hasattrr[  r?   adapt_versionr   rW  rQ  maxlencopy_thresholdsend_multipartDONEdebugr   )r{   streammsg_or_typerE  rH  rc   rZ  r\  r   rF  r=  idxr^   viewrB   emsgrU  rJ   longestrG  r^  s                        r0   sendSession.send  sA   n &#**--Efckk0011%%%ZZ&&v'8'89FkGT?33 C7B!7G((!  C >>biikTXX5L  !SUXY"W!'*HC#z**1%c?D t\**4??? !Csj!PQQ +  //0C..,ww/w!s1vw/0,,,g%++G%t+LGG!!'!5G::MM#MM'"MM'" I
C ! 1MD#D/q01 0s   J.K.
K8KKc                   / n[        U[        5      (       a  U/nUb  UR                  U5        UR                  [        5        UR                  U R                  USS 5      5        UR                  U5        [        U[        R                  R                  5      (       a)  [        R                  R                  UR                  5      nUR                  XcUS9  g)a  Send a raw message via ident path.

This method is used to send a already serialized message.

Parameters
----------
stream : ZMQStream or Socket
    The ZMQ stream or socket to use for sending the message.
msg_list : list
    The serialized list of messages to send. This only includes the
    [p_header,p_parent,p_metadata,p_content,buffer1,buffer2,...] portion of
    the message.
ident : ident or list
    A single ident or a list of idents to use in sending.
Nr   rZ   r]  )r#   rG   rQ  rR  rS  rM  r   r`  r_  ra  rb  rj  )r{   rm  r<  flagsrG  rc   rU  s          r0   send_rawSession.send_rawl  s    . eU##GENN5!utyy!A/0x fckk0011ZZ&&v'8'89Fg48r1   c                   [        U[        5      (       a  UR                  n[        U[        R                  R
                  5      (       a)  [        R
                  R                  UR                  5      n UR                  X$S9nU R                  XT5      u  pu XpR                  XSUS94$ ! [        R                   a)  nUR                  [        R                  :X  a   SnAge SnAff = f! [         a  nUeSnAff = f)a	  Receive and unpack a message.

Parameters
----------
socket : ZMQStream or Socket
    The socket or stream to use in receiving.

Returns
-------
[idents], msg
    [idents] is a list of idents and msg is a nested message dict of
    same format as self.msg returns.
r]  N)NN)rE  rG  )r#   r   socketr   r`  r_  ra  rb  recv_multipartZMQErrorerrnoEAGAINfeed_identitiesdeserializer;  )r{   rz  moderE  rG  r<  rB   identss           r0   recvSession.recv  s    ( fi((]]Ffckk0011ZZ&&v'8'89F	,,T,=H  //?	++HD+QQQ || 	ww#**$ "	  	G	s6   5B) C) )C&=C! C!!C&)
C:3C55C:c                
   U(       aM  [         R                  " [         R                  [           U5      nUR	                  [
        5      nUSU XS-   S 4$ [         R                  " [         R                  [        R                     U5      nSn[        U5       H  u  p5UR                  [
        :X  d  M  Sn  O   U(       a  Sn[        U5      eUSW XS-   S pU Vs/ s H  n[        UR                  5      PM     snU4$ s  snf )a  Split the identities from the rest of the message.

Feed until DELIM is reached, then return the prefix as idents and
remainder as msg_list. This is easily broken by setting an IDENT to DELIM,
but that would be silly.

Parameters
----------
msg_list : a list of Message or bytes objects
    The message to be split.
copy : bool
    flag determining whether the arguments are bytes or Messages

Returns
-------
(idents, msg_list) : two lists
    idents will always be a list of bytes, each of which is a ZMQ
    identity. msg_list will be a list of bytes or zmq.Messages of the
    form [HMAC,p_header,p_parent,p_content,buffer1,buffer2,...] and
    should be unpackable/unserializable via self.deserialize at this
    point.
Nr   TFzDELIM not in msg_list)
r6  castListrG   indexrS  r   r   r*   r?   )r{   r<  rG  ro  failedrL  r=  r  s           r0   r  Session.feed_identities  s    2 vvaffUmX6H..'CDS>8!GI#666vvaffS[[18<HF#H-77e#"F . - o%'~xa	/BH,23FqE!''NF3X==3s   D c                    U R                   S:X  a  gU R                  R                  U5        [        U R                  5      U R                   :  a  U R	                  5         gg)z9add a digest to history to protect against replay attacksr   N)digest_history_sizer(  addrh  _cull_digest_history)r{   rV  s     r0   _add_digestSession._add_digest  sQ    ##q(	*t""#d&>&>>%%' ?r1   c                <   [        U R                  5      n[        [        US-  5      XR                  -
  5      nX!:  a  [        5       U l        g[        R                  " [        [        U R                  5      5      U5      nU R                  R                  U5        g)zOcull the digest history

Removes a randomly selected 10% of the digest history

   N)rh  r(  rg  intr  r'  randomsampletuplesorteddifference_update)r{   r   	n_to_cullto_culls       r0   r  Session._cull_digest_history  sy    
 d))*GrM*G6N6N,NO	"%%D--fT-@-@&A BIN--g6r1   c                   Sn0 nU(       d  [         R                  " [         R                  [        R                     U5      nUSU  Vs/ s H  n[        UR
                  5      PM     nn[         R                  " [         R                  [
           U5      nXqUS -   n[         R                  " [         R                  [
           U5      nU R                  b  US   nU(       d  Sn[        U5      eXR                  ;   a  [        SU-  5      eU(       a  U R                  U5        U R                  USS 5      n	[        X5      (       d  SU-  n[        U5      e[        U5      U:  d  SU-  n[        U5      eU R                  US   5      n
[        U
5      US	'   U
S
   US
'   U
S   US'   [        U R                  US   5      5      US'   U R                  US   5      US'   U(       a  U R                  US   5      US'   OUS   US'   USS  Vs/ s H  n[!        U5      PM     nnU(       aw  US   R"                  cg  [         R                  " [         R                  [        R                     U5      nUSS  Vs/ s H!  n[!        [        UR
                  5      5      PM#     nnXS'   U R$                  (       a  [&        R&                  " U5        [)        U5      $ s  snf s  snf s  snf )a'  Unserialize a msg_list to a nested message dict.

This is roughly the inverse of serialize. The serialize/deserialize
methods work with full message lists, whereas pack/unpack work with
the individual message parts in the message list.

Parameters
----------
msg_list : list of bytes or Message objects
    The list of message parts of the form [HMAC,p_header,p_parent,
    p_metadata,p_content,buffer1,buffer2,...].
content : bool (True)
    Whether to unpack the content dict (True), or leave it packed
    (False).
copy : bool (True)
    Whether msg_list contains bytes (True) or the non-copying Message
    objects in each place (False).

Returns
-------
msg : dict
    The nested message dict with top-level keys [header, parent_header,
    content, buffers].  The buffers are returned as memoryviews.
   Nr   zUnsigned MessagezDuplicate Signature: %rr   zInvalid Signature: %rz1malformed message, must have at least %i elementsr   r   r   r9   rD     rF  rZ   rE  rZ  )r6  r  r  r   r   rG   r
  r?   r(  r  rM  r   rh  r>   r   r   rd  shaperl  r   r   )r{   r<  rE  rG  minlenmessager=  msg_list_beginningrV  checkr   brZ  s                r0   r  Session.deserialize  s   < vvaffS[[18<H>Fw>O!P>Os%		"2>O!PvvaffUmX6H)VW,==H66!&&-299  I( o%/// !:Y!FGG  +IIhqm,E!)33-	9 o%8}&ENCC. Xa[))&1"8,$Z0
#0Xa[1I#J "kk(1+6
!%Xa[!9GI!)!GI*212,7,Q:a=,7wqz''/vvaffS[[18<H;CAB<H<az%.1<GH$	::MM'"W~Q "Q> 8 Is   	KK9(K#c                Z    [         R                  " S[        SS9  U R                  " U0 UD6$ )z'**DEPRECATED** Use deserialize instead.z;Session.unserialize is deprecated. Use Session.deserialize.r9   r:   )r@   rA   rj   r  )r{   argsr   s      r0   unserializeSession.unserializeK  s1     	I	

 000r1   )r
  r   r(  r   r-   r  r   r   r!  r   r   r   r   r   rG   )r   z
t.Callable)r   r   r   )r   rf   )r   r(   r   r   )NNNN)r   r(   rE  zdict | NonerH  dict[str, t.Any] | Noner   r  rF  r  r   r   )r<  r%   r   rG   r   )r=  r   rc   zlist[bytes] | bytes | Noner   zlist[bytes])NNNNFNN)rm  z*zmq.sugar.socket.Socket | ZMQStream | Nonern  zdict[str, t.Any] | strrE  r  rH  r  rc   bytes | list[bytes] | NonerZ  zlist[bytes] | Noner\  r   r   r  rF  r  r   r  )r   TN)rm  zmq.sugar.socket.Socketr<  r%   rv  r  rG  r   rc   r  r   r   )
rz  r  r  r  rE  r   rG  r   r   z2tuple[list[bytes] | None, dict[str, t.Any] | None])T)r<  list[bytes] | list[zmq.Message]rG  r   r   z3tuple[list[bytes], list[bytes] | list[zmq.Message]])rV  rG   r   r   )TT)r<  r  rE  r   rG  r   r   r   )r  r   r   r   r   r   )Qr   r   r   r   r   r
   rl  rc  r   r   r   r   r   r   r   r   r   r   r   r   r   r[   environrP  r   r   rF  r   rf  r-   r   r   r   r   r	   r   r  r   r  r	  r
  r   r   r(  r  re   r  r!  default_packerr   r  default_unpackerr   r  ri  	MAX_BYTESbuffer_threshold	MAX_ITEMSitem_thresholdr   r,  r0  propertyr   r  r   r=  rM  rW  rs  rw  r   NOBLOCKr  r  r  r  r  r  r   r   r   s   @r0   rf   rf   -  s   &P t*KLEI 1F X. .  9H Z0 0 r$-UVG
 Y5 5 c{H


vz*MH 
H AJM #M
NC U^  +  	 !	 J DII$/D UN! b,XYGY( (
 )C ~DV_K K
 !"FXM M YN
  N2h$ M@ @
%.NN  $*.*.,0  (	
 ( * 
4&$ -1>> *> 
	>H ,0*.,0&**.,0x:x ,x )	x
 (x *x $x x (x *x 
!x| ,0#9'#9 #9 	#9
 #9 *#9 
#9P KK)') ) 	)
 ) 
<)X GK(>7(>?C(>	<(>T	(7  	K1K K 	K
 
KZ1 1r1   )r,   r   r   r   )r,   r   r   rG   )rJ   zstr | bytesr   r   )rO   r   r   rG   r   r  )rk   r   r   r   )r   r   )
r   r(   r   r(   r   r(   r   zSession | strr   r   )r   r   r   r   )Qr   
__future__r   r   r  r<   rw   r[   rM   r   r  typingr6  r@   binasciir   r   r   r   zmq.asyncior   tornado.ioloopr   	traitletsr	   r
   r   r   r   r   r   r   r   r   r   r   traitlets.config.configurabler   r   traitlets.logr   traitlets.utils.importstringr   zmq.eventloop.zmqstreamr   _versionr   adapterr   jsonutilr   r   r   r    DEFAULT_PROTOCOLrN   ro   r'   r  r  rD   rK   rP   rI   r   r  r  rS  MessageTrackerrk  r_   rb   session_aliasessession_flagsrl   rp   rr   r   r   r   rf   ra   r1   r0   <module>r     s  	 #     	       '   !    L $ 4 - &  K K))ll( 		8:
 ,,  
L$   
LNr:;	 
CB/0*
%-( -B   >*-8E(f1l f1r1   