+
     hE  c                   s   R t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHt ^ RI5  ! R R	]4      t]R
8X  d    ^ RIHt ]! R4       ]! ^
RR7      t]P+                  4       t]P.                  P1                  4        ]! ]P.                  P3                  4       R,           ]! ]P.                  P5                  4       4      ,           4       ]P.                  P7                  4        R# R# )am  PCSC Smartcard request.

__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)datetime)Card)AbstractCardRequest)CardConnectionExceptionCardRequestExceptionCardRequestTimeoutExceptionListReadersException)
PCSCReader)Z*c                   sR   a  ] tR t^(t o RtRR ltR tR tR tR t	R t
R	 tR
tV tR# )PCSCCardRequestzPCSC CardRequest class.Nc                s   \         P                  ! WW#WE4       V P                  f   \        V n        M!\	        V P                  R,          4      V n        \        \        4      w  q`n        V\        8w  d   RV n        \        VR7      h\        P                  ! 4       V n        \        V n        / V n        . V n        V P                  V n        R# )a  Construct new PCSCCardRequest.

@param newcardonly: if C{True}, request a new card. default is
C{False}, i.e. accepts cards already inserted

@param readers: the list of readers to consider for requesting a
card default is to consider all readers

@param cardType: the L{CardType} class to wait for; default is
L{AnyCardType}, i.e.  the request will returns with new or already
inserted cards

@param cardServiceClass: the specific card service class to
create and bind to the card default is to create and bind a
L{PassThruCardService}

@param timeout: the time in seconds we are ready to wait for
connecting to the requested card.  default is to wait one second
to wait forever, set timeout to C{None}
N  hresult)r   __init__timeoutINFINITEintSCardEstablishContextSCARD_SCOPE_USERhcontextSCARD_S_SUCCESSr   	threadingZEventevtr   readerstates	newstatestimeout_init)selfnewcardonlyreaderscardTypecardServiceClassr   r   s   &&&&&& E/usr/lib64/python3.14/site-packages/smartcard/pcsc/PCSCCardRequest.pyr   ZPCSCCardRequest.__init__+   s    8 	$$w2B	

 <<#DL t||d23DL!67G!Ho% DM)'::??$& LL    c                s&    V P                  4        R # N)releaser      &r   __del__ZPCSCCardRequest.__del__\   s    r   c                s    V P                   e6   \        V P                   4      pV\        8w  d   \        VR7      hR V n         R # R # )Nr
   )r   SCardReleaseContextr   r   )r   r   s   & r   r!   ZPCSCCardRequest.release_   s9    ==$)$--8G/)-g>> DM	 %r   c                s2   \        V P                  . 4      w  rV\        \        39   dr   \	        V P                  4      pV\
        8w  d   \        VR7      h\        \        4      w  qn        V\
        8w  d   \        VR7      h\        V P                  . 4      w  r\        V8X  d   . # \
        V8w  d   \        V4      h. pV P                  f   TpV# V P                   F5  p\        V\        4      '       g   \        V4      pWB9   g   K,  W4.,           pK7  	  V# )z<Returns the list of PCSC readers on which to wait for cards.r
   )ZSCardListReadersr   ZSCARD_E_SERVICE_STOPPEDSCARD_E_NO_SERVICEr%   r   r   r   r   ZSCARD_E_NO_READERS_AVAILABLEr   readersAskedZ
isinstanceZstr)r   r   Zpcscreadersr   readers   &    r   getReaderNamesZPCSCCardRequest.getReaderNamesf   s      0rB .0BCC)$--8G/)-g>>%:;K%L"G]/)-g>>#3DMM2#F G'72Ig%&w// $!G  ++!&#.. [F(%0G	 , r   c                s    \        V P                  V P                  \        V P                  P                  4       4      4      w  V n        V n        V P                  P                  4        R # r    )
SCardGetStatusChanger   r   listr   valuesr   r   r   Zsetr"   r#   r   Z__getStatusChangeZ!PCSCCardRequest.__getStatusChange   sG    ';MM4<<d.?.?.F.F.H)I(
$dn 	r   c                sZ
   \         P                  ! V 4       Rp/ pV P                  4       pVP                  R4       V F  pWB9  g   K  V\        3W$&   K  	  / V8w  d2   \        V P                  ^ \        VP                  4       4      4      w  rVM\        p. p\        V8w  d4   \        V8w  d)   \        V8w  d   \        R\        V4      ,           VR7      hV F  pVw  rp
