
    |~g!                     L   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ i ddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+Z G d, d-e      Z G d. d/ej$                        Zy)0    N)	AnyListIterableCallableOptionalTupleUnionMutableSequenceIO)GObject)GLib)open_rfcomm)GSignals   z~An immediately fatal error of some kind  occurred, such as an essential system call failing, or running out of virtual memory.   zkAn  error  was detected in processing the options given, such as two mutually exclusive options being used.   z:Pppd is not setuid-root and the invoking user is not root.   ziThe kernel does not support PPP, for example, the  PPP kernel driver is not included or cannot be loaded.   zGPppd terminated because it was sent a SIGINT, SIGTERM or SIGHUP signal.   z$The serial port could not be locked.   z$The serial port could not be opened.   z<The connect script failed (returned a non-zero exit status).	   zLThe command specified as the argument to the  pty  option  could not be run.
   zyThe PPP negotiation failed, that is, it didn't reach the point where at least one network protocol (e.g. IP) was running.   z;The peer system failed (or refused) to authenticate itself.   zJThe link was established successfully and terminated because  it was idle.   z`The link was established successfully and terminated because the connect time limit was reached.   zICallback was negotiated  and  an  incoming  call  should  arrive shortly.   zLThe link was terminated because the peer is not responding to echo requests.   z0The link was terminated by the modem hanging up.   z@The PPP negotiation failed because serial loopback was detected.z9The init script failed (returned a non-zero exit status).z0We failed to authenticate ourselves to the peer.)      c                       e Zd Zy)PPPExceptionN)__name__
__module____qualname__     </usr/lib/python3/dist-packages/blueman/main/PPPConnection.pyr$   r$   *   s    r)   r$   c                       e Zd ZU ej                  j
                  deffej                  j
                  deffdZee	d<   ddededededed	df fd
Z
ddZdee   d	dfdZdeee      dee   ded	dfdZd ded	dfdZddZdee   dej.                  d	efdZd	efdZded	dfdZdedej.                  ded	efdZded	dfdZ xZS )!PPPConnectionN)	connectederror-occurred__gsignals__portnumberapnuserpwdreturnc                 8   t         |           || _        || _        || _        || _        || _        d | _        dddd| j                   | j                  g dfg| _	        | j                  dk7  r+| j                  j                  dd| j                   d	       y y )
NzATZ E0 V1 X4 &C1 +FCLASS=0ATE0zAT+GCAPATD)CONNECTz
NO CARRIERBUSYz	NO ANSWERzNO DIALTONEOKERROR zAT+CGDCONT=1,"IP","")super__init__r2   r1   r3   r4   r0   	interfaceconnect_callbackcommandsinsert)selfr0   r1   r2   r3   r4   	__class__s         r*   rA   zPPPConnection.__init__4   s    		(, )dkk]#%%\		n
 88r>MM  ':488*A%FG r)   c                 B    t        j                  | j                         y N)osclosefile)rF   s    r*   cleanupzPPPConnection.cleanupK   s    
r)   responsec                 L   d|v rt        j                  d       t        j                  d| j                   ddddgdt        j
                  	      | _        | j                  j                  J t        j                  | j                  j                  t        j                  t        j                  z  t        j                  z  | j                         t        j                  d
| j                         | j!                          y | j!                          t#        d|d    d      )Nr9   zStarting pppdz/usr/sbin/pppd115200defaultrouteupdetach
usepeerdnsr   )bufsizestdouti  zBad modem response r   z, expected CONNECT)logginginfo
subprocessPopenr0   PIPEpppdrU   r   io_add_watchIO_INIO_ERRIO_HUPon_pppd_stdouttimeout_add
check_pppdrM   r$   )rF   rN   s     r*   rC   zPPPConnection.connect_callbackN   s     LL)"((!dii[8^ZYefpq!(DI 99##///dii..

