;ò í?ò>c@sŠdZdklZlZlZlZlZdkZdkl Z dk l Z dfd„ƒYZ de fd„ƒYZ e e d „ZdS( s'This module contains the MainCLI class.(sargvsstdinsstdoutsstderrsexitN(s InvalidKey(sAutomaticClasssMainCLIcBsPtZdZd„Zd„Zd„Zd„Zd„Zd„Ze d„Z RS(s8This class is responsible for command-line parsing, etc.cCs/ttƒdjo|iƒn |iƒdS(s<Run as a GNOME application or as a command-line application.iN(slensargvsselfs_runCommandLineApplications_runGnomeApplication(sself((s ./MainCLI.pys__init__scCs`dk}|idƒdk}dk}dkl}|ititiƒ|ƒ|i ƒdS(s}Run as a GNOME application. This method does not return until the application is finished. Ns2.0(sMainGUI( spygtksrequiresgtksgnomesMainGUIs program_initsConstsNAMEsVERSIONsmainloop(sselfsgnomesgtkspygtksMainGUI((s ./MainCLI.pys_runGnomeApplications     c CsMdkl}l}g}t}y|tddƒ\} }x·| D]¯\}}|i ƒdjo,|i t d|d|djdt ƒƒqB|djo0t|ƒ otd dƒn||d _qB|d jo t}qBtd |ƒ‚qBW|o|i||ƒn|i||ƒWn%|j o}t|idƒnXd S(sÃRun as a command-line application. See the man page for a description of all of these arguments. This method does not return until the application is finished. (sgetopts GetoptErrorisc:C:k:ps-csciphersencryptskeys-ks key specified before any ciphersiÿÿÿÿs-psunhandled option %sN(sgetopts GetoptErrors operationssFalses proxyModesargvsoptssargssosvslowersappends _OperationsNoneslensusageskeysTruesAssertionErrorsselfs _runProxyModes_runFilterModesesmsg( sselfs operationss GetoptErrorsargss proxyModesosvsgetoptsesopts((s ./MainCLI.pys_runCommandLineApplication$s0     c Csèdkl}dk}dk}t|ƒdj otddƒn|\}}}yK|||i |ƒ|i |ƒ|i |ƒ|i |t ƒƒ|iƒWnC|ij o4} tidti| idfƒtdƒnXdS(sgHandle the rest of the arguments and run in proxy mode. This method does not return. (sProxyNis'proxy mode requires exactly 3 argumentsis%s: socket error: %s (sProxysasyncoressocketslensargssusages proxiedHosts proxiedPorts listeningPortsselfs_castToValidPorts_composeOperationss operationssTruesloopserrorsesstderrswritesConstsNAMEsexit( sselfs operationssargssasyncoressockets listeningPorts proxiedPorts proxiedHostsProxyse((s ./MainCLI.pys _runProxyModeFs"      !cCssd}d}y5t|ƒ}||jo ||jpt‚|SWn+tidti|fƒt dƒnXdS(s:Cast and return port as a valid port or complain and exit.iis%s: '%s' is not a valid port N( sMIN_PORTsMAX_PORTsintsportsAssertionErrorsstderrswritesConstsNAMEsexit(sselfsportsMIN_PORTsMAX_PORT((s ./MainCLI.pys_castToValidPort]s !c Csmt|ƒ}t}t}y |djo|ddjot|ddƒ}n|djo|ddjot|ddƒ}n|djotddƒn|i |ƒ}x8no0|i ƒ}| oPn|i||ƒƒq¼W|tjo|iƒn|tjo|iƒnWnBtj o6}tidti|i|ifƒtdƒnXd S( sŠHandle the rest of the arguments and run in filter mode. This method does not return until the application is finished. iis-sriswstoo many argumentss %s: %s: %s N(slensargsslenargssstdinsinputsstdoutsoutputsopensusagesselfs_composeOperationss operationssoperationsFunctionsreadlineslineswritesclosesIOErrorsesstderrsConstsNAMEsfilenamesstrerrorsexit( sselfs operationssargsslenargssoperationsFunctionsoutputsinputslinese((s ./MainCLI.pys_runFilterModeis2     #csD‡d†}gi}|D]}||i|ƒƒq~‰|SdS(sªCall getFunction for each operation and compose a closure. invert - Should the meaning of the encrypt attribute for each operation be reversed? cs%xˆD]}||ƒ}qW|SdS(s0Apply all of the operations on s, and return it.N(s functionssfss(sssf(s functions(s ./MainCLI.pysclosures N(sclosuresappends_[1]s operationssis getFunctionsinverts functions(sselfs operationssinvertsclosures functionssis_[1]((s functionss ./MainCLI.pys_composeOperations‡s 0( s__name__s __module__s__doc__s__init__s_runGnomeApplications_runCommandLineApplications _runProxyModes_castToValidPorts_runFilterModesFalses_composeOperations(((s ./MainCLI.pysMainCLI s    "  s _OperationcBs#tZdZd„Zed„ZRS(sThis is a simple class representing an encryption operation. The following attributes are used: cipher - This string is the name of a cipher. encrypt - If true, do encrypt. Otherwise, do decrypt. key - This string is the key to use with the cipher. cCsti|ƒdddgSdS(Nsciphersencryptskey(sAutomaticClasss getAttributessself(sself((s ./MainCLI.pys getAttributes¥scCs(yÃtd|itƒtƒ|iƒ}t||iƒ}|ƒ}t |dƒo$|i t jo|i |_ qŸn)|i t jot d|idƒn|i p|o |i Sn|iSWn^tj ot d|idƒn9tj o,}t d|i ti|ifdƒnXdS(s,This is a factory for a function representing this _Operation. Instantiate the cipher, set the key, and return either the encrypt or decrypt function. This function may call usage and exit. invert - Should the meaning of the encrypt attribute be reversed? scipher.skeysno key required for cipher '%s'isfailed to import cipher '%s's0invalid key '%s' for cipher '%s'; it's not '%s'.N(s __import__sselfsciphersglobalsslocalss CipherModulesgetattrs CipherClassscipherInstanceshasattrskeysNonesusagesencryptsinvertsdecrypts ImportErrors InvalidKeyses operationskeyDescription(sselfsinverts CipherClassses CipherModulescipherInstance((s ./MainCLI.pys getFunction©s&   (s__name__s __module__s__doc__s getAttributessFalses getFunction(((s ./MainCLI.pys _Operation™s  cCsX|otidti|fƒntidtiƒ|tjot|ƒndS(s·Print usage information. warning - If this is not None, it will be printed as well. exitCode - If this is not None, the application will exit with this exit code. s%s: %s s#Try `man %s' for more information. N(swarningsstderrswritesConstsNAMEsexitCodesNonesexit(swarningsexitCode((s ./MainCLI.pysusageÈs  (s__doc__ssyssargvsstdinsstdoutsstderrsexitsConstscipher.KeyedCiphers InvalidKeysAutomaticClasssMainCLIs _OperationsNonesusage( s _OperationsConstsAutomaticClasssstdoutsMainCLIsstdins InvalidKeysargvsexitsstderrsusage((s ./MainCLI.pys?s%   /