î »ê[°!ã@s£dZddlmZdd„ZGdd„deƒZGdd„deƒZGd d „d eƒZ Gd d „d e ƒZ Gd d„dde ƒZ dd„Z dS)z3Abstract Base Classes (ABCs) according to PEP 3119.é)ÚWeakSetcCs d|_|S)aÞA decorator indicating abstract methods. Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract methods are overridden. The abstract methods can be called using any of the normal 'super' call mechanisms. Usage: class C(metaclass=ABCMeta): @abstractmethod def my_abstract_method(self, ...): ... T)Ú__isabstractmethod__)Úfuncobj©rú/usr/lib/python3.4/abc.pyÚabstractmethod s rcs.eZdZdZdZ‡fdd†Z‡S)ÚabstractclassmethodaO A decorator indicating abstract classmethods. Similar to abstractmethod. Usage: class C(metaclass=ABCMeta): @abstractclassmethod def my_abstract_classmethod(cls, ...): ... 'abstractclassmethod' is deprecated. Use 'classmethod' with 'abstractmethod' instead. Tcsd|_tƒj|ƒdS)NT)rÚsuperÚ__init__)ÚselfÚcallable)Ú __class__rrr 0s zabstractclassmethod.__init__)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr rr)r rrs rcs.eZdZdZdZ‡fdd†Z‡S)ÚabstractstaticmethodaO A decorator indicating abstract staticmethods. Similar to abstractmethod. Usage: class C(metaclass=ABCMeta): @abstractstaticmethod def my_abstract_staticmethod(...): ... 'abstractstaticmethod' is deprecated. Use 'staticmethod' with 'abstractmethod' instead. Tcsd|_tƒj|ƒdS)NT)rr r )r r )r rrr Hs zabstractstaticmethod.__init__)rrrrrr rr)r rr5s rc@seZdZdZdZdS)Úabstractpropertyak A decorator indicating abstract properties. Requires that the metaclass is ABCMeta or derived from it. A class that has a metaclass derived from ABCMeta cannot be instantiated unless all of its abstract properties are overridden. The abstract properties can be called using any of the normal 'super' call mechanisms. Usage: class C(metaclass=ABCMeta): @abstractproperty def my_abstract_property(self): ... This defines a read-only property; you can also define a read-write abstract property using the 'long' form of property declaration: class C(metaclass=ABCMeta): def getx(self): ... def setx(self, value): ... x = abstractproperty(getx, setx) 'abstractproperty' is deprecated. Use 'property' with 'abstractmethod' instead. TN)rrrrrrrrrrMs rcsaeZdZdZdZ‡fdd†Zdd„Zddd „Zd d „Zd d „Z ‡S)ÚABCMetaaiMetaclass for defining Abstract Base Classes (ABCs). Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as 'virtual subclasses' -- these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won't show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()). rcsÜtƒj||||ƒ}dd„|jƒDƒ}xb|D]Z}xQt|dtƒƒD]:}t||dƒ}t|ddƒrW|j|ƒqWqWWq;Wt|ƒ|_tƒ|_ tƒ|_ tƒ|_ t j |_|S)NcSs.h|]$\}}t|ddƒr|’qS)rF)Úgetattr)Ú.0ÚnameÚvaluerrrú ‡s  z"ABCMeta.__new__..Ú__abstractmethods__rF)r Ú__new__ÚitemsrÚsetÚaddÚ frozensetrrÚ _abc_registryÚ _abc_cacheÚ_abc_negative_cacherÚ_abc_invalidation_counterÚ_abc_negative_cache_version)ÚmclsrÚbasesÚ namespaceÚclsÚ abstractsÚbaser)r rrr„s      zABCMeta.__new__cCsrt|tƒstdƒ‚nt||ƒr1|St||ƒrOtdƒ‚n|jj|ƒtjd7_|S)zsRegister a virtual subclass of an ABC. Returns the subclass, to allow usage as a class decorator. zCan only register classesz'Refusing to create an inheritance cycleé) Ú isinstanceÚtypeÚ TypeErrorÚ issubclassÚ RuntimeErrorr rrr#)r(ÚsubclassrrrÚregister—szABCMeta.registerNcCs–td|j|jfd|ƒtdtjd|ƒxXt|jjƒƒD]A}|jdƒrMt ||ƒ}td||fd|ƒqMqMWdS)z'Debug helper to print the ABC registry.z Class: %s.%sÚfilezInv.counter: %sÚ_abc_z%s: %rN) Úprintrrrr#ÚsortedÚ__dict__ÚkeysÚ startswithr)r(r3rrrrrÚ_dump_registry©s  zABCMeta._dump_registrycs‰|j}|ˆjkrdSt|ƒ}||krfˆjtjkrY|ˆjkrYdSˆj|ƒSt‡fdd†||hDƒƒS)z'Override for isinstance(instance, cls).TFc3s|]}ˆj|ƒVqdS)N)Ú__subclasscheck__)rÚc)r(rrú Àsz,ABCMeta.__instancecheck__..) r r!r-r$rr#r"r;Úany)r(Úinstancer1Úsubtyper)r(rÚ__instancecheck__²s     zABCMeta.__instancecheck__cCsa||jkrdS|jtjkr@tƒ|_tj|_n||jkrSdS|j|ƒ}|tk r°t|t ƒsƒt ‚|rœ|jj |ƒn|jj |ƒ|S|t |dfƒkrÜ|jj |ƒdSx4|j D])}t||ƒræ|jj |ƒdSqæWx7|jƒD])}t||ƒr |jj |ƒdSq W|jj |ƒdS)z'Override for issubclass(subclass, cls).TFÚ__mro__)r!r$rr#rr"Ú__subclasshook__ÚNotImplementedr,ÚboolÚAssertionErrorrrr r/Ú__subclasses__)r(r1ÚokÚrclsÚsclsrrrr;Âs6  zABCMeta.__subclasscheck__) rrrrr#rr2r:rAr;rr)r rrms   rc@seZdZdZdS)ÚABCzVHelper class that provides a standard way to create an ABC using inheritance. N)rrrrrrrrrKês rKÚ metaclasscCstjS)zûReturns the current ABC cache token. The token is an opaque object (supporting equality testing) identifying the current version of the ABC cache for virtual subclasses. The token changes with every call to ``register()`` on any ABC. )rr#rrrrÚget_cache_tokenñsrMN)rÚ _weakrefsetrrÚ classmethodrÚ staticmethodrÚpropertyrr-rrKrMrrrrÚs  }