def connect(uri_str, additional_headers=None): """ :param uri_str: :param additional_headers: list of HttpHeader :raise IOError on failure :return: """ uri = uritools.urisplit(uri_str) if not uri.userinfo: raise ValueError( "TCPEventSocket::connect requires 'userinfo'. uri was " + uri_str) if uri.scheme != "tecs" and uri.scheme != "tecs-tcp": raise ValueError( "TCPEventSocket::connect requires 'tecs' or 'tecs-tcp' as scheme. got " + uri.scheme) req = HttpRequest(HttpMethod.CONNECT, uri.host, uri.path) req.add_header("Upgrade", constants.HTTP_UPGRADE_HEADER) req.add_header("Connection", "Upgrade") req.add_header("Client-Time", str(current_millis())) req.add_header("Client-Id", uri.userinfo) req.add_header("Client-Name", uri.userinfo) if additional_headers is not None: for header in additional_headers: req.add_header(header.get_key(), header.get_value()) eve_socket = TCPEventSocket( uri.userinfo, socket.socket(socket.AF_INET, socket.SOCK_STREAM)) tecs.get_logger(eve_socket).info("connecting to %s", uri_str) try: eve_socket.__socket.connect((uri.host, int(uri.port))) except socket.error as s_err: raise IOError(s_err.strerror) except OSError as os_err: raise IOError(os_err.strerror) req.transmit(eve_socket.__sos) # TODO set socket read timeout for detecting invalid behavior of remote endpoint http_rsp = HttpResponse() http_rsp.receive(eve_socket.__sis) if http_rsp.code() != 101: eve_socket.__socket.close() raise IOError("unexpected http code " + str(http_rsp.code())) tecs.get_logger(eve_socket).info("connected to %s", uri_str) return eve_socket
def __init__(self, id, service_selector): super(TCPPSClient, self).__init__(id) self.__log = tecs.get_logger(self) self.__service_selector = service_selector self.__uri_str = None self.__service_selector_gen = None
def __init__(self, method=None, host=None, res=None): self.__log = get_logger(self) self.__method = method self.__host = host self.__res = res self.__headers = [] self.__contentLength = 0 self.__body = None self.add_header("Host", host)
def __init__(self, event_factory, port=0, reuse_addr=False): self.__log = tecs.get_logger(self) self.__event_factory = event_factory self.__port = port self.__reuseAddr = reuse_addr self.__bound = False self.__socket = None self.__remote_addr = ("localhost", port) self.__duplicate_filter = DuplicateEventFilter()
def __init__(self, id): self.__log = get_logger(self) self._id = id self.__in_recv_pipe, self.__out_recv_pipe = Pipe() self.__in_send_pipe, self.__out_send_pipe = Pipe() self._subscriptions = set() # self.__event_factory = EventFactory(self.id) self._socket = None self.__state = self.State.OFFLINE self._lock = threading.Lock()
def __init__(self, id="py-service-provider", mc_group=constants.MULTICAST_IPV4, mc_port=constants.DEFAULT_PORT): self.__socket = UDPEventSocket(EventFactory(id), mc_port, True) self.__mc_group = mc_group self.__mc_port = mc_port self.__log = tecs.get_logger(self) self.__services = [] self.__lock = threading.Lock() self.__active = False self.__thread = None
def __init__(self, type_regex, id="py-discovery", context="", mc_group=constants.MULTICAST_IPV4, mc_port=constants.DEFAULT_PORT): self.__log = tecs.get_logger(self) self.__type_regex = type_regex self.__id = id self.__context = context self.__mc_group = mc_group self.__mc_port = mc_port self.__lock = threading.Lock() self.__socket = None
def __init__(self, resource): self.__log = tecs.get_logger(self) self._resource = resource pass
def __init__(self, id, mc_addr, mc_port): super(UDPPSClient, self).__init__(id) self.__log = tecs.get_logger(self) self.__event_factory = EventFactory(id) self.__mc_addr = mc_addr self.__mc_port = mc_port
def __init__(self, client_factory, uri_supplier): self.__log = tecs.get_logger(self) self.__client_factory = client_factory self.__uri_supplier = uri_supplier
def __init__(self, id, socket): self.__log = tecs.get_logger(self) self.__socket = socket self.__sos = SocketOutputStream(self.__socket) self.__sis = SocketInputStream(self.__socket) self.__event_factory = EventFactory(id)