; Dc@sdklZlZddd!ZdkZdkZdkZdkZdkZdk Z dk l Z dfdYZ de fd YZ d Z ed Zd Zd ZdZdZddddddZdZdZdZdZddddZdZggdZdfd YZd!Zd"fd#YZd$fd%YZd&fd'YZ d(fd)YZ!d*Z"y;dk#Z#dk$Z$d+kl%Z%l&Z&d,Z'd-Z(Wnd.Z(nXe)d/Z*d0e+fd1YZ,d2Z-d3Z.ei/d4d5Z0d6Z1d7Z2d8Z3d9d:d;d<d=d>d?d@dAdBdddCdDddEd"d&d(dFdGd0dHdIdJdKgZ4dS(L(s nested_scopess generatorss$Revision: 1.51 $i iN(sUserDictsInsensitiveDictcBstZdZeddZdZdZdZdZdZ e Z dZ d Z d Z d Zed Zd ZdZdZdZdZdZdZdZdZdZdZRS(sDictionary, that has case-insensitive keys. Normally keys are retained in their original form when queried with .keys() or .items(). If initialized with preserveCase=0, keys are both looked up in lowercase and returned in lowercase by .keys() and .items(). icCs.h|_||_|o|i|ndS(s2Create an empty dictionary, or update from 'dict'.N(sselfsdataspreservesdictsupdate(sselfsdictspreserve((s./twisted/python/util.pys__init__s   cCs|i|}|i|=dS(N(sselfs_lowerOrReturnskeysksdata(sselfskeysk((s./twisted/python/util.pys __delitem__#scCs6t|tp t|to|iSn|SdS(N(s isinstanceskeysstrsunicodeslower(sselfskey((s./twisted/python/util.pys_lowerOrReturn's cCs"|i|}|i|dSdS(s7Retrieve the value associated with 'key' (in any case).iN(sselfs_lowerOrReturnskeysksdata(sselfskeysk((s./twisted/python/util.pys __getitem__-scCs&|i|}||f|i|s+cCst|iSdS(s$List of keys in their original case.N(slistsselfsiterkeys(sself((s./twisted/python/util.pyskeysEscCst|iSdS(sList of values.N(slistsselfs itervalues(sself((s./twisted/python/util.pysvaluesIscCst|iSdS(sList of (key,value) pairs.N(slistsselfs iteritems(sself((s./twisted/python/util.pysitemsMscCs*y ||SWntj o |SnXdS(s\Retrieve value associated with 'key' or return default value if 'key' doesn't exist.N(sselfskeysKeyErrorsdefault(sselfskeysdefault((s./twisted/python/util.pysgetQs  cCs+|i| o|||c s`t|ddgd}ddd|f|_|SdS(sNCreates a function that will return a string representing a progress bar. iscst|djp tdt|}|d}d||f}|o||d<|Sn||djodSn||d<|SdS(Nis#Don't mess with the last parameter.is[%s%s%s]is(slenslastsAssertionErrorsintsaValuespositionsdoneswidthstoDosdoneChars currentChars undoneCharsresultsforce(spositionsforceslastsdonesresultstoDo(saValues undoneCharsdoneCharswidths currentChar(s./twisted/python/util.pysstatBarZs  sRstatBar(position, force = 0) -> '[%s%s%s]'-style progress bar returned string is %d characters long, and the range goes from 0..%d. The 'position' argument is where the '%s' will be drawn. If force is false, '' will be returned instead if the resulting progress bar is identical to the previously returned progress bar. iN( swidthsfloats maxPositionsaValuesstatBarsdoneChars currentChars undoneChars__doc__(swidths maxPositionsdoneChars undoneChars currentCharsstatBarsaValue((swidthsdoneChars undoneChars currentCharsaValues./twisted/python/util.pys makeStatBarVs ! 'cCsdkl}|iidoj|id}t|do|i|i}n|it |}d|i i |t |fGHn"d|i i |i i|ifGHdS(sLA trace function for sys.settrace that prints every function or method call.(sreflectsselfs __class__smethod %s of %s at %ssfunction %s in %s, line %sN(stwisted.pythonsreflectsframesf_localsshas_keysseshasattrsquals __class__skstypesf_codesco_namesids co_filenamesf_lineno(sframesssignoredsreflectssesk((s./twisted/python/util.pysspewerps  "c Cs tii|}|iti} tii}tii}tii }xt | o|| ti}d}x1|D])}|d||f o d}PqxqxW|o8x5|D])} |d|| f o d}PqqWn|o|Sn| idqKWtSdS(sWalk upwards from start, looking for a directory containing all files and directories given as arguments:: >>> searchupwards('.', ['foo.txt'], ['bar', 'bam']) If not found, return None is%s%siiN(sosspathsabspathsstartssplitssepsparentssexistssjoinsisdirslens candidates allpresentsfilessfsdirssdspopsNone( sstartsfilessdirssjoins candidatesexistssfsisdirs allpresentsparentssd((s./twisted/python/util.pys searchupwardss.$   sLineLogcBs>tZdZddZdZdZdZdZRS(s A limited-size line-based log, useful for logging line-based protocols such as SMTP. When the log fills up, old entries drop off the end. i cCs4|djo d}ntg||_||_dS(s Create a new log, with size lines of storage (default 10). A log size of 0 (or less) means an infinite log. iN(ssizesNonesselfslog(sselfssize((s./twisted/python/util.pys__init__s   cCsC|io%|id|id*||ids( shasattrsselfs fancybasenames __class__s__name__srsshowAttributessattrs isinstancesstrsappendsgetattrsjoin(sselfsattrsr((s./twisted/python/util.pys__str__s, $4 (s__name__s __module__s__doc__sshowAttributess__str__s__repr__(((s./twisted/python/util.pys FancyStrMixins  s FancyEqMixincBs tZfZdZdZRS(NcCsy|i o||jSnt||i otSnx9|iD].}t||t||j otSq?q?WtSdS(N( sselfscompareAttributessothers isinstances __class__sFalsesattrsgetattrsTrue(sselfsothersattr((s./twisted/python/util.pys__eq__!s    cCs|i| SdS(N(sselfs__eq__sother(sselfsother((s./twisted/python/util.pys__ne__,s(s__name__s __module__scompareAttributess__eq__s__ne__(((s./twisted/python/util.pys FancyEqMixins cCsgi}ttt||D]%\}}|||||fq#~}|i gi}|D]}||dqi~SdS(Ni( sappends_[1]szipsrangeslenslistsiseskeysL2ssort(slistskeysesis_[1]sL2((s./twisted/python/util.pysdsu/sQ (s setgroupss getgroupscCsxnoyt|Wn|tj o(t|djo |d=qqtj o=}|itijot|djo |d=qqXdSq WdS(Nii(s setgroupssls ValueErrorslensOSErrorseserrnosEINVAL(slse((s./twisted/python/util.pys_setgroups_until_success8s & c Csytid}Wn d}nXti|d}g}|t j o|i |nxVt i D]H\}} }}||jo)|i |t||joPqqgqgWyt|WnWtj oK} | itijo,x,tD]}||joqqWqnXdS(sInitializes the group access list. This is done by reading the group database /etc/group and using all groups of which C{uid} is a member. The additional group C{primaryGid} is also added to the list. If the given user is a member of more than C{NGROUPS}, arbitrary groups will be silently discarded to bring the number below that limit. sSC_NGROUPS_MAXiN(sosssysconfs max_groupsspwdsgetpwuidsuidsusernamesls primaryGidsNonesappendsgrpsgetgralls groupnamespasswordsgidsuserlistslens_setgroups_until_successsOSErrorseserrnosEPERMs getgroupssg( suids primaryGidsusernamesuserlistsls groupnames max_groupssgsgidspasswordse((s./twisted/python/util.pys initgroupsQs0         cCsdS(sbDo nothing. Underlying platform support require to manipulate groups is missing. N((suids primaryGid((s./twisted/python/util.pys initgroupszscCsv|oti}ti}nti}ti}|tj o||n|tj ot ||||ndS(N( seuidsossseteuidssetuidssetegidssetgidsgidsNonesuids initgroups(suidsgidseuidssetuidssetgid((s./twisted/python/util.pys switchUIDs       sSubclassableCStringIOcBstZdZeZdZdZdZdZdZ ddZ dZ d d Z ed Z dd Zed ZdZdZdZdZRS(s3A wrapper around cStringIO to allow for subclassingcOs#dkl}||||_dS(N(sStringIO(s cStringIOsStringIOsaskwsselfs_SubclassableCStringIO__csio(sselfsaskwsStringIO((s./twisted/python/util.pys__init__s cCs|iiSdS(N(sselfs_SubclassableCStringIO__csios__iter__(sself((s./twisted/python/util.pys__iter__scCs|iiSdS(N(sselfs_SubclassableCStringIO__csiosnext(sself((s./twisted/python/util.pysnextscCs|iiSdS(N(sselfs_SubclassableCStringIO__csiosclose(sself((s./twisted/python/util.pysclosescCs|iiSdS(N(sselfs_SubclassableCStringIO__csiosisatty(sself((s./twisted/python/util.pysisattysicCs|ii||SdS(N(sselfs_SubclassableCStringIO__csiosseekspossmode(sselfspossmode((s./twisted/python/util.pysseekscCs|iiSdS(N(sselfs_SubclassableCStringIO__csiostell(sself((s./twisted/python/util.pystellsicCs|ii|SdS(N(sselfs_SubclassableCStringIO__csiosreadsn(sselfsn((s./twisted/python/util.pysreadscCs|ii|SdS(N(sselfs_SubclassableCStringIO__csiosreadlineslength(sselfslength((s./twisted/python/util.pysreadlinescCs|ii|SdS(N(sselfs_SubclassableCStringIO__csios readlinesssizehint(sselfssizehint((s./twisted/python/util.pys readlinesscCs|ii|SdS(N(sselfs_SubclassableCStringIO__csiostruncatessize(sselfssize((s./twisted/python/util.pystruncatescCs|ii|SdS(N(sselfs_SubclassableCStringIO__csioswritess(sselfss((s./twisted/python/util.pyswritescCs|ii|SdS(N(sselfs_SubclassableCStringIO__csios writelinesslist(sselfslist((s./twisted/python/util.pys writelinesscCs|iiSdS(N(sselfs_SubclassableCStringIO__csiosflush(sself((s./twisted/python/util.pysflushscCs|iiSdS(N(sselfs_SubclassableCStringIO__csiosgetvalue(sself((s./twisted/python/util.pysgetvalues(s__name__s __module__s__doc__sNones_SubclassableCStringIO__csios__init__s__iter__snextsclosesisattysseekstellsreadsreadlines readlinesstruncateswrites writelinessflushsgetvalue(((s./twisted/python/util.pysSubclassableCStringIOs"               c Csdkl} dhd|<d|<d|<} y| i|} Wn,t j o t d|||fnXx*t | i D]\}}|||