W3W(&   K  	  V P                  '       g   V F  pVw  rp
V	\        ,          '       g   K  \!        V4      pV P"                  P%                  W4      '       g   KK  V P&                  P)                  R4      '       g   Kn  RpV P'                  VP+                  4       4      u # 	  \,        P.                  ! 4       pV P0                  V n        V'       Eg   V P                  4       pV P4                  f   VP                  R4       V F  pWB9  g   K  V\        3W$&   K  	  \        VP7                  4       4       F  pW9  g   K  W, K  	  W n        \:        P<                  ! V P>                  R7      pVPA                  4         VPC                  4        V PH                  PK                  RR
7       V PL                  pV PN                  pV P2                  \P        8w  dl   \,        P.                  ! 4       V,
          pV ;P2                  \S        VPU                  4       R,          4      ,          un        V P2                  ^ 8  d   ^ V n        V\        \V        39   d   \Y        VR7      h\        V8X  d   EK  V\Z        \\        39   d   EK  \        V8w  d   \        R\        V4      ,           VR7      hV EF=  pVw  rp
W(,          w  ppV P                  '       dF   V\        ,          '       d3   V	\^        \        ,          ,          '       d   V	R\^        ,          ,          p	V P                  '       d'   V	\        ,          '       d   V	\^        ,          '       g&   V P                  '       g   V	\        ,          '       dq   \!        V4      pV P"                  P%                  W4      '       dE   V P&                  P)                  R4      '       d$   RpV P'                  VP+                  4       4      u # W3W(&   EK@  	  EK'  R#   \D         dB    \G        T P                  4      pT\        8w  d   \        R	\        T4      ,           TR7      h ELi ; i)z3Wait for card insertion and returns a card service.F\\?PnP?\NotificationzFailed to SCardGetStatusChange r
   ZdummyTNZtargetFailed to SCardCancel r   r	   Failed to get status change l    )0r   waitforcardr)   appendSCARD_STATE_UNAWAREr*   r   r+   r,   r   SCARD_E_TIMEOUTSCARD_E_UNKNOWN_READERr   SCardGetErrorMessager   SCARD_STATE_PRESENTr   r   Zmatchesr   ZsupportsZcreateConnectionr    nowr   r   r'   Zkeysr   r   Thread!_PCSCCardRequest__getStatusChangestartjoinKeyboardInterruptSCardCancelr   waitr   r   r   r   total_secondsSCARD_E_CANCELLEDr   SCARD_E_SYSTEM_CANCELLEDr&   SCARD_STATE_CHANGED)r   Z	cardfoundr   readernamesr(   r   r   state
readername
eventstateatr	startDateZ	oldreader
waitThreaddeltaZrZoldstates   &                r   r2   ZPCSCCardRequest.waitforcard   sh   ''-	 ))+45!F)(.0C'D$ "
 !5q$|':':'<"="GY &GI w&7*&'1&14H4QQ  E*/'JC(2'?L$ 
 ".3+
 333'
3F}},,S990099'BB(,I#'#8#89P9P9R#SS # LLN	(() --/K  (""#<=%-,24G+HL( &
 ","3"3"56	/$/ 7
 !-"))1G1GHJ! HHMM$M' llGI ||x' 2E$7$7$9D$@ AA<<!##$DL ?,=>>1'BB (72 57IJJ !G+*25I'5RR#  'E27/JC".":KAx '''#&999j/2EE? ? *4zDW7W)XJ (((&)<<<&)<<<"...:@S3S3S!+J!7==00==#44==gFF,0	'+'<'<V=T=T=V'W W 1;/GL,5 'S 4 % %dmm4o-.03G3PP '  .s   *S AT*)T*c           	     s   \         P                  ! V 4       . p\        P                  ! 4       pRpV P                  V n        V P                  4       pV'       EgV   V P                  pV P                  4       pTpV P                  f   VP                  R4       \        V4      ^ 8X  dU   V F  pV\        3WX&   K  	  \        V P                  ^ \        VP                  4       4      4      w  rV
 F  w  rpW3WX&   K  	  V Fh  pW9  g   K  V\        3WX&   \        V P                  ^ \        VP                  4       4      4      w  rV
