ϪfdZdgZddlmZddlmZmZmZmZm Z ddl m Z m Z e GddZ dedeeefd eefd Zdeeefd e efd Zy ) z Integration with systemd. Currently only the minimum APIs necessary for using systemd's socket activation feature are supported. ListenFDs)getpid)DictListMappingOptionalSequence)FactorydefineceZdZUdZeeed<eeZ ee ed<dZ e d de ee e fde eddfd Zdeefd Zdee effd Zy) ra L{ListenFDs} provides access to file descriptors inherited from systemd. Typically L{ListenFDs.fromEnvironment} should be used to construct a new instance of L{ListenFDs}. @cvar _START: File descriptors inherited from systemd are always consecutively numbered, with a fixed lowest "starting" descriptor. This gives the default starting descriptor. Since this must agree with the value systemd is using, it typically should not be overridden. @ivar _descriptors: A C{list} of C{int} giving the descriptors which were inherited. @ivar _names: A L{Sequence} of C{str} giving the names of the descriptors which were inherited. _descriptors_namesNenvironstartreturnc|ddlm}|}| |j}tt |j dk(rt ||}t|}ng}d}t|t|k7r |gdS|||S)a @param environ: A dictionary-like object to inspect to discover inherited descriptors. By default, L{None}, indicating that the real process environment should be inspected. The default is suitable for typical usage. @param start: An integer giving the lowest value of an inherited descriptor systemd will give us. By default, L{None}, indicating the known correct (that is, in agreement with systemd) value will be used. The default is suitable for typical usage. @return: A new instance of C{cls} which can be used to look up the descriptors which have been inherited. r)r LISTEN_PID) osr_STARTstrrget_parseDescriptors _parseNameslen)clsrr_environ descriptorsnamess 8/usr/lib/python3/dist-packages/twisted/python/systemd.pyfromEnvironmentzListenFDs.fromEnvironment.s( ? .G =JJE vx=GKK 5 5%6ug%FK#.w#7EKE u:[) )r2; ;&&c,t|jS)z6 @return: The configured descriptors. )listr selfs r!inheritedDescriptorszListenFDs.inheritedDescriptors\sD%%&&r#cTtt|j|jS)zr @return: A mapping from the names of configured descriptors to their integer values. )dictziprr r&s r!inheritedNamedDescriptorsz#ListenFDs.inheritedNamedDescriptorsbs C T%6%6788r#)NN)__name__ __module__ __qualname____doc__r int__annotations__r tuplerrr classmethodrrr"rr(rr,rr#r!rrs$3-#ENFHSM* F04#+''#s(+,+'}+'  +'+'Z'd3i' 94S>9r#rrrc t|d}tt|||z}|d=|d=|S#ttf$rgcYSwxYw)a Parse the I{LISTEN_FDS} environment variable supplied by systemd. @param start: systemd provides only a count of the number of descriptors that have been inherited. This is the integer value of the first inherited descriptor. Subsequent inherited descriptors are numbered counting up from here. See L{ListenFDs._START}. @param environ: The environment variable mapping in which to look for the value to parse. @return: The integer values of the inherited file descriptors, in order. LISTEN_FDSr)r1r%rangeKeyError ValueError)rrcountrs r!rrjs_GL)*5 67  L !7<#8# j ! s0AAcx|jdd}t|dkDrt|jdSy)z Parse the I{LISTEN_FDNAMES} environment variable supplied by systemd. @param environ: The environment variable mapping in which to look for the value to parse. @return: The names of the inherited descriptors, in order. LISTEN_FDNAMESr:r)rrr3split)rr s r!rrs7 KK(" -E 5zA~U[[%&& r#N)r0__all__rrtypingrrrrr attrsr r rr1rrrrr#r!rCs  -::!Q9Q9Q9h!S!738+<!c!H c* x} r#