def __init__(self, timeout=1.0, encoding='utf-8', debug_mode=False): self.timeout = timeout self.translator = Translator(encoding) self.deferred = Deferred() self.deferredResponses = deque() self.divvyProtocol = None self.running = True self.addr = None self.debug_mode = debug_mode
def setUp(self): self.savedReactor = twisted_client.reactor self.clock = task.Clock() twisted_client.reactor = self.clock self.transport = proto_helpers.StringTransport() self.factory = twisted_client.DivvyFactory(timeout=30) self.protocol = self.factory.buildProtocol(('127.0.0.1', 0)) self.protocol.makeConnection(self.transport) self.translator = Translator()
def setUp(self): self.host = "127.0.0.1" self.factory = DivvyServerFactory() self.listeningPort = reactor.listenTCP(0, self.factory, interface=self.host) self.addCleanup(self.listeningPort.stopListening) self.port = self.listeningPort.getHost().port self.translator = Translator() self.client = None
def __init__(self, host='localhost', port=8321, socket_timeout=1, socket_connect_timeout=1, socket_keepalive=False, socket_keepalive_options=None, socket_type=0, retry_on_timeout=False, socket_read_size=1024, encoding='utf-8'): self.host = host self.port = port self.socket_timeout = socket_timeout self.socket_connect_timeout = socket_connect_timeout self.socket_keepalive = socket_keepalive self.socket_keepalive_options = socket_keepalive_options or {} self.socket_type = socket_type self.retry_on_timeout = retry_on_timeout self.socket_read_size = socket_read_size self._translator = Translator(encoding) self._sock = None
def __init__(self, host='localhost', port=8321, socket_timeout=1, socket_connect_timeout=1, socket_keepalive=False, socket_keepalive_options=None, socket_type=0, retry_on_timeout=False, encoding='utf-8'): self.host = host self.port = port self.translator = Translator(encoding=encoding) self.connection = Connection( host=host, port=port, socket_timeout=socket_timeout, socket_connect_timeout=socket_connect_timeout, socket_keepalive=socket_keepalive, socket_keepalive_options=socket_keepalive_options, socket_type=socket_type, retry_on_timeout=retry_on_timeout)
def __init__(self, timeout=1.0, encoding='utf-8'): super(DivvyProtocol, self).__init__() self.timeout = timeout self.translator = Translator(encoding) self.deferred = None
def setUp(self): self.t = Translator()
from twisted.internet import reactor from twisted.internet.defer import Deferred, succeed, fail from twisted.internet.protocol import ReconnectingClientFactory from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol from twisted.internet.error import TimeoutError, ConnectionDone, ConnectionLost from twisted.internet.task import deferLater from twisted.logger import Logger from twisted.python import log from twisted.python.failure import Failure from twisted.protocols.basic import LineOnlyReceiver from twisted.protocols.policies import TimeoutMixin from divvy.protocol import Translator translator = Translator() class DivvyClient(object): log = Logger(__name__) def __init__(self, host, port, timeout=1.0, encoding='utf-8', debug_mode=False): """ Configures a client that can speak to a Divvy rate limiting server. """ self.host = host self.port = port self.timeout = timeout self.encoding = encoding self.connection = None self.debug_mode = debug_mode # this may be a unwanted side effect for a constructor