3 گaA@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZddlZddlZddlZddlZdd lmZddlmZddlmZddlmZddlmZddlmZejeZ dddddddddddddd d!d"d#gZ!Gd$d%d%Z"Gd&d'd'e Z#d(Z$d)Z%d*Z&d+Z'e ej(e e)d,d-d.Z*e ej(e e)d,d/d0Z+ej(e ej(e e)d1d2d3Z,dS)4z.Utilities for plugins discovery and selection.N)Callable)cast)Dict)Iterable)Iterator)List)Mapping)Optional)Type)Union) configuration)errors) interfaces) constants)os)Errorcertbotzcertbot-apachezcertbot-dns-cloudflarezcertbot-dns-cloudxnszcertbot-dns-digitaloceanzcertbot-dns-dnsimplezcertbot-dns-dnsmadeeasyzcertbot-dns-gehirnzcertbot-dns-googlezcertbot-dns-linodezcertbot-dns-luadnszcertbot-dns-nsonezcertbot-dns-ovhzcertbot-dns-rfc2136zcertbot-dns-route53zcertbot-dns-sakuracloudz certbot-nginxc@seZdZdZdZd2ejeddddZe e eddd Z e ejee dd d Z ee d d dZee d ddZee d ddZeje ddddZeed ddZejeddddZeeedddZeed ddZd3e ejejddd Zeeed!d"d#Zeed d$d%Zeee fd d&d'Z!eed d(d)Z"ee e#d d*d+Z$eed d,d-Z%e d d.d/Z&e d d0d1Z'dS)4PluginEntryPointzPlugin entry point.NF) entry_point with_prefixreturncCs@|j|||_|j|_||_d|_d|_d|_d|_d|_ dS)NF) entry_point_to_plugin_namenameload plugin_clsrwarning_message _initialized _prepared_hidden_long_description)selfrrr!/usr/lib/python3.6/disco.py__init__:s zPluginEntryPoint.__init__)rrcCs$||jkr |jrtj|jdSdS)z(Check if the name refers to this plugin.TF)rrloggerwarning)r rr!r!r" check_nameDs   zPluginEntryPoint.check_namecCs6|r0|jstjd|jd|jjd|jS|jS)z)Unique plugin name for an ``entry_point``z Entrypoint z has no distribution!:)distr rrkey)clsrrr!r!r"rLs z+PluginEntryPoint.entry_point_to_plugin_name)rcCs|jjS)zDescription of the plugin.)r description)r r!r!r"r+VszPluginEntryPoint.descriptioncCsdj|j|jS)z$Description with name. Handy for UI.z {0} ({1}))formatr+r)r r!r!r"description_with_name[sz&PluginEntryPoint.description_with_namecCs|jr |jSt|jd|jS)zLong description of the plugin.long_description)rgetattrrr+)r r!r!r"r.`sz!PluginEntryPoint.long_description)r+rcCs ||_dS)N)r)r r+r!r!r"r.gscCs|jpt|jddS)z%Should this plugin be hidden from UI?hiddenF)rr/r)r r!r!r"r0kszPluginEntryPoint.hidden)hidercCs ||_dS)N)r)r r1r!r!r"r0ps) ifaces_groupsrcs| ptfdd|DS)z2Does plugin implements specified interface groups?c3s$|]}tfdd|DVqdS)c3s|]}tj|VqdS)N) _implementsr).0iface)r r!r" wsz4PluginEntryPoint.ifaces...N)all)r4ifaces)r r!r"r6wsz*PluginEntryPoint.ifaces..)any)r r2r!)r r"r8ts zPluginEntryPoint.ifacescCs |jdk S)z(Has the plugin been initialized already?N)r)r r!r!r" initialized{szPluginEntryPoint.initialized)configrcCs&|js |jj|j||j|_|jS)zMemoized plugin initialization.)rrZrequirerr)r r;r!r!r"inits zPluginEntryPoint.init)r8rcCs6|jstdx"|D]}t|j|j|sdSqWdS)z.zEntry point: {0}zInitialized: {0}z Prep: {0} ) r,rrr+joinmrorr:appendr<rArC)r linesr!r!r"__str__s  zPluginEntryPoint.__str__)F)N)(rNrM __qualname____doc____hash__ pkg_resources EntryPointrEr#r strr& classmethodrpropertyr+r-r.setterr0rr r8r:r NamespaceConfigrPluginr<r?rAr rrCrHrIrJrKrLrTr!r!r!r"r4sF   rc@sNeZdZdZeeefddddZeddddZ ee j e eefe ed d d Zeed d dZeedddZedddZejeejdddZeege fddddZddddZeeddddZeedddd Z ee!e e"fdd!d"Z#ddd#d$Z$eje%ed%d&d'Z&edd(d)Z'edd*d+Z(dS),PluginsRegistryzPlugins registry.N)pluginsrcCstt|j|_dS)N)dictsorteditems_plugins)r rar!r!r"r#szPluginsRegistry.__init__)rc Csi}tjd}|r|jdng}tjj|x|D]}tjj|q2Wt j tj t j tj t j}xd|D]\}|j||dd}|jjtkrh|j||dd}d|_dj|j|j} | |_dj| |j|_qhW||S)z+Find plugins using setuptools entry points.ZCERTBOT_PLUGIN_PATHr'F)rTzRPlugin legacy name {0} may be removed in a future version. Please use {1} instead.z(WARNING: {0}) {1})rgetenvsplitsyspathextendrXZ working_setZ add_entry itertoolschainZiter_entry_pointsrZSETUPTOOLS_PLUGINS_ENTRY_POINTZ"OLD_SETUPTOOLS_PLUGINS_ENTRY_POINT_load_entry_pointr(r)PREFIX_FREE_DISTRIBUTIONSr0r,rrr.) r*raZplugin_paths_stringZ plugin_pathsZ plugin_pathZ entry_pointsr plugin_epZprefixed_plugin_epmessager!r!r"find_alls,       zPluginsRegistry.find_all)rrarrcCst||}|j|kr^||j}|jjr0|jjjnd}|jjrF|jjjnd}tdj|j||t|jt j rx|||j<n t j d||S)Nunknownz+Duplicate plugin name {0} from {1} and {2}.z)%r does not inherit from Plugin, skipping) rrrr(r)rIr, _providesrrr_r$r%)r*rrarroZother_epZplugin1Zplugin2r!r!r"rms    z!PluginsRegistry._load_entry_point)rrcCs |j|S)N)re)r rr!r!r" __getitem__szPluginsRegistry.__getitem__cCs t|jS)N)iterre)r r!r!r"__iter__szPluginsRegistry.__iter__cCs t|jS)N)lenre)r r!r!r"__len__szPluginsRegistry.__len__)r;rcsfdd|jjDS)z'Initialize all plugins in the registry.csg|]}|jqSr!)r<)r4ro)r;r!r" sz(PluginsRegistry.init..)revalues)r r;r!)r;r"r<s zPluginsRegistry.init)predrcs t|fdd|jjDS)z"Filter plugins based on predicate.csi|]\}}|r||qSr!r!)r4rro)r{r!r" $sz*PluginsRegistry.filter..)typererd)r r{r!)r{r"filter"szPluginsRegistry.filtercCs|jddS)z#Filter plugins based on visibility.cSs|j S)N)r0)ror!r!r")sz)PluginsRegistry.visible..)r~)r r!r!r"visible'szPluginsRegistry.visible)r2rcs|jfddS)z#Filter plugins based on interfaces.cs |jS)N)r8)p_ep)r2r!r"r-sz(PluginsRegistry.ifaces..)r~)r r2r!)r2r"r8+szPluginsRegistry.ifaces)r8rcs|jfddS)z%Filter plugins based on verification.cs |jS)N)r?)r)r8r!r"r1sz(PluginsRegistry.verify..)r~)r r8r!)r8r"r?/szPluginsRegistry.verifycCsdd|jjDS)z$Prepare all plugins in the registry.cSsg|] }|jqSr!)rC)r4ror!r!r"ry5sz+PluginsRegistry.prepare..)rerz)r r!r!r"rC3szPluginsRegistry.preparecCs|jddS)z%Filter plugins based on availability.cSs|jS)N)rK)rr!r!r"r9sz+PluginsRegistry.available..)r~)r r!r!r"rK7szPluginsRegistry.available)pluginrcs(fdd|jjD}|r$|dSdS)aMFind an initialized plugin. This is particularly useful for finding a name for the plugin:: # plugin is an instance providing Plugin, initialized # somewhere else in the code plugin_registry.find_init(plugin).name Returns ``None`` if ``plugin`` is not found in the registry. cs"g|]}|jr|jkr|qSr!)r:r<)r4ro)rr!r"ryIsz-PluginsRegistry.find_init..rN)rerz)r rZ candidatesr!)rr" find_init<s zPluginsRegistry.find_initcCs&dj|jjdjdd|jjDS)Nz{0}({1}),css|]}t|VqdS)N)repr)r4rr!r!r"r6Ssz+PluginsRegistry.__repr__..)r, __class__rNrPrerz)r r!r!r"rLPs zPluginsRegistry.__repr__cCs$|js dSdjdd|jjDS)Nz No pluginsz css|]}t|VqdS)N)rZ)r4rr!r!r"r6Xsz*PluginsRegistry.__str__..)rerPrz)r r!r!r"rTUszPluginsRegistry.__str__))rNrMrUrVrrZrr#r[rqrXrYrrErmrtrrvintrxr r^rrr_r<rr~rrr r8r?r rrCrKr rrLrTr!r!r!r"r`s* r`zbZope interface certbot.interfaces.IPlugin is deprecated, use ABC certbot.interface.Plugin instead.zpZope interface certbot.interfaces.IAuthenticator is deprecated, use ABC certbot.interface.Authenticator instead.zhZope interface certbot.interfaces.IInstaller is deprecated, use ABC certbot.interface.Installer instead.ziZope interface certbot.interfaces.IPluginFactory is deprecated, use ABC certbot.interface.Plugin instead.) target_classr5rcCsBt||rdS|tjkr>tjj|r>tjttj tt dSdS)NTF) issubclassrr_ZIPluginFactoryZ providedByloggingr%_DEPRECATION_FACTORYwarningswarnDeprecationWarning)rr5r!r!r"rshs   rscCst||rdS|tjkr>tjj|r>tjttj tt dS|tj krntj j|rntjt tj t t dS|tjkrtjj|rtjttj tt dSdS)NTF)rrr_IPlugin implementedByrr%_DEPRECATION_PLUGINrrr AuthenticatorIAuthenticator_DEPRECATION_AUTHENTICATOR Installer IInstaller_DEPRECATION_INSTALLER)rr5r!r!r"r3ts       r3)target_instancerr5rcCst||rdSd}d}|tjkr*tj}t}|tjkr>tj}t}|tjkrRtj }t }|sft d|j y*t jjj||tj|tj|tdSt jjjk r}z&|j|rtjd||j |ddWYdd}~XnXdS)NTzUnexpected type: z/%s implements %s but object does not verify: %s)rBF)rrr_rrrrrrrrr=rNzopeZ interfacer?Z verifyObjectrr%rrr exceptionsZBrokenImplementationrr$r@)rrr5Z zope_ifacerprFr!r!r"r>s4       "r>)-rVrkrrhZtypingrrrrrrrr r r rrXZzope.interfacerZzope.interface.verifyrr r rZcertbot._internalrZcertbot.compatrZcertbot.errorsrZ getLoggerrNr$rnrr`rrrrr_rErsr3r>r!r!r!r"sj                 $