
    TOgQ              	       t   % 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JrJ	r	J
r
Jr  S SKr\R                  " \5      r\R                   " \ R"                  R%                  SS5      S9  Sq\\S'   Sq\\S'   Sq\\S	'   Sq\\S
'   Sq\\S'   Sq\\S'   0 r\\\	4   \S'   Sq\\S'   Sq\\S'   Sq\\S'   Sq \\S'   Sq!\\S'   Sq"\\S'   Sq#\\S'    " S S5      r$S\SS4S jr%S\	S\4S jr& S7S\S\SS4S jjr'S8S\S\	S\SS4S  jjr(S!\
\   SS4S" jr)S#\S$\\\	4   SS4S% jr*S&\S$\\\	4   SS4S' jr+S\
\   4S( jr,S)\
\   S*\\   S+\SS4S, jr-S)\
\   S*\\   S+\SS4S- jr.  S9S.\\   S*\\   S\
\   4S/ jjr/ S:S*\\   S\
\   4S0 jjr0S;S1 jr1S+\SS4S2 jr2S;S3 jr3S;S4 jr4S;S5 jr5\S6:X  a  \5" 5         gg)<    N)OptionalTupleAnyListDictLOGLEVELINFOlevelF
SIMPLISTICWithRedacted	PrintJsonVerbosePrintGetRawWhoisResultRulesetFailuresIgnoreReturncode
TestAllTldTestRunOnlyWithPublicSuffixWithExtractServersWithStripHttpStatusWithNoIgnoreWwwc                       \ rS rSr% \\S'   0 r\\\4   \S'   S\4S jr	S\S\4S jr
S\\   S\\   4S	 jrS
\\   S\\   4S jr  SS\S\S\\\\\4   4   4S jjrSS jrSrg)ResponseCleaner,   datarDictpathToTestFilec                 0    U R                  U5      U l        g N)readInputFiler   )selfr   s     O/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/whois/main.py__init__ResponseCleaner.__init__0   s     &&~6	    returnc                     [         R                  R                  U5      (       d  g[        USS9 nUR	                  5       R                  SS9sS S S 5        $ ! , (       d  f       g = f)N rb)modeignore)errors)ospathexistsopenreaddecode)r#   r   fs      r$   r"   ResponseCleaner.readInputFile6   sF     ww~~n--.t,668??(?3 -,,s   A
A%sectionc                    [        U5      S:X  a  U$ SnSn[        R                  " X!U   5      (       a1  UR                  U5        [        R                  " X!U   5      (       a  M1  [        U5      S-
  n[        R                  " X!U   5      (       a?  UR                  U5        [        U5      S-
  n[        R                  " X!U   5      (       a  M?  U$ )Nr   ^\s*$   )lenrematchpop)r#   r7   rrns       r$   cleanSectionResponseCleaner.cleanSectionA   s     w<1Nhhr1:&&KKN hhr1:&& L1hhr1:&&KKNGq A hhr1:&& r'   bodyc                     / nSnUR                  / 5        U HJ  n[        R                  " SU5      (       a  US-  nUR                  / 5        M7  X#   R                  U5        ML     SnU[        U5      :  a+  U R	                  X%   5      X%'   US-  nU[        U5      :  a  M+  / nSnU[        U5      :  aI  [        X%   5      S:  a"  UR                  SR                  X%   5      5        US-  nU[        U5      :  a  MI  U$ )Nr   r9   r:   
)appendr<   r=   r;   rA   join)r#   rC   sectionsr@   linem	sections2s          r$   splitBodyInSections#ResponseCleaner.splitBodyInSectionsW   s     %'Dxx$''Q#Kt$  #h-++HK8HKFA #h-
  "	#h-8;!#  8;!78FA #h-
 r'   verbosewith_cleanup_resultsc                    [         R                  " U R                  UU5      nS/ / / / S.U l        / n/ nUR	                  S5      nSnSnSn	U GHI  n
USL a=  U
R                  S5      (       a%  U R                  S   R                  U
5        SU
-   n
MD  SnUSL aB  U	SL a=  U
R                  S5      (       a%  U R                  S	   R                  U
5        S
U
-   n
M  Sn	USL aD  U
R                  S5      (       d,  U
R                  S5      (       d  U
R                  S5      (       a  SnUSL a&  U R                  S   R                  U
5        SU
-   n
GM  UR                  U
5        SU
;   a  SU
-   n
U
R                  S5      (       a  SU
-   n
UR                  U
5        GML     U R                  U5      nU R                  U5      U R                  S'   SR                  U5      U R                  4$ )NF)BodyHasSectionsPreamblePercentBody	PostamblerE   [rR   zPRE;T%rS   zPERCENT;z-- z>>> zCopyright noticerU   zPOST;	zTAB;zCR;rT   )whoiscleanupWhoisResponser   r   split
startswithrF   endswithrA   rL   rG   )r#   rN   rO   resultrC   r?   zpreambleSeenpostambleSeenpercentSeenrI   s              r$   r[   $ResponseCleaner.cleanupWhoisResponsew   s   
 ++II 
  %&

 LLDu$??3''JJz*11$7!D=D#t#u(<??3''JJy)006%,D"%??5))T__V-D-DXjHkHk$(M$

;'..t4~KKt|}}}T""t|IIdOA D   &!55d;

6yy}djj((r'   Nc                    / SQnU H;  nSnU R                   U    H#  nSU;   a  SOSnSU;   a  SOSn[        X&XT5        M%     M=     SnU R                   U   (       au  SnU R                   U    H_  n[        R                  " S	U5      (       a  S
OSnSU;   a  SOSnSU;   a  SOSn[        SU SU SU U U 35        US-  n[        U5        Ma     g g )N)rR   rS   rU   r   rX   z [TAB] r*   rY   z [CR] rT   z[ \t]+\r?\nz [WHITESPACE AT END] z# --- z
 Section:  r:   )r   printr<   search)r#   zzkr@   linestabcrwss           r$   printMeResponseCleaner.printMe   s    1AAA#'5=ib!%XBaS( '  ::a=AA02		.%0P0P,VX#'5=ib!%XBqcA3atC5=>Qe ' r'   )r   r   )FFr(   N)__name__
__module____qualname____firstlineno__str__annotations__r   r   r   r%   r"   r   rA   rL   boolr   r[   ro   __static_attributes__ r'   r$   r   r   ,   s    
IE4S>77	4	4 
	4c 
c,3i 
cD %*=)=) #=) 
sDcN"	#	=)~r'   r   dr(   c                 L    [         SL a  [        S5        [        SU  S35        g g )NFr*   ztest domain: <<<<<<<<<< z >>>>>>>>>>>>>>>>>>>>)r   rg   )r{   s    r$   prepItemr}      s)    Eb	(+@AB r'   xc                 B    [        U 5       nUR                  S5      S   $ )N'r:   )typer\   )r~   ss     r$   xTyper      s    7)A773<?r'   printgetRawWhoisResultc                    [         R                  " [        [        S[        [
        [        [        [        [        [        S9
n[         R                  " XS9nUc+  [        S5        [        S[         R                  " 5       5        g UR                  n[        SL a7  S H  nXT;   d  M
  XE    XE'   M     [        [         R"                  " U5      5        g UR%                  5        H  u  pg[
        (       a?  Sn['        U[(        5      (       a  [        US-   Xg4-  5        M;  [        US	-   Xg4-  5        MO  S
n['        U[(        5      (       a  [        US-   U[+        U5      U4-  5        M  [        US	-   U[+        U5      U4-  5        M     g )NT)
ignore_returncoderN   internationalizedinclude_raw_whois_text
simplisticwithRedactedwithPublicSuffixextractServersstripHttpStatusnoIgnoreWww)domainpcNonerE   )creation_dateexpiration_datelast_updatedz%-18s z'%s'z%sz%-18s %-17s )rZ   ParameterContextr   r   r   r   r   r   r   r   r   queryrg   get_last_raw_whois_data__dict__r   jsondumpsitems
isinstancerv   r   )	r{   r   r   wwdr5   rj   vsss	            r$   testItemr      s@   $ 
		*5!))+#
B 	1$AyfdE1134 
BDEAw5' F 	djjn
:B!S!!rF{qf,-rDyQF*+B!S!!rF{q%(A&667rDyQa!$445 r'   ewhatc                 n    U[         ;  a	  0 [         U'   U[         U   U '   SU  SU SU 3n[        U5        g )NzDomain: z; Exception: z	; Error: )r   rg   )r{   r   r   messages       r$   	errorItemr     s@    8HTN1=is;G	'Nr'   aListc                 ^   U  H  nU(       d  M  [        UR                  5       5      S:X  a  M+  UR                  5       R                  S5      (       a  MQ  UR                  S5      S   nUR                  5       n[	        U5         [        U5        M     g ! [        R                   a  n[        XSS9   S nAM  S nAf[        R                   a  n[        XSS9   S nAM  S nAf[        R                   a  n[        XSS9   S nAGM  S nAf[        R                   a  n[        XSS9   S nAGM,  S nAf[        R                   a  n[        XSS9   S nAGMT  S nAf[        R                   a  n[        XS	S9   S nAGM|  S nAf[        R                   a  n[        XS
S9   S nAGM  S nAff = f)Nr   #
UnknownTld)r   FailedParsingWhoisOutputUnknownDateFormatWhoisCommandFailedWhoisQuotaExceededWhoisPrivateRegistryWhoisCommandTimeout)r;   stripr]   r\   r}   r   rZ   r   r   r   r   r   r   r   r   )r   r{   r   s      r$   testDomainsr   '  sG   qwwy>Q 779$$ GGCLOGGI	8QK% &  	/a..-- 	=a!;<<&& 	6a!455'' 	7a!566'' 	7a!566)) 	9a!788(( 	8a!677	8s`   BF,(
B88F,
CF,6
DF,
D//F,
EF,.
E??F,
F''F,fPathfileDatac                    [         R                  R                  U 5      (       d  g U R                  S5      (       d  g U S S n/ X'   X   n[	        U SS9 n[        U5       Hr  u  pVUR                  5       n[        U5      S:X  d  UR                  S5      (       a  M<  [        R                  " SU5      nUS   U;  d  M^  UR                  US   5        Mt     S S S 5        g ! , (       d  f       g = f)Nz.txtzutf-8)encodingr   r   z\s+)r/   r0   isfiler^   r2   	enumerater   r;   r]   r<   r\   rF   )r   r   bNamexxr5   indexrI   aas           r$   getTestFileOner   M  s    77>>%  >>&!!#2JEHO	B	eg	&!$Q<KE::<D4yA~!5!5&$'B!uB		"Q%  ( 
'  
'	& s   A&C>C
C-tDirc                 b    [         R                  " U 5       H  nU  SU 3n[        X15        M     g )N/)r/   listdirr   )r   r   itemr   s       r$   getTestFilesAllr   e  s/     

4 &$ u' !r'   c                  ,    [         R                  " 5       $ r!   )rZ   	validTldsrz   r'   r$   getAllCurrentTldr   n  s    ??r'   r?   allRegextldc                     [         SL a7  [        R                  " U5      nU(       a  UOSU 3nU R                  U 5        g U R                  SU 35        g )NTzmeta.r   rZ   getTestHintrF   r?   r   r   hints       r$   appendHintOrMetar   r  sK     T  %t5
		TF
		E#- r'   c                 x    [         SL a1  [        R                  " U5      nU(       a  U R                  U 5        g g g )NTr   r   s       r$   
appendHintr     s7     T  %II   r'   	allHavingc                     / n[        5        H=  nUc  [        X!U5        M  [        R                  " X5      (       d  M1  [        X!U5        M?     U$ r!   )r   r   r<   rh   )r   r   r?   r   s       r$   makeMetaAllCurrentTldr     sI     B!R3/99X##R3/ " Ir'   c                     / n[        5        H=  nU c  [        XU5        M  [        R                  " X5      (       d  M1  [        XU5        M?     U$ r!   )r   r   r<   rh   )r   r?   r   s      r$   makeTestAllCurrentTldr     sI     B!rS)99X##rS) " Ir'   c                  R    [        S5        [        5        H  n [        U 5        M     g )NzTld's currently supported)rg   r   )r   s    r$   showAllCurrentTldr     s    	
%&!c
 "r'   c                    [         R                  " 5       nX;   ae  [        X   R                  5       5       HE  nX   U    nSU;   a(  UR	                  S5      S   nUR	                  S5      S   n[        X#S5        MG     g g )Nz
re.compilezre.compile(r:   z, re.IGNORECASE)r   
IGNORECASE)rZ   
get_TLD_REsortedkeysr\   rg   )r   r?   keyrules       r$   ShowRulesetr     sw    				B
y"',,.)Cgcl^Dt#zz-03zz"45a8#\* * r'   c                      [         R                  R                  [        R                  S   5      n [        SU  SU  SU  SU  SU  S35         [        R                  " S5        g )	Nr   rE   a   
    [ -h | --usage ]
        print this text and exit

    [ -V | --Version ]
        print the build version string
        and exit

    [ -S | --SupportedTld ]
        print all known top level domains
        and exit

    [ -a | --all]
        test all existing tld currently supported
        and exit

    [ -f <filename> | --file = <filename> " ]
        use the named file to test all domains (one domain per line)
        lines starting with # or empty lines are skipped, anything after the domain is ignored
        the option can be repeated to specify more then one file
        exits after processing all the files

    [ -D <directory> | --Directory = <directory> " ]
        use the named directory, ald use all files ending in .txt as files containing domains
        files are processed as in the -f option so comments and empty lines are skipped
        the option can be repeated to specify more then one directory
        exits after processing all the dirs

    [ -d <domain> | --domain = <domain> " ]
        only analyze the given domains
        the option can be repeated to specify more domain's

    [ -v | --verbose ]
        set verbose to True,
        verbose output will be printed on stderr only

    [ -j | --json ]
        print each result as json

    [ -I | --IgnoreReturncode ]
        sets the IgnoreReturncode to True,

    [ -p | --print ]
        also print text containing the raw output of the cli whois

    [ -R | --Ruleset ]
        dump the ruleset for the requested tld and exit
        should be combined with -d to specify tld's

    [ -C <file> | --Cleanup <file> ]
        read the input file specified and run the same cleanup as in whois.query,
        then exit

    # test two domains with verbose and IgnoreReturncode
    example: zn -v -I -d meta.org -d meta.com

    # test all supported tld's with verbose and IgnoreReturncode
    example: zW -v -I -a

    # test one specific file with verbose and IgnoreReturncode
    example: zq -v -I -f tests/ok-domains.txt

    # test one specific directory with verbose and IgnoreReturncode
    example: z -v -I -D tests

r:   )r/   r0   basenamesysargvrg   exit)names    r$   usager     s    77CHHQK(D	 6l V  V  V  V AB	DL HHQKr'   c                     [        [        5      (       am  [        S5        [        [        R	                  5       5       H@  n [        [        U    R	                  5       5       H  n[        X[        U    U   5        M     MB     g g )Nz
# ========================)r;   r   rg   r   r   )ijs     r$   showFailuresr     s\    
8}},-(AHQK,,./aHQKN+ 0 ) r'   c                  \   [         R                  R                  [        R                  S   5      n U S:X  a  SqOSq [        R                  " [        R                  SS  S/ SQ5      u  pS nS nS n/ nS n/ nS n	/ n
0 nW GH   u  pUS	;   aF  [        [        R                  " 5       5       H  n[        U5        M     [        R                  " S5        US
;   a4  [        [        R                  " 5       5        [        R                  " S5        US:X  a   [        5         [        R                  " S5        US;   a  SqUS;   a  Sq[!        U5      nUS;   a  Sq[!        U5      nUS;   a  Sq[$        R&                  " SS9  US;   a  SqUS;   a  SqUS;   a@  Sq[-        S 5      n[        U5       H  n[        U5        M     [        R                  " S5        US;   a  SqSqUS;   a  SqUS;   aW  Un[         R                  R3                  U5      nUSL a1  [        U S3[        R4                  S9  [        R                  " S5        US;   a  Un[         R                  R7                  U5      nUSL a1  [        U S3[        R4                  S9  [        R                  " S5        [9        U5      nUR;                  5       u  nnUR=                  5         [        R                  " S5        US;   ao  Un[         R                  R7                  U5      nUSL a1  [        U S3[        R4                  S9  [        R                  " S5        Xx;  a  UR?                  U5        SqUS;   a  Un	X;  a  U
R?                  U	5        US;   a  Sq US ;   a  Sq!US!;   a  Sq"US";   a  Sq#US#;   d  GM  Sq$GM#     U  S$[
         3n[J        RM                  U5        [0        SL a1  U
(       a*  U
 H  n	[O        U	5        M     [        R                  " S5        [        (       aR  [.        SL a  [Q        [S        X45      5        O[Q        [-        U5      5        [U        5         [        R                  " S5        U(       a\  0 nU H  n[W        UU5        M     URY                  5        H  u  nn[Q        U5        M     [U        5         [        R                  " S5        U(       a\  0 nU H  n[[        UU5        M     URY                  5        H  u  nn[Q        U5        M     [U        5         [        R                  " S5        U
(       a+  [Q        U
5        [U        5         [        R                  " S5        [        5         [        R                  " S5        g ! [        R                   a$    [        5         [        R                  " S5         GN@f = f)%Nr   ztest2.pyFTr:   zTtjRSpvVIhaf:d:D:r:H:C:)Testingtestr   r   SupportedTldrg   rN   Versionr   allzfile=z
Directory=zdomain=zreg=zhaving=zCleanup=r   r   r   r   withNoIgnoreWww   )z-Sr   )z-Vr   z-h)z-az--all)z-Hz--having)z-rz--reg)z-vz	--verboseDEBUGr
   )z-pz--print)z-jz--json)z-Tz	--Testing)z-tz--test)z-Rz	--Ruleset)z-Dz--Directoryz& cannot be found or is not a directory)filee   )z-Cz	--Cleanupz! cannot be found or is not a file)z-fz--file)z-dz--domainz--extractServersz--stripHttpStatusz--withRedactedz--withPublicSuffixz--withNoIgnoreWwwz SIMPLISTIC: ).r/   r0   r   r   r   r   getoptGetoptErrorr   r   r   rZ   r   rg   
getVersionr   rv   r   loggingbasicConfigr   r   r   r   r   isdirstderrr   r   r[   ro   rF   r   r   r   r   r   logdebugr   r   r   r   r   r   r   )r   optsargsr   r   	directorydirsfilenamefilesr   domainsr   optargr   r?   r   isDirinFileisFilercd1r   msgdNametestFiler~   s                              r$   mainr    s      !-Dz

]]HHQRL%

B  $I"H#ID"HE FG!H((eoo/0c
 1HHQK##%""$%HHQK$;GHHQK/!J$$JCI/!J3xH%%Gg.##%)"""I%%J&t,Br
d #HHQK"" JK%%G''IGGMM),E~#IJQTQ[Q[\%%FWW^^C(F ABT (B//1IBJJLHHQK""HWW^^H-F
"CD3::V$X&"
$$F$v&%&!%&'"&#$L'(#&'"OI L F-
|
,CIIcN$7F z%-iBC-h78EE8, #>>+KHaN ,H8X. #>>+KHaN ,G	GHHQKG  s   -U3 34V+*V+__main__)F)Generic)NNr!   rq   )6r/   r<   r   r   r   r   typingr   r   r   r   r   rZ   	getLoggerrr   r   r   environgetr   rx   rw   r   r   r   r   r   r   rv   r   r   r   r   r   r   r   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rz   r'   r$   <module>r     s   
 	  
    !   "**..V< = 
D d 	4  $  $ $sCx.  $ 
D T  $   D  ! T ! \ \~C C CS S  $)C6
C6 C6 
C6P  C  !8tCy !8T !8L# c3h D 0(
(38n( 
($s) !S	!sm! 
! 
	! !S	!sm! 
! 
	!  $"}sm 
#Y" #sm	#Y+S +T +Qh,Tn zF r'   