jstrports.py 978 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- test-case-name: twisted.words.test -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """ A temporary placeholder for client-capable strports, until we
  5. sufficient use cases get identified """
  6. from __future__ import absolute_import, division
  7. from twisted.internet.endpoints import _parse
  8. def _parseTCPSSL(factory, domain, port):
  9. """ For the moment, parse TCP or SSL connections the same """
  10. return (domain, int(port), factory), {}
  11. def _parseUNIX(factory, address):
  12. return (address, factory), {}
  13. _funcs = { "tcp" : _parseTCPSSL,
  14. "unix" : _parseUNIX,
  15. "ssl" : _parseTCPSSL }
  16. def parse(description, factory):
  17. args, kw = _parse(description)
  18. return (args[0].upper(),) + _funcs[args[0]](factory, *args[1:], **kw)
  19. def client(description, factory):
  20. from twisted.application import internet
  21. name, args, kw = parse(description, factory)
  22. return getattr(internet, name + 'Client')(*args, **kw)