ib$dZddlmZddlZddlZddlZddlmZddlm Z ddl Z ddl Z ddl m Z mZddlmZddlmZd eDZ Gd d ZGd d eZedkrddlmZeeZeZdZeD]Zeeer eedz Zedz Z e Z!ee"e!kre#dede"e!de#de$de#de$de#de$ddSdS)zA utility class for a code container. A code container is a class which holds source code for a debugger. It knows how to color the text, and also how to translate lines into offsets, and back. ) annotationsN)kwlist)Any)axdebugcontexts)_wrap) COMExceptionc:h|]}||S)islower).0_keywords OC:\PYTHON\_runtimes\venv\Lib\site-packages\win32comext/axdebug/codecontainer.py rs:         ceZdZ dddZdZdZd Zd Zd Zd Z d Z dZ dZ dZ dZdZdZdZdZdZdZdS)SourceCodeContainer rNtext str | Nonec||_||_|r|d|_||_i|_||_||_||_dSNr) sourceContextr _buildlines nextLineNofileName codeContextssitestartLineNumber debugDocument)selfrrrrrr s r__init__zSourceCodeContainer.__init__s`+ $          ,. .*rchdx|_x|_|_d|_d|_d|_d|_dSN)rlines lineOffsetsrr rrr!s r_ClosezSourceCodeContainer._Close4s=488 8DJ!1 ! !rc|jSr$)rr's rGetTextzSourceCodeContainer.GetText;s yrc td)NzYou must subclass this)NotImplementedError)r!dnts rGetNamezSourceCodeContainer.GetName>s!":;;;rc|jSr$)rr's r GetFileNamezSourceCodeContainer.GetFileNameAs }rc| |j|S#t$rttjwxYw)Nscode)r*r& IndexErrorr winerrorS_FALSE)r! cLineNumbers rGetPositionOfLinez%SourceCodeContainer.GetPositionOfLineDsQ  7#K0 0 7 7 7X%5666 6 7s #%Ac|d}d}|jddD]}||krn"|}|dz }ttj|||z fS)Nrr2)r*r&r r5r6)r!charPos lastOffsetlineNo lineOffsets rGetLineOfPositionz%SourceCodeContainer.GetLineOfPositionKsz  *122. 7 7JG###J aKFFX%5666 6*,--rc|jt|jkr d|_dS|j|j}|xjdz c_|S)Nrr:)rlenr%)r!rcs r GetNextLinezSourceCodeContainer.GetNextLineZsF ?c$*oo - -DO2 Z ( 1 rcD||j|Sr$)r*r%)r!nums rGetLinezSourceCodeContainer.GetLinebs z#rcDt|Sr$)rBr*r's r GetNumCharszSourceCodeContainer.GetNumCharsfs4<<>>"""rcR|t|jSr$)r*rBr%r's r GetNumLineszSourceCodeContainer.GetNumLinesis 4:rc|jd|}|dkrt|j}n|dz}|j||}||fS)N rr:)rfindrB)r!posinewposrs r _buildlinezSourceCodeContainer._buildlinemsR INN4 % % q55^^FFUF Ic&j !&yrcg|_dg|_|d\}}|rP|j||j|||\}}|NdSdSr)r%r&rSappend)r!linerOs rrzSourceCodeContainer._buildlinesvs 3OOA&& c - J  d # # #   # #C ( ( (,,ID# - - - - -rc$|\}}|\}} ||dz } |j| |z} | |jz } | dkrnQ| dkr%|jt jn&|jt j| ft|} | | z|_d}|tj kr|tvr t j }ns|tj kr t j }nV|tjkr t j}n9|tjkr t j}n|tjkr t j}| dkrdS| dkr|j|dS|j|| fdS)Nr:r)r*r&lastPosattrsrUrSOURCETEXT_ATTR_COMMENTrBtokenizeNAME _keywordsSOURCETEXT_ATTR_KEYWORDSTRINGSOURCETEXT_ATTR_STRINGNUMBERSOURCETEXT_ATTR_NUMBEROPSOURCETEXT_ATTR_OPERATORCOMMENT)r!typetokensposeposrVsrowscolerowecollinenum realCharPos numskippedkwSizeattrs r _ProcessTokenz!SourceCodeContainer._ProcessTokens d d (&w/$6  4</ ??  1__ J  g= > > > > J  w> K L L LU"V+  8=  !!6 X_ $ $1DD X_ $ $1DD X[ 3DD X% % %2D Q;; D q[[ J  d # # # # # J  tVn - - - - -rcHd|_g|_ tj|jD] }|j| n#tj$rYnwxYwt ||jz }|r&|jtj |f|jSr) rXrYr[rDrs TokenErrorrBr*rUrrZ)r!tokensnumAtEnds rGetSyntaxColorAttributesz,SourceCodeContainer.GetSyntaxColorAttributess   "+D,<== , ,""F+++ ,"    D t||~~&&5  K J  w>I J J Jzs&7A A c lttj|||||jtjSr$)rrDebugCodeContextrrIID_IDebugCodeContext)r!r=r;rBs r_MakeDebugCodeContextz)SourceCodeContainer._MakeDebugCodeContexts2  %fgsD$) L L  )   rc||\}} ||dz}n #|}YnxYw|||||z }|S)Nr:)r?r8r|)r!r;r=offsetendPos codecontexts r_MakeContextAtPositionz*SourceCodeContainer._MakeContextAtPositionsk//88 ++FQJ77FF FFF00&7BRSS s39c||\}}||} |j|}n/#t$r"||}||j|<YnwxYw|Sr$)r?r8rKeyErrorr)r!r;r=r~ccs rGetCodeContextAtPositionz,SourceCodeContainer.GetCodeContextAtPositions//88((00 ,"7+BB , , ,,,W55B)+D g & & & , s =)A)(A))rrrNN)rr)__name__ __module__ __qualname__r"r(r*r.r0r8r?rDrGrIrKrSrrsrxr|rrr rrrrs>  +++++*"""<<<777 . . .###---".".".H           rrc eZdZdZdZdZdS)SourceModuleContainerc|||_t|drK|jj}|ddvr |dd} tj|}nR#tj$rYnAwxYw|jdkr0ttj dkrtj d}nd}t |d|dS)N__file__)OoCcSs__main__rz ) modulehasattrrwin32apiGetFullPathNameerrorrrBsysargvrr")r!rfnames rr"zSourceModuleContainer.__init__s 6: & & %K(ERy:::crc   077>    *,,SX1B1B $$$T477777sAA A c&|j|}|rJ t|d|_n1#t$r}d||_Yd}~nd}~wwxYwd|jd|_||jS)NrRz# COMException opening file # z # No file available for module '')rr0openreadOSErrorrr)r!rdetailss rr*zSourceModuleContainer.GetTexts 9 $$&&E NN $UC 0 0 5 5 7 7DIINNN M' M MDIIIIIINNt{MMM      ys'A A% A  A%c|jj} tj|jj}n.#tj$r|jj}Ynt $r|}YnwxYw|tjkr| ddS|tj kr|S|tj kr%tj |dS|tjkrd|Stt j)N.rr:zfile:r2)rrrrrrAttributeErrorrDOCUMENTNAMETYPE_APPNODEsplitDOCUMENTNAMETYPE_TITLEDOCUMENTNAMETYPE_FILE_TAILospathDOCUMENTNAMETYPE_URLr r5 E_UNEXPECTED)r!r-namers rr.zSourceModuleContainer.GetNames{# ,T[-ABBEE~ ) ) )K(EEE   EEE  '2 2 2::c??2& & G2 2 2L G6 6 67==''* * G0 0 0"5?? "X%:;;; ;s-A AAN)rrrr"r*r.r rrrrsA888$   <<<<rso #""""" ........''''''222222      nnnnnnnnb1<1<1<1<1</1<1<1