a '¡Dg"ã @sæddlZddlZddlZddlmZmZddlmZddlm Z e  e ¡Z Gdd„deƒZ ejGdd„de dgd ¢¡ƒƒZeeed œd d „Zejeeed œdd„Zddddœeeeeeee dœdd„Zddœeeedœdd„ZdS)éN)Ú NamedTupleÚOptional)Úfeatures)Úloggersc@seZdZUeed<eed<dS)ÚDeprecationLogZ log_levelÚmessageN)Ú__name__Ú __module__Ú __qualname__ÚintÚ__annotations__Ústr©rrú7/usr/lib/python3.9/site-packages/cloudinit/lifecycle.pyr s rcs|eZdZdZdeeeeddœ‡fdd„ Zeeddœdd„ƒZd d „Z d d „Z d d„Z dd„Z dd„Z dedœdd„Z‡ZS)Ú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 éÿÿÿÿ)ÚmajorÚminorÚpatchÚrevÚreturncstt|ƒ |||||¡S)zPDefault of -1 allows us to tiebreak in favor of the most specific number)ÚsuperrÚ__new__)Úclsrrrr©Ú __class__rrr/szVersion.__new__)ÚversionrcCs|ttt| d¡ƒƒŽS)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. Ú.)ÚlistÚmapr Úsplit)rrrrrÚfrom_str6s zVersion.from_strcCsd| |¡kS)Né)Ú_compare_version©ÚselfÚotherrrrÚ__gt__CszVersion.__gt__cCs0|j|jko.|j|jko.|j|jko.|j|jkS©N©rrrrr$rrrÚ__eq__Fs  ÿ þ üzVersion.__eq__ccs6|j|j|j|jfD]}|dkr,t|ƒVqq2qdS)z)Iterate over the version (drop sentinels)rN)rrrrr )r%ÚnrrrÚ__iter__Ns zVersion.__iter__cCs d |¡S)Nr)Újoin©r%rrrÚ__str__VszVersion.__str__cCs tt|ƒƒSr()Úhashr r.rrrÚ__hash__YszVersion.__hash__)r&rcCsP||kr dS|j|jkrdS|j|jkr,dS|j|jkr other, 1 if self < other, else 0 rr"rr)r$rrrr#\s    zVersion._compare_version)rrrr)rr r Ú__doc__r rÚ classmethodr r!r'r*r,r/r1r#Ú __classcell__rrrrrsÿþ rr))rÚboundary_versionrcCs|dkpt |¡t |¡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. Zdevel)rr!)rr5rrrÚshould_log_deprecationps  ÿþr6)ÚloggerrÚrequested_levelÚmsgcCs,t|tjƒr| |||¡n | ||¡dS)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)r6rÚDEPRECATION_INFO_BOUNDARYÚlogÚdebug)r7rr8r9ÚargsrrrÚlog_with_downgradable_level}s r>éF)Ú extra_messageÚscheduleÚskip_log)Ú deprecatedÚdeprecated_versionr@rArBrc CsÔttdƒsttdtƒƒ|pd}t|||t|ƒƒ}t |¡}t|j||j ƒ}|›d|›d|›d|›�  ¡} t |t j ƒs†tj} nttdƒr˜tj} ntj} ttdƒ} |sÊ|| vrÊ|  |¡t | | ¡t| | ƒS)aýMark 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 r;Úz is deprecated in z and scheduled to be removed in z. rC)ÚhasattrÚ deprecateÚsetattrÚsetr0r rr!rrÚrstripr6rr:ÚloggingÚINFOÚLOGrZ DEPRECATEDZWARNÚgetattrÚaddr;r) rCrDr@rArBrZdeduprZversion_removedZ deprecate_msgÚlevelZ log_cacherrrrG™s4  ÿþþÿÿ     rG)rA©rDr@rAcs‡‡‡fdd„}|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 cs t ˆ¡‡‡‡‡fdd„ƒ}|S)Ncs$ˆ|i|¤Ž}tˆˆjˆˆd�|S)N)rDrCr@rA)rGr)r=ÚkwargsÚout)rDr@ÚfuncrArrÚ decoratoråsüz2deprecate_call..wrapper..decorator)Ú functoolsÚwraps)rTrUrQ)rTrÚwrapperäs zdeprecate_call..wrapperr)rDr@rArXrrQrÚdeprecate_callÑsrY)Ú collectionsrVrKÚtypingrrZ cloudinitrZ cloudinit.logrZ getLoggerrrMrÚtotal_orderingÚ namedtuplerr Úboolr6ZLoggerr r>rGrYrrrrÚs@    ÿ]û úù 9ÿÿ