a oe#@sXdZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z iZdD] Zdee<qdGd d d ZGd d d eZed krTddlZejdddlZeeZeZdZeD]*ZeeedkreedZqedZqeZeeekr$e deeefe de!de de!de de!ddS)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. N)axdebug) Exception)contexts) RaiseNotImpl_wrapz and assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while c@seZdZd(ddZddZdd Zd d Zd d ZddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS))SourceCodeContainer rNcCs@||_||_|r|d|_||_i|_||_||_d|_dSNr) sourceContexttext _buildlines nextLineNofileName codeContextssitestartLineNumber debugDocument)selfr rr rrrrBC:\Program Files\Certbot\pkgs\win32comext\axdebug\codecontainer.py__init__s zSourceCodeContainer.__init__cCs.d|_|_|_d|_d|_d|_d|_dSN)r lines lineOffsetsrrrr rrrr_Close0s zSourceCodeContainer._ClosecCs|jSr)r rrrrGetText7szSourceCodeContainer.GetTextcCsds JddS)NrzYou must subclass thisr)rdntrrrGetName:szSourceCodeContainer.GetNamecCs|jSr)rrrrr GetFileName=szSourceCodeContainer.GetFileNamecCs8|z |j|WSty2ttjdYn0dS)NZscode)rr IndexErrorrwinerrorS_FALSE)rZ cLineNumberrrrGetPositionOfLine@s   z%SourceCodeContainer.GetPositionOfLinecCsT|d}d}|jddD]}||kr.qH|}|d}qttjd|||fS)Nrrr!)rrrr#r$)rcharPosZ lastOffsetlineNoZ lineOffsetrrrGetLineOfPositionGs  z%SourceCodeContainer.GetLineOfPositioncCs6|jt|jkrd|_dS|j|j}|jd|_|S)Nrr)rlenr)rrcrrr GetNextLineVs   zSourceCodeContainer.GetNextLinecCs||j|Sr)rr)rZnumrrrGetLine^szSourceCodeContainer.GetLinecCs t|Sr)r*rrrrr GetNumCharsbszSourceCodeContainer.GetNumCharscCs|t|jSr)rr*rrrrr GetNumLineseszSourceCodeContainer.GetNumLinescCs@|jd|}|dkr"t|j}n|d}|j||}||fS)N rr)r findr*)rposiZnewposrrrr _buildlineis  zSourceCodeContainer._buildlinecCsLg|_dg|_|d\}}|rH|j||j|||\}}qdSr )rrr5append)rliner2rrrr rs  zSourceCodeContainer._buildlinescCs|\}}|\}} ||d} |j| |} | |j} | dkrBn*| dkrZ|jtjn|jtj| ft|} | | |_d}|tj kr|t vrtj }nF|tj krtj }n4|tjkrtj}n"|tjkrtj}n|tjkrtj}| dkrn(| dkr|j|n|j|| fdS)Nrr)rrlastPosattrsr6rSOURCETEXT_ATTR_COMMENTr*tokenizeNAME _keywordsZSOURCETEXT_ATTR_KEYWORDSTRINGZSOURCETEXT_ATTR_STRINGNUMBERZSOURCETEXT_ATTR_NUMBEROPZSOURCETEXT_ATTR_OPERATORCOMMENT)rtypetokensposeposr7ZsrowZscolZerowZecolZlinenumZ realCharPosZ numskippedZkwSizeattrrrr _ProcessToken{s<        z!SourceCodeContainer._ProcessTokencCsdd|_g|_zt|j|jWntjy4Yn0t||j}|r^|jt j |f|jSr ) r8r9r;r,rG TokenErrorr*rr6rr:)rZnumAtEndrrrGetSyntaxColorAttributessz,SourceCodeContainer.GetSyntaxColorAttributescCstt|||||jtjSr)rrZDebugCodeContextrrZIID_IDebugCodeContext)rr'r&r*rrr_MakeDebugCodeContextsz)SourceCodeContainer._MakeDebugCodeContextcCsH||\}}z||d}Wn|}Yn0|||||}|S)Nr)r(r%rJ)rr&r'offsetZendPosZ codecontextrrr_MakeContextAtPositions z*SourceCodeContainer._MakeContextAtPositioncCsR||\}}||}z|j|}Wn&tyL||}||j|<Yn0|Sr)r(r%rKeyErrorrL)rr&r'rKZccrrrGetCodeContextAtPositions   z,SourceCodeContainer.GetCodeContextAtPosition)r rrNN)__name__ __module__ __qualname__rrrrr r%r(r,r-r.r/r5r rGrIrJrLrNrrrrrs.   $  rc@s$eZdZddZddZddZdS)SourceModuleContainercCs||_t|drV|jj}|ddvr0|dd}zt|}Wq~tjyRYq~0n(|jdkrzttj dkrztj d}nd}t |d|dS)N__file__)OoCcSs__main__rz ) modulehasattrrSwin32apiGetFullPathNameerrorrOr*sysargvrr)rr\fnamerrrrs    zSourceModuleContainer.__init__c Csz|jdurt|}|r`zt|d|_Wqlty\}zdt||_WYd}~qld}~00n d|j|_||jS)Nr4z# Exception opening file # %sz## No file available for module '%s')r r openreadIOErrorreprr\r )rrcZdetailsrrrrs & zSourceModuleContainer.GetTextcCs|jj}zt|jj}Wn0tjy6|jj}YntyJ|}Yn0|tjkrd| ddS|tj krr|S|tj krt j |dS|tjkrd|SttjddS)N.rTrzfile:%sr!)r\rOr^r_rSr`AttributeErrorrZDOCUMENTNAMETYPE_APPNODEsplitZDOCUMENTNAMETYPE_TITLEZDOCUMENTNAMETYPE_FILE_TAILospathZDOCUMENTNAMETYPE_URLrr#Z E_UNEXPECTED)rrnamercrrrrs        zSourceModuleContainer.GetNameN)rOrPrQrrrrrrrrRs rRr[rhrzLengths dont match!!! (%d/%d)z GetLineOfPos= )"__doc__rar;r^r#Zwin32com.axdebugrZwin32com.server.exceptionrr)rutilrrr=rjrmrrRrOrlr6ZttestZscrIr9ZattrlenrFrBrr r*printr(rrrrs>     14