o x[h+ @sddlZddlZddlZddlmZmZddlmZddlm Z e e Z GdddeZ ejGdddedgd Zd ed ed efd dZdejd edededef ddZdddddededeededed e f ddZdddededefd d!ZdS)"N) NamedTupleOptional)features)loggersc@seZdZUeed<eed<dS)DeprecationLog log_levelmessageN)__name__ __module__ __qualname__int__annotations__strrr5/usr/lib/python3/dist-packages/cloudinit/lifecycle.pyr s  rc seZdZdZ ddededededdf fdd Zed eddfd d Zd dZ ddZ ddZ ddZ ddZ dddefddZZS)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 majorminorpatchrevreturncstt||||||S)zPDefault of -1 allows us to tiebreak in favor of the most specific number)superr__new__)clsrrrr __class__rrr/szVersion.__new__versioncCs|ttt|dS)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. .)listmapr split)rrrrrfrom_str6s zVersion.from_strcCsd||kS)N)_compare_versionselfotherrrr__gt__CszVersion.__gt__cCs0|j|jko|j|jko|j|jko|j|jkSNrrrrr%rrr__eq__Fs    zVersion.__eq__ccs8|j|j|j|jfD]}|dkrt|Vq dSdS)z)Iterate over the version (drop sentinels)rN)rrrrr)r&nrrr__iter__Ns  zVersion.__iter__cCs d|S)Nr)joinr&rrr__str__Vs zVersion.__str__cCs tt|Sr))hashrr/rrr__hash__Ys zVersion.__hash__r'cCsP||krdS|j|jkrdS|j|jkrdS|j|jkrdS|j|jkr&dSdS)zCompare this Version to another. :param other: A Version object. :return: -1 if self > other, 1 if self < other, else 0 rr#rr*r%rrrr$\s    zVersion._compare_version)rrrr)r r r __doc__r r classmethodrr"r(r+r-r0r2r$ __classcell__rrrrrs, rr*rboundary_versionrcCs|dkp t|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. devel)rr")rr6rrrshould_log_deprecationps r8loggerrequested_levelmsgargscCs:t|tjr|j||g|RdS|j|g|RdS)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)r8rDEPRECATION_INFO_BOUNDARYlogdebug)r9rr:r;r<rrrlog_with_downgradable_level}s r@F) extra_messagescheduleskip_log deprecateddeprecated_versionrBrCrDc Csttds ttdt|pd}t|||t|}t|}t|j||j }|d|d|d| } t |t j sCtj} n ttdrLtj} ntj} ttd} |se|| vre| |t| | 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 r>z is deprecated in z and scheduled to be removed in z. rE)hasattr deprecatesetattrsetr1rrr"rrrstripr8rr=loggingINFOLOGr DEPRECATEDWARNgetattraddr>r) rErFrBrCrDrdeduprversion_removed deprecate_msglevel log_cacherrrrIs6        rI)rCcsfdd}|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 tfdd}|S)Ncs$|i|}tjd|S)N)rFrErBrC)rIr )r<kwargsout)rFrBfuncrCrr decoratorsz2deprecate_call..wrapper..decorator) functoolswraps)r[r\rFrBrC)r[rwrappers zdeprecate_call..wrapperr)rFrBrCr`rr_rdeprecate_callsra) collectionsr]rMtypingrr cloudinitr cloudinit.logr getLoggerr rOrtotal_ordering namedtuplerrboolr8Loggerr tupler@rIrarrrrs`    ]    9