+
     h   c                   sZ   R t ^ RIt^ RIHtHtHt ^ RIHt ^ RIH	t	 ^ RI
HtHt ^ RIHtHt ^ RIHt Rt ! R	 R
]4      t ! R R4      t ! R R4      t]R8X  dQ   ]! R4        ! R R]4      t ! R R]4      t]! ^4      t]! ^4      t]P9                  4        ]P9                  4        R# R# )aP  Smart card insertion/removal monitoring classes.

CardObserver is a base class for objects that are to be notified
upon smart card insertion/removal.

CardMonitor is a singleton object notifying registered CardObservers
upon reader insertion/removal.

__author__ = "https://www.gemalto.com/"

Copyright 2001-2012 gemalto
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com

This file is part of pyscard.

pyscard is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

pyscard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with pyscard; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
N)EventLockThread)sleep)CardRequest)CardRequestTimeoutExceptionSmartcardException)
ObservableObserver)SCARD_E_NO_SERVICEFc                   s0   a  ] tR t^,t o RtR tR tRtV tR# )CardObserverzp
CardObserver is a base abstract class for objects that are to be notified
upon smart card insertion / removal.
c                    R # N self   &?/usr/lib64/python3.14/site-packages/smartcard/CardMonitoring.py__init__ZCardObserver.__init__2   s        c                s    R# )zCalled upon smart card insertion / removal.

@param observable:
@param handlers:
  - addedcards: list of inserted smart cards causing notification
  - removedcards: list of removed smart cards causing notification
Nr   )r   
observablehandlerss   &&&r   updateZCardObserver.update5   s     	r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell__Z__classdict__   @r   r
   r
   ,   s     
 r   r
   c                   sX   a  ] tR t^@t o Rt ! R R]4      tRt]! 4       t	R t
R tRtV tR# )CardMonitora  Class that monitors smart card insertion / removals.
and notify observers

note: a card monitoring thread will be running
as long as the card monitor has observers, or CardMonitor.stop()
is called. Do not forget to delete all your observers by
calling L{deleteObserver}, or your program will run forever...

Uses the singleton pattern from Thinking in Python
Bruce Eckel, http://mindview.net/Books/TIPython to make sure
there is only one L{CardMonitor}.
c                   s<   a  ] tR t^Nt o RtR tR tR tR tRt	V t
R# )"CardMonitor.__CardMonitorSingletonzpThe real smart card monitor class.

A single instance of this class is created
by the public CardMonitor class.
c                s|    \         P                  ! V 4       \        '       d
   R V n        R # \	        V 4      V n        R # r   )r   r   _START_ON_DEMAND_rmthreadCardMonitoringThreadr   r   r   r   Z+CardMonitor.__CardMonitorSingleton.__init__U   s)    %   $ 4T :r   c                s
   \         P                  ! W4       \        '       d:   V P                  4       ^ 8  d#   V P                  f   \        V 4      V n        R# R# R# VP                  W P                  P                  . 34       R# )zUAdd an observer.

We only start the card monitoring thread when
there are observers.
N)r   addObserverr"   countObserversr#   r$   r   cardsr   observer   &&r   r%   Z.CardMonitor.__CardMonitorSingleton.addObserver\   sd     ""42  &&(1,1F$8$>DM 2G, }}':':B&?@r   c                s   \         P                  ! W4       \        '       de   V P                  4       ^ 8X  dN   V P                  e>   V P                  P                  4        V P                  P                  4        RV n        R# R# R# R# )zgRemove an observer.