R,          w  rpV\         ,          '       g   Kf  RpKj  	  . pV F;  pW9  g   K  WX,          w  rV\         ,          '       d   RpVP                  V4       K=  	  V'       d<   V F  pWX K  	  \        V P                  ^ \        VP                  4       4      4      w  rV'       d   EMTpWPn        \"        P$                  ! V P&                  R7      pVP)                  4         VP+                  4        V P6                  P9                  RR7       V P:                  p	V P<                  p
V P
                  \>        8w  dl   \        P                  ! 4       V,
          pV ;P
                  \A        VPC                  4       R	,          4      ,          un        V P
                  ^ 8  d   ^ V n        V	\D        \F        39   d   \I        V	R7      h\J        V	8X  d   MiV	\L        \N        39   d   MW\0        V	8w  d   \3        R
\5        V	4      ,           V	R7      hV
 F)  pVw  pppVR8X  d   K  V\P        ,          '       g   K'  RpK+  	  / V n        V
 F  w  rpW3V P                  V&   K  	  EK^  X
 FM  pVw  pppVR8X  d   K  V\         ,          '       g   K'  VP                  \R        PR                  ! VV4      4       KO  	  V#   \,         dB    \/        T P                  4      p	T	\0        8w  d   \3        R\5        T	4      ,           T	R7      h ELi ; i)z#Wait for card insertion or removal.FNr-   Tr.   r/   r
   r0   r	   r1   i)*r   waitforcardeventr    r9   r   r   r)   r   r'   r3   Zlenr4   r*   r   r+   r,   r8   r   r:   r;   r<   r=   r>   r?   r   r   r7   r   r@   r   r   r   r   rA   r5   rB   r   r6   rC   r&   rD   r   )r   ZpresentcardsrJ   Z
eventfoundZprevious_readernamesr   Z_readernamesrE   r(   r   r   rF   Z_Z	to_removerK   rL   rG   rH   rI   s   &                  r   rM   Z PCSCCardRequest.waitforcardevent/  s   ,,T2LLN	
((#224*  ,,L  ..0L&K  (""#<= < A%)F,24G+HL( * &:MM1d<+>+>+@&A&"
 )2$F1,2?L( )2 '-,24G+HL()=q$|/B/B/D*E*&G
 #,B-KAa222%)
 '  I&,+3HA222%)
$$V, ' 'F$, (
 &:MM1d<+>+>+@&A&"  $0  !-"))1G1GHJ! HHMM$M' llGI ||x' 2E$7$7$9D$@ AA<<!##$DL ?,=>>1'BB (72 57IJJ !G+*25I'5RR#  'E27/J
C "%>> !$777%)
 ' !#D&/"s-3O!!&) '0 E*/'J
C66///##DIIj#$>?  E % %dmm4o-.03G3PP '  .s   3P AQQ)r   r   r   r   r   r   r   )FNNNi   )__name__Z
__module__Z__qualname__Z__firstlineno____doc__r   r$   r!   r)   r;   r2   rM   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r   (   s7     !/)b!#NZHxZ Zr   r   Z__main__)toHexStringz#Insert a new card within 10 secondsT)r   r   Z )rO   r   r    Z	smartcardr   Zsmartcard.AbstractCardRequestr   Zsmartcard.Exceptionsr   r   r   r   Zsmartcard.pcsc.PCSCReaderr   Zsmartcard.scardr   rN   Zsmartcard.utilrP   ZprintZcrr2   ZcsZ
connectionZconnectZ	getReaderZgetATRZ
disconnect) r   r   <module>rQ      s   0    =  1 a) aH zB*	
/0		6B		BMM	"--
!
!
#c
)K8L8L8N,O
OPMM r   