&_ljd'|UdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z ddl!m"Z"ddl#m$Z$dd l!TiZ%d e&d <dXdZ'e'e Z GddZ(ej)dYdZ*dZdZ+d[dZ,edZ-edZ.d\dZ/d]d#Z0d^d&Z1d_d)Z2d`d+Z3d_d,Z4dadbd/Z5Gd0d1Z6dcd4Z7Gd5d6Z8ddd:Z9ded=Z:dadfd@Z;dgdCZ didjdOZ?dkdldUZ@dmdWZAdS)nz$Miscellaneous stuff for coverage.py.) annotationsN) ModuleType) AnyCallableDictIOIterableIteratorListMappingOptionalSequenceTupleTypeVarUnion)env)CoverageException)TArc)*zDict[ModuleType, ModuleType]ISOLATED_MODULESmodrreturnc,|tvrtj|j}|t|<t |D]L}t ||}t |tjrt|}t|||Mt|S)aJCopy a module so that we are isolated from aggressive mocking. If a test suite mocks os.path.exists (for example), and then we need to use it during the test, everything will get tangled up if we use their mock. Making a copy of the module when we import it will isolate coverage.py from those complications. ) rtypesr__name__dirgetattr isinstanceisolate_modulesetattr)rnew_modnamevalues /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/coverage/misc.pyrr(s """"3<00 'HH * *DC&&E%!122 .&u-- GT5 ) ) ) ) C  c"eZdZdZddZddZdS)SysModuleSaverzASaves the contents of sys.modules, and removes new modules later.rNonecBttj|_dSNsetsysmodules old_modulesselfs r$__init__zSysModuleSaver.__init__?ss{++r%clttj|jz }|D]}tj|=dS)z6Remove any modules imported since this object started.Nr+)r1 new_modulesms r$restorezSysModuleSaver.restoreBs=#+&&)99   A A  r%Nrr()r __module__ __qualname____doc__r2r6r%r$r'r'=sBKK,,,,r%r'Iterator[None]c#Kt} dV|dS#|wxYw)z@A context manager to remove any modules imported during a block.N)r'r6)savers r$sys_modules_savedr?IsD   E   s ,AmodnamestrTuple[ModuleType, bool]ct5 tj|dfcdddS#t$rtdfcYcdddSwxYw#1swxYwYdS)aImport a third-party module we need, but might not be installed. This also cleans out the module after the import, so that coverage won't appear to have imported it. This lets the third party use coverage for their own tests. Arguments: modname (str): the name of the module to import. Returns: The imported module, and a boolean indicating if the module could be imported. If the boolean is False, the module returned is not the one you want: don't use it. TNF)r? importlib import_module ImportErrorr-)r@s r$import_third_partyrGSs    *733T9   :    s,A3AAAAAApairrc0|\}}||krd|zSd||fzS)zMake a nice string representation of a pair of numbers. If the numbers are equal, just return the number, otherwise return the pair with a dash between them, indicating the range. z%dz%d-%dr;)rHstartends r$ nice_pairrLjs/JE3 ||e|%%%r%TSelfTRetValfnCallable[[TSelf], TRetVal]cHtjrdjzdfd }|SS) zA decorator to indicate that a method shouldn't be called more than once. Normally, this does nothing. During testing, this raises an exception if called more than once. _once_r1rMrrNct|rtdjdt|d|S)NzShouldn't have called z more than onceT)hasattrAssertionErrorrr )r1attrrOs r$_wrapperzexpensive.._wrappersQtT"" \$%Zbk%Z%Z%Z[[[ D$ % % %2d88Or%N)r1rMrrN)rTESTINGr)rOrWrVs` @r$ expensiverY{sK { "+%         r%brOptional[bool]c(|dSt|S)z"Return bool(b), but preserve None.N)bool)rZs r$ bool_or_noner^sytAwwr%regexes Iterable[str]ct|}t|dkr|dSdd|DS)zDCombine a series of regex strings into one that matches any of them.r|c3"K|] }d|dV dS)z(?:)Nr;).0rs r$ zjoin_regex..s*44q a 444444r%)listlenjoin)r_s r$ join_regexrlsI7mmG 7||qqzxx44G444444r%pathr(c tj|dS#t$r!}|jtjkrYd}~dSd}~wwxYw)z9Remove a file, and don't get annoyed if it doesn't exist.N)osremoveOSErrorerrnoENOENT)rmes r$ file_be_gonerus] $  7el " "  # " " " " "s A>A directoryc:|rtj|ddSdS)zVMake sure the directory exists. If `directory` is None or empty, do nothing. T)exist_okN)romakedirs)rvs r$ ensure_dirrzs1 . I------..r%c^ttj|dS)z,Make sure the directory for the path exists.N)rzrormdirname)rms r$ensure_dir_for_filer}s$rwt$$%%%%%r%outfileOptional[IO[str]]c| tj}t|ddp-ttjddpt j}|S)zHDetermine the encoding to use for output written to `outfile` or stdout.Nencoding)r-stdoutr __stdout__localegetpreferredencoding)r~rs r$output_encodingrsP*T** & D11 &#%% Or%c*eZdZdZd dZd dZd d Zd S)Hasherz&Hashes Python data for fingerprinting.rr(c8tjd|_dS)Nsha3_256)hashlibnewhashr0s r$r2zHasher.__init__sK ++ r%vrc|jtt|dt |tr/|j|dnt |t r|j|nv|nrt |ttfr<|jt|dnt |ttfr|D]}||nt |trW| }t|D]2}|||||3nwt|D]g}|drt!||}t#j|r=||||h|jddS)z+Add `v` to the hash, recursively if needed.zutf-8N__.)rupdaterAtypeencoderbytesintfloattupleridictkeyssortedr startswithrinspect isroutine)r1rrtrkas r$rz Hasher.updates T!WW,,W55666 a    I  QXXg.. / / / / 5 ! !  I  Q     Y  C< ( (  I  SVV]]733 4 4 4 4 E4= ) )    A  4 6688DD\\ " " A AaD!!!! "VV  <<%%AqMM$Q'' A A r%rAcD|jddS)z$Retrieve the hex digest of the hash.N )r hexdigestr0s r$rzHasher.hexdigestsy""$$SbS))r%Nr7)rrrr(rrA)rr8r9r:r2rrr;r%r$rrsV00,,,,<******r%rthat func_namect|dr d}|j}nd}|j}|jd|j}t |d|d|d)z7Helper to raise NotImplementedError in interface stubs._coverage_plugin_namePluginClass. z needs to implement z())rTr __class__r8rNotImplementedError)rrthingr"klasss r$_needs_to_implementrsvt,--6)"55U^55  <<4<\$) | # a dollar sign, or (?P\w+) | # a plain word, or { # a {-wrapped (?P\w+) # word, (?: (?P\?) | # with a strict marker -(?P[^}]*) # or a default value )? # maybe. } ) )dollarword1word2match re.Match[str]rrActd|jD}|dkrdS|vr|S|drd|d}t||dS)zCalled for each $replacement.c3K|]}||V dSr*r;)rfgs r$rhz?substitute_variables..dollar_replace..,s'@@!a@A@@@@@@r%$strictz Variable z is undefined: defval)nextgroupr)rwordmsg dollar_groupsrrs r$dollar_replacez,substitute_variables..dollar_replace)s@@{u{M:@@@@@ 3;;3 Y  T? " 8_ #;d;;4;;C#C(( (? "r%)rrrrA)resub)rrdollar_patternrrs`` @r$substitute_variablesrsU  N1M # # # # # # # # 6..$ 7 7D Kr%dtdatetime.datetimecP|dS)z?Return a string with local timezone representing the date. z%Y-%m-%d %H:%M %z) astimezonestrftime)rs r$format_local_datetimer;s! ==?? # #$7 8 88r%modfile Optional[str]c||dz}tj||}|Jtj|}|tj|<|jJ|j||S)zImport a local file as a module. Opens a file in the current directory named `modname`.py, imports it as `modname`, and returns the module object. `modfile` is the file to import if it isn't in the current directory. Nz.py)rDutilspec_from_file_locationmodule_from_specr-r.loader exec_module)r@rspecrs r$import_local_filerAsE/ > 1 1'7 C CD     . ) )$ / /CCK ; " " "KC   Jr%sList[Union[str, int]]cNddfdtjd|DS) z\Turn a string into a list of string and number chunks. "z23a" -> ["z", 23, "a"] rrArUnion[str, int]cF t|S#t$r|cYSwxYw)z6If `s` is a number, return an int, else `s` unchanged.)r ValueError)rs r$tryintz_human_key..tryintYs6 q66M   HHH s   c&g|] }|Sr;r;)rfcrs r$ z_human_key..`s! 5 5 5!FF1II 5 5 5r%z(\d+))rrArr)rsplit)rrs @r$ _human_keyrUs? 6 5 5 5rx!44 5 5 55r%strings List[str]c.t|tS)zSort the given iterable of strings the way that humans expect. Numeric components in the strings are sorted as numbers. Returns the sorted list. )key)rr)rs r$ human_sortedrbs 'z * * **r% SortableItem)boundFitemsIterable[SortableItem]reverser]List[SortableItem]c(t|d|S)zSort (string, ...) items the way humans expect. The elements of `items` can be any tuple/list. They'll be sorted by the first element (a string), with ties broken by the remaining elements. Returns the sorted list of items. cDt|dg|ddRS)Nrrb)r)items r$z$human_sorted_items..ys%:d1g+>+>*Jabb*J*Jr%)rr)r)rrs r$human_sorted_itemsrns %JJT[ \ \ \\r%nrrthingsc |dkr|S|p|dzS)zZPluralize a word. If n is 1, return thing. Otherwise return things, or thing+s. rbrr;)rrrs r$pluralr|s!  Avv &%#+&r%urlcttjdr'tjr d|d|dS|S)zFormat text+url as a clickable link for stdout. If attached to a terminal, use escape sequences. Otherwise, just return the text. isattyz]8;;z]8;;)rTr-rr)rrs r$ stdout_linkrsK sz8$$):):)<)<1#111111 r%)rrrr)rr<)r@rArrB)rHrrrA)rOrPrrP)rZrrr[)r_r`rrA)rmrArr()rvrArr(r*)r~rrrA)rrrrArr()rrArrrrA)rrrrA)r@rArrrr)rrArr)rr`rr)F)rrrr]rr)rr)rrrrArrArrA)rrArrArrA)Br: __future__r contextlibdatetimerrrrDimportlib.utilrrroos.pathrr-rrtypingrrrrr r r r r rrrrcoveragercoverage.exceptionsrcoverage.typesrr__annotations__rr'contextmanagerr?rGrLrMrNrYr^rlrurzr}rrrrrrrrrrrrrr;r%r$rs-+**""""""    111111 "!!!133333!!!!$^B         . & & & &  ')  (5555....&&&&     %*%*%*%*%*%*%*%*P            0000f9999 ( 6 6 6 6++++w~Xc];;;  ] ] ] ] ]'''''      r%