We delete the L{CardMonitoringThread} reference when there
are no more observers.
N)r   deleteObserverr"   r&   r#   stopjoinr(   r*   r   r+   Z1CardMonitor.__CardMonitorSingleton.deleteObserveri   si     %%d5  &&(A-}}0**,**,(, 1 . !r   c                r   )r    r   r   r   r   __str__Z*CardMonitor.__CardMonitorSingleton.__str__w   s     r   )r#   N)r   r   r   r   r   r   r%   r+   r.   r   r   r   r   r   __CardMonitorSingletonr!   N   s$     		;	A	-	! 	!r   r/   Nc                s    \         P                  ;_uu_ 4        \         P                  '       g   \         P                  4       \         n        R R R 4       R #   + '       g   i     R # ; ir   )r    lockinstance"_CardMonitor__CardMonitorSingletonr   r   r   r   ZCardMonitor.__init__~   s:    ''''2'I'I'K$ s   4AA(	c                s.    \        V P                  V4      # r   )getattrr1   r   Znamer*   r   __getattr__ZCardMonitor.__getattr__   s    t}}d++r   r   )r   r   r   r   r   r   r2   r1   r   r0   r   r5   r   r   r   r   r   r    r    @   s5     *! *!Z H6DL
, ,r   r    c                   sP   a  ] tR t^t o Rt ! R R]4      tRtR tR t	R t
RtV tR# )	r$   z=Card insertion thread.
This thread waits for card insertion.
c                   s6   a  ] tR t^t o RtR tR tR tRtV t	R# )4CardMonitoringThread.__CardMonitoringThreadSingletonzThe real card monitoring thread class.

A single instance of this class is created
by the public L{CardMonitoringThread} class.
c                s    \         P                  ! V 4       Wn        \        4       V n        V P                  P                  4        . V n        R V n        R# )TN)r   r   r   r    	stopEventZclearr'   daemonr   r   r*   r   r   Z=CardMonitoringThread.__CardMonitoringThreadSingleton.__init__   s:    OOD!(O"WDNNN  "DJDKr   c                s   \        ^<R7      V n        V P                  P                  4       ^8w  d    V P                  P	                  4       p. pV F7  pV P
                  P                  V4      '       d   K&  VP                  V4       K9  	  . pV P
                   F-  pVP                  V4      '       d   K  VP                  V4       K/  	  V. 8w  g   V. 8w  d@   Wn        V P                  P                  4        V P                  P                  W$34       EK  EK  R#   \         d     EK  \         dX   p\        P                  ! 4        TP                  \         8X  d"   T P                  P#                  4         Rp?EKn   Rp?EKu  Rp?ii ; i)zVRuns until stopEvent is notified, and notify
observers of all card insertion/removal.
)ZtimeoutN)r   cardrequestr7   Zis_setZwaitforcardeventr'   Z__contains__Zappendr   Z
setChangedZnotifyObserversr   r   	tracebackZ	print_excZhresultr	   set)r   Zcurrentcards
addedcardsZcardremovedcardsZexcs   &     r   runZ8CardMonitoringThread.__CardMonitoringThreadSingleton.run   s:     +26D..'')Q.-#'#3#3#D#D#FL!#J ,#zz66t<<&--d3 !- $&L $

+88>>(//5 !+ "R'<2+=%1
224778RS ,> /& 3 ) -'')
 {{&88**,, 9-s1   ?D 6:D 5AD F+F4F5AFFc                s:    V P                   P                  4        R # r   )r7   r<   r   r   r   r,   Z9CardMonitoringThread.__CardMonitoringThreadSingleton.stop   s    NN r   )r:   r'   r8   r   r7   N)
r   r   r   r   r   r   r?   r,   r   r   r   r   r   __CardMonitoringThreadSingletonr6      s     		#	-L	! 	!r   r@   Nc                s    \         P                  '       g?   \         P                  V4      \         n        \         P                  P                  4        R # R # r   )r$   r1   4_CardMonitoringThread__CardMonitoringThreadSingletonstartr9   r*   r   r   ZCardMonitoringThread.__init__   s=    #,,,$DDZP !) !))//1	 -r   c                s|    V P                   '       d*   V P                   P                  ! V/ VB  R \        n         R # R # r   )r1   r-   r$   )r   ZargsZkwargss   &*,r   r-   ZCardMonitoringThread.join   s0    ===MM//,0 ) r   c                sV    V P                   '       d   \        V P                   V4      # R # r   )r1   r3   r4   r*   r   r5   Z CardMonitoringThread.__getattr__   s!    ===4==$// r   r   )r   r   r   r   r   r   rA   r1   r   r-   r5   r   r   r   r   r   r$   r$      s2     7!& 7!t H21
0 0r   r$   Z__main__z-insert or remove cards in the next 10 secondsc                   s,   a  ] tR t^t o R tR tRtV tR# )printobserverc                s    Wn         R # r   obsindexr   rE   r*   r   r   Zprintobserver.__init__   s    $Mr   c                s    Vw  r4\        R V P                  \        V4      3,          4       \        RV P                  \        V4      3,          4       R# )z%d - added:   %sz%d - removed: %sN)printrE   Zstr)r   r   r   r=   r>   s   &&&  r   r   Zprintobserver.update   sA    '/$J$s:'GGH$s<7H'IIJr   rD   N)r   r   r   r   r   r   r   r   r   r   r   rC   rC      s     	%	K 	Kr   rC   c                   s,   a  ] tR t^t o R tR tRtV tR# )
testthreadc                sj    \         P                  ! V 4       \        4       V n        Wn        R V n        R # r   )r   r   r    readermonitorrE   r)   rF   r*   r   r   Ztestthread.__init__   s$    OOD!!,D$M DMr   c                s    \        V P                  4      V n        V P                  P	                  V P                  4       \        ^
4       V P                  P                  V P                  4       R# )i
   N)rC   rE   r)   rI   r%   r   r+   r   r   r   r?   Ztestthread.run   sI    )$--8DM**4==9"I--dmm<r   )r)   rE   rI   N)r   r   r   r   r   r?   r   r   r   r   r   rH   rH      s     	!	= 	=r   rH   )r   r;   Z	threadingr    r   r   Ztimer   Zsmartcard.CardRequestr   Zsmartcard.Exceptionsr   r   Zsmartcard.Observerr   r   Zsmartcard.scardr	   r"   r
   r    r$   r   rG   rC   rH   Zt1Zt2rB   r   r   r   <module>rJ      s   <  ) )  - P 3 . 8 (D, D,NO0 O0d z	
9:K K=V = 
AB	ABHHJHHJA r   