x[h+ fddlZddlZddlZddlmZmZddlmZddlm Z eje Z GddeZ ejGddejdgd Zd ed ed efd Zdej(d edededef dZdddddededeededed e f dZdddededefdZy)N) NamedTupleOptional)features)loggersc"eZdZUeed<eed<y)DeprecationLog log_levelmessageN)__name__ __module__ __qualname__int__annotations__str5/usr/lib/python3/dist-packages/cloudinit/lifecycle.pyrr s N Lrrc eZdZdZ ddededededdf fd Zededdfd Zd Z d Z d Z d Z dZ dddefdZxZS)Versiona>A class for comparing versions. Implemented as a named tuple with all ordering methods. Comparisons between X.Y.N and X.Y always treats the more specific number as larger. :param major: the most significant number in a version :param minor: next greatest significant number after major :param patch: next greatest significant number after minor :param rev: the least significant number in a version :raises TypeError: If invalid arguments are given. :raises ValueError: If invalid arguments are given. Examples: >>> Version(2, 9) == Version.from_str("2.9") True >>> Version(2, 9, 1) > Version.from_str("2.9.1") False >>> Version(3, 10) > Version.from_str("3.9.9.9") True >>> Version(3, 7) >= Version.from_str("3.7") True majorminorpatchrevreturnc2tt| |||||S)zPDefault of -1 allows us to tiebreak in favor of the most specific number)superr__new__)clsrrrr __class__s rrzVersion.__new__/s Wc*3ueSIIrversionc X|ttt|jdS)a%Create a Version object from a string. :param version: A period-delimited version string, max 4 segments. :raises TypeError: Raised if invalid arguments are given. :raises ValueError: Raised if invalid arguments are given. :return: A Version object. .)listmaprsplit)rr s rfrom_strzVersion.from_str6s$T#c7==#56799rc*d|j|k(S)N)_compare_versionselfothers r__gt__zVersion.__gt__CsD))%000rc|j|jk(xrO|j|jk(xr4|j|jk(xr|j|jk(SNrrrrr*s r__eq__zVersion.__eq__FsX JJ%++ % & ekk) & ekk) &EII%  rc#K|j|j|j|jfD]}|dk7rt |yyw)z)Iterate over the version (drop sentinels)N)rrrrr)r+ns r__iter__zVersion.__iter__NsA**djj$**dhh? ABw!f   sA A c$dj|S)Nr")joinr+s r__str__zVersion.__str__Vsxx~rc*tt|Sr/)hashrr8s r__hash__zVersion.__hash__YsCIrr,c||k(ry|j|jkDry|j|jkDry|j|jkDry|j|jkDryy)zCompare this Version to another. :param other: A Version object. :return: -1 if self > other, 1 if self < other, else 0 rr(r3r0r*s rr)zVersion._compare_version\s] 5= :: # :: # :: # 88eii r)r3r3r3r3)r r r __doc__rr classmethodrr&r-r1r5r9r<r) __classcell__)rs@rrrs4LNJJ%(J69JEHJ J :s :y : :1 iCrrr0r boundary_versionrcf|dk(xs+tj|tj|kS)a Determine if a deprecation message should be logged. :param version: The version in which the thing was deprecated. :param boundary_version: The version at which deprecation level is logged. :return: True if the message should be logged, else False. devel)rr&)r rAs rshould_log_deprecationrDps: w & ,'*:*:+   * ++,,rloggerrequested_levelmsgargsct|tjr|j||g|y|j|g|y)auLog a message at the requested level, if that is acceptable. If the log level is too high due to the version boundary, log at DEBUG level. Useful to add new warnings to previously unguarded code without disrupting stable downstreams. :param logger: Logger object to log with :param version: Version string of the version that this log was introduced :param level: Preferred level at which this message should be logged :param msg: Message, as passed to the logger. :param args: Message formatting args, as passed to the logger :return: True if the message should be logged, else False. N)rDrDEPRECATION_INFO_BOUNDARYlogdebug)rEr rFrGrHs rlog_with_downgradable_levelrM}s<,gx'I'IJ ?C/$/ S 4 rF) extra_messagescheduleskip_log deprecateddeprecated_versionrOrPrQcttdsttdt|xsd}t ||z|zt |z}t j|}t |j|z|j}|d|d|d|j} t|tjstj} n1tt drt"j$} ntj&} t)td} |s+|| vr'| j+|t j-| | t/| | S)aMark a "thing" as deprecated. Deduplicated deprecations are logged. :param deprecated: Noun to be deprecated. Write this as the start of a sentence, with no period. Version and extra message will be appended. :param deprecated_version: The version in which the thing was deprecated :param extra_message: A remedy for the user's problem. A good message will be actionable and specific (i.e., don't use a generic "Use updated key." if the user used a deprecated key). End the string with a period. :param schedule: Manually set the deprecation schedule. Defaults to 5 years. Leave a comment explaining your reason for deviation if setting this value. :param skip_log: Return log text rather than logging it. Useful for running prior to logging setup. :return: NamedTuple containing log level and log message DeprecationLog(level: int, message: str) Note: uses keyword-only arguments to improve legibility rKz is deprecated in z and scheduled to be removed in z. rR)hasattr deprecatesetattrsetr;rrr&rrrstriprDrrJloggingINFOLOGr DEPRECATEDWARNgetattraddrKr) rRrSrOrPrQr dedupr version_removed deprecate_msglevel log_caches rrWrWs< 9e $ 5#%(!rG g%(::S]J KE12Ggmmh6 FO ,(  >  2gY ( fh  "H>>   l #""  5)I Y. e }% % //r)rPcfd}|S)a~Mark a "thing" as deprecated. Deduplicated deprecations are logged. :param deprecated_version: The version in which the thing was deprecated :param extra_message: A remedy for the user's problem. A good message will be actionable and specific (i.e., don't use a generic "Use updated key." if the user used a deprecated key). End the string with a period. :param schedule: Manually set the deprecation schedule. Defaults to 5 years. Leave a comment explaining your reason for deviation if setting this value. Note: uses keyword-only arguments to improve legibility cJtjfd}|S)NcJ|i|}tj|S)N)rSrRrOrP)rWr )rHkwargsoutrSrOfuncrPs r decoratorz2deprecate_call..wrapper..decorators3''C #5==+!   Jr) functoolswraps)rlrmrSrOrPs` rwrapperzdeprecate_call..wrappers&     rr)rSrOrPrps``` rdeprecate_callrqs&  Nr) collectionsrnr[typingrr cloudinitr cloudinit.logr getLoggerr r]rtotal_ordering namedtuplerrboolrDLoggerrtuplerMrWrqrrrr|s2'!g!Z  ZK9&HIZZz ,C ,3 ,4 ,! NN!! ! !  !@$( 505050C= 50  50  5050rEF""/2">A"r