T[[0H4;;0VX\XkXklT4??3LLNLLN!4Xa[MASTUUr)   	exception
command_idc                 (   |r| j                  dt        |             y | j                  |   }t        |t              r|J 	  |d   |       | j                  |dz          y # t
        $ r%}| j                  dt        |             Y d }~y d }~ww xY w)Nr.   r   )emitstrrD   
isinstancetupler$   send_commands)rF   rN   rc   rd   commandes         r*   __cmd_response_cbzPPPConnection.__cmd_response_cb]   s    II&I7mmJ/G'5)+++GAJx(
 zA~.	 $ II.A7s   A# #	B,BBstartc                     	 | j                   |   }| j                  t        |t              r|d   n|       | j                  |       y # t        $ r Y y w xY w)Nr   )rD   
IndexErrorsend_commandrh   ri   wait_for_reply)rF   rn   items      r*   rj   zPPPConnection.send_commandsm   sV    	=='D 	Ze%<$q'$GE"	  		s   A	 		AAc           	      l   t        | j                  t        j                        | _        t        j                  | j                         t        j                  | j                        }|dxx   t        j                  t        j                  z  t        j                  z  t        j                  z  t        j                  z  t        j                  z  t        j                  z   z  cc<   |dxx   t        j                   t        j"                  z  t        j$                  z  t        j&                  z  t        j(                  z   z  cc<   |dxx   t        j*                  t-        t        dd      z  t        j.                  z  t        j0                  z  t        j2                  z   z  cc<   |dxx   t        j.                  t        j0                  z   z  cc<   d|d   t        j4                  <   d|d   t        j6                  <   d|d   t        j8                  <   |dxx   t        j:                  t        j<                  z  t        j>                  z  t        j@                  z  t        jB                  z   z  cc<   |dxx   t        jD                  t        jF                  z  t        jH                  z  t        jB                  z  z  cc<   t        jJ                  | j                  t        jL                  |       t        jN                  | j                  t        jP                         | jS                          y )Nr   r   r   XCASEr   r   r   )*r   r0   rJ   O_RDWRrL   ttysetrawtermios	tcgetattrIGNCRICRNLIUCLCINPCKIXONIXANYIGNPAROPOSTOLCUCOCRNLONLCRONLRETICANONgetattrECHOECHOEECHONLVMINVTIMEVEOFCBAUDCSIZECSTOPBCLOCALPARENBB9600CS8CREAD	tcsetattrTCSANOWtcflush	TCIOFLUSHrj   )rF   attrss     r*   connect_rfcommzPPPConnection.connect_rfcommv   s   		2995	

499",,TYY7agmmgmm3gmmCgmmSV]VbVbbelererrnn% & 	&agmmgmm3gmmCgmmSV]VdVddeeagnnww'CCgllRU\UbUbbelesessttagllW]]233!"a"#a!"aagmmgmm3gnnDw~~UX_XfXffggaW]]W[[07==@7>>QR$))W__e<		7#4#45r)   sourcecondc                    |t         j                  z  s|t         j                  z  ry|j                         j	                  d      }t        j                  d|      }|r|j                         d   | _        t        j                  |       y)NFutf-8zUsing interface (ppp[0-9]*)r   T)r   r^   r_   readlinedecoderematchgroupsrB   rV   rW   )rF   r   r   linems        r*   r`   zPPPConnection.on_pppd_stdout   sg    $++!3 ''0HH3T:XXZ]DNTr)   c                 &   | j                   j                         }|d|dk(  r| j                  d| j                         n(	 dt        t        |         z   }| j                  d|       t        j                  d|d       yy	# t        $ r d}Y :w xY w)
Nr   r-   zpppd exited: zpppd exited with unknown errorr.   zpppd exited with status dFT)	r[   pollrf   rB   pppd_errorsintKeyErrorrV   warning)rF   statusmsgs      r*   rb   zPPPConnection.check_pppd   s    !{		+t~~6;)KF,DDC 		*C0OO6vajAB   ;:C;s    B BBrk   c                     t        j                  d|        | d}t        j                  | j                  |j                  d             t        j                  | j                         y )Nz--> 
zUTF-8)rV   rW   rJ   writerL   encodery   tcdrain)rF   rk   outs      r*   rq   zPPPConnection.send_command   sL    tG9%&	
CJJw/0		"r)   _source	conditionc                    |t         j                  z  s|t         j                  z  rLt        j                  | j                         | j                  d t        d      |       | j                          y	 | xj                  t        j                  | j                  d      j                  d      z  c_        t'        | j(                  |   t*              r| j(                  |   d   ndd	g| j                  j-                  d
      }t/        fd|D              rP|D cg c]  }|dk7  s	|j1                  d
       }}t!        j2                  d|        | j                  |d |       yy# t        $ r}|j                  t        j                  k(  rt!        j"                  d       Y d }~y| j                  d t        d      |       t!        j$                  |       | j                          Y d }~yd }~ww xY wc c}w )NzSocket errorFr   r   z
