Twisted logic

download Twisted logic

of 33

  • date post

    08-May-2015
  • Category

    Technology

  • view

    157
  • download

    0

Embed Size (px)

Transcript of Twisted logic

  • 1.Twisted Logic PyCon 2013 - Ashwini Oruganti@_ashfall_

2. Twistedasynchronous event-drivennetworking framework 3. Twistedasynchronous event-drivennetworking frameworkaka... HARD 4. Google Summer of Code spend the summer working on an open source project with amentoring organization 5. Endpointan interface with a single method thattakes an argument* returns :a listening port / a connected protocol 6. Server endpoint = TCP4ServerEndpoint(reactor, 8007) endpoint.listen(Factory())Client endpoint = TCP4ClientEndpoint(reactor, "localhost", 8007) endpoint.connect(Factory()) 7. class TCP4ServerEndpoint(object):"""Implements TCP server endpoint with an IPv4configuration"""...def __init__(self, reactor, port, backlog=50, interface=):...def listen(self, protocolFactory):return defer.execute(self._reactor.listenTCP,...) 8. class TCP6ServerEndpoint(object):"""Implements TCP server endpoint with an IPv6configuration"""...def __init__(self, reactor, port,backlog=50, interface=::):...def listen(self, protocolFactory):return defer.execute( self._reactor.listenTCP,...) 9. Its just code. 10. class StandardIOEndpoint(object):"""A Standard Input/Output endpoint"""implements(interfaces.IStreamServerEndpoint)def __init__(self, reactor):...def listen(self, stdioProtocolFactory):return defer.execute(stdio.StandardIO,stdioProtocolFactory.buildProtocol(PipeAddress())) 11. Moral of the story:Do not get flustered. Do not overthink.. Forget its Twisted 12. Moral of the story: Read the code. Solve the problem(write code) 13. Theres nothing more boringthan thecomfort zone 14. TCP Client EndpointIPv6 addressesHostname Resolution 15. class TCP6ClientEndpoint(object): def __init__(self, reactor, host, port, timeout=30, bindAddress=None): ...def connect(self, protocolFactory):"""Connect via TCP, once the hostnameresolution is done."""... 16. def _nameResolution(self, host):"""Resolve the hostname string into a tuplecontaining the host IPv6 address."""...def _resolvedHostConnect(self, resolvedHost, protocolFactory):"""Connect to the server using the resolvedhostname."""... 17. DeferredCallbacks and Errbacks Flow is not obvious Debugging is tricky 18. class SomeState(object):def __init__(self):self.values = []def getValue(self):return self.values.pop(0)def addValue(self, value):self.values.append(value) 19. def foo(): return SomeState()def bar():state = foo()print state.getValue() 20. Firing the Deferreddef foo():s = SomeState()s.addValue(2)return s 21. Its just code. 22. Its X, when it isntreally X 23. Its full of highlycomplex concepts! 24. It was created by a couple ofdudes who dropped out ofschool, and a 16-year-old.HOW HARD COULD IT BE? 25. Its foreign! 26. camelCase PEP8: July 5, 2001 Twisteds codingstandard: May 2, 2001 27. Its huge! 28. Core can fit into a floppydisk. 29. Know what youre doing. 30.