Ticket #1272: interfaces_1272.diff
| File interfaces_1272.diff, 36.9 KB (added by therve, 3 years ago) |
|---|
-
twisted/internet/interfaces.py
2 2 # See LICENSE for details. 3 3 4 4 5 """Interface documentation. 5 """ 6 Interface documentation. 6 7 7 8 API Stability: stable, other than IReactorUDP (semi-stable) and 8 9 IReactorMulticast (unstable). … … 14 15 15 16 16 17 class IAddress(Interface): 17 """An address, e.g. a TCP (host, port). 18 """ 19 An address, e.g. a TCP (host, port). 18 20 19 21 Default implementations are in L{twisted.internet.address}. 20 22 """ … … 23 25 ### Reactor Interfaces 24 26 25 27 class IConnector(Interface): 26 """Object used to interface between connections and protocols. 28 """ 29 Object used to interface between connections and protocols. 27 30 28 31 Each IConnector manages one connection. 29 32 """ 30 33 31 34 def stopConnecting(): 32 """Stop attempting to connect.""" 35 """ 36 Stop attempting to connect. 37 """ 33 38 34 39 def disconnect(): 35 """Disconnect regardless of the connection state. 40 """ 41 Disconnect regardless of the connection state. 36 42 37 43 If we are connected, disconnect, if we are trying to connect, 38 44 stop trying. 39 45 """ 40 46 41 47 def connect(): 42 """Try to connect to remote address.""" 48 """ 49 Try to connect to remote address. 50 """ 43 51 44 52 def getDestination(): 45 """Return destination this will try to connect to. 53 """ 54 Return destination this will try to connect to. 46 55 47 56 @return: An object which provides L{IAddress}. 48 57 """ 49 58 50 59 51 60 class IResolverSimple(Interface): 61 52 62 def getHostByName(name, timeout = (1, 3, 11, 45)): 53 """Resolve the domain name C{name} into an IP address. 63 """ 64 Resolve the domain name C{name} into an IP address. 54 65 55 66 @type name: C{str} 56 67 @type timeout: C{tuple} … … 68 79 """ 69 80 70 81 class IResolver(IResolverSimple): 82 71 83 def lookupRecord(name, cls, type, timeout = 10): 72 """Lookup the records associated with the given name73 that are of the given type and in the given class.74 84 """ 85 Lookup the records associated with the given name 86 that are of the given type and in the given class. 87 """ 75 88 76 89 def query(query, timeout = 10): 77 """Interpret and dispatch a query object to the appropriate 90 """ 91 Interpret and dispatch a query object to the appropriate 78 92 lookup* method. 79 93 """ 80 94 81 95 def lookupAddress(name, timeout = 10): 82 """Lookup the A records associated with C{name}.""" 96 """ 97 Lookup the A records associated with C{name}. 98 """ 83 99 84 100 def lookupAddress6(name, timeout = 10): 85 """Lookup all the A6 records associated with C{name}.""" 101 """ 102 Lookup all the A6 records associated with C{name}. 103 """ 86 104 87 105 def lookupIPV6Address(name, timeout = 10): 88 """Lookup all the AAAA records associated with C{name}.""" 106 """ 107 Lookup all the AAAA records associated with C{name}. 108 """ 89 109 90 110 def lookupMailExchange(name, timeout = 10): 91 """Lookup the MX records associated with C{name}.""" 111 """ 112 Lookup the MX records associated with C{name}. 113 """ 92 114 93 115 def lookupNameservers(name, timeout = 10): 94 """Lookup the the NS records associated with C{name}.""" 116 """ 117 Lookup the the NS records associated with C{name}. 118 """ 95 119 96 120 def lookupCanonicalName(name, timeout = 10): 97 """Lookup the CNAME records associated with C{name}.""" 121 """ 122 Lookup the CNAME records associated with C{name}. 123 """ 98 124 99 125 def lookupMailBox(name, timeout = 10): 100 """Lookup the MB records associated with C{name}.""" 126 """ 127 Lookup the MB records associated with C{name}. 128 """ 101 129 102 130 def lookupMailGroup(name, timeout = 10): 103 """Lookup the MG records associated with C{name}.""" 131 """ 132 Lookup the MG records associated with C{name}. 133 """ 104 134 105 135 def lookupMailRename(name, timeout = 10): 106 """Lookup the MR records associated with C{name}.""" 136 """ 137 Lookup the MR records associated with C{name}. 138 """ 107 139 108 140 def lookupPointer(name, timeout = 10): 109 """Lookup the PTR records associated with C{name}.""" 141 """ 142 Lookup the PTR records associated with C{name}. 143 """ 110 144 111 145 def lookupAuthority(name, timeout = 10): 112 """Lookup the SOA records associated with C{name}.""" 146 """ 147 Lookup the SOA records associated with C{name}. 148 """ 113 149 114 150 def lookupNull(name, timeout = 10): 115 """Lookup the NULL records associated with C{name}.""" 151 """ 152 Lookup the NULL records associated with C{name}. 153 """ 116 154 117 155 def lookupWellKnownServices(name, timeout = 10): 118 """Lookup the WKS records associated with C{name}.""" 156 """ 157 Lookup the WKS records associated with C{name}. 158 """ 119 159 120 160 def lookupHostInfo(name, timeout = 10): 121 """Lookup the HINFO records associated with C{name}.""" 161 """ 162 Lookup the HINFO records associated with C{name}. 163 """ 122 164 123 165 def lookupMailboxInfo(name, timeout = 10): 124 """Lookup the MINFO records associated with C{name}.""" 166 """ 167 Lookup the MINFO records associated with C{name}. 168 """ 125 169 126 170 def lookupText(name, timeout = 10): 127 """Lookup the TXT records associated with C{name}.""" 171 """ 172 Lookup the TXT records associated with C{name}. 173 """ 128 174 129 175 def lookupResponsibility(name, timeout = 10): 130 """Lookup the RP records associated with C{name}.""" 176 """ 177 Lookup the RP records associated with C{name}. 178 """ 131 179 132 180 def lookupAFSDatabase(name, timeout = 10): 133 """Lookup the AFSDB records associated with C{name}.""" 181 """ 182 Lookup the AFSDB records associated with C{name}. 183 """ 134 184 135 185 def lookupService(name, timeout = 10): 136 """Lookup the SRV records associated with C{name}.""" 186 """ 187 Lookup the SRV records associated with C{name}. 188 """ 137 189 138 190 def lookupAllRecords(name, timeout = 10): 139 """Lookup all records associated with C{name}.""" 191 """ 192 Lookup all records associated with C{name}. 193 """ 140 194 141 195 def lookupZone(name, timeout = 10): 142 """Perform a zone transfer for the given C{name}.""" 196 """ 197 Perform a zone transfer for the given C{name}. 198 """ 143 199 144 200 145 201 class IReactorArbitrary(Interface): 202 146 203 def listenWith(portType, *args, **kw): 147 """Start an instance of the given C{portType} listening. 204 """ 205 Start an instance of the given C{portType} listening. 148 206 149 207 @type portType: type which implements L{IListeningPort} 150 208 … … 169 227 class IReactorTCP(Interface): 170 228 171 229 def listenTCP(port, factory, backlog=50, interface=''): 172 """Connects a given protocol factory to the given numeric TCP/IP port. 230 """ 231 Connects a given protocol factory to the given numeric TCP/IP port. 173 232 174 233 @param port: a port number on which to listen 175 234 … … 188 247 """ 189 248 190 249 def connectTCP(host, port, factory, timeout=30, bindAddress=None): 191 """Connect a TCP client. 250 """ 251 Connect a TCP client. 192 252 193 253 @param host: a host name 194 254 … … 212 272 class IReactorSSL(Interface): 213 273 214 274 def connectSSL(host, port, factory, contextFactory, timeout=30, bindAddress=None): 215 """Connect a client Protocol to a remote SSL socket. 275 """ 276 Connect a client Protocol to a remote SSL socket. 216 277 217 278 @param host: a host name 218 279 … … 250 311 251 312 252 313 class IReactorUNIX(Interface): 253 """UNIX socket methods.""" 314 """ 315 UNIX socket methods. 316 """ 254 317 255 318 def connectUNIX(address, factory, timeout=30, checkPID=0): 256 """Connect a client protocol to a UNIX socket. 319 """ 320 Connect a client protocol to a UNIX socket. 257 321 258 322 @param address: a path to a unix socket on the filesystem. 259 323 … … 269 333 """ 270 334 271 335 def listenUNIX(address, factory, backlog=50, mode=0666, wantPID=0): 272 """Listen on a UNIX socket. 336 """ 337 Listen on a UNIX socket. 273 338 274 339 @param address: a path to a unix socket on the filesystem. 275 340 … … 286 351 287 352 288 353 class IReactorUNIXDatagram(Interface): 289 """datagram UNIX socket methods.""" 354 """ 355 Datagram UNIX socket methods. 356 """ 290 357 291 358 def connectUNIXDatagram(address, protocol, maxPacketSize=8192, mode=0666, bindAddress=None): 292 """Connect a client protocol to a datagram UNIX socket. 359 """ 360 Connect a client protocol to a datagram UNIX socket. 293 361 294 362 @param address: a path to a unix socket on the filesystem. 295 363 … … 305 373 """ 306 374 307 375 def listenUNIXDatagram(address, protocol, maxPacketSize=8192, mode=0666): 308 """Listen on a datagram UNIX socket. 376 """ 377 Listen on a datagram UNIX socket. 309 378 310 379 @param address: a path to a unix socket on the filesystem. 311 380 … … 320 389 321 390 322 391 class IReactorUDP(Interface): 323 """UDP socket methods. 392 """ 393 UDP socket methods. 324 394 325 395 IMPORTANT: This is an experimental new interface. It may change 326 396 without backwards compatability. Suggestions are welcome. 327 397 """ 328 398 329 399 def listenUDP(port, protocol, interface='', maxPacketSize=8192): 330 """Connects a given DatagramProtocol to the given numeric UDP port. 400 """ 401 Connects a given DatagramProtocol to the given numeric UDP port. 331 402 332 403 @return: object which provides L{IListeningPort}. 333 404 """ 334 405 335 406 def connectUDP(remotehost, remoteport, protocol, localport=0, 336 407 interface='', maxPacketSize=8192): 337 """DEPRECATED. 408 """ 409 DEPRECATED. 338 410 339 411 Connects a L{twisted.internet.protocol.ConnectedDatagramProtocol} 340 412 instance to a UDP port. … … 342 414 343 415 344 416 class IReactorMulticast(Interface): 345 """UDP socket methods that support multicast. 417 """ 418 UDP socket methods that support multicast. 346 419 347 420 IMPORTANT: This is an experimental new interface. It may change 348 421 without backwards compatability. Suggestions are welcome. … … 366 439 367 440 def spawnProcess(processProtocol, executable, args=(), env={}, path=None, 368 441 uid=None, gid=None, usePTY=0, childFDs=None): 369 """Spawn a process, with a process protocol. 442 """ 443 Spawn a process, with a process protocol. 370 444 371 445 @param processProtocol: a L{twisted.internet.protocol.ProcessProtocol} instance 372 446 … … 430 504 """ 431 505 432 506 class IReactorTime(Interface): 433 """Time methods that a Reactor should implement.434 507 """ 508 Time methods that a Reactor should implement. 509 """ 435 510 436 511 def callLater(delay, callable, *args, **kw): 437 """Call a function later. 512 """ 513 Call a function later. 438 514 439 515 @type delay: C{float} 440 516 @param delay: the number of seconds to wait. … … 452 528 """ 453 529 454 530 def cancelCallLater(callID): 455 """This method is deprecated. 531 """ 532 This method is deprecated. 456 533 457 534 Cancel a call that would happen later. 458 535 … … 463 540 """ 464 541 465 542 def getDelayedCalls(): 466 """Retrieve all currently scheduled delayed calls. 543 """ 544 Retrieve all currently scheduled delayed calls. 467 545 468 546 @return: A tuple of all L{IDelayedCall} providers representing all 469 547 currently scheduled calls. This is everything that has been … … 472 550 473 551 474 552 class IDelayedCall(Interface): 475 """A scheduled call. 553 """ 554 A scheduled call. 476 555 477 556 There are probably other useful methods we can add to this interface; 478 557 suggestions are welcome. 479 558 """ 480 559 481 560 def getTime(): 482 """Get time when delayed call will happen. 561 """ 562 Get time when delayed call will happen. 483 563 484 564 @return: time in seconds since epoch (a float). 485 565 """ 486 566 487 567 def cancel(): 488 """Cancel the scheduled call. 568 """ 569 Cancel the scheduled call. 489 570 490 571 @raises twisted.internet.error.AlreadyCalled: if the call has already 491 572 happened. … … 494 575 """ 495 576 496 577 def delay(secondsLater): 497 """Delay the scheduled call. 578 """ 579 Delay the scheduled call. 498 580 499 581 @param secondsLater: how many seconds from its current firing time to delay 500 582 … … 505 587 """ 506 588 507 589 def reset(secondsFromNow): 508 """Reset the scheduled call's timer. 590 """ 591 Reset the scheduled call's timer. 509 592 510 593 @param secondsFromNow: how many seconds from now it should fire, 511 594 equivalent to C{.cancel()} and then doing another … … 524 607 """ 525 608 526 609 class IReactorThreads(Interface): 527 """Dispatch methods to be run in threads. 610 """ 611 Dispatch methods to be run in threads. 528 612 529 613 Internally, this should use a thread pool and dispatch methods to them. 530 614 """ 531 615 532 616 def callInThread(callable, *args, **kwargs): 533 """Run the callable object in a separate thread.534 617 """ 618 Run the callable object in a separate thread. 619 """ 535 620 536 621 def callFromThread(callable, *args, **kw): 537 """Cause a function to be executed by the reactor thread. 622 """ 623 Cause a function to be executed by the reactor thread. 538 624 539 625 Use this method when you want to run a function in the reactor's thread 540 626 from another thread. Calling callFromThread should wake up the main … … 554 640 555 641 556 642 class IReactorCore(Interface): 557 """Core methods that a Reactor must implement.558 643 """ 644 Core methods that a Reactor must implement. 645 """ 559 646 560 647 def resolve(name, timeout=10): 561 """Return a L{twisted.internet.defer.Deferred} that will resolve a hostname.562 648 """ 649 Return a L{twisted.internet.defer.Deferred} that will resolve a hostname. 650 """ 563 651 564 565 652 def run(): 566 """Fire 'startup' System Events, move the reactor to the 'running' 653 """ 654 Fire 'startup' System Events, move the reactor to the 'running' 567 655 state, then run the main loop until it is stopped with stop() or 568 656 crash(). 569 657 """ 570 658 571 659 def stop(): 572 """Fire 'shutdown' System Events, which will move the reactor to the 573 'stopped' state and cause reactor.run() to exit. """ 660 """ 661 Fire 'shutdown' System Events, which will move the reactor to the 662 'stopped' state and cause reactor.run() to exit. 663 """ 574 664 575 665 def crash(): 576 """Stop the main loop *immediately*, without firing any system events. 666 """ 667 Stop the main loop *immediately*, without firing any system events. 577 668 578 669 This is named as it is because this is an extremely "rude" thing to do; 579 670 it is possible to lose data and put your system in an inconsistent … … 582 673 """ 583 674 584 675 def iterate(delay=0): 585 """Run the main loop's I/O polling function for a period of time. 676 """ 677 Run the main loop's I/O polling function for a period of time. 586 678 587 679 This is most useful in applications where the UI is being drawn "as 588 680 fast as possible", such as games. All pending L{IDelayedCall}s will … … 596 688 """ 597 689 598 690 def fireSystemEvent(eventType): 599 """Fire a system-wide event. 691 """ 692 Fire a system-wide event. 600 693 601 694 System-wide events are things like 'startup', 'shutdown', and 602 695 'persist'. 603 696 """ 604 697 605 698 def addSystemEventTrigger(phase, eventType, callable, *args, **kw): 606 """Add a function to be called when a system event occurs. 699 """ 700 Add a function to be called when a system event occurs. 607 701 608 702 Each "system event" in Twisted, such as 'startup', 'shutdown', and 609 703 'persist', has 3 phases: 'before', 'during', and 'after' (in that … … 637 731 """ 638 732 639 733 def removeSystemEventTrigger(triggerID): 640 """Removes a trigger added with addSystemEventTrigger. 734 """ 735 Removes a trigger added with addSystemEventTrigger. 641 736 642 737 @param triggerID: a value returned from addSystemEventTrigger. 643 738 """ 644 739 645 740 def callWhenRunning(callable, *args, **kw): 646 """Call a function when the reactor is running. 741 """ 742 Call a function when the reactor is running. 647 743 648 744 If the reactor has not started, the callable will be scheduled 649 745 to run when it does start. Otherwise, the callable will be invoked … … 661 757 662 758 663 759 class IReactorPluggableResolver(Interface): 664 """A reactor with a pluggable name resolver interface.665 760 """ 761 A reactor with a pluggable name resolver interface. 762 """ 666 763 def installResolver(resolver): 667 """Set the internal resolver to use to for name lookups. 764 """ 765 Set the internal resolver to use to for name lookups. 668 766 669 767 @type resolver: An object implementing the L{IResolverSimple} interface 670 768 @param resolver: The new resolver to use. … … 683 781 """ 684 782 685 783 def addReader(reader): 686 """I add reader to the set of file descriptors to get read events for. 784 """ 785 I add reader to the set of file descriptors to get read events for. 687 786 688 787 @param reader: An L{IReadDescriptor} provider that will be checked for 689 788 read events until it is removed from the reactor with … … 693 792 """ 694 793 695 794 def addWriter(writer): 696 """I add writer to the set of file descriptors to get write events for. 795 """ 796 I add writer to the set of file descriptors to get write events for. 697 797 698 798 @param writer: An L{IWriteDescriptor} provider that will be checked for 699 799 read events until it is removed from the reactor with … … 703 803 """ 704 804 705 805 def removeReader(reader): 706 """Removes an object previously added with L{addReader}. 806 """ 807 Removes an object previously added with L{addReader}. 707 808 708 809 @return: C{None}. 709 810 """ 710 811 711 812 def removeWriter(writer): 712 """Removes an object previously added with L{addWriter}. 813 """ 814 Removes an object previously added with L{addWriter}. 713 815 714 816 @return: C{None}. 715 817 """ 716 818 717 819 def removeAll(): 718 """Remove all readers and writers. 820 """ 821 Remove all readers and writers. 719 822 720 823 Should not remove reactor internal reactor connections (like a waker). 721 824 … … 725 828 726 829 727 830 class IListeningPort(Interface): 728 """A listening port.729 831 """ 832 A listening port. 833 """ 730 834 731 835 def startListening(): 732 """Start listening on this port. 836 """ 837 Start listening on this port. 733 838 734 839 @raise CannotListenError: If it cannot listen on this port (e.g., it is 735 840 a TCP port and it cannot bind to the required … … 737 842 """ 738 843 739 844 def stopListening(): 740 """Stop listening on this port. 845 """ 846 Stop listening on this port. 741 847 742 848 If it does not complete immediately, will return Deferred that fires 743 849 upon completion. 744 850 """ 745 851 746 852 def getHost(): 747 """Get the host that this port is listening for. 853 """ 854 Get the host that this port is listening for. 748 855 749 856 @return: An L{IAddress} provider. 750 857 """ 751 858 752 859 753 860 class IFileDescriptor(Interface): 754 """A file descriptor.755 861 """ 862 A file descriptor. 863 """ 756 864 757 865 def fileno(): 758 866 """ … … 761 869 """ 762 870 763 871 def connectionLost(reason): 764 """Called when the connection was lost. 872 """ 873 Called when the connection was lost. 765 874 766 875 This is called when the connection on a selectable object has been 767 876 lost. It will be called whether the connection was closed explicitly, … … 777 886 failure may be of other classes as well. 778 887 """ 779 888 889 def logPrefix(): 890 """ 891 Prefix used when logging execution of reading or writing from this 892 descriptor. 893 """ 894 780 895 class IReadDescriptor(IFileDescriptor): 781 896 782 897 def doRead(): 783 """Some data is available for reading on your descriptor.784 898 """ 899 Some data is available for reading on your descriptor. 900 """ 785 901 786 902 787 903 class IWriteDescriptor(IFileDescriptor): 788 904 789 905 def doWrite(): 790 """Some data can be written to your descriptor.791 906 """ 907 Some data can be written to your descriptor. 908 """ 792 909 793 910 794 911 class IReadWriteDescriptor(IReadDescriptor, IWriteDescriptor): 795 """I am a L{FileDescriptor<twisted.internet.abstract.FileDescriptor>} that can both read and write.796 912 """ 913 I am a L{FileDescriptor<twisted.internet.abstract.FileDescriptor>} that can both read and write. 914 """ 797 915 798 916 799 917 class IHalfCloseableDescriptor(Interface): 800 """A descriptor that can be half-closed.""" 918 """ 919 A descriptor that can be half-closed. 920 """ 801 921 802 922 def writeConnectionLost(reason): 803 """Indicates write connection was lost.""" 923 """ 924 Indicates write connection was lost. 925 """ 804 926 805 927 def readConnectionLost(reason): 806 """Indicates read connection was lost.""" 928 """ 929 Indicates read connection was lost. 930 """ 807 931 808 932 809 933 class ISystemHandle(Interface): 810 """An object that wraps a networking OS-specific handle.""" 934 """ 935 An object that wraps a networking OS-specific handle. 936 """ 811 937 812 938 def getHandle(): 813 """Return a system- and reactor-specific handle. 939 """ 940 Return a system- and reactor-specific handle. 814 941 815 942 This might be a socket.socket() object, or some other type of 816 943 object, depending on which reactor is being used. Use and … … 822 949 823 950 824 951 class IConsumer(Interface): 825 """A consumer consumes data from a producer.""" 952 """ 953 A consumer consumes data from a producer. 954 """ 826 955 827 956 def registerProducer(producer, streaming): 828 957 """ … … 850 979 """ 851 980 852 981 def unregisterProducer(): 853 """Stop consuming data from a producer, without disconnecting.854 982 """ 983 Stop consuming data from a producer, without disconnecting. 984 """ 855 985 856 986 def write(data): 857 """The producer will write data by calling this method.""" 987 """ 988 The producer will write data by calling this method. 989 """ 858 990 859 991 class IFinishableConsumer(IConsumer): 860 """A Consumer for producers that finish. 992 """ 993 A Consumer for producers that finish. 861 994 862 995 This interface is semi-stable. 863 996 """ 864 997 def finish(): 865 """The producer has finished producing.""" 998 """ 999 The producer has finished producing. 1000 """ 866 1001 867 1002 class IProducer(Interface): 868 """A producer produces data for a consumer. 1003 """ 1004 A producer produces data for a consumer. 869 1005 870 1006 Typically producing is done by calling the write method of an class 871 1007 implementing L{IConsumer}. 872 1008 """ 873 1009 874 1010 def stopProducing(): 875 """Stop producing data. 1011 """ 1012 Stop producing data. 876 1013 877 1014 This tells a producer that its consumer has died, so it must stop 878 1015 producing data for good. … … 891 1028 """ 892 1029 893 1030 def pauseProducing(): 894 """Pause producing data. 1031 """ 1032 Pause producing data. 895 1033 896 1034 Tells a producer that it has produced too much data to process for 897 1035 the time being, and to stop until resumeProducing() is called. 898 1036 """ 899 1037 def resumeProducing(): 900 """Resume producing data. 1038 """ 1039 Resume producing data. 901 1040 902 1041 This tells a producer to re-add itself to the main loop and produce 903 1042 more data for its consumer. … … 912 1051 """ 913 1052 914 1053 def resumeProducing(): 915 """Produce data for the consumer a single time. 1054 """ 1055 Produce data for the consumer a single time. 916 1056 917 1057 This tells a producer to produce data for the consumer once 918 1058 (not repeatedly, once only). Typically this will be done … … 923 1063 class IProtocol(Interface): 924 1064 925 1065 def dataReceived(data): 926 """Called whenever data is received. 1066 """ 1067 Called whenever data is received. 927 1068 928 1069 Use this method to translate to a higher-level message. Usually, some 929 1070 callback will be made upon the receipt of each complete protocol … … 937 1078 """ 938 1079 939 1080 def connectionLost(reason): 940 """Called when the connection is shut down. 1081 """ 1082 Called when the connection is shut down. 941 1083 942 1084 Clear any circular references here, and any external references 943 1085 to this Protocol. The connection has been closed. The C{reason} … … 949 1091 """ 950 1092 951 1093 def makeConnection(transport): 952 """Make a connection to a transport and a server.953 1094 """ 1095 Make a connection to a transport and a server. 1096 """ 954 1097 955 1098 def connectionMade(): 956 """Called when a connection is made. 1099 """ 1100 Called when a connection is made. 957 1101 958 1102 This may be considered the initializer of the protocol, because 959 1103 it is called when the connection is completed. For clients, … … 965 1109 966 1110 967 1111 class IHalfCloseableProtocol(Interface): 968 """Implemented to indicate they want notification of half-closes. 1112 """ 1113 Implemented to indicate they want notification of half-closes. 969 1114 970 1115 TCP supports the notion of half-closing the connection, e.g. 971 1116 closing the write side but still not stopping reading. A protocol … … 974 1119 """ 975 1120 976 1121 def readConnectionLost(): 977 """Notification of the read connection being closed. 1122 """ 1123 Notification of the read connection being closed. 978 1124 979 1125 This indicates peer did half-close of write side. It is now 980 1126 the responsiblity of the this protocol to call … … 988 1134 """ 989 1135 990 1136 def writeConnectionLost(): 991 """Notification of the write connection being closed. 1137 """ 1138 Notification of the write connection being closed. 992 1139 993 1140 This will never be called for TCP connections as TCP does not 994 1141 support notification of this type of half-close. … … 996 1143 997 1144 998 1145 class IProtocolFactory(Interface): 999 """Interface for protocol factories.1000 1146 """ 1147 Interface for protocol factories. 1148 """ 1001 1149 1002 1150 def buildProtocol(addr): 1003 """Called when a connection has been established to addr. 1151 """ 1152 Called when a connection has been established to addr. 1004 1153 1005 1154 If None is returned, the connection is assumed to have been refused, 1006 1155 and the Port will close the connection. … … 1013 1162 """ 1014 1163 1015 1164 def doStart(): 1016 """Called every time this is connected to a Port or Connector.""" 1165 """ 1166 Called every time this is connected to a Port or Connector. 1167 """ 1017 1168 1018 1169 def doStop(): 1019 """Called every time this is unconnected from a Port or Connector.""" 1170 """ 1171 Called every time this is unconnected from a Port or Connector. 1172 """ 1020 1173 1021 1174 1022 1175 class ITransport(Interface): 1023 """I am a transport for bytes. 1176 """ 1177 I am a transport for bytes. 1024 1178 1025 1179 I represent (and wrap) the physical connection and synchronicity 1026 1180 of the framework which is talking to the network. I make no … … 1032 1186 """ 1033 1187 1034 1188 def write(data): 1035 """Write some data to the physical connection, in sequence, in a 1189 """ 1190 Write some data to the physical connection, in sequence, in a 1036 1191 non-blocking fashion. 1037 1192 1038 1193 If possible, make sure that it is all written. No data will … … 1041 1196 """ 1042 1197 1043 1198 def writeSequence(data): 1044 """Write a list of strings to the physical connection. 1199 """ 1200 Write a list of strings to the physical connection. 1045 1201 1046 1202 If possible, make sure that all of the data is written to 1047 1203 the socket at once, without first copying it all into a … … 1049 1205 """ 1050 1206 1051 1207 def loseConnection(): 1052 """Close my connection, after writing all pending data. 1208 """ 1209 Close my connection, after writing all pending data. 1053 1210 1054 1211 Note that if there is a registered producer on a transport it 1055 1212 will not be closed until the producer has been unregistered. 1056 1213 """ 1057 1214 1058 1215 def getPeer(): 1059 """Get the remote address of this connection. 1216 """ 1217 Get the remote address of this connection. 1060 1218 1061 1219 Treat this method with caution. It is the unfortunate result of the 1062 1220 CGI and Jabber standards, but should not be considered reliable for … … 1076 1234 1077 1235 1078 1236 class ITCPTransport(ITransport): 1079 """A TCP based transport.""" 1237 """ 1238 A TCP based transport. 1239 """ 1080 1240 1081 1241 def loseWriteConnection(): 1082 """Half-close the write side of a TCP connection. 1242 """ 1243 Half-close the write side of a TCP connection. 1083 1244 1084 1245 If the protocol instance this is attached to provides 1085 1246 IHalfCloseableProtocol, it will get notified when the operation is … … 1089 1250 """ 1090 1251 1091 1252 def getTcpNoDelay(): 1092 """Return if TCP_NODELAY is enabled.""" 1253 """ 1254 Return if TCP_NODELAY is enabled.""" 1093 1255 1094 1256 def setTcpNoDelay(enabled): 1095 """Enable/disable TCP_NODELAY. 1257 """ 1258 Enable/disable TCP_NODELAY. 1096 1259 1097 1260 Enabling TCP_NODELAY turns off Nagle's algorithm. Small packets are 1098 sent sooner, possibly at the expense of overall throughput.""" 1261 sent sooner, possibly at the expense of overall throughput. 1262 """ 1099 1263 1100 1264 def getTcpKeepAlive(): 1101 """Return if SO_KEEPALIVE enabled.""" 1265 """ 1266 Return if SO_KEEPALIVE enabled. 1267 """ 1102 1268 1103 1269 def setTcpKeepAlive(enabled): 1104 """Enable/disable SO_KEEPALIVE. 1270 """ 1271 Enable/disable SO_KEEPALIVE. 1105 1272 1106 1273 Enabling SO_KEEPALIVE sends packets periodically when the connection 1107 1274 is otherwise idle, usually once every two hours. They are intended 1108 to allow detection of lost peers in a non-infinite amount of time.""" 1275 to allow detection of lost peers in a non-infinite amount of time. 1276 """ 1109 1277 1110 1278 def getHost(): 1111 """Returns L{IPv4Address}.""" 1279 """ 1280 Returns L{IPv4Address}. 1281 """ 1112 1282 1113 1283 def getPeer(): 1114 """Returns L{IPv4Address}.""" 1284 """ 1285 Returns L{IPv4Address}. 1286 """ 1115 1287 1116 1288 1117 1289 class ITLSTransport(ITCPTransport): 1118 """A TCP transport that supports switching to TLS midstream. 1290 """ 1291 A TCP transport that supports switching to TLS midstream. 1119 1292 1120 1293 Once TLS mode is started the transport will implement L{ISSLTransport}. 1121 1294 """ 1122 1295 1123 1296 def startTLS(contextFactory): 1124 """Initiate TLS negotiation. 1297 """ 1298 Initiate TLS negotiation. 1125 1299 1126 1300 @param contextFactory: A context factory (see L{ssl.py<twisted.internet.ssl>}) 1127 1301 """ 1128 1302 1129 1303 class ISSLTransport(ITCPTransport): 1130 """A SSL/TLS based transport.""" 1304 """ 1305 A SSL/TLS based transport. 1306 """ 1131 1307 1132 1308 def getPeerCertificate(): 1133 """Return an object with the peer's certificate info.""" 1309 """ 1310 Return an object with the peer's certificate info. 1311 """ 1134 1312 1135 1313 1136 1314 class IProcessTransport(ITransport): 1137 """A process transport. 1315 """ 1316 A process transport. 1138 1317 1139 1318 @ivar pid: The Process-ID of this process. 1140 1319 """ 1141 1320 1142 1321 def closeStdin(): 1143 """Close stdin after all data has been written out.""" 1322 """ 1323 Close stdin after all data has been written out. 1324 """ 1144 1325 1145 1326 def closeStdout(): 1146 """Close stdout.""" 1327 """ 1328 Close stdout. 1329 """ 1147 1330 1148 1331 def closeStderr(): 1149 """Close stderr.""" 1332 """ 1333 Close stderr. 1334 """ 1150 1335 1151 1336 def closeChildFD(descriptor): 1152 1337 """ … … 1171 1356 """ 1172 1357 1173 1358 def loseConnection(): 1174 """Close stdin, stderr and stdout.""" 1359 """ 1360 Close stdin, stderr and stdout. 1361 """ 1175 1362 1176 1363 def signalProcess(signalID): 1177 """Send a signal to the process. 1364 """ 1365 Send a signal to the process. 1178 1366 1179 1367 @param signalID: can be 1180 1368 - one of C{\"HUP\"}, C{\"KILL\"}, C{\"STOP\"}, or C{\"INT\"}. … … 1190 1378 1191 1379 1192 1380 class IServiceCollection(Interface): 1193 """An object which provides access to a collection of services.""" 1381 """ 1382 An object which provides access to a collection of services. 1383 """ 1194 1384 1195 1385 def getServiceNamed(serviceName): 1196 """Retrieve the named service from this application. 1386 """ 1387 Retrieve the named service from this application. 1197 1388 1198 1389 Raise a KeyError if there is no such service name. 1199 1390 """ 1200 1391 1201 1392 def addService(service): 1202 """Add a service to this collection.1203 1393 """ 1394 Add a service to this collection. 1395 """ 1204 1396 1205 1397 def removeService(service): 1206 """Remove a service from this collection.""" 1398 """ 1399 Remove a service from this collection. 1400 """ 1207 1401 1208 1402 1209 1403 class IUDPTransport(Interface): 1210 """Transport for UDP DatagramProtocols.""" 1404 """ 1405 Transport for UDP DatagramProtocols. 1406 """ 1211 1407 1212 1408 def write(packet, addr=None): 1213 """Write packet to given address. 1409 """ 1410 Write packet to given address. 1214 1411 1215 1412 @param addr: a tuple of (ip, port). For connected transports must 1216 1413 be the address the transport is connected to, or None. … … 1221 1418 """ 1222 1419 1223 1420 def connect(host, port): 1224 """Connect the transport to an address. 1421 """ 1422 Connect the transport to an address. 1225 1423 1226 1424 This changes it to connected mode. Datagrams can only be sent to 1227 1425 this address, and will only be received from this address. In addition … … 1233 1431 """ 1234 1432 1235 1433 def getHost(): 1236 """Returns IPv4Address.""" 1434 """ 1435 Returns IPv4Address. 1436 """ 1237 1437 1238 1438 def stopListening(): 1239 """Stop listening on this port. 1439 """ 1440 Stop listening on this port. 1240 1441 1241 1442 If it does not complete immediately, will return Deferred that fires 1242 1443 upon completion. … … 1244 1445 1245 1446 1246 1447 class IUDPConnectedTransport(Interface): 1247 """DEPRECATED. Transport for UDP ConnectedPacketProtocols.""" 1448 """ 1449 DEPRECATED. Transport for UDP ConnectedPacketProtocols. 1450 """ 1248 1451 1249 1452 def write(packet): 1250 """Write packet to address we are connected to.""" 1453 """ 1454 Write packet to address we are connected to. 1455 """ 1251 1456 1252 1457 def getHost(): 1253 """Returns UNIXAddress.""" 1458 """ 1459 Returns UNIXAddress. 1460 """ 1254 1461 1255 1462 1256 1463 class IUNIXDatagramTransport(Interface): 1257 """Transport for UDP PacketProtocols.""" 1464 """ 1465 Transport for UDP PacketProtocols. 1466 """ 1258 1467 1259 1468 def write(packet, address): 1260 """Write packet to given address.""" 1469 """ 1470 Write packet to given address. 1471 """ 1261 1472 1262 1473 def getHost(): 1263 """Returns UNIXAddress.""" 1474 """ 1475 Returns UNIXAddress. 1476 """ 1264 1477 1265 1478 1266 1479 class IUNIXDatagramConnectedTransport(Interface): 1267 """Transport for UDP ConnectedPacketProtocols.""" 1480 """ 1481 Transport for UDP ConnectedPacketProtocols. 1482 """ 1268 1483 1269 1484 def write(packet): 1270 """Write packet to address we are connected to.""" 1485 """ 1486 Write packet to address we are connected to. 1487 """ 1271 1488 1272 1489 def getHost(): 1273 """Returns UNIXAddress.""" 1490 """ 1491 Returns UNIXAddress. 1492 """ 1274 1493 1275 1494 def getPeer(): 1276 """Returns UNIXAddress.""" 1495 """ 1496 Returns UNIXAddress. 1497 """ 1277 1498 1278 1499 1279 1500 class IMulticastTransport(Interface): 1280 """Additional functionality for multicast UDP.""" 1501 """ 1502 Additional functionality for multicast UDP. 1503 """ 1281 1504 1282 1505 def getOutgoingInterface(): 1283 """Return interface of outgoing multicast packets.""" 1506 """ 1507 Return interface of outgoing multicast packets. 1508 """ 1284 1509 1285 1510 def setOutgoingInterface(addr): 1286 """Set interface for outgoing multicast packets. 1511 """ 1512 Set interface for outgoing multicast packets. 1287 1513 1288 1514 Returns Deferred of success. 1289 1515 """ 1290 1516 1291 1517 def getLoopbackMode(): 1292 """Return if loopback mode is enabled.""" 1518 """ 1519 Return if loopback mode is enabled. 1520 """ 1293 1521 1294 1522 def setLoopbackMode(mode): 1295 """Set if loopback mode is enabled.""" 1523 """ 1524 Set if loopback mode is enabled. 1525 """ 1296 1526 1297 1527 def getTTL(): 1298 """Get time to live for multicast packets.""" 1528 """ 1529 Get time to live for multicast packets. 1530 """ 1299 1531 1300 1532 def setTTL(ttl): 1301 """Set time to live on multicast packets.""" 1533 """ 1534 Set time to live on multicast packets. 1535 """ 1302 1536 1303 1537 def joinGroup(addr, interface=""): 1304 """Join a multicast group. Returns Deferred of success or failure. 1538 """ 1539 Join a multicast group. Returns Deferred of success or failure. 1305 1540 1306 1541 If an error occurs, the returned Deferred will fail with 1307 1542 L{error.MulticastJoinError}. 1308 1543 """ 1309 1544 1310 1545 def leaveGroup(addr, interface=""): 1311 """Leave multicast group, return Deferred of success.""" 1546 """ 1547 Leave multicast group, return Deferred of success. 1548 """ 1549