Got EAGAINTr   r;   r<   r   c              3   4   K   | ]  }D ]  }||v  
  y wrI   r(   ).0r   
terminatorterminatorss      r*   	<genexpr>z.PPPConnection.on_data_ready.<locals>.<genexpr>   s#     RdkR
zT!R!Rs   r=   z<-- )r   r^   r_   source_removetimeout_PPPConnection__cmd_response_cbr$   rM   bufferrJ   readrL   r   OSErrorerrnoEAGAINrV   errorrc   rh   rD   ri   splitanystriprW   )rF   r   r   rd   rl   linesxr   s          @r*   on_data_readyzPPPConnection.on_data_ready   s   t{{"i$++&=t||,""4n)EzRLLN
	KK277499a077@@K 7AzAZ\a6bdmmJ/2imovhw!!&)ReRR.3?qBwQWWV_?E?LL4w(""5$
;+  	ww%,,&l+&&t\.-I:V!!!$	 @s,   5AE* 
G8(G8*	G532G0*AG00G5c                 6    dt         f fd}d _        d _        t        j                   j
                  t        j                  t        j                  z  t        j                  z   j                         _
        t        j                  d|       _        y )Nr5   c                      t        j                  j                         j                  d t	        d              j                          y)NzModem initialization timed outF)r   r   io_watchr   r$   rM   )rd   rF   s   r*   
on_timeoutz0PPPConnection.wait_for_reply.<locals>.on_timeout   s:    t}}-""46V)WYcdLLNr)   r=   Fi:  )boolr   
term_foundr   r\   rL   r]   r^   r_   r   r   ra   r   )rF   rd   r   s   `` r*   rr   zPPPConnection.wait_for_reply   sr    	D 	 ))$))TZZ$++5MPTP[P[5[]a]o]o*46''z:r)   )z*99#r=   r=   r=   )r5   N)r   )r%   r&   r'   r   SignalFlagsNO_HOOKSrg   r/   r   __annotations__rA   rM   r   rC   r   r$   r   r   rj   r   r   bytesr   IOConditionr   r`   rb   rq   r   rr   __classcell__)rG   s   @r*   r,   r,   .   sa   ))22D3&A"..77vFL( 
HS H# HS HS H\_ Him H.Vc Vt V/(49*= /(S_J` /&)/.2/ #3 #t #4RY d6F6F 4 D "#C #D #S T5E5E SV [_ >; ; ;r)   r,   )r   rV   rJ   r   rX   ry   rw   typingr   r   r   r   r   r   r	   r
   r   gi.repositoryr   r   blueman.Functionsr   blueman.bluemantypingr   r   	Exceptionr$   r,   r(   r)   r*   <module>r      sA     	 	   
 ] ] ] !  ) * + t C	
 r P - - E U  	! E T j  S!" V#$ :%& J'( 	D:+2	9 	q;GOO q;r)   