Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interfaces.py 96KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Interface documentation.
  5. Maintainer: Itamar Shtull-Trauring
  6. """
  7. from typing import (
  8. TYPE_CHECKING,
  9. Any,
  10. AnyStr,
  11. Callable,
  12. Iterable,
  13. List,
  14. Mapping,
  15. Optional,
  16. Sequence,
  17. Tuple,
  18. Union,
  19. )
  20. from zope.interface import Attribute, Interface
  21. from twisted.python.failure import Failure
  22. if TYPE_CHECKING:
  23. from socket import AddressFamily
  24. try:
  25. from OpenSSL.SSL import (
  26. Connection as OpenSSLConnection,
  27. Context as OpenSSLContext,
  28. )
  29. except ImportError:
  30. OpenSSLConnection = OpenSSLContext = object # type: ignore[misc,assignment]
  31. from twisted.internet.abstract import FileDescriptor
  32. from twisted.internet.address import IPv4Address, IPv6Address, UNIXAddress
  33. from twisted.internet.defer import Deferred
  34. from twisted.internet.protocol import (
  35. ClientFactory,
  36. ConnectedDatagramProtocol,
  37. DatagramProtocol,
  38. Factory,
  39. ServerFactory,
  40. )
  41. from twisted.internet.ssl import ClientContextFactory
  42. from twisted.names.dns import Query, RRHeader
  43. from twisted.protocols.tls import TLSMemoryBIOProtocol
  44. from twisted.python.runtime import platform
  45. if platform.supportsThreads():
  46. from twisted.python.threadpool import ThreadPool
  47. else:
  48. ThreadPool = object # type: ignore[misc, assignment]
  49. class IAddress(Interface):
  50. """
  51. An address, e.g. a TCP C{(host, port)}.
  52. Default implementations are in L{twisted.internet.address}.
  53. """
  54. ### Reactor Interfaces
  55. class IConnector(Interface):
  56. """
  57. Object used to interface between connections and protocols.
  58. Each L{IConnector} manages one connection.
  59. """
  60. def stopConnecting() -> None:
  61. """
  62. Stop attempting to connect.
  63. """
  64. def disconnect() -> None:
  65. """
  66. Disconnect regardless of the connection state.
  67. If we are connected, disconnect, if we are trying to connect,
  68. stop trying.
  69. """
  70. def connect() -> None:
  71. """
  72. Try to connect to remote address.
  73. """
  74. def getDestination() -> IAddress:
  75. """
  76. Return destination this will try to connect to.
  77. @return: An object which provides L{IAddress}.
  78. """
  79. class IResolverSimple(Interface):
  80. def getHostByName(name: str, timeout: Sequence[int]) -> "Deferred[str]":
  81. """
  82. Resolve the domain name C{name} into an IP address.
  83. @param name: DNS name to resolve.
  84. @param timeout: Number of seconds after which to reissue the query.
  85. When the last timeout expires, the query is considered failed.
  86. @return: The callback of the Deferred that is returned will be
  87. passed a string that represents the IP address of the
  88. specified name, or the errback will be called if the
  89. lookup times out. If multiple types of address records
  90. are associated with the name, A6 records will be returned
  91. in preference to AAAA records, which will be returned in
  92. preference to A records. If there are multiple records of
  93. the type to be returned, one will be selected at random.
  94. @raise twisted.internet.defer.TimeoutError: Raised
  95. (asynchronously) if the name cannot be resolved within the
  96. specified timeout period.
  97. """
  98. class IHostResolution(Interface):
  99. """
  100. An L{IHostResolution} represents represents an in-progress recursive query
  101. for a DNS name.
  102. @since: Twisted 17.1.0
  103. """
  104. name = Attribute(
  105. """
  106. L{unicode}; the name of the host being resolved.
  107. """
  108. )
  109. def cancel() -> None:
  110. """
  111. Stop the hostname resolution in progress.
  112. """
  113. class IResolutionReceiver(Interface):
  114. """
  115. An L{IResolutionReceiver} receives the results of a hostname resolution in
  116. progress, initiated by an L{IHostnameResolver}.
  117. @since: Twisted 17.1.0
  118. """
  119. def resolutionBegan(resolutionInProgress: IHostResolution) -> None:
  120. """
  121. A hostname resolution began.
  122. @param resolutionInProgress: an L{IHostResolution}.
  123. """
  124. def addressResolved(address: IAddress) -> None:
  125. """
  126. An internet address. This is called when an address for the given name
  127. is discovered. In the current implementation this practically means
  128. L{IPv4Address} or L{IPv6Address}, but implementations of this interface
  129. should be lenient to other types being passed to this interface as
  130. well, for future-proofing.
  131. @param address: An address object.
  132. """
  133. def resolutionComplete() -> None:
  134. """
  135. Resolution has completed; no further addresses will be relayed to
  136. L{IResolutionReceiver.addressResolved}.
  137. """
  138. class IHostnameResolver(Interface):
  139. """
  140. An L{IHostnameResolver} can resolve a host name and port number into a
  141. series of L{IAddress} objects.
  142. @since: Twisted 17.1.0
  143. """
  144. def resolveHostName(
  145. resolutionReceiver: IResolutionReceiver,
  146. hostName: str,
  147. portNumber: int,
  148. addressTypes: Sequence[IAddress],
  149. transportSemantics: str,
  150. ) -> IResolutionReceiver:
  151. """
  152. Initiate a hostname resolution.
  153. @param resolutionReceiver: an object that will receive each resolved
  154. address as it arrives.
  155. @param hostName: The name of the host to resolve. If this contains
  156. non-ASCII code points, they will be converted to IDNA first.
  157. @param portNumber: The port number that the returned addresses should
  158. include.
  159. @param addressTypes: An iterable of implementors of L{IAddress} that
  160. are acceptable values for C{resolutionReceiver} to receive to its
  161. L{addressResolved <IResolutionReceiver.addressResolved>}. In
  162. practice, this means an iterable containing
  163. L{twisted.internet.address.IPv4Address},
  164. L{twisted.internet.address.IPv6Address}, both, or neither.
  165. @param transportSemantics: A string describing the semantics of the
  166. transport; either C{'TCP'} for stream-oriented transports or
  167. C{'UDP'} for datagram-oriented; see
  168. L{twisted.internet.address.IPv6Address.type} and
  169. L{twisted.internet.address.IPv4Address.type}.
  170. @return: The resolution in progress.
  171. """
  172. class IResolver(IResolverSimple):
  173. def query(
  174. query: "Query", timeout: Sequence[int]
  175. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  176. """
  177. Dispatch C{query} to the method which can handle its type.
  178. @param query: The DNS query being issued, to which a response is to be
  179. generated.
  180. @param timeout: Number of seconds after which to reissue the query.
  181. When the last timeout expires, the query is considered failed.
  182. @return: A L{Deferred} which fires with a three-tuple of lists of
  183. L{twisted.names.dns.RRHeader} instances. The first element of the
  184. tuple gives answers. The second element of the tuple gives
  185. authorities. The third element of the tuple gives additional
  186. information. The L{Deferred} may instead fail with one of the
  187. exceptions defined in L{twisted.names.error} or with
  188. C{NotImplementedError}.
  189. """
  190. def lookupAddress(
  191. name: str, timeout: Sequence[int]
  192. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  193. """
  194. Perform an A record lookup.
  195. @param name: DNS name to resolve.
  196. @param timeout: Number of seconds after which to reissue the query.
  197. When the last timeout expires, the query is considered failed.
  198. @return: A L{Deferred} which fires with a three-tuple of lists of
  199. L{twisted.names.dns.RRHeader} instances. The first element of the
  200. tuple gives answers. The second element of the tuple gives
  201. authorities. The third element of the tuple gives additional
  202. information. The L{Deferred} may instead fail with one of the
  203. exceptions defined in L{twisted.names.error} or with
  204. C{NotImplementedError}.
  205. """
  206. def lookupAddress6(
  207. name: str, timeout: Sequence[int]
  208. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  209. """
  210. Perform an A6 record lookup.
  211. @param name: DNS name to resolve.
  212. @param timeout: Number of seconds after which to reissue the query.
  213. When the last timeout expires, the query is considered failed.
  214. @return: A L{Deferred} which fires with a three-tuple of lists of
  215. L{twisted.names.dns.RRHeader} instances. The first element of the
  216. tuple gives answers. The second element of the tuple gives
  217. authorities. The third element of the tuple gives additional
  218. information. The L{Deferred} may instead fail with one of the
  219. exceptions defined in L{twisted.names.error} or with
  220. C{NotImplementedError}.
  221. """
  222. def lookupIPV6Address(
  223. name: str, timeout: Sequence[int]
  224. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  225. """
  226. Perform an AAAA record lookup.
  227. @param name: DNS name to resolve.
  228. @param timeout: Number of seconds after which to reissue the query.
  229. When the last timeout expires, the query is considered failed.
  230. @return: A L{Deferred} which fires with a three-tuple of lists of
  231. L{twisted.names.dns.RRHeader} instances. The first element of the
  232. tuple gives answers. The second element of the tuple gives
  233. authorities. The third element of the tuple gives additional
  234. information. The L{Deferred} may instead fail with one of the
  235. exceptions defined in L{twisted.names.error} or with
  236. C{NotImplementedError}.
  237. """
  238. def lookupMailExchange(
  239. name: str, timeout: Sequence[int]
  240. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  241. """
  242. Perform an MX record lookup.
  243. @param name: DNS name to resolve.
  244. @param timeout: Number of seconds after which to reissue the query.
  245. When the last timeout expires, the query is considered failed.
  246. @return: A L{Deferred} which fires with a three-tuple of lists of
  247. L{twisted.names.dns.RRHeader} instances. The first element of the
  248. tuple gives answers. The second element of the tuple gives
  249. authorities. The third element of the tuple gives additional
  250. information. The L{Deferred} may instead fail with one of the
  251. exceptions defined in L{twisted.names.error} or with
  252. C{NotImplementedError}.
  253. """
  254. def lookupNameservers(
  255. name: str, timeout: Sequence[int]
  256. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  257. """
  258. Perform an NS record lookup.
  259. @param name: DNS name to resolve.
  260. @param timeout: Number of seconds after which to reissue the query.
  261. When the last timeout expires, the query is considered failed.
  262. @return: A L{Deferred} which fires with a three-tuple of lists of
  263. L{twisted.names.dns.RRHeader} instances. The first element of the
  264. tuple gives answers. The second element of the tuple gives
  265. authorities. The third element of the tuple gives additional
  266. information. The L{Deferred} may instead fail with one of the
  267. exceptions defined in L{twisted.names.error} or with
  268. C{NotImplementedError}.
  269. """
  270. def lookupCanonicalName(
  271. name: str, timeout: Sequence[int]
  272. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  273. """
  274. Perform a CNAME record lookup.
  275. @param name: DNS name to resolve.
  276. @param timeout: Number of seconds after which to reissue the query.
  277. When the last timeout expires, the query is considered failed.
  278. @return: A L{Deferred} which fires with a three-tuple of lists of
  279. L{twisted.names.dns.RRHeader} instances. The first element of the
  280. tuple gives answers. The second element of the tuple gives
  281. authorities. The third element of the tuple gives additional
  282. information. The L{Deferred} may instead fail with one of the
  283. exceptions defined in L{twisted.names.error} or with
  284. C{NotImplementedError}.
  285. """
  286. def lookupMailBox(
  287. name: str, timeout: Sequence[int]
  288. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  289. """
  290. Perform an MB record lookup.
  291. @param name: DNS name to resolve.
  292. @param timeout: Number of seconds after which to reissue the query.
  293. When the last timeout expires, the query is considered failed.
  294. @return: A L{Deferred} which fires with a three-tuple of lists of
  295. L{twisted.names.dns.RRHeader} instances. The first element of the
  296. tuple gives answers. The second element of the tuple gives
  297. authorities. The third element of the tuple gives additional
  298. information. The L{Deferred} may instead fail with one of the
  299. exceptions defined in L{twisted.names.error} or with
  300. C{NotImplementedError}.
  301. """
  302. def lookupMailGroup(
  303. name: str, timeout: Sequence[int]
  304. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  305. """
  306. Perform an MG record lookup.
  307. @param name: DNS name to resolve.
  308. @param timeout: Number of seconds after which to reissue the query.
  309. When the last timeout expires, the query is considered failed.
  310. @return: A L{Deferred} which fires with a three-tuple of lists of
  311. L{twisted.names.dns.RRHeader} instances. The first element of the
  312. tuple gives answers. The second element of the tuple gives
  313. authorities. The third element of the tuple gives additional
  314. information. The L{Deferred} may instead fail with one of the
  315. exceptions defined in L{twisted.names.error} or with
  316. C{NotImplementedError}.
  317. """
  318. def lookupMailRename(
  319. name: str, timeout: Sequence[int]
  320. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  321. """
  322. Perform an MR record lookup.
  323. @param name: DNS name to resolve.
  324. @param timeout: Number of seconds after which to reissue the query.
  325. When the last timeout expires, the query is considered failed.
  326. @return: A L{Deferred} which fires with a three-tuple of lists of
  327. L{twisted.names.dns.RRHeader} instances. The first element of the
  328. tuple gives answers. The second element of the tuple gives
  329. authorities. The third element of the tuple gives additional
  330. information. The L{Deferred} may instead fail with one of the
  331. exceptions defined in L{twisted.names.error} or with
  332. C{NotImplementedError}.
  333. """
  334. def lookupPointer(
  335. name: str, timeout: Sequence[int]
  336. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  337. """
  338. Perform a PTR record lookup.
  339. @param name: DNS name to resolve.
  340. @param timeout: Number of seconds after which to reissue the query.
  341. When the last timeout expires, the query is considered failed.
  342. @return: A L{Deferred} which fires with a three-tuple of lists of
  343. L{twisted.names.dns.RRHeader} instances. The first element of the
  344. tuple gives answers. The second element of the tuple gives
  345. authorities. The third element of the tuple gives additional
  346. information. The L{Deferred} may instead fail with one of the
  347. exceptions defined in L{twisted.names.error} or with
  348. C{NotImplementedError}.
  349. """
  350. def lookupAuthority(
  351. name: str, timeout: Sequence[int]
  352. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  353. """
  354. Perform an SOA record lookup.
  355. @param name: DNS name to resolve.
  356. @param timeout: Number of seconds after which to reissue the query.
  357. When the last timeout expires, the query is considered failed.
  358. @return: A L{Deferred} which fires with a three-tuple of lists of
  359. L{twisted.names.dns.RRHeader} instances. The first element of the
  360. tuple gives answers. The second element of the tuple gives
  361. authorities. The third element of the tuple gives additional
  362. information. The L{Deferred} may instead fail with one of the
  363. exceptions defined in L{twisted.names.error} or with
  364. C{NotImplementedError}.
  365. """
  366. def lookupNull(
  367. name: str, timeout: Sequence[int]
  368. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  369. """
  370. Perform a NULL record lookup.
  371. @param name: DNS name to resolve.
  372. @param timeout: Number of seconds after which to reissue the query.
  373. When the last timeout expires, the query is considered failed.
  374. @return: A L{Deferred} which fires with a three-tuple of lists of
  375. L{twisted.names.dns.RRHeader} instances. The first element of the
  376. tuple gives answers. The second element of the tuple gives
  377. authorities. The third element of the tuple gives additional
  378. information. The L{Deferred} may instead fail with one of the
  379. exceptions defined in L{twisted.names.error} or with
  380. C{NotImplementedError}.
  381. """
  382. def lookupWellKnownServices(
  383. name: str, timeout: Sequence[int]
  384. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  385. """
  386. Perform a WKS record lookup.
  387. @param name: DNS name to resolve.
  388. @param timeout: Number of seconds after which to reissue the query.
  389. When the last timeout expires, the query is considered failed.
  390. @return: A L{Deferred} which fires with a three-tuple of lists of
  391. L{twisted.names.dns.RRHeader} instances. The first element of the
  392. tuple gives answers. The second element of the tuple gives
  393. authorities. The third element of the tuple gives additional
  394. information. The L{Deferred} may instead fail with one of the
  395. exceptions defined in L{twisted.names.error} or with
  396. C{NotImplementedError}.
  397. """
  398. def lookupHostInfo(
  399. name: str, timeout: Sequence[int]
  400. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  401. """
  402. Perform a HINFO record lookup.
  403. @param name: DNS name to resolve.
  404. @param timeout: Number of seconds after which to reissue the query.
  405. When the last timeout expires, the query is considered failed.
  406. @return: A L{Deferred} which fires with a three-tuple of lists of
  407. L{twisted.names.dns.RRHeader} instances. The first element of the
  408. tuple gives answers. The second element of the tuple gives
  409. authorities. The third element of the tuple gives additional
  410. information. The L{Deferred} may instead fail with one of the
  411. exceptions defined in L{twisted.names.error} or with
  412. C{NotImplementedError}.
  413. """
  414. def lookupMailboxInfo(
  415. name: str, timeout: Sequence[int]
  416. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  417. """
  418. Perform an MINFO record lookup.
  419. @param name: DNS name to resolve.
  420. @param timeout: Number of seconds after which to reissue the query.
  421. When the last timeout expires, the query is considered failed.
  422. @return: A L{Deferred} which fires with a three-tuple of lists of
  423. L{twisted.names.dns.RRHeader} instances. The first element of the
  424. tuple gives answers. The second element of the tuple gives
  425. authorities. The third element of the tuple gives additional
  426. information. The L{Deferred} may instead fail with one of the
  427. exceptions defined in L{twisted.names.error} or with
  428. C{NotImplementedError}.
  429. """
  430. def lookupText(
  431. name: str, timeout: Sequence[int]
  432. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  433. """
  434. Perform a TXT record lookup.
  435. @param name: DNS name to resolve.
  436. @param timeout: Number of seconds after which to reissue the query.
  437. When the last timeout expires, the query is considered failed.
  438. @return: A L{Deferred} which fires with a three-tuple of lists of
  439. L{twisted.names.dns.RRHeader} instances. The first element of the
  440. tuple gives answers. The second element of the tuple gives
  441. authorities. The third element of the tuple gives additional
  442. information. The L{Deferred} may instead fail with one of the
  443. exceptions defined in L{twisted.names.error} or with
  444. C{NotImplementedError}.
  445. """
  446. def lookupResponsibility(
  447. name: str, timeout: Sequence[int]
  448. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  449. """
  450. Perform an RP record lookup.
  451. @param name: DNS name to resolve.
  452. @param timeout: Number of seconds after which to reissue the query.
  453. When the last timeout expires, the query is considered failed.
  454. @return: A L{Deferred} which fires with a three-tuple of lists of
  455. L{twisted.names.dns.RRHeader} instances. The first element of the
  456. tuple gives answers. The second element of the tuple gives
  457. authorities. The third element of the tuple gives additional
  458. information. The L{Deferred} may instead fail with one of the
  459. exceptions defined in L{twisted.names.error} or with
  460. C{NotImplementedError}.
  461. """
  462. def lookupAFSDatabase(
  463. name: str, timeout: Sequence[int]
  464. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  465. """
  466. Perform an AFSDB record lookup.
  467. @param name: DNS name to resolve.
  468. @param timeout: Number of seconds after which to reissue the query.
  469. When the last timeout expires, the query is considered failed.
  470. @return: A L{Deferred} which fires with a three-tuple of lists of
  471. L{twisted.names.dns.RRHeader} instances. The first element of the
  472. tuple gives answers. The second element of the tuple gives
  473. authorities. The third element of the tuple gives additional
  474. information. The L{Deferred} may instead fail with one of the
  475. exceptions defined in L{twisted.names.error} or with
  476. C{NotImplementedError}.
  477. """
  478. def lookupService(
  479. name: str, timeout: Sequence[int]
  480. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  481. """
  482. Perform an SRV record lookup.
  483. @param name: DNS name to resolve.
  484. @param timeout: Number of seconds after which to reissue the query.
  485. When the last timeout expires, the query is considered failed.
  486. @return: A L{Deferred} which fires with a three-tuple of lists of
  487. L{twisted.names.dns.RRHeader} instances. The first element of the
  488. tuple gives answers. The second element of the tuple gives
  489. authorities. The third element of the tuple gives additional
  490. information. The L{Deferred} may instead fail with one of the
  491. exceptions defined in L{twisted.names.error} or with
  492. C{NotImplementedError}.
  493. """
  494. def lookupAllRecords(
  495. name: str, timeout: Sequence[int]
  496. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  497. """
  498. Perform an ALL_RECORD lookup.
  499. @param name: DNS name to resolve.
  500. @param timeout: Number of seconds after which to reissue the query.
  501. When the last timeout expires, the query is considered failed.
  502. @return: A L{Deferred} which fires with a three-tuple of lists of
  503. L{twisted.names.dns.RRHeader} instances. The first element of the
  504. tuple gives answers. The second element of the tuple gives
  505. authorities. The third element of the tuple gives additional
  506. information. The L{Deferred} may instead fail with one of the
  507. exceptions defined in L{twisted.names.error} or with
  508. C{NotImplementedError}.
  509. """
  510. def lookupSenderPolicy(
  511. name: str, timeout: Sequence[int]
  512. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  513. """
  514. Perform a SPF record lookup.
  515. @param name: DNS name to resolve.
  516. @param timeout: Number of seconds after which to reissue the query.
  517. When the last timeout expires, the query is considered failed.
  518. @return: A L{Deferred} which fires with a three-tuple of lists of
  519. L{twisted.names.dns.RRHeader} instances. The first element of the
  520. tuple gives answers. The second element of the tuple gives
  521. authorities. The third element of the tuple gives additional
  522. information. The L{Deferred} may instead fail with one of the
  523. exceptions defined in L{twisted.names.error} or with
  524. C{NotImplementedError}.
  525. """
  526. def lookupNamingAuthorityPointer(
  527. name: str, timeout: Sequence[int]
  528. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  529. """
  530. Perform a NAPTR record lookup.
  531. @param name: DNS name to resolve.
  532. @param timeout: Number of seconds after which to reissue the query.
  533. When the last timeout expires, the query is considered failed.
  534. @return: A L{Deferred} which fires with a three-tuple of lists of
  535. L{twisted.names.dns.RRHeader} instances. The first element of the
  536. tuple gives answers. The second element of the tuple gives
  537. authorities. The third element of the tuple gives additional
  538. information. The L{Deferred} may instead fail with one of the
  539. exceptions defined in L{twisted.names.error} or with
  540. C{NotImplementedError}.
  541. """
  542. def lookupZone(
  543. name: str, timeout: Sequence[int]
  544. ) -> "Deferred[Tuple[RRHeader, RRHeader, RRHeader]]":
  545. """
  546. Perform an AXFR record lookup.
  547. NB This is quite different from other DNS requests. See
  548. U{http://cr.yp.to/djbdns/axfr-notes.html} for more
  549. information.
  550. NB Unlike other C{lookup*} methods, the timeout here is not a
  551. list of ints, it is a single int.
  552. @param name: DNS name to resolve.
  553. @param timeout: When this timeout expires, the query is
  554. considered failed.
  555. @return: A L{Deferred} which fires with a three-tuple of lists of
  556. L{twisted.names.dns.RRHeader} instances.
  557. The first element of the tuple gives answers.
  558. The second and third elements are always empty.
  559. The L{Deferred} may instead fail with one of the
  560. exceptions defined in L{twisted.names.error} or with
  561. C{NotImplementedError}.
  562. """
  563. class IReactorTCP(Interface):
  564. def listenTCP(
  565. port: int, factory: "ServerFactory", backlog: int, interface: str
  566. ) -> "IListeningPort":
  567. """
  568. Connects a given protocol factory to the given numeric TCP/IP port.
  569. @param port: a port number on which to listen
  570. @param factory: a L{twisted.internet.protocol.ServerFactory} instance
  571. @param backlog: size of the listen queue
  572. @param interface: The local IPv4 or IPv6 address to which to bind;
  573. defaults to '', ie all IPv4 addresses. To bind to all IPv4 and IPv6
  574. addresses, you must call this method twice.
  575. @return: an object that provides L{IListeningPort}.
  576. @raise CannotListenError: as defined here
  577. L{twisted.internet.error.CannotListenError},
  578. if it cannot listen on this port (e.g., it
  579. cannot bind to the required port number)
  580. """
  581. def connectTCP(
  582. host: str,
  583. port: int,
  584. factory: "ClientFactory",
  585. timeout: float,
  586. bindAddress: Optional[Tuple[str, int]],
  587. ) -> IConnector:
  588. """
  589. Connect a TCP client.
  590. @param host: A hostname or an IPv4 or IPv6 address literal.
  591. @param port: a port number
  592. @param factory: a L{twisted.internet.protocol.ClientFactory} instance
  593. @param timeout: number of seconds to wait before assuming the
  594. connection has failed.
  595. @param bindAddress: a (host, port) tuple of local address to bind
  596. to, or None.
  597. @return: An object which provides L{IConnector}. This connector will
  598. call various callbacks on the factory when a connection is
  599. made, failed, or lost - see
  600. L{ClientFactory<twisted.internet.protocol.ClientFactory>}
  601. docs for details.
  602. """
  603. class IReactorSSL(Interface):
  604. def connectSSL(
  605. host: str,
  606. port: int,
  607. factory: "ClientFactory",
  608. contextFactory: "ClientContextFactory",
  609. timeout: float,
  610. bindAddress: Optional[Tuple[str, int]],
  611. ) -> IConnector:
  612. """
  613. Connect a client Protocol to a remote SSL socket.
  614. @param host: a host name
  615. @param port: a port number
  616. @param factory: a L{twisted.internet.protocol.ClientFactory} instance
  617. @param contextFactory: a L{twisted.internet.ssl.ClientContextFactory} object.
  618. @param timeout: number of seconds to wait before assuming the
  619. connection has failed.
  620. @param bindAddress: a (host, port) tuple of local address to bind to,
  621. or L{None}.
  622. @return: An object which provides L{IConnector}.
  623. """
  624. def listenSSL(
  625. port: int,
  626. factory: "ServerFactory",
  627. contextFactory: "IOpenSSLContextFactory",
  628. backlog: int,
  629. interface: str,
  630. ) -> "IListeningPort":
  631. """
  632. Connects a given protocol factory to the given numeric TCP/IP port.
  633. The connection is a SSL one, using contexts created by the context
  634. factory.
  635. @param port: a port number on which to listen
  636. @param factory: a L{twisted.internet.protocol.ServerFactory} instance
  637. @param contextFactory: an implementor of L{IOpenSSLContextFactory}
  638. @param backlog: size of the listen queue
  639. @param interface: the hostname to bind to, defaults to '' (all)
  640. """
  641. class IReactorUNIX(Interface):
  642. """
  643. UNIX socket methods.
  644. """
  645. def connectUNIX(
  646. address: str, factory: "ClientFactory", timeout: float, checkPID: bool
  647. ) -> IConnector:
  648. """
  649. Connect a client protocol to a UNIX socket.
  650. @param address: a path to a unix socket on the filesystem.
  651. @param factory: a L{twisted.internet.protocol.ClientFactory} instance
  652. @param timeout: number of seconds to wait before assuming the connection
  653. has failed.
  654. @param checkPID: if True, check for a pid file to verify that a server
  655. is listening. If C{address} is a Linux abstract namespace path,
  656. this must be C{False}.
  657. @return: An object which provides L{IConnector}.
  658. """
  659. def listenUNIX(
  660. address: str, factory: "Factory", backlog: int, mode: int, wantPID: bool
  661. ) -> "IListeningPort":
  662. """
  663. Listen on a UNIX socket.
  664. @param address: a path to a unix socket on the filesystem.
  665. @param factory: a L{twisted.internet.protocol.Factory} instance.
  666. @param backlog: number of connections to allow in backlog.
  667. @param mode: The mode (B{not} umask) to set on the unix socket. See
  668. platform specific documentation for information about how this
  669. might affect connection attempts.
  670. @param wantPID: if True, create a pidfile for the socket. If C{address}
  671. is a Linux abstract namespace path, this must be C{False}.
  672. @return: An object which provides L{IListeningPort}.
  673. """
  674. class IReactorUNIXDatagram(Interface):
  675. """
  676. Datagram UNIX socket methods.
  677. """
  678. def connectUNIXDatagram(
  679. address: str,
  680. protocol: "ConnectedDatagramProtocol",
  681. maxPacketSize: int,
  682. mode: int,
  683. bindAddress: Optional[Tuple[str, int]],
  684. ) -> IConnector:
  685. """
  686. Connect a client protocol to a datagram UNIX socket.
  687. @param address: a path to a unix socket on the filesystem.
  688. @param protocol: a L{twisted.internet.protocol.ConnectedDatagramProtocol} instance
  689. @param maxPacketSize: maximum packet size to accept
  690. @param mode: The mode (B{not} umask) to set on the unix socket. See
  691. platform specific documentation for information about how this
  692. might affect connection attempts.
  693. @param bindAddress: address to bind to
  694. @return: An object which provides L{IConnector}.
  695. """
  696. def listenUNIXDatagram(
  697. address: str, protocol: "DatagramProtocol", maxPacketSize: int, mode: int
  698. ) -> "IListeningPort":
  699. """
  700. Listen on a datagram UNIX socket.
  701. @param address: a path to a unix socket on the filesystem.
  702. @param protocol: a L{twisted.internet.protocol.DatagramProtocol} instance.
  703. @param maxPacketSize: maximum packet size to accept
  704. @param mode: The mode (B{not} umask) to set on the unix socket. See
  705. platform specific documentation for information about how this
  706. might affect connection attempts.
  707. @return: An object which provides L{IListeningPort}.
  708. """
  709. class IReactorWin32Events(Interface):
  710. """
  711. Win32 Event API methods
  712. @since: 10.2
  713. """
  714. def addEvent(event: object, fd: "FileDescriptor", action: str) -> None:
  715. """
  716. Add a new win32 event to the event loop.
  717. @param event: a Win32 event object created using win32event.CreateEvent()
  718. @param fd: an instance of L{twisted.internet.abstract.FileDescriptor}
  719. @param action: a string that is a method name of the fd instance.
  720. This method is called in response to the event.
  721. """
  722. def removeEvent(event: object) -> None:
  723. """
  724. Remove an event.
  725. @param event: a Win32 event object added using L{IReactorWin32Events.addEvent}
  726. @return: None
  727. """
  728. class IReactorUDP(Interface):
  729. """
  730. UDP socket methods.
  731. """
  732. def listenUDP(
  733. port: int, protocol: "DatagramProtocol", interface: str, maxPacketSize: int
  734. ) -> "IListeningPort":
  735. """
  736. Connects a given L{DatagramProtocol} to the given numeric UDP port.
  737. @param port: A port number on which to listen.
  738. @param protocol: A L{DatagramProtocol} instance which will be
  739. connected to the given C{port}.
  740. @param interface: The local IPv4 or IPv6 address to which to bind;
  741. defaults to '', ie all IPv4 addresses.
  742. @param maxPacketSize: The maximum packet size to accept.
  743. @return: object which provides L{IListeningPort}.
  744. """
  745. class IReactorMulticast(Interface):
  746. """
  747. UDP socket methods that support multicast.
  748. IMPORTANT: This is an experimental new interface. It may change
  749. without backwards compatibility. Suggestions are welcome.
  750. """
  751. def listenMulticast(
  752. port: int,
  753. protocol: "DatagramProtocol",
  754. interface: str,
  755. maxPacketSize: int,
  756. listenMultiple: bool,
  757. ) -> "IListeningPort":
  758. """
  759. Connects a given
  760. L{DatagramProtocol<twisted.internet.protocol.DatagramProtocol>} to the
  761. given numeric UDP port.
  762. @param listenMultiple: If set to True, allows multiple sockets to
  763. bind to the same address and port number at the same time.
  764. @returns: An object which provides L{IListeningPort}.
  765. @see: L{twisted.internet.interfaces.IMulticastTransport}
  766. @see: U{http://twistedmatrix.com/documents/current/core/howto/udp.html}
  767. """
  768. class IReactorSocket(Interface):
  769. """
  770. Methods which allow a reactor to use externally created sockets.
  771. For example, to use C{adoptStreamPort} to implement behavior equivalent
  772. to that of L{IReactorTCP.listenTCP}, you might write code like this::
  773. from socket import SOMAXCONN, AF_INET, SOCK_STREAM, socket
  774. portSocket = socket(AF_INET, SOCK_STREAM)
  775. # Set FD_CLOEXEC on port, left as an exercise. Then make it into a
  776. # non-blocking listening port:
  777. portSocket.setblocking(False)
  778. portSocket.bind(('192.168.1.2', 12345))
  779. portSocket.listen(SOMAXCONN)
  780. # Now have the reactor use it as a TCP port
  781. port = reactor.adoptStreamPort(
  782. portSocket.fileno(), AF_INET, YourFactory())
  783. # portSocket itself is no longer necessary, and needs to be cleaned
  784. # up by us.
  785. portSocket.close()
  786. # Whenever the server is no longer needed, stop it as usual.
  787. stoppedDeferred = port.stopListening()
  788. Another potential use is to inherit a listening descriptor from a parent
  789. process (for example, systemd or launchd), or to receive one over a UNIX
  790. domain socket.
  791. Some plans for extending this interface exist. See:
  792. - U{http://twistedmatrix.com/trac/ticket/6594}: AF_UNIX SOCK_DGRAM ports
  793. """
  794. def adoptStreamPort(
  795. fileDescriptor: int, addressFamily: "AddressFamily", factory: "ServerFactory"
  796. ) -> "IListeningPort":
  797. """
  798. Add an existing listening I{SOCK_STREAM} socket to the reactor to
  799. monitor for new connections to accept and handle.
  800. @param fileDescriptor: A file descriptor associated with a socket which
  801. is already bound to an address and marked as listening. The socket
  802. must be set non-blocking. Any additional flags (for example,
  803. close-on-exec) must also be set by application code. Application
  804. code is responsible for closing the file descriptor, which may be
  805. done as soon as C{adoptStreamPort} returns.
  806. @param addressFamily: The address family (or I{domain}) of the socket.
  807. For example, L{socket.AF_INET6}.
  808. @param factory: A L{ServerFactory} instance to use to create new
  809. protocols to handle connections accepted via this socket.
  810. @return: An object providing L{IListeningPort}.
  811. @raise twisted.internet.error.UnsupportedAddressFamily: If the
  812. given address family is not supported by this reactor, or
  813. not supported with the given socket type.
  814. @raise twisted.internet.error.UnsupportedSocketType: If the
  815. given socket type is not supported by this reactor, or not
  816. supported with the given socket type.
  817. """
  818. def adoptStreamConnection(
  819. fileDescriptor: int, addressFamily: "AddressFamily", factory: "ServerFactory"
  820. ) -> None:
  821. """
  822. Add an existing connected I{SOCK_STREAM} socket to the reactor to
  823. monitor for data.
  824. Note that the given factory won't have its C{startFactory} and
  825. C{stopFactory} methods called, as there is no sensible time to call
  826. them in this situation.
  827. @param fileDescriptor: A file descriptor associated with a socket which
  828. is already connected. The socket must be set non-blocking. Any
  829. additional flags (for example, close-on-exec) must also be set by
  830. application code. Application code is responsible for closing the
  831. file descriptor, which may be done as soon as
  832. C{adoptStreamConnection} returns.
  833. @param addressFamily: The address family (or I{domain}) of the socket.
  834. For example, L{socket.AF_INET6}.
  835. @param factory: A L{ServerFactory} instance to use to create a new
  836. protocol to handle the connection via this socket.
  837. @raise UnsupportedAddressFamily: If the given address family is not
  838. supported by this reactor, or not supported with the given socket
  839. type.
  840. @raise UnsupportedSocketType: If the given socket type is not supported
  841. by this reactor, or not supported with the given socket type.
  842. """
  843. def adoptDatagramPort(
  844. fileDescriptor: int,
  845. addressFamily: "AddressFamily",
  846. protocol: "DatagramProtocol",
  847. maxPacketSize: int,
  848. ) -> "IListeningPort":
  849. """
  850. Add an existing listening I{SOCK_DGRAM} socket to the reactor to
  851. monitor for read and write readiness.
  852. @param fileDescriptor: A file descriptor associated with a socket which
  853. is already bound to an address and marked as listening. The socket
  854. must be set non-blocking. Any additional flags (for example,
  855. close-on-exec) must also be set by application code. Application
  856. code is responsible for closing the file descriptor, which may be
  857. done as soon as C{adoptDatagramPort} returns.
  858. @param addressFamily: The address family or I{domain} of the socket.
  859. For example, L{socket.AF_INET6}.
  860. @param protocol: A L{DatagramProtocol} instance to connect to
  861. a UDP transport.
  862. @param maxPacketSize: The maximum packet size to accept.
  863. @return: An object providing L{IListeningPort}.
  864. @raise UnsupportedAddressFamily: If the given address family is not
  865. supported by this reactor, or not supported with the given socket
  866. type.
  867. @raise UnsupportedSocketType: If the given socket type is not supported
  868. by this reactor, or not supported with the given socket type.
  869. """
  870. class IReactorProcess(Interface):
  871. def spawnProcess(
  872. processProtocol: "IProcessProtocol",
  873. executable: Union[bytes, str],
  874. args: Sequence[Union[bytes, str]],
  875. env: Optional[Mapping[AnyStr, AnyStr]],
  876. path: Union[bytes, str],
  877. uid: int,
  878. gid: int,
  879. usePTY: bool,
  880. childFDs: Mapping[int, Union[int, str]],
  881. ) -> "IProcessTransport":
  882. """
  883. Spawn a process, with a process protocol.
  884. Arguments given to this function that are listed as L{bytes} or
  885. L{unicode} may be encoded or decoded depending on the platform and the
  886. argument type given. On UNIX systems (Linux, FreeBSD, macOS) and
  887. Python 2 on Windows, L{unicode} arguments will be encoded down to
  888. L{bytes} using the encoding given by L{sys.getfilesystemencoding}, to be
  889. used with the "narrow" OS APIs. On Python 3 on Windows, L{bytes}
  890. arguments will be decoded up to L{unicode} using the encoding given by
  891. L{sys.getfilesystemencoding} (C{utf8}) and given to Windows's native "wide" APIs.
  892. @param processProtocol: An object which will be notified of all events
  893. related to the created process.
  894. @param executable: the file name to spawn - the full path should be
  895. used.
  896. @param args: the command line arguments to pass to the process; a
  897. sequence of strings. The first string should be the executable's
  898. name.
  899. @param env: the environment variables to pass to the child process.
  900. The resulting behavior varies between platforms. If:
  901. - C{env} is not set:
  902. - On POSIX: pass an empty environment.
  903. - On Windows: pass L{os.environ}.
  904. - C{env} is L{None}:
  905. - On POSIX: pass L{os.environ}.
  906. - On Windows: pass L{os.environ}.
  907. - C{env} is a L{dict}:
  908. - On POSIX: pass the key/value pairs in C{env} as the
  909. complete environment.
  910. - On Windows: update L{os.environ} with the key/value
  911. pairs in the L{dict} before passing it. As a
  912. consequence of U{bug #1640
  913. <http://twistedmatrix.com/trac/ticket/1640>}, passing
  914. keys with empty values in an effort to unset
  915. environment variables I{won't} unset them.
  916. @param path: the path to run the subprocess in - defaults to the
  917. current directory.
  918. @param uid: user ID to run the subprocess as. (Only available on POSIX
  919. systems.)
  920. @param gid: group ID to run the subprocess as. (Only available on
  921. POSIX systems.)
  922. @param usePTY: if true, run this process in a pseudo-terminal.
  923. optionally a tuple of C{(masterfd, slavefd, ttyname)}, in which
  924. case use those file descriptors. (Not available on all systems.)
  925. @param childFDs: A dictionary mapping file descriptors in the new child
  926. process to an integer or to the string 'r' or 'w'.
  927. If the value is an integer, it specifies a file descriptor in the
  928. parent process which will be mapped to a file descriptor (specified
  929. by the key) in the child process. This is useful for things like
  930. inetd and shell-like file redirection.
  931. If it is the string 'r', a pipe will be created and attached to the
  932. child at that file descriptor: the child will be able to write to
  933. that file descriptor and the parent will receive read notification
  934. via the L{IProcessProtocol.childDataReceived} callback. This is
  935. useful for the child's stdout and stderr.
  936. If it is the string 'w', similar setup to the previous case will
  937. occur, with the pipe being readable by the child instead of
  938. writeable. The parent process can write to that file descriptor
  939. using L{IProcessTransport.writeToChild}. This is useful for the
  940. child's stdin.
  941. If childFDs is not passed, the default behaviour is to use a
  942. mapping that opens the usual stdin/stdout/stderr pipes.
  943. @see: L{twisted.internet.protocol.ProcessProtocol}
  944. @return: An object which provides L{IProcessTransport}.
  945. @raise OSError: Raised with errno C{EAGAIN} or C{ENOMEM} if there are
  946. insufficient system resources to create a new process.
  947. """
  948. class IReactorTime(Interface):
  949. """
  950. Time methods that a Reactor should implement.
  951. """
  952. def seconds() -> float:
  953. """
  954. Get the current time in seconds.
  955. @return: A number-like object of some sort.
  956. """
  957. def callLater(
  958. delay: float, callable: Callable[..., Any], *args: object, **kwargs: object
  959. ) -> "IDelayedCall":
  960. """
  961. Call a function later.
  962. @param delay: the number of seconds to wait.
  963. @param callable: the callable object to call later.
  964. @param args: the arguments to call it with.
  965. @param kwargs: the keyword arguments to call it with.
  966. @return: An object which provides L{IDelayedCall} and can be used to
  967. cancel the scheduled call, by calling its C{cancel()} method.
  968. It also may be rescheduled by calling its C{delay()} or
  969. C{reset()} methods.
  970. """
  971. def getDelayedCalls() -> Sequence["IDelayedCall"]:
  972. """
  973. See L{twisted.internet.interfaces.IReactorTime.getDelayedCalls}
  974. """
  975. class IDelayedCall(Interface):
  976. """
  977. A scheduled call.
  978. There are probably other useful methods we can add to this interface;
  979. suggestions are welcome.
  980. """
  981. def getTime() -> float:
  982. """
  983. Get time when delayed call will happen.
  984. @return: time in seconds since epoch (a float).
  985. """
  986. def cancel() -> None:
  987. """
  988. Cancel the scheduled call.
  989. @raises twisted.internet.error.AlreadyCalled: if the call has already
  990. happened.
  991. @raises twisted.internet.error.AlreadyCancelled: if the call has already
  992. been cancelled.
  993. """
  994. def delay(secondsLater: float) -> None:
  995. """
  996. Delay the scheduled call.
  997. @param secondsLater: how many seconds from its current firing time to delay
  998. @raises twisted.internet.error.AlreadyCalled: if the call has already
  999. happened.
  1000. @raises twisted.internet.error.AlreadyCancelled: if the call has already
  1001. been cancelled.
  1002. """
  1003. def reset(secondsFromNow: float) -> None:
  1004. """
  1005. Reset the scheduled call's timer.
  1006. @param secondsFromNow: how many seconds from now it should fire,
  1007. equivalent to C{.cancel()} and then doing another
  1008. C{reactor.callLater(secondsLater, ...)}
  1009. @raises twisted.internet.error.AlreadyCalled: if the call has already
  1010. happened.
  1011. @raises twisted.internet.error.AlreadyCancelled: if the call has already
  1012. been cancelled.
  1013. """
  1014. def active() -> bool:
  1015. """
  1016. @return: True if this call is still active, False if it has been
  1017. called or cancelled.
  1018. """
  1019. class IReactorFromThreads(Interface):
  1020. """
  1021. This interface is the set of thread-safe methods which may be invoked on
  1022. the reactor from other threads.
  1023. @since: 15.4
  1024. """
  1025. def callFromThread(
  1026. callable: Callable[..., Any], *args: object, **kwargs: object
  1027. ) -> None:
  1028. """
  1029. Cause a function to be executed by the reactor thread.
  1030. Use this method when you want to run a function in the reactor's thread
  1031. from another thread. Calling L{callFromThread} should wake up the main
  1032. thread (where L{reactor.run() <IReactorCore.run>} is executing) and run
  1033. the given callable in that thread.
  1034. If you're writing a multi-threaded application the C{callable}
  1035. may need to be thread safe, but this method doesn't require it as such.
  1036. If you want to call a function in the next mainloop iteration, but
  1037. you're in the same thread, use L{callLater} with a delay of 0.
  1038. """
  1039. class IReactorInThreads(Interface):
  1040. """
  1041. This interface contains the methods exposed by a reactor which will let you
  1042. run functions in another thread.
  1043. @since: 15.4
  1044. """
  1045. def callInThread(
  1046. callable: Callable[..., Any], *args: object, **kwargs: object
  1047. ) -> None:
  1048. """
  1049. Run the given callable object in a separate thread, with the given
  1050. arguments and keyword arguments.
  1051. """
  1052. class IReactorThreads(IReactorFromThreads, IReactorInThreads):
  1053. """
  1054. Dispatch methods to be run in threads.
  1055. Internally, this should use a thread pool and dispatch methods to them.
  1056. """
  1057. def getThreadPool() -> "ThreadPool":
  1058. """
  1059. Return the threadpool used by L{IReactorInThreads.callInThread}.
  1060. Create it first if necessary.
  1061. """
  1062. def suggestThreadPoolSize(size: int) -> None:
  1063. """
  1064. Suggest the size of the internal threadpool used to dispatch functions
  1065. passed to L{IReactorInThreads.callInThread}.
  1066. """
  1067. class IReactorCore(Interface):
  1068. """
  1069. Core methods that a Reactor must implement.
  1070. """
  1071. running = Attribute(
  1072. "A C{bool} which is C{True} from I{during startup} to "
  1073. "I{during shutdown} and C{False} the rest of the time."
  1074. )
  1075. def resolve(name: str, timeout: Sequence[int]) -> "Deferred[str]":
  1076. """
  1077. Return a L{twisted.internet.defer.Deferred} that will resolve
  1078. a hostname.
  1079. """
  1080. def run() -> None:
  1081. """
  1082. Fire 'startup' System Events, move the reactor to the 'running'
  1083. state, then run the main loop until it is stopped with C{stop()} or
  1084. C{crash()}.
  1085. """
  1086. def stop() -> None:
  1087. """
  1088. Fire 'shutdown' System Events, which will move the reactor to the
  1089. 'stopped' state and cause C{reactor.run()} to exit.
  1090. """
  1091. def crash() -> None:
  1092. """
  1093. Stop the main loop *immediately*, without firing any system events.
  1094. This is named as it is because this is an extremely "rude" thing to do;
  1095. it is possible to lose data and put your system in an inconsistent
  1096. state by calling this. However, it is necessary, as sometimes a system
  1097. can become wedged in a pre-shutdown call.
  1098. """
  1099. def iterate(delay: float) -> None:
  1100. """
  1101. Run the main loop's I/O polling function for a period of time.
  1102. This is most useful in applications where the UI is being drawn "as
  1103. fast as possible", such as games. All pending L{IDelayedCall}s will
  1104. be called.
  1105. The reactor must have been started (via the C{run()} method) prior to
  1106. any invocations of this method. It must also be stopped manually
  1107. after the last call to this method (via the C{stop()} method). This
  1108. method is not re-entrant: you must not call it recursively; in
  1109. particular, you must not call it while the reactor is running.
  1110. """
  1111. def fireSystemEvent(eventType: str) -> None:
  1112. """
  1113. Fire a system-wide event.
  1114. System-wide events are things like 'startup', 'shutdown', and
  1115. 'persist'.
  1116. """
  1117. def addSystemEventTrigger(
  1118. phase: str,
  1119. eventType: str,
  1120. callable: Callable[..., Any],
  1121. *args: object,
  1122. **kwargs: object,
  1123. ) -> Any:
  1124. """
  1125. Add a function to be called when a system event occurs.
  1126. Each "system event" in Twisted, such as 'startup', 'shutdown', and
  1127. 'persist', has 3 phases: 'before', 'during', and 'after' (in that
  1128. order, of course). These events will be fired internally by the
  1129. Reactor.
  1130. An implementor of this interface must only implement those events
  1131. described here.
  1132. Callbacks registered for the "before" phase may return either None or a
  1133. Deferred. The "during" phase will not execute until all of the
  1134. Deferreds from the "before" phase have fired.
  1135. Once the "during" phase is running, all of the remaining triggers must
  1136. execute; their return values must be ignored.
  1137. @param phase: a time to call the event -- either the string 'before',
  1138. 'after', or 'during', describing when to call it
  1139. relative to the event's execution.
  1140. @param eventType: this is a string describing the type of event.
  1141. @param callable: the object to call before shutdown.
  1142. @param args: the arguments to call it with.
  1143. @param kwargs: the keyword arguments to call it with.
  1144. @return: an ID that can be used to remove this call with
  1145. removeSystemEventTrigger.
  1146. """
  1147. def removeSystemEventTrigger(triggerID: Any) -> None:
  1148. """
  1149. Removes a trigger added with addSystemEventTrigger.
  1150. @param triggerID: a value returned from addSystemEventTrigger.
  1151. @raise KeyError: If there is no system event trigger for the given
  1152. C{triggerID}.
  1153. @raise ValueError: If there is no system event trigger for the given
  1154. C{triggerID}.
  1155. @raise TypeError: If there is no system event trigger for the given
  1156. C{triggerID}.
  1157. """
  1158. def callWhenRunning(
  1159. callable: Callable[..., Any], *args: object, **kwargs: object
  1160. ) -> Optional[Any]:
  1161. """
  1162. Call a function when the reactor is running.
  1163. If the reactor has not started, the callable will be scheduled
  1164. to run when it does start. Otherwise, the callable will be invoked
  1165. immediately.
  1166. @param callable: the callable object to call later.
  1167. @param args: the arguments to call it with.
  1168. @param kwargs: the keyword arguments to call it with.
  1169. @return: None if the callable was invoked, otherwise a system
  1170. event id for the scheduled call.
  1171. """
  1172. class IReactorPluggableResolver(Interface):
  1173. """
  1174. An L{IReactorPluggableResolver} is a reactor which can be customized with
  1175. an L{IResolverSimple}. This is a fairly limited interface, that supports
  1176. only IPv4; you should use L{IReactorPluggableNameResolver} instead.
  1177. @see: L{IReactorPluggableNameResolver}
  1178. """
  1179. def installResolver(resolver: IResolverSimple) -> IResolverSimple:
  1180. """
  1181. Set the internal resolver to use to for name lookups.
  1182. @param resolver: The new resolver to use.
  1183. @return: The previously installed resolver.
  1184. """
  1185. class IReactorPluggableNameResolver(Interface):
  1186. """
  1187. An L{IReactorPluggableNameResolver} is a reactor whose name resolver can be
  1188. set to a user-supplied object.
  1189. """
  1190. nameResolver = Attribute(
  1191. """
  1192. Read-only attribute; the resolver installed with L{installResolver}.
  1193. An L{IHostnameResolver}.
  1194. """
  1195. )
  1196. def installNameResolver(resolver: IHostnameResolver) -> IHostnameResolver:
  1197. """
  1198. Set the internal resolver to use for name lookups.
  1199. @param resolver: The new resolver to use.
  1200. @return: The previously installed resolver.
  1201. """
  1202. class IReactorDaemonize(Interface):
  1203. """
  1204. A reactor which provides hooks that need to be called before and after
  1205. daemonization.
  1206. Notes:
  1207. - This interface SHOULD NOT be called by applications.
  1208. - This interface should only be implemented by reactors as a workaround
  1209. (in particular, it's implemented currently only by kqueue()).
  1210. For details please see the comments on ticket #1918.
  1211. """
  1212. def beforeDaemonize() -> None:
  1213. """
  1214. Hook to be called immediately before daemonization. No reactor methods
  1215. may be called until L{afterDaemonize} is called.
  1216. """
  1217. def afterDaemonize() -> None:
  1218. """
  1219. Hook to be called immediately after daemonization. This may only be
  1220. called after L{beforeDaemonize} had been called previously.
  1221. """
  1222. class IReactorFDSet(Interface):
  1223. """
  1224. Implement me to be able to use L{IFileDescriptor} type resources.
  1225. This assumes that your main-loop uses UNIX-style numeric file descriptors
  1226. (or at least similarly opaque IDs returned from a .fileno() method)
  1227. """
  1228. def addReader(reader: "IReadDescriptor") -> None:
  1229. """
  1230. I add reader to the set of file descriptors to get read events for.
  1231. @param reader: An L{IReadDescriptor} provider that will be checked for
  1232. read events until it is removed from the reactor with
  1233. L{removeReader}.
  1234. """
  1235. def addWriter(writer: "IWriteDescriptor") -> None:
  1236. """
  1237. I add writer to the set of file descriptors to get write events for.
  1238. @param writer: An L{IWriteDescriptor} provider that will be checked for
  1239. write events until it is removed from the reactor with
  1240. L{removeWriter}.
  1241. """
  1242. def removeReader(reader: "IReadDescriptor") -> None:
  1243. """
  1244. Removes an object previously added with L{addReader}.
  1245. """
  1246. def removeWriter(writer: "IWriteDescriptor") -> None:
  1247. """
  1248. Removes an object previously added with L{addWriter}.
  1249. """
  1250. def removeAll() -> List[Union["IReadDescriptor", "IWriteDescriptor"]]:
  1251. """
  1252. Remove all readers and writers.
  1253. Should not remove reactor internal reactor connections (like a waker).
  1254. @return: A list of L{IReadDescriptor} and L{IWriteDescriptor} providers
  1255. which were removed.
  1256. """
  1257. def getReaders() -> List["IReadDescriptor"]:
  1258. """
  1259. Return the list of file descriptors currently monitored for input
  1260. events by the reactor.
  1261. @return: the list of file descriptors monitored for input events.
  1262. """
  1263. def getWriters() -> List["IWriteDescriptor"]:
  1264. """
  1265. Return the list file descriptors currently monitored for output events
  1266. by the reactor.
  1267. @return: the list of file descriptors monitored for output events.
  1268. """
  1269. class IListeningPort(Interface):
  1270. """
  1271. A listening port.
  1272. """
  1273. def startListening() -> None:
  1274. """
  1275. Start listening on this port.
  1276. @raise CannotListenError: If it cannot listen on this port (e.g., it is
  1277. a TCP port and it cannot bind to the required
  1278. port number).
  1279. """
  1280. def stopListening() -> Optional["Deferred"]:
  1281. """
  1282. Stop listening on this port.
  1283. If it does not complete immediately, will return Deferred that fires
  1284. upon completion.
  1285. """
  1286. def getHost() -> IAddress:
  1287. """
  1288. Get the host that this port is listening for.
  1289. @return: An L{IAddress} provider.
  1290. """
  1291. class ILoggingContext(Interface):
  1292. """
  1293. Give context information that will be used to log events generated by
  1294. this item.
  1295. """
  1296. def logPrefix() -> str:
  1297. """
  1298. @return: Prefix used during log formatting to indicate context.
  1299. """
  1300. class IFileDescriptor(ILoggingContext):
  1301. """
  1302. An interface representing a UNIX-style numeric file descriptor.
  1303. """
  1304. def fileno() -> object:
  1305. """
  1306. @return: The platform-specified representation of a file descriptor
  1307. number. Or C{-1} if the descriptor no longer has a valid file
  1308. descriptor number associated with it. As long as the descriptor
  1309. is valid, calls to this method on a particular instance must
  1310. return the same value.
  1311. """
  1312. def connectionLost(reason: Failure) -> None:
  1313. """
  1314. Called when the connection was lost.
  1315. This is called when the connection on a selectable object has been
  1316. lost. It will be called whether the connection was closed explicitly,
  1317. an exception occurred in an event handler, or the other end of the
  1318. connection closed it first.
  1319. See also L{IHalfCloseableDescriptor} if your descriptor wants to be
  1320. notified separately of the two halves of the connection being closed.
  1321. @param reason: A failure instance indicating the reason why the
  1322. connection was lost. L{error.ConnectionLost} and
  1323. L{error.ConnectionDone} are of special note, but the
  1324. failure may be of other classes as well.
  1325. """
  1326. class IReadDescriptor(IFileDescriptor):
  1327. """
  1328. An L{IFileDescriptor} that can read.
  1329. This interface is generally used in conjunction with L{IReactorFDSet}.
  1330. """
  1331. def doRead() -> Optional[Failure]:
  1332. """
  1333. Some data is available for reading on your descriptor.
  1334. @return: If an error is encountered which causes the descriptor to
  1335. no longer be valid, a L{Failure} should be returned. Otherwise,
  1336. L{None}.
  1337. """
  1338. class IWriteDescriptor(IFileDescriptor):
  1339. """
  1340. An L{IFileDescriptor} that can write.
  1341. This interface is generally used in conjunction with L{IReactorFDSet}.
  1342. """
  1343. def doWrite() -> Optional[Failure]:
  1344. """
  1345. Some data can be written to your descriptor.
  1346. @return: If an error is encountered which causes the descriptor to
  1347. no longer be valid, a L{Failure} should be returned. Otherwise,
  1348. L{None}.
  1349. """
  1350. class IReadWriteDescriptor(IReadDescriptor, IWriteDescriptor):
  1351. """
  1352. An L{IFileDescriptor} that can both read and write.
  1353. """
  1354. class IHalfCloseableDescriptor(Interface):
  1355. """
  1356. A descriptor that can be half-closed.
  1357. """
  1358. def writeConnectionLost(reason: Failure) -> None:
  1359. """
  1360. Indicates write connection was lost.
  1361. """
  1362. def readConnectionLost(reason: Failure) -> None:
  1363. """
  1364. Indicates read connection was lost.
  1365. """
  1366. class ISystemHandle(Interface):
  1367. """
  1368. An object that wraps a networking OS-specific handle.
  1369. """
  1370. def getHandle() -> object:
  1371. """
  1372. Return a system- and reactor-specific handle.
  1373. This might be a socket.socket() object, or some other type of
  1374. object, depending on which reactor is being used. Use and
  1375. manipulate at your own risk.
  1376. This might be used in cases where you want to set specific
  1377. options not exposed by the Twisted APIs.
  1378. """
  1379. class IConsumer(Interface):
  1380. """
  1381. A consumer consumes data from a producer.
  1382. """
  1383. def registerProducer(producer: "IProducer", streaming: bool) -> None:
  1384. """
  1385. Register to receive data from a producer.
  1386. This sets self to be a consumer for a producer. When this object runs
  1387. out of data (as when a send(2) call on a socket succeeds in moving the
  1388. last data from a userspace buffer into a kernelspace buffer), it will
  1389. ask the producer to resumeProducing().
  1390. For L{IPullProducer} providers, C{resumeProducing} will be called once
  1391. each time data is required.
  1392. For L{IPushProducer} providers, C{pauseProducing} will be called
  1393. whenever the write buffer fills up and C{resumeProducing} will only be
  1394. called when it empties. The consumer will only call C{resumeProducing}
  1395. to balance a previous C{pauseProducing} call; the producer is assumed
  1396. to start in an un-paused state.
  1397. @param streaming: C{True} if C{producer} provides L{IPushProducer},
  1398. C{False} if C{producer} provides L{IPullProducer}.
  1399. @raise RuntimeError: If a producer is already registered.
  1400. """
  1401. def unregisterProducer() -> None:
  1402. """
  1403. Stop consuming data from a producer, without disconnecting.
  1404. """
  1405. def write(data: bytes) -> None:
  1406. """
  1407. The producer will write data by calling this method.
  1408. The implementation must be non-blocking and perform whatever
  1409. buffering is necessary. If the producer has provided enough data
  1410. for now and it is a L{IPushProducer}, the consumer may call its
  1411. C{pauseProducing} method.
  1412. """
  1413. class IProducer(Interface):
  1414. """
  1415. A producer produces data for a consumer.
  1416. Typically producing is done by calling the C{write} method of a class
  1417. implementing L{IConsumer}.
  1418. """
  1419. def stopProducing() -> None:
  1420. """
  1421. Stop producing data.
  1422. This tells a producer that its consumer has died, so it must stop
  1423. producing data for good.
  1424. """
  1425. class IPushProducer(IProducer):
  1426. """
  1427. A push producer, also known as a streaming producer is expected to
  1428. produce (write to this consumer) data on a continuous basis, unless
  1429. it has been paused. A paused push producer will resume producing
  1430. after its C{resumeProducing()} method is called. For a push producer
  1431. which is not pauseable, these functions may be noops.
  1432. """
  1433. def pauseProducing() -> None:
  1434. """
  1435. Pause producing data.
  1436. Tells a producer that it has produced too much data to process for
  1437. the time being, and to stop until C{resumeProducing()} is called.
  1438. """
  1439. def resumeProducing() -> None:
  1440. """
  1441. Resume producing data.
  1442. This tells a producer to re-add itself to the main loop and produce
  1443. more data for its consumer.
  1444. """
  1445. class IPullProducer(IProducer):
  1446. """
  1447. A pull producer, also known as a non-streaming producer, is
  1448. expected to produce data each time L{resumeProducing()} is called.
  1449. """
  1450. def resumeProducing() -> None:
  1451. """
  1452. Produce data for the consumer a single time.
  1453. This tells a producer to produce data for the consumer once
  1454. (not repeatedly, once only). Typically this will be done
  1455. by calling the consumer's C{write} method a single time with
  1456. produced data. The producer should produce data before returning
  1457. from C{resumeProducing()}, that is, it should not schedule a deferred
  1458. write.
  1459. """
  1460. class IProtocol(Interface):
  1461. def dataReceived(data: bytes) -> None:
  1462. """
  1463. Called whenever data is received.
  1464. Use this method to translate to a higher-level message. Usually, some
  1465. callback will be made upon the receipt of each complete protocol
  1466. message.
  1467. Please keep in mind that you will probably need to buffer some data
  1468. as partial (or multiple) protocol messages may be received! We
  1469. recommend that unit tests for protocols call through to this method
  1470. with differing chunk sizes, down to one byte at a time.
  1471. @param data: bytes of indeterminate length
  1472. """
  1473. def connectionLost(reason: Failure) -> None:
  1474. """
  1475. Called when the connection is shut down.
  1476. Clear any circular references here, and any external references
  1477. to this Protocol. The connection has been closed. The C{reason}
  1478. Failure wraps a L{twisted.internet.error.ConnectionDone} or
  1479. L{twisted.internet.error.ConnectionLost} instance (or a subclass
  1480. of one of those).
  1481. """
  1482. def makeConnection(transport: "ITransport") -> None:
  1483. """
  1484. Make a connection to a transport and a server.
  1485. """
  1486. def connectionMade() -> None:
  1487. """
  1488. Called when a connection is made.
  1489. This may be considered the initializer of the protocol, because
  1490. it is called when the connection is completed. For clients,
  1491. this is called once the connection to the server has been
  1492. established; for servers, this is called after an accept() call
  1493. stops blocking and a socket has been received. If you need to
  1494. send any greeting or initial message, do it here.
  1495. """
  1496. class IProcessProtocol(Interface):
  1497. """
  1498. Interface for process-related event handlers.
  1499. """
  1500. def makeConnection(process: "IProcessTransport") -> None:
  1501. """
  1502. Called when the process has been created.
  1503. @param process: An object representing the process which has been
  1504. created and associated with this protocol.
  1505. """
  1506. def childDataReceived(childFD: int, data: bytes) -> None:
  1507. """
  1508. Called when data arrives from the child process.
  1509. @param childFD: The file descriptor from which the data was
  1510. received.
  1511. @param data: The data read from the child's file descriptor.
  1512. """
  1513. def childConnectionLost(childFD: int) -> None:
  1514. """
  1515. Called when a file descriptor associated with the child process is
  1516. closed.
  1517. @param childFD: The file descriptor which was closed.
  1518. """
  1519. def processExited(reason: Failure) -> None:
  1520. """
  1521. Called when the child process exits.
  1522. @param reason: A failure giving the reason the child process
  1523. terminated. The type of exception for this failure is either
  1524. L{twisted.internet.error.ProcessDone} or
  1525. L{twisted.internet.error.ProcessTerminated}.
  1526. @since: 8.2
  1527. """
  1528. def processEnded(reason: Failure) -> None:
  1529. """
  1530. Called when the child process exits and all file descriptors associated
  1531. with it have been closed.
  1532. @param reason: A failure giving the reason the child process
  1533. terminated. The type of exception for this failure is either
  1534. L{twisted.internet.error.ProcessDone} or
  1535. L{twisted.internet.error.ProcessTerminated}.
  1536. """
  1537. class IHalfCloseableProtocol(Interface):
  1538. """
  1539. Implemented to indicate they want notification of half-closes.
  1540. TCP supports the notion of half-closing the connection, e.g.
  1541. closing the write side but still not stopping reading. A protocol
  1542. that implements this interface will be notified of such events,
  1543. instead of having connectionLost called.
  1544. """
  1545. def readConnectionLost() -> None:
  1546. """
  1547. Notification of the read connection being closed.
  1548. This indicates peer did half-close of write side. It is now
  1549. the responsibility of the this protocol to call
  1550. loseConnection(). In addition, the protocol MUST make sure a
  1551. reference to it still exists (i.e. by doing a callLater with
  1552. one of its methods, etc.) as the reactor will only have a
  1553. reference to it if it is writing.
  1554. If the protocol does not do so, it might get garbage collected
  1555. without the connectionLost method ever being called.
  1556. """
  1557. def writeConnectionLost() -> None:
  1558. """
  1559. Notification of the write connection being closed.
  1560. This will never be called for TCP connections as TCP does not
  1561. support notification of this type of half-close.
  1562. """
  1563. class IHandshakeListener(Interface):
  1564. """
  1565. An interface implemented by a L{IProtocol} to indicate that it would like
  1566. to be notified when TLS handshakes complete when run over a TLS-based
  1567. transport.
  1568. This interface is only guaranteed to be called when run over a TLS-based
  1569. transport: non TLS-based transports will not respect this interface.
  1570. """
  1571. def handshakeCompleted() -> None:
  1572. """
  1573. Notification of the TLS handshake being completed.
  1574. This notification fires when OpenSSL has completed the TLS handshake.
  1575. At this point the TLS connection is established, and the protocol can
  1576. interrogate its transport (usually an L{ISSLTransport}) for details of
  1577. the TLS connection.
  1578. This notification *also* fires whenever the TLS session is
  1579. renegotiated. As a result, protocols that have certain minimum security
  1580. requirements should implement this interface to ensure that they are
  1581. able to re-evaluate the security of the TLS session if it changes.
  1582. """
  1583. class IFileDescriptorReceiver(Interface):
  1584. """
  1585. Protocols may implement L{IFileDescriptorReceiver} to receive file
  1586. descriptors sent to them. This is useful in conjunction with
  1587. L{IUNIXTransport}, which allows file descriptors to be sent between
  1588. processes on a single host.
  1589. """
  1590. def fileDescriptorReceived(descriptor: int) -> None:
  1591. """
  1592. Called when a file descriptor is received over the connection.
  1593. @param descriptor: The descriptor which was received.
  1594. @return: L{None}
  1595. """
  1596. class IProtocolFactory(Interface):
  1597. """
  1598. Interface for protocol factories.
  1599. """
  1600. def buildProtocol(addr: IAddress) -> Optional[IProtocol]:
  1601. """
  1602. Called when a connection has been established to addr.
  1603. If None is returned, the connection is assumed to have been refused,
  1604. and the Port will close the connection.
  1605. @param addr: The address of the newly-established connection
  1606. @return: None if the connection was refused, otherwise an object
  1607. providing L{IProtocol}.
  1608. """
  1609. def doStart() -> None:
  1610. """
  1611. Called every time this is connected to a Port or Connector.
  1612. """
  1613. def doStop() -> None:
  1614. """
  1615. Called every time this is unconnected from a Port or Connector.
  1616. """
  1617. class ITransport(Interface):
  1618. """
  1619. I am a transport for bytes.
  1620. I represent (and wrap) the physical connection and synchronicity
  1621. of the framework which is talking to the network. I make no
  1622. representations about whether calls to me will happen immediately
  1623. or require returning to a control loop, or whether they will happen
  1624. in the same or another thread. Consider methods of this class
  1625. (aside from getPeer) to be 'thrown over the wall', to happen at some
  1626. indeterminate time.
  1627. """
  1628. def write(data: bytes) -> None:
  1629. """
  1630. Write some data to the physical connection, in sequence, in a
  1631. non-blocking fashion.
  1632. If possible, make sure that it is all written. No data will
  1633. ever be lost, although (obviously) the connection may be closed
  1634. before it all gets through.
  1635. @param data: The data to write.
  1636. """
  1637. def writeSequence(data: Iterable[bytes]) -> None:
  1638. """
  1639. Write an iterable of byte strings to the physical connection.
  1640. If possible, make sure that all of the data is written to
  1641. the socket at once, without first copying it all into a
  1642. single byte string.
  1643. @param data: The data to write.
  1644. """
  1645. def loseConnection() -> None:
  1646. """
  1647. Close my connection, after writing all pending data.
  1648. Note that if there is a registered producer on a transport it
  1649. will not be closed until the producer has been unregistered.
  1650. """
  1651. def getPeer() -> IAddress:
  1652. """
  1653. Get the remote address of this connection.
  1654. Treat this method with caution. It is the unfortunate result of the
  1655. CGI and Jabber standards, but should not be considered reliable for
  1656. the usual host of reasons; port forwarding, proxying, firewalls, IP
  1657. masquerading, etc.
  1658. @return: An L{IAddress} provider.
  1659. """
  1660. def getHost() -> IAddress:
  1661. """
  1662. Similar to getPeer, but returns an address describing this side of the
  1663. connection.
  1664. @return: An L{IAddress} provider.
  1665. """
  1666. class ITCPTransport(ITransport):
  1667. """
  1668. A TCP based transport.
  1669. """
  1670. def loseWriteConnection() -> None:
  1671. """
  1672. Half-close the write side of a TCP connection.
  1673. If the protocol instance this is attached to provides
  1674. IHalfCloseableProtocol, it will get notified when the operation is
  1675. done. When closing write connection, as with loseConnection this will
  1676. only happen when buffer has emptied and there is no registered
  1677. producer.
  1678. """
  1679. def abortConnection() -> None:
  1680. """
  1681. Close the connection abruptly.
  1682. Discards any buffered data, stops any registered producer,
  1683. and, if possible, notifies the other end of the unclean
  1684. closure.
  1685. @since: 11.1
  1686. """
  1687. def getTcpNoDelay() -> bool:
  1688. """
  1689. Return if C{TCP_NODELAY} is enabled.
  1690. """
  1691. def setTcpNoDelay(enabled: bool) -> None:
  1692. """
  1693. Enable/disable C{TCP_NODELAY}.
  1694. Enabling C{TCP_NODELAY} turns off Nagle's algorithm. Small packets are
  1695. sent sooner, possibly at the expense of overall throughput.
  1696. """
  1697. def getTcpKeepAlive() -> bool:
  1698. """
  1699. Return if C{SO_KEEPALIVE} is enabled.
  1700. """
  1701. def setTcpKeepAlive(enabled: bool) -> None:
  1702. """
  1703. Enable/disable C{SO_KEEPALIVE}.
  1704. Enabling C{SO_KEEPALIVE} sends packets periodically when the connection
  1705. is otherwise idle, usually once every two hours. They are intended
  1706. to allow detection of lost peers in a non-infinite amount of time.
  1707. """
  1708. def getHost() -> Union["IPv4Address", "IPv6Address"]:
  1709. """
  1710. Returns L{IPv4Address} or L{IPv6Address}.
  1711. """
  1712. def getPeer() -> Union["IPv4Address", "IPv6Address"]:
  1713. """
  1714. Returns L{IPv4Address} or L{IPv6Address}.
  1715. """
  1716. class IUNIXTransport(ITransport):
  1717. """
  1718. Transport for stream-oriented unix domain connections.
  1719. """
  1720. def sendFileDescriptor(descriptor: int) -> None:
  1721. """
  1722. Send a duplicate of this (file, socket, pipe, etc) descriptor to the
  1723. other end of this connection.
  1724. The send is non-blocking and will be queued if it cannot be performed
  1725. immediately. The send will be processed in order with respect to other
  1726. C{sendFileDescriptor} calls on this transport, but not necessarily with
  1727. respect to C{write} calls on this transport. The send can only be
  1728. processed if there are also bytes in the normal connection-oriented send
  1729. buffer (ie, you must call C{write} at least as many times as you call
  1730. C{sendFileDescriptor}).
  1731. @param descriptor: An C{int} giving a valid file descriptor in this
  1732. process. Note that a I{file descriptor} may actually refer to a
  1733. socket, a pipe, or anything else POSIX tries to treat in the same
  1734. way as a file.
  1735. """
  1736. class IOpenSSLServerConnectionCreator(Interface):
  1737. """
  1738. A provider of L{IOpenSSLServerConnectionCreator} can create
  1739. L{OpenSSL.SSL.Connection} objects for TLS servers.
  1740. @see: L{twisted.internet.ssl}
  1741. @note: Creating OpenSSL connection objects is subtle, error-prone, and
  1742. security-critical. Before implementing this interface yourself,
  1743. consider using L{twisted.internet.ssl.CertificateOptions} as your
  1744. C{contextFactory}. (For historical reasons, that class does not
  1745. actually I{implement} this interface; nevertheless it is usable in all
  1746. Twisted APIs which require a provider of this interface.)
  1747. """
  1748. def serverConnectionForTLS(
  1749. tlsProtocol: "TLSMemoryBIOProtocol",
  1750. ) -> "OpenSSLConnection":
  1751. """
  1752. Create a connection for the given server protocol.
  1753. @return: an OpenSSL connection object configured appropriately for the
  1754. given Twisted protocol.
  1755. """
  1756. class IOpenSSLClientConnectionCreator(Interface):
  1757. """
  1758. A provider of L{IOpenSSLClientConnectionCreator} can create
  1759. L{OpenSSL.SSL.Connection} objects for TLS clients.
  1760. @see: L{twisted.internet.ssl}
  1761. @note: Creating OpenSSL connection objects is subtle, error-prone, and
  1762. security-critical. Before implementing this interface yourself,
  1763. consider using L{twisted.internet.ssl.optionsForClientTLS} as your
  1764. C{contextFactory}.
  1765. """
  1766. def clientConnectionForTLS(
  1767. tlsProtocol: "TLSMemoryBIOProtocol",
  1768. ) -> "OpenSSLConnection":
  1769. """
  1770. Create a connection for the given client protocol.
  1771. @param tlsProtocol: the client protocol making the request.
  1772. @return: an OpenSSL connection object configured appropriately for the
  1773. given Twisted protocol.
  1774. """
  1775. class IProtocolNegotiationFactory(Interface):
  1776. """
  1777. A provider of L{IProtocolNegotiationFactory} can provide information about
  1778. the various protocols that the factory can create implementations of. This
  1779. can be used, for example, to provide protocol names for Next Protocol
  1780. Negotiation and Application Layer Protocol Negotiation.
  1781. @see: L{twisted.internet.ssl}
  1782. """
  1783. def acceptableProtocols() -> List[bytes]:
  1784. """
  1785. Returns a list of protocols that can be spoken by the connection
  1786. factory in the form of ALPN tokens, as laid out in the IANA registry
  1787. for ALPN tokens.
  1788. @return: a list of ALPN tokens in order of preference.
  1789. """
  1790. class IOpenSSLContextFactory(Interface):
  1791. """
  1792. A provider of L{IOpenSSLContextFactory} is capable of generating
  1793. L{OpenSSL.SSL.Context} classes suitable for configuring TLS on a
  1794. connection. A provider will store enough state to be able to generate these
  1795. contexts as needed for individual connections.
  1796. @see: L{twisted.internet.ssl}
  1797. """
  1798. def getContext() -> "OpenSSLContext":
  1799. """
  1800. Returns a TLS context object, suitable for securing a TLS connection.
  1801. This context object will be appropriately customized for the connection
  1802. based on the state in this object.
  1803. @return: A TLS context object.
  1804. """
  1805. class ITLSTransport(ITCPTransport):
  1806. """
  1807. A TCP transport that supports switching to TLS midstream.
  1808. Once TLS mode is started the transport will implement L{ISSLTransport}.
  1809. """
  1810. def startTLS(
  1811. contextFactory: Union[
  1812. IOpenSSLClientConnectionCreator, IOpenSSLServerConnectionCreator
  1813. ]
  1814. ) -> None:
  1815. """
  1816. Initiate TLS negotiation.
  1817. @param contextFactory: An object which creates appropriately configured
  1818. TLS connections.
  1819. For clients, use L{twisted.internet.ssl.optionsForClientTLS}; for
  1820. servers, use L{twisted.internet.ssl.CertificateOptions}.
  1821. @type contextFactory: L{IOpenSSLClientConnectionCreator} or
  1822. L{IOpenSSLServerConnectionCreator}, depending on whether this
  1823. L{ITLSTransport} is a server or not. If the appropriate interface
  1824. is not provided by the value given for C{contextFactory}, it must
  1825. be an implementor of L{IOpenSSLContextFactory}.
  1826. """
  1827. class ISSLTransport(ITCPTransport):
  1828. """
  1829. A SSL/TLS based transport.
  1830. """
  1831. def getPeerCertificate() -> object:
  1832. """
  1833. Return an object with the peer's certificate info.
  1834. """
  1835. class INegotiated(ISSLTransport):
  1836. """
  1837. A TLS based transport that supports using ALPN/NPN to negotiate the
  1838. protocol to be used inside the encrypted tunnel.
  1839. """
  1840. negotiatedProtocol = Attribute(
  1841. """
  1842. The protocol selected to be spoken using ALPN/NPN. The result from ALPN
  1843. is preferred to the result from NPN if both were used. If the remote
  1844. peer does not support ALPN or NPN, or neither NPN or ALPN are available
  1845. on this machine, will be L{None}. Otherwise, will be the name of the
  1846. selected protocol as C{bytes}. Note that until the handshake has
  1847. completed this property may incorrectly return L{None}: wait until data
  1848. has been received before trusting it (see
  1849. https://twistedmatrix.com/trac/ticket/6024).
  1850. """
  1851. )
  1852. class ICipher(Interface):
  1853. """
  1854. A TLS cipher.
  1855. """
  1856. fullName = Attribute("The fully qualified name of the cipher in L{unicode}.")
  1857. class IAcceptableCiphers(Interface):
  1858. """
  1859. A list of acceptable ciphers for a TLS context.
  1860. """
  1861. def selectCiphers(availableCiphers: Tuple[ICipher]) -> Tuple[ICipher]:
  1862. """
  1863. Choose which ciphers to allow to be negotiated on a TLS connection.
  1864. @param availableCiphers: A L{tuple} of L{ICipher} which gives the names
  1865. of all ciphers supported by the TLS implementation in use.
  1866. @return: A L{tuple} of L{ICipher} which represents the ciphers
  1867. which may be negotiated on the TLS connection. The result is
  1868. ordered by preference with more preferred ciphers appearing
  1869. earlier.
  1870. """
  1871. class IProcessTransport(ITransport):
  1872. """
  1873. A process transport.
  1874. """
  1875. pid = Attribute(
  1876. "From before L{IProcessProtocol.makeConnection} is called to before "
  1877. "L{IProcessProtocol.processEnded} is called, C{pid} is an L{int} "
  1878. "giving the platform process ID of this process. C{pid} is L{None} "
  1879. "at all other times."
  1880. )
  1881. def closeStdin() -> None:
  1882. """
  1883. Close stdin after all data has been written out.
  1884. """
  1885. def closeStdout() -> None:
  1886. """
  1887. Close stdout.
  1888. """
  1889. def closeStderr() -> None:
  1890. """
  1891. Close stderr.
  1892. """
  1893. def closeChildFD(descriptor: int) -> None:
  1894. """
  1895. Close a file descriptor which is connected to the child process, identified
  1896. by its FD in the child process.
  1897. """
  1898. def writeToChild(childFD: int, data: bytes) -> None:
  1899. """
  1900. Similar to L{ITransport.write} but also allows the file descriptor in
  1901. the child process which will receive the bytes to be specified.
  1902. @param childFD: The file descriptor to which to write.
  1903. @param data: The bytes to write.
  1904. @raise KeyError: If C{childFD} is not a file descriptor that was mapped
  1905. in the child when L{IReactorProcess.spawnProcess} was used to create
  1906. it.
  1907. """
  1908. def loseConnection() -> None:
  1909. """
  1910. Close stdin, stderr and stdout.
  1911. """
  1912. def signalProcess(signalID: Union[str, int]) -> None:
  1913. """
  1914. Send a signal to the process.
  1915. @param signalID: can be
  1916. - one of C{"KILL"}, C{"TERM"}, or C{"INT"}.
  1917. These will be implemented in a
  1918. cross-platform manner, and so should be used
  1919. if possible.
  1920. - an integer, where it represents a POSIX
  1921. signal ID.
  1922. @raise twisted.internet.error.ProcessExitedAlready: If the process has
  1923. already exited.
  1924. @raise OSError: If the C{os.kill} call fails with an errno different
  1925. from C{ESRCH}.
  1926. """
  1927. class IServiceCollection(Interface):
  1928. """
  1929. An object which provides access to a collection of services.
  1930. """
  1931. def getServiceNamed(serviceName: str) -> object:
  1932. """
  1933. Retrieve the named service from this application.
  1934. Raise a C{KeyError} if there is no such service name.
  1935. """
  1936. def addService(service: object) -> None:
  1937. """
  1938. Add a service to this collection.
  1939. """
  1940. def removeService(service: object) -> None:
  1941. """
  1942. Remove a service from this collection.
  1943. """
  1944. class IUDPTransport(Interface):
  1945. """
  1946. Transport for UDP DatagramProtocols.
  1947. """
  1948. def write(packet: bytes, addr: Optional[Tuple[str, int]]) -> None:
  1949. """
  1950. Write packet to given address.
  1951. @param addr: a tuple of (ip, port). For connected transports must
  1952. be the address the transport is connected to, or None.
  1953. In non-connected mode this is mandatory.
  1954. @raise twisted.internet.error.MessageLengthError: C{packet} was too
  1955. long.
  1956. """
  1957. def connect(host: str, port: int) -> None:
  1958. """
  1959. Connect the transport to an address.
  1960. This changes it to connected mode. Datagrams can only be sent to
  1961. this address, and will only be received from this address. In addition
  1962. the protocol's connectionRefused method might get called if destination
  1963. is not receiving datagrams.
  1964. @param host: an IP address, not a domain name ('127.0.0.1', not 'localhost')
  1965. @param port: port to connect to.
  1966. """
  1967. def getHost() -> Union["IPv4Address", "IPv6Address"]:
  1968. """
  1969. Get this port's host address.
  1970. @return: an address describing the listening port.
  1971. """
  1972. def stopListening() -> Optional["Deferred"]:
  1973. """
  1974. Stop listening on this port.
  1975. If it does not complete immediately, will return L{Deferred} that fires
  1976. upon completion.
  1977. """
  1978. def setBroadcastAllowed(enabled: bool) -> None:
  1979. """
  1980. Set whether this port may broadcast.
  1981. @param enabled: Whether the port may broadcast.
  1982. """
  1983. def getBroadcastAllowed() -> bool:
  1984. """
  1985. Checks if broadcast is currently allowed on this port.
  1986. @return: Whether this port may broadcast.
  1987. """
  1988. class IUNIXDatagramTransport(Interface):
  1989. """
  1990. Transport for UDP PacketProtocols.
  1991. """
  1992. def write(packet: bytes, addr: str) -> None:
  1993. """
  1994. Write packet to given address.
  1995. """
  1996. def getHost() -> "UNIXAddress":
  1997. """
  1998. Returns L{UNIXAddress}.
  1999. """
  2000. class IUNIXDatagramConnectedTransport(Interface):
  2001. """
  2002. Transport for UDP ConnectedPacketProtocols.
  2003. """
  2004. def write(packet: bytes) -> None:
  2005. """
  2006. Write packet to address we are connected to.
  2007. """
  2008. def getHost() -> "UNIXAddress":
  2009. """
  2010. Returns L{UNIXAddress}.
  2011. """
  2012. def getPeer() -> "UNIXAddress":
  2013. """
  2014. Returns L{UNIXAddress}.
  2015. """
  2016. class IMulticastTransport(Interface):
  2017. """
  2018. Additional functionality for multicast UDP.
  2019. """
  2020. def getOutgoingInterface() -> str:
  2021. """
  2022. Return interface of outgoing multicast packets.
  2023. """
  2024. def setOutgoingInterface(addr: str) -> None:
  2025. """
  2026. Set interface for outgoing multicast packets.
  2027. Returns Deferred of success.
  2028. """
  2029. def getLoopbackMode() -> bool:
  2030. """
  2031. Return if loopback mode is enabled.
  2032. """
  2033. def setLoopbackMode(mode: bool) -> None:
  2034. """
  2035. Set if loopback mode is enabled.
  2036. """
  2037. def getTTL() -> int:
  2038. """
  2039. Get time to live for multicast packets.
  2040. """
  2041. def setTTL(ttl: int) -> None:
  2042. """
  2043. Set time to live on multicast packets.
  2044. """
  2045. def joinGroup(addr: str, interface: str) -> "Deferred[None]":
  2046. """
  2047. Join a multicast group. Returns L{Deferred} of success or failure.
  2048. If an error occurs, the returned L{Deferred} will fail with
  2049. L{error.MulticastJoinError}.
  2050. """
  2051. def leaveGroup(addr: str, interface: str) -> "Deferred[None]":
  2052. """
  2053. Leave multicast group, return L{Deferred} of success.
  2054. """
  2055. class IStreamClientEndpoint(Interface):
  2056. """
  2057. A stream client endpoint is a place that L{ClientFactory} can connect to.
  2058. For example, a remote TCP host/port pair would be a TCP client endpoint.
  2059. @since: 10.1
  2060. """
  2061. def connect(protocolFactory: IProtocolFactory) -> "Deferred[IProtocol]":
  2062. """
  2063. Connect the C{protocolFactory} to the location specified by this
  2064. L{IStreamClientEndpoint} provider.
  2065. @param protocolFactory: A provider of L{IProtocolFactory}
  2066. @return: A L{Deferred} that results in an L{IProtocol} upon successful
  2067. connection otherwise a L{Failure} wrapping L{ConnectError} or
  2068. L{NoProtocol <twisted.internet.error.NoProtocol>}.
  2069. """
  2070. class IStreamServerEndpoint(Interface):
  2071. """
  2072. A stream server endpoint is a place that a L{Factory} can listen for
  2073. incoming connections.
  2074. @since: 10.1
  2075. """
  2076. def listen(protocolFactory: IProtocolFactory) -> "Deferred[IListeningPort]":
  2077. """
  2078. Listen with C{protocolFactory} at the location specified by this
  2079. L{IStreamServerEndpoint} provider.
  2080. @param protocolFactory: A provider of L{IProtocolFactory}
  2081. @return: A L{Deferred} that results in an L{IListeningPort} or an
  2082. L{CannotListenError}
  2083. """
  2084. class IStreamServerEndpointStringParser(Interface):
  2085. """
  2086. An L{IStreamServerEndpointStringParser} is like an
  2087. L{IStreamClientEndpointStringParserWithReactor}, except for
  2088. L{IStreamServerEndpoint}s instead of clients. It integrates with
  2089. L{endpoints.serverFromString} in much the same way.
  2090. """
  2091. prefix = Attribute(
  2092. """
  2093. A C{str}, the description prefix to respond to. For example, an
  2094. L{IStreamServerEndpointStringParser} plugin which had C{"foo"} for its
  2095. C{prefix} attribute would be called for endpoint descriptions like
  2096. C{"foo:bar:baz"} or C{"foo:"}.
  2097. """
  2098. )
  2099. def parseStreamServer(
  2100. reactor: IReactorCore, *args: object, **kwargs: object
  2101. ) -> IStreamServerEndpoint:
  2102. """
  2103. Parse a stream server endpoint from a reactor and string-only arguments
  2104. and keyword arguments.
  2105. @see: L{IStreamClientEndpointStringParserWithReactor.parseStreamClient}
  2106. @return: a stream server endpoint
  2107. """
  2108. class IStreamClientEndpointStringParserWithReactor(Interface):
  2109. """
  2110. An L{IStreamClientEndpointStringParserWithReactor} is a parser which can
  2111. convert a set of string C{*args} and C{**kwargs} into an
  2112. L{IStreamClientEndpoint} provider.
  2113. This interface is really only useful in the context of the plugin system
  2114. for L{endpoints.clientFromString}. See the document entitled "I{The
  2115. Twisted Plugin System}" for more details on how to write a plugin.
  2116. If you place an L{IStreamClientEndpointStringParserWithReactor} plugin in
  2117. the C{twisted.plugins} package, that plugin's C{parseStreamClient} method
  2118. will be used to produce endpoints for any description string that begins
  2119. with the result of that L{IStreamClientEndpointStringParserWithReactor}'s
  2120. prefix attribute.
  2121. """
  2122. prefix = Attribute(
  2123. """
  2124. L{bytes}, the description prefix to respond to. For example, an
  2125. L{IStreamClientEndpointStringParserWithReactor} plugin which had
  2126. C{b"foo"} for its C{prefix} attribute would be called for endpoint
  2127. descriptions like C{b"foo:bar:baz"} or C{b"foo:"}.
  2128. """
  2129. )
  2130. def parseStreamClient(
  2131. reactor: IReactorCore, *args: object, **kwargs: object
  2132. ) -> IStreamClientEndpoint:
  2133. """
  2134. This method is invoked by L{endpoints.clientFromString}, if the type of
  2135. endpoint matches the return value from this
  2136. L{IStreamClientEndpointStringParserWithReactor}'s C{prefix} method.
  2137. @param reactor: The reactor passed to L{endpoints.clientFromString}.
  2138. @param args: The byte string arguments, minus the endpoint type, in the
  2139. endpoint description string, parsed according to the rules
  2140. described in L{endpoints.quoteStringArgument}. For example, if the
  2141. description were C{b"my-type:foo:bar:baz=qux"}, C{args} would be
  2142. C{(b'foo', b'bar')}
  2143. @param kwargs: The byte string arguments from the endpoint description
  2144. passed as keyword arguments. For example, if the description were
  2145. C{b"my-type:foo:bar:baz=qux"}, C{kwargs} would be
  2146. C{dict(baz=b'qux')}.
  2147. @return: a client endpoint
  2148. """
  2149. class _ISupportsExitSignalCapturing(Interface):
  2150. """
  2151. An implementor of L{_ISupportsExitSignalCapturing} will capture the
  2152. value of any delivered exit signal (SIGINT, SIGTERM, SIGBREAK) for which
  2153. it has installed a handler. The caught signal number is made available in
  2154. the _exitSignal attribute.
  2155. """
  2156. _exitSignal = Attribute(
  2157. """
  2158. C{int} or C{None}, the integer exit signal delivered to the
  2159. application, or None if no signal was delivered.
  2160. """
  2161. )