a „oeÀZã@sVdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZdZdZdZdZd  d ¡Zd  d ¡Zd  d ¡Zd  d ¡ZGdd„de jƒZdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z!d1dd„Z"da#da$ea%d2dd „Z&d!d"„Z'd#d$„Z(d%d&„Z)d3d'd(„Z*d4d)d*„Z+d5d+d,„Z,d-d.„Z-d6d/d0„Z.dS)7z2 Various utilities for running/importing a script éN)Údialog)ÚTreeViewé)Ú ParseArgséézaNo debugging Step-through in the debugger Run in the debugger Post-Mortem of unhandled exceptionsÚ ú Úasciiz c@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú DlgRunScriptz#A class for the 'run script' dialogcCsVtj |tj¡| tjd¡| tjd¡| tjdd¡|  |j tj ¡||_ dS)NÚscriptÚargsÚ debuggingTypeÚi) rÚDialogÚ__init__Úwin32uiZIDD_RUN_SCRIPTZAddDDXZ IDC_EDIT1Z IDC_EDIT2Ú IDC_COMBO1Z HookCommandÚOnBrowseZ IDC_BUTTON2Ú bHaveDebugger)Úselfr©rúFC:\Program Files\Certbot\pkgs\pythonwin\pywin\framework\scriptutils.pyr(s zDlgRunScript.__init__cCsNtj |¡}| tj¡}tD]}| |¡q| |d¡|j sJ|  d¡dS)Nrr) rrÚ OnInitDialogZ GetDlgItemrrÚdebugging_optionsZ AddStringZ SetCurSelrZ EnableWindow)rÚrcZcboÚorrrr0s   zDlgRunScript.OnInitDialogcCsb|dkr dStjtjB}t ddd|d|¡}| d¡| ¡tjkrHdS| ¡|d<|  d¡dS)NrrzPython Scripts (*.py)|*.py||z Run Scriptr ) Úwin32conÚOFN_OVERWRITEPROMPTÚOFN_FILEMUSTEXISTrÚCreateFileDialogÚ SetOFNTitleÚDoModalÚIDOKÚ GetPathNameZ UpdateData)rÚidÚcodeÚ openFlagsÚdlgrrrr9s  ÿ   zDlgRunScript.OnBrowseN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrr %s r cCs*zddl}|jWSty$YdS0dS)aGet the default Python debugger. Returns the debugger, or None. It is assumed the debugger has a standard "pdb" defined interface. Currently always returns the 'pywin.debugger' debugger, or None (pdb is _not_ returned as it is not effective in this GUI environment) rN)Zpywin.debuggerÚdebuggerÚ ImportError)ZpywinrrrÚ GetDebuggerHs  r/c CsftjD]Z}z|r&t |¡|kr&WdSWqtjy^}ztd||fƒWYd}~qd}~00qdS)zUGiven a path only, see if it is on the Pythonpath. Assumes path is a full path spec.rz.Warning: The sys.path entry '%s' is invalid %sNr)ÚsysÚpathrÚFullPathÚerrorÚprint)r1ZsyspathÚdetailsrrrÚIsOnPythonPathWs   ÿr6cCsêtj |¡\}}t |¡}}tj |¡d}g}d}t|ƒsât|ƒdkrÞtj |¡\}}| |¡t|ƒr>|t j vr>tj  tj  ||d¡¡s¾tj  tj  ||d¡¡s¾tj  tj  ||d¡¡r>|  ¡d  |¡d||fSq>|}||fS)z»Given a filename, return (module name, new path). eg - given "c:\c\my.py", return ("b.c.my",None) if "c:" is on sys.path. If no package found, will return ("my", "c:\c") rNrz __init__.pyz __init__.pycz __init__.pyoÚ.)Úosr1Úsplitrr2Úsplitextr6ÚlenÚappendr0ÚmodulesÚexistsÚjoinÚreverse)ÚfileNamer1ÚfnameZorigPathZmodBitsZ newPathReturnZmodBitrrrÚGetPackageModuleNamefs.  ÿþüûú rCcCs6zt ¡ ¡\}}| ¡WStjy0YdS0dS)zt$yt}z$t d |j%|j&f¡WYd}~dSd}~00| '¡ (t)t*¡ (t+t*¡t*}t!j,}t-|ƒt!_,t!j, .d| ¡t!jd}tj | ¡d}|sà|t!jd<d}nt!j .d|¡d}d}t /d¡tj | ¡d}t 0¡t 1d |d¡d}dd l2m3}|durZ|t4krZt d¡t4}zt5|| dƒ}Wnt6d| ƒYdS0| t7_8zR|tkrª|j9|t7j:ddn*|t krÈ|j9|t7j:ddn t;|t7j:ƒd}Wntdƒd}d}Ynìt?y.}z|}d}WYd}~nÈd}~0tyŠ|j@rZ|j@jArZ|j@jA B¡tC D¡|j@r‚|j@jAr‚|j@jA Eg¡d}Ynd|j@r®|j@jAr®|j@jA B¡tC D¡|j@rÖ|j@jArÖ|j@jA Eg¡|tFkrè| G¡Yn0t7`8|t!_,|rt!jd=n |t!jd<| H¡|r4t 1d| |f¡nt 1d|¡zt!jI J¡Wnt ydYn0t /d¡dS)NrrTr r rrzéThere are no active break-points. Selecting this debug option without any break-points is unlikely to have the desired effect as the debugger is unlikely to be invoked.. Would you like to step-through in the debugger instead?ú.pyz The file '%s' can not be locatedÚrbz&The file could not be opened - %s (%d)zRunning script %s...)Úinteractz?No debugger is installed. Debugging options have been ignored!Úexecz run script)Zstart_steppingzDebugging session cancelled.z!Script '%s' returned exit code %sz)Exception raised while running script %s)Kr/rSrQÚ lastScriptÚlastArgsÚlastDebuggingTyper r"rr#ÚRS_DEBUGGER_GOZ_GetCurrentDebuggerrFr;ZbreaksrÚ MessageBoxZ LoadStringZ IDR_DEBUGGERZMB_YESNOCANCELZMB_ICONINFORMATIONZIDCANCELZIDYESÚRS_DEBUGGER_STEPr8r1r:r9Ústatr3ÚLocatePythonFiler2r6r0r<ÚopenÚIOErrorÚstrerrorÚerrnoÚreadÚreplaceÚ byte_crlfÚbyte_lfÚbyte_crÚargvrÚinsertÚ DoWaitCursorZPumpWaitingMessagesÚ SetStatusTextZpywin.frameworkrWÚRS_DEBUGGER_NONEÚcompileÚ_HandlePythonFailureÚ__main__Ú__file__ÚrunÚ__dict__rXÚbdbZBdbQuitr4Ú SystemExitZeditZ currentViewZEnsureNoPromptÚ tracebackÚ print_excZAppendToPromptÚRS_DEBUGGER_PMZpmÚcloseÚstdoutÚflush)ZdefNameZdefArgsZ bShowDialogrZ_debugger_stop_frame_r-rRr r(r ZrdÚmsgrr1Z fnameonlyZ fullScriptÚfÚexcr&ZoldArgvZoldPath0ZnewPath0Z insertedPath0ZbWorkedÚbaseZexitCoderWZ codeObjectrrrÚ RunScript×s"         ý  ÿ      ÿ     ÿ          rcCs:z tƒ}Wnty d}Yn0|durFtj |¡d ¡dvrFd}|durtjtjB}t   ddd|d¡}|  d¡|  ¡tj krˆdS| ¡}tj |¡\}}tj |¡\}}d}ttj ¡ƒD]X\}}t|ddƒrÂ|j} tj | ¡\} } |  ¡dvrüd } | | } t  | |¡rÂ|}q:qÂt|ƒ\}}|r:tj |¡|tjvrPd} d } nd } d} t  |  ¡d d¡t  d¡ztd |ddƒ}Wn(ty²t  d|d¡YdS0zbt|tj ƒtj !|¡}| rîddl"m#}|tj|ƒ}t  d| d|dt|ddƒ¡Wnt$| ƒYn0t  d¡dS)z—This code looks for the current window, and determines if it can be imported. If not, it will prompt for a file name, and allow it to be imported.Nr)rUz.pywz.pyxz.Python Scripts (*.py;*.pyw)|*.py;*.pyw;*.pyx||z Import Scriptrrr)z.pyoz.pycrUÚreloadÚimportú ing module...zimport z rXzInvalid filename for import: "ú")r‚z Successfully z ed module 'z': %sz )%rSrQr8r1r:Úlowerrrrrr r!r"r#r$r9Úlistr0r=ÚitemsÚgetattrrrZ ComparePathrCr<rmÚ capitalizerlroÚ SyntaxErrorrXrqrtÚgetÚ importlibr‚rp)rRr'r(r1ZmodNameZmodExtZnewPathÚkeyÚmodrBr€ÚextZ bNeedReloadÚwhatÚcodeObjr‚rrrÚ ImportFileœs€     ÿ           ÿþýüÿr“c Cs$z tƒ}WntyYdS0d}t | ¡dd¡t d¡z t|ƒ}Wn6ty„}ztd||fƒWYd}~dSd}~00z|  ¡d}W|  ¡n |  ¡0z2t ||dƒ}t |ƒrÚt dt j |¡d ¡Wn8tyút||ƒYnt ¡t|ƒYn0t d ¡dS) zˆThis code looks for the current window, and gets Python to check it without actually executing any code (ie, by compiling only) NÚcheckr„rzCant open file '%s' - %srrXz7Python and the TabNanny successfully checked the file 'ú'r)rSrQrrmrŠrlrarbr4rerzroÚ RunTabNannyr8r1Úbasenamer‹rprwrx)rRr‘r~r5r&r’rrrÚ CheckFileïs>      ÿþÿr˜c Csúddl}tƒ}|dur$t d¡dS| ¡}tjtjf}|t_t_z| |¡W|\t_t_n|\t_t_0|  ¡}|rözN|  ¡d}t |ƒ}t ||ƒzt ƒ d¡Wn Yn0t d|¡Wn(tttfyðtdƒt|ƒYn0dSdS)Nrz9The TabNanny is not around, so the children can run amok!rz%The TabNanny found trouble at line %dz/The tab nanny complained, but I cant see where!)ÚioÚ FindTabNannyrr]ÚStringIOr0Ústderrr{r”Úgetvaluer9ÚintÚ_JumpToPositionrHZ SCISetViewWSrmÚ IndexErrorÚ TypeErrorÚ ValueErrorr4)Úfilenamer™ÚtabnannyZnewoutZold_outÚdataÚlinenorrrr–s6      r–cCst|||ƒdS)N)ÚJumpToDocument)rAr¦ÚcolrrrrŸ7srŸc Cst ¡ |¡}|durdS| ¡ ¡}z*| ¡}| ¡|krF| |¡| ¡Wnt yj| ¡}Yn0|dkrÜ|  |d¡}||d} |  ¡} z|  |¡Wnt y¾t dƒYn0| t| | ƒt| || ƒ¡|r| ¡} |d| } | | d¡| ¡|S)Nrrz%Doesnt appear to be one of our views?)rZGetAppZOpenDocumentFileZ GetFirstViewZGetParentFrameZ GetEditorViewrDZ SetActiveViewZ AutoRestorerFZ LineIndexZ GetTextLengthZEnsureCharsVisibler4ZSetSelÚminZGetFirstVisibleLineZ LineScrollZSetFocus) rAr¦r¨ZnCharsZ bScrollToToprKÚframerGZcharNoÚstartÚsizeZcurTopZnScrollrrrr§;s4         r§c Cs®t ¡\}}}t|tƒr„z4|\}\}}}} |r6|dkr>|r>|}t|||ƒWnttfyjt|ƒ}Yn0t  d|d|¡n"t   ¡t  d|dt|ƒ¡d}dS)Nzz Failed to z - syntax error - %sz - ) r0Úexc_inforIr‹rŸr¡r¢Ústrrrmrwrx) r‘ZsyntaxErrorPathNameÚtypr5Útbr}rAÚliner¨Útextrrrrp_s rpcCsþz tdƒWStyYn0d}zt tjdtj¡}Wn*tjydt dƒt d|ƒYdS0t j   |d|¡}zt   |¡Wn&t jy¬t d||fƒYdS0t j  |¡\}}t j  |¡d}tj  d|¡zt|ƒWtj d=Stj d=0dS) Nr¤z tabnanny.pyz)SOFTWARE\Python\PythonCore\%s\InstallPathzDWARNING - The Python registry does not have an 'InstallPath' settingz* The file '%s' can not be locatedzTools\Scripts\%sz7WARNING - The file '%s' can not be located in path '%s'r)Ú __import__r.Úwin32apiZ RegQueryValuerÚHKEY_LOCAL_MACHINEr0Úwinverr3r4r8r1r?r_r9r:rk)r£r1rBZ tabnannyhomeZ tabnannybaserrrršqs<  þ  ÿýršcCs¬tj |¡s¢|}tjD]†}tj tj ||¡¡}tj |¡r„|rœt ddddd¡}|  |¡|  ¡}|t j kr||  ¡}q¢qœdSq|d}tj |¡rq¢qdSt |¡S)z>Given a file name, return a fully qualified file name, or Nonerz*.pyNrz&Python Files (*.py)|*.py|All files|*.*rU)r8r1Úisfiler0Úabspathr?Úisdirrr ZSetOFNInitialDirr"rr#r$r2)rAZ bBrowseIfDirZbaseNamer1Údrrrrr`•s(    ÿ   r`)r)NNrN)r)rrrr)N)r)/r,rurOr8r0rwrqr´rrZ pywin.mfcrZpywin.mfc.docviewrZcmdlinerrnr^r\ryr9rÚencoderirhrgrr r/r6rCrDrHrLrSrYrZr[rr“r˜r–rŸr§rpršr`rrrrÚsV   ü   #"  $ FS%#  $ $