ϪfqkddlmZddlZddlZddlZddlZddlmZ ddlZ ddl Z e Ze Z ddlm ZmZeZeZ ddlmZddlmZmZmZmZmZmZmZmZmZddlmZddlmZeed d d dd d dedZ Gddee!e fZ"dZ#d5dZ$dZ%dZ& d6dZ'dZ( d7dZ)dZ*dZ+d8dZ,dZ-ggfdZ.GddZ/d Z0Gd!d"Z1Gd#d$Z2Gd%d&Z3Gd'd(Z4 dd)lm5Z6e6Z7e7d*Z5nd+Z5d9d,Z8d-Z9d.Z:d/Z;d0Zd3Z?gd4Z@y#e $rdZ dZYwxYw#e $rdZdZ Y wxYw#e $rdZ7YPwxYw):) annotationsN)AnyStr) getgroups setgroups) OrderedDict) AnyCallableClassVarMappingMutableMappingSequenceTupleTypeVarUnion)Version)deprecatedModuleAttributeTwistedz$Use collections.OrderedDict instead.ztwisted.python.utilr_TceZdZdZ dfd ZdZdZdZdZdZ e Z dZ d Z d Z d Zdd Zd ZdZddZdZeZdZdZeZefdZdZdZdZdZddZxZS)InsensitiveDicta Dictionary, 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(). cft|i|_||_|r|j |yy)zD Create an empty dictionary, or update from 'dict'. N)super__init__datapreserveupdate)selfdictr __class__s 5/usr/lib/python3/dist-packages/twisted/python/util.pyrzInsensitiveDict.__init__Is2     KK  c@|j|}|j|=yN_lowerOrReturnrrkeyks r" __delitem__zInsensitiveDict.__delitem__Ss    $ IIaLr#cft|tst|tr|jS|Sr%) isinstancebytesstrlowerrr)s r"r'zInsensitiveDict._lowerOrReturnWs& c5 !ZS%999; Jr#cH|j|}|j|dS)zI Retrieve the value associated with 'key' (in any case). r&r(s r" __getitem__zInsensitiveDict.__getitem__]s&    $yy|Ar#cH|j|}||f|j|<y)z| Associate 'value' with 'key'. If 'key' already exists, but in different case, it will be replaced. Nr&)rr)valuer*s r" __setitem__zInsensitiveDict.__setitem__ds%    $U| ! r#c@|j|}||jvS)z= Case insensitive test whether 'key' exists. r&r(s r"has_keyzInsensitiveDict.has_keyls"    $DII~r#c~|js0t|tst|tr|j S|Sr%)rr-r.r/r0r1s r" _doPreservezInsensitiveDict._doPreserveus,}}*S%"8JsC|jD] \}}|||< y)z5 Copy (key,value) pairs from 'dict'. NrF)rr r*vs r"rzInsensitiveDict.updates&JJL DAqDG r#c dj|jDcgc] \}}|d|c}}}d|zScc}}w)z: String representation of the dictionary. z, z: zInsensitiveDict({%s}))joinrF)rr*rPrFs r"__repr__zInsensitiveDict.__repr__sB FAqe2aUOFG&..Gs= c#vK|jjD]}|j|dywNrrrCr;rrPs r"r>zInsensitiveDict.iterkeyss7!!# )A""1Q4( ( )s79c#XK|jjD] }|d ywNr3)rrCrWs r"rBzInsensitiveDict.itervaluess+!!# AA$J s(*c#zK|jjD]\}}|j||fywr%rV)rr*rPs r"rEzInsensitiveDict.iteritemss<II$$& )DAq""1%q( ( )s9;c |jj|j|dS#t$r||jur|cYSwxYw)zB @see: L{dict.pop} @since: Twisted 21.2.0 r3)rpopr'rH _notFoundrIs r"r\zInsensitiveDict.popsM  99==!4!4S!9:1= = $..(N s,/A  A c8|jd}||d=|SrUrO)ris r"popitemzInsensitiveDict.popitems! JJLO 1Jr#c4|jD]}||=yr%)r@)rr*s r"clearzInsensitiveDict.clears AQ r#c.t||jSr%)rrr?s r"copyzInsensitiveDict.copystT]]33r#c,t|jSr%)lenrr?s r"__len__zInsensitiveDict.__len__s499~r#ct|tr=|jD]\}}||vs |||k7syt|t|k(StS)NF)r-r rFrfNotImplemented)rotherr*rPs r"__eq__zInsensitiveDict.__eq__sT eW %  !1E>U1X]  !t9E * *! !r#rYr%returnr/rjobjectrmbool) __name__ __module__ __qualname____doc__rr+r'r4r7r9 __contains__r;r@rCrFrKrMrrSr>__iter__rBrEror]r\r`rbrdrgrk __classcell__)r!s@r"rr;s  $L % ' & /)H)I(  4"r#rcxt}g}|D](}||vr|j||j|*|S)z Make the elements of a list unique by inserting them into a dictionary. This must not change the order of the input lst. )setappendadd)lstseenresultr*s r"uniquifyrsD 5D F  D= MM!    Mr#ct||kDrtdt||fz|g|z}t||dt||S)aT Pads a sequence out to n elements, filling in with a default value if it is not long enough. If the input sequence is longer than n, raises ValueError. Details, details: This returns a new list; it does not extend the original sequence. The new list contains the values of the original sequence, not copies. z%d elements is more than %d.N)rf ValueErrorr=)nseqrJblanks r"padTorsL 3x!|73s8Q-GHH IMES E*CH Lr#c tjdtdddl}tj j tj jtj jtj j|jd}tj jd}tj jd}ttj j|||g}|S)NzCtwisted.python.util.getPluginDirs is deprecated since Twisted 12.2. stacklevelrpluginsz~/TwistedPluginsz ~/.twisted) warningswarnDeprecationWarningtwistedospathrRdirnameabspath__file__ expanduserfilterisdir)r systemPlugins userPlugins confPlugins allPluginss r" getPluginDirsrs MMM GGLL 8H8H(IJKYM''$$%78K''$$\2K {K'PQJ r#ctjdtdtjj t y)NzBtwisted.python.util.addPluginDir is deprecated since Twisted 12.2.rr)rrrsysrextendrr#r" addPluginDirrs+ MML HHOOMO$r#ctjjtjjtjj ||S)z Return the path to a sibling of a file in the filesystem. This is useful in conjunction with the special C{__file__} attribute that Python provides for modules, so modules can load associated resource files. )rrrRrr)rsiblings r"sibpathr"s3 77<<(=> HHr#cddl} |j|S#t$r)}|jtjk(rtd}~wt $rtwxYw)z: Helper to turn IOErrors into KeyboardInterrupts. rN)getpassOSErrorerrnoEINTRKeyboardInterruptEOFError)promptres r"_getpassr/sR v&&  77ekk !# #   s A$AActtjdxrtjj}d} |s|rB tjtjf}t ddxt_t_netjj}|ddk(r|dd}||r6tjj|\t_t_SS t|}|s:||r6tjj|\t_t_SSt|} || k(r:||r6tjj|\t_t_SStjj|dz#t $r tdwxYw#|r6tjj|\t_t_wwxYw)a+ Obtain a password by prompting or from stdin. If stdin is a terminal, prompt for a new password, and confirm (if C{confirm} is true) by asking again to make sure the user typed the same thing, as keystrokes will not be echoed. If stdin is not a terminal, and C{forceTTY} is not true, read in a line and use it as the password, less the trailing newline, if any. If C{forceTTY} is true, attempt to open a tty and prompt for the password using it. Raise a RuntimeError if this is not possible. @returns: C{str} isattyNz/dev/ttyzr+zCannot obtain a TTY ) hasattrrstdinrstdoutopen BaseException RuntimeErrorreadlinecloserstderrwrite) rconfirmforceTTY confirmPromptmismatchMessageisaTTYoldpasswordtry1try2s r" getPasswordr?s*SYY ) @cii.>.>.@F C(>))SZZ/C-1*d-CCCI 99--/B<4''}H  IIOO $' !CIsz F#D  IIOO $' !CIsz  M*Dt|  IIOO $' !CIsz    4!78%>&'<==>$  IIOO $' !CIsz s6F6AF-F6)F61F6;#F6F33F66:G0ctjjdjt t |dzy)N r)rrrrRmapr/)as r"printlnrts(JJSXXc#qk*T12r#c tdj|Dcgc]}tt||z c}Scc}w)N)rRchrord)sbcs r"str_xorr}s+ 77Q/CA O/ 00/s5crt|z ddgffd }ddzdz|fz|_|S)zS Creates a function that will return a string representing a progress bar. rrct|dk(sJdt|z} |z dz }d|z |zd}|r||d<|S||dk(ry||d<|S)Nr3z#Don't mess with the last parameter.r[]rr)rfint) positionforcelastdonetoDor~aValue currentChardoneChar undoneCharwidths r"statBarzmakeStatBar..statBars4yA~DDD~6H$%t|aX_%k]:3D2EQG DGM T!W Q r#aRstatBar(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. )floatrt)r maxPositionrrrrrs` ``` @r" makeStatBarrs[U;' 'F !   1 Q   GO Nr#c ddlm}d|jvr|jd}t|dr|j |j }n|j t |}td|jjd|dt|y td|jjd |jjd |jy ) zV A trace function for sys.settrace that prints every function or method call. r)reflectrr!zmethod z of z at z function z in z, line N) twisted.pythonrf_localsrqualr!typeprintf_codeco_nameid co_filenamef_lineno)framerignoredrser*s r"spewerrs'  ^^F # 2{ # R\\*A T"X&A  ,,-T!DBAB ||##U\\%=%=u~~ O r#c tjj|}|jtj}tjj }tjj }tjj}t|rl||tjz}d}|D]} ||| rd}n|r|D]} ||| rd}n|r|S|jdt|rly)z Walk 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 r3rrN) rrrsplitsepexistsrRrrfr\) startfilesdirsparentsrrRr candidate allpresentfds r" searchupwardsrs GGOOE "Ekk"&&!G WW^^F 66;;D GGMME g,MBFF*   AYKs+,     {1#./!"J    B g, r#c6eZdZdZd dZdZdZdZdZdZ y) LineLogz 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. c6|dkrd}dg|z|_||_y)z Create a new log, with size lines of storage (default 10). A log size of 0 (or less) means an infinite log. rN)logsize)rrs r"rzLineLog.__init__s$ !8D6D= r#c|jr,|jdd|jdd||jd<y|jj|y)Nr3r)rrrz)rlines r"rzzLineLog.appends? 99 HHQRLDHHSbMDHHRL HHOOD !r#ct|Sr%)r.r?s r"r/z LineLog.strs T{r#cLdjtd|jS)N )rRrrr?s r" __bytes__zLineLog.__bytes__szz&txx011r#c4td|j|Sr%)rr)ritems r"r4zLineLog.__getitem__sdDHH%d++r#c.dg|jz|_y)z Empty the log. N)rrr?s r"rbz LineLog.clears6DII%r#N) ) rqrrrsrtrrzr/rr4rbrr#r"rrs%"2,&r#rc, ||i|y#|$rYywxYw)zF Determine whether the given call raises the given exception. r3rr) exceptionrargskwargss r"raisesrs- 46  s  ceZdZdZddZdZy)IntervalDifferentiala Given a list of intervals, generate the amount of time to sleep between "instants". For example, given 7, 11 and 13, the three (infinite) sequences:: 7 14 21 28 35 ... 11 22 33 44 ... 13 26 39 52 ... will be generated, merged, and used to produce:: (7, 0) (4, 1) (2, 2) (1, 0) (7, 0) (1, 1) (4, 2) (2, 0) (5, 1) (2, 0) New intervals may be added or removed as iteration proceeds using the proper methods. c&|dd|_||_y)a @type intervals: C{list} of C{int}, C{long}, or C{float} param @param intervals: The intervals between instants. @type default: C{int}, C{long}, or C{float} @param default: The duration to generate if the intervals list becomes empty. N) intervalsrJ)rrrJs r"rzIntervalDifferential.__init__s#1 r#cBt|j|jSr%)_IntervalDifferentialIteratorrrJr?s r"rvzIntervalDifferential.__iter__+s,T^^T\\JJr#N)<)rqrrrsrtrrvrr#r"rr s$ Kr#rc(eZdZdZdZeZdZdZy)rct|tt|Dcgc] \}}|||g c}}|_||_d|_ycc}}wrU)ziprangerfrrJr)rr_rrrs r"rz&_IntervalDifferentialIterator.__init__0sA25as1v2GHA1a)H  IsA c:|js|jdfS|jdd|jdd}}|jddxx|jddz cc<|jj||jz }||_||fS)Nrrr3)rrJsortr)rrindexr~s r"__next__z&_IntervalDifferentialIterator.__next__5s~~LL$' 'nnQ'*DNN1,=a,@e q!q 1! 44  ! u}r#c@|jrt|jdd|jddz }|jj||z|t|jg|jjy|jj||dgy)Nrr3)rrzrfr$)rr_delays r" addIntervalz)_IntervalDifferentialIterator.addIntervalBs} >>NN1%a(4>>!+>*+ A~~a #x/q)!,NN1%"Ate|! " IJJr#N)rqrrrsrr&nextr)r,rr#r"rr/s  D- Kr#rc,eZdZUdZdZded<ddZeZy) FancyStrMixinaO Mixin providing a flexible implementation of C{__str__}. C{__str__} output will begin with the name of the class, or the contents of the attribute C{fancybasename} if it is set. The body of C{__str__} can be controlled by overriding C{showAttributes} in a subclass. Set C{showAttributes} to a sequence of strings naming attributes, or sequences of C{(attributeName, callable)}, or sequences of C{(attributeName, displayName, formatCharacter)}. In the second case, the callable is passed the value of the attribute and its return value used in the output of C{__str__}. In the final case, the attribute is looked up using C{attributeName}, but the output uses C{displayName} instead, and renders the value of the attribute using C{formatCharacter}, e.g. C{"%.3f"} might be used for a float. rzLSequence[Union[str, Tuple[str, str, str], Tuple[str, Callable[[Any], str]]]]showAttributesc dt|d|jjg}|jD]}t |t r"|j d|dt||5t|dk(r2|j d|dd|dt||dzu|j d|dz|dt||dfz|j d d j|S) N< fancybasenamer=rrr3z %s=>r) getattrr!rqr0r-r/rzrfrR)rrattrs r"__str__zFancyStrMixin.__str__ms '$1H1HI J'' QD$$1TF!GD$$7#:;<TaAd1gYa.GDGGD$q'4J,KKL&47*tAwd1g8N.OOP  Q  wwqzr#Nrl)rqrrrsrtr0__annotations__r9rSrr#r"r/r/Vs'(   Hr#r/c0eZdZUdZdZded<ddZddZy) FancyEqMixinz Mixin that implements C{__eq__} and C{__ne__}. Comparison is done using the list of attributes defined in C{compareAttributes}. rzClassVar[Sequence[str]]compareAttributescjsuStjrtfdjDStS)Nc3PK|]}t|t|k(ywr%)r6).0namerjrs r" z&FancyEqMixin.__eq__..s,d#wud';;s#&)r=r-r!allri)rrjs``r"rkzFancyEqMixin.__eq__sL%%5= dEOO , 22 r#c>|j|}|tur|S| Sr%)rkri)rrjr~s r"__ne__zFancyEqMixin.__ne__s%U# ^ #Mzr#Nrn)rqrrrsrtr=r:rkrErr#r"r<r<s24.3r#r<) initgroupscy)zk Do nothing. Underlying platform support require to manipulate groups is missing. Nruid primaryGids r"rFrFsr#cTttj|j|S)a Initializes the group access list. This uses the stdlib support which calls initgroups(3) under the hood. 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. @type uid: C{int} @param uid: The UID for which to look up group information. @type primaryGid: C{int} @param primaryGid: The GID to include when setting the groups. ) _initgroupspwdgetpwuidpw_namerHs r"rFrFs 3<<,44jAAr#c|r1tj}tj}tj}n0tj}tj }tj }||||c||k(rD|xrdxsd}d|d|}|d|}tjdj||yt||||yy)a Attempts to switch the uid/euid and gid/egid for the current process. If C{uid} is the same value as L{os.getuid} (or L{os.geteuid}), this function will issue a L{UserWarning} and not raise an exception. @type uid: C{int} or L{None} @param uid: the UID (or EUID) to switch the current process to. This parameter will be ignored if the value is L{None}. @type gid: C{int} or L{None} @param gid: the GID (or EGID) to switch the current process to. This parameter will be ignored if the value is L{None}. @type euid: C{bool} @param euid: if True, set only effective user-id rather than real user-id. (This option has no effect unless the process is running as root, in which case it means not to shed all privileges, retaining the option to regain privileges in cases such as spawning processes. Use with caution.) NeuidrIz tried to drop privileges and setrz is already z){} but {}; should we be root? Continuing.) rseteuidsetegidgeteuidsetuidsetgidgetuidrrformatrF) rIgidrQrUrVrWuidText actionText problemTexts r" switchUIDr]s,  s   &(?ov.G;G9AcUKJ$I\&(> | + FNDt9>FND $CRyH"&r(K$$X.&/D  &~~' -(. |..0 ! !! T 88I r#cv t|S#t$r"ttj|dcYSwxYw)a Convert a user identifier, as a string, into an integer UID. @type uidString: C{str} @param uidString: A string giving the base-ten representation of a UID or the name of a user which can be converted to a UID via L{pwd.getpwnam}. @rtype: C{int} @return: The integer UID corresponding to the given string. @raise ValueError: If the user name is supplied and L{pwd} is not available. r)rrrMgetpwnam) uidStrings r" uidFromStringruQ<*9~ * ; ||I&q))* (88cv t|S#t$r"ttj|dcYSwxYw)a Convert a group identifier, as a string, into an integer GID. @type gidString: C{str} @param gidString: A string giving the base-ten representation of a GID or the name of a group which can be converted to a GID via L{grp.getgrnam}. @rtype: C{int} @return: The integer GID corresponding to the given string. @raise ValueError: If the group name is supplied and L{grp} is not available. r)rrgrpgetgrnam) gidStrings r" gidFromStringr|grvrwctjtj}}||k(r ||k(r||i|S|dk7r||k7s||k7rtjd||k7rtj||dk7r||k7s||k7rtj| ||i||dk7r||k7s||k7rtjd||k7rtj||dk7r!||k7s||k7rtj|SSS#|dk7r||k7s||k7rtjd||k7rtj||dk7r!||k7s||k7rtj|wwwxYw)a, Run the given function wrapped with seteuid/setegid calls. This will try to minimize the number of seteuid/setegid calls, comparing current and wanted permissions @param euid: effective UID used to call the function. @type euid: C{int} @type egid: effective GID used to call the function. @param egid: C{int} @param function: the function run with the specific permission. @type function: any callable @param args: arguments passed to C{function} @param kwargs: keyword arguments passed to C{function} r)rrTgetegidrRrS)rQegidfunctionrrrIrYs r"runAsEffectiveUserr}sF&zz|RZZ\C d{sd{((( !8t JJqM $; JJt  19$#+ JJt  T,V,qycTkSD[ 1 d{ 3axSD[C4K 3-8x qycTkSD[ 1 d{ 3axSD[C4K 3-8xs D A&E0ctj5|D]\}}tj|i|||i|cdddS#1swYyxYw)a  Run C{f(*args, **kwargs)}, but with some warnings suppressed. Unlike L{twisted.internet.utils.runWithWarningsSuppressed}, it has no special support for L{twisted.internet.defer.Deferred}. @param suppressedWarnings: A list of arguments to pass to L{warnings.filterwarnings}. Must be a sequence of 2-tuples (args, kwargs). @param f: A callable. @param args: Arguments for C{f}. @param kwargs: Keyword arguments for C{f} @return: The result of C{f(*args, **kwargs)}. N)rcatch_warningsfilterwarnings)suppressedWarningsrrrrr_s r"runWithWarningsSuppressedrsX&  ""' .EAr  # #Q -" - .$!&!"""s 'AA)rrrrrrrrrrrrrrrr/r<r]rfrqrur|rr`rr%)ros.PathLike[AnyStr] | AnyStrrrrmr)z Password: rrzConfirm password: zPasswords don't match.)r4-r5)F)A __future__rrrrrtypingrry_grprM_pwd ImportErrorr _getgroupsr _setgroups collectionsrrr r r r r rrr incrementalrtwisted.python.deprecaterrr/rrrrrrrrrrrrrrrrrr/r<rF __initgroupsrLr]r`rfrqrur|rr__all__rr#r"rs#  C CC II$    > Ir1a *  T]e"nS"W-e"P ."% I & I1M I  I  "  &, 2(j31!H ( ">&&&&R  K KF$K$KN&&R6-K B&,^0 6+\*,*,% P"2 _ C CIIJKs4D&D67E& D32D36 EEEE