예제 #1
0
    def __init__(self, out_stream):
        self.out_stream = out_stream
        self.logger = newLogger(type(self).__name__)

        self.write_queue = queue.Queue()

        threading.Thread.__init__(self)
예제 #2
0
    def __init__(self):
        self.logger = newLogger(type(self).__name__)

        self.component_id = None
        self.added_to_hicp = None

        self.changed_header_list = {}
예제 #3
0
    def __init__(self, event_thread):

        self.event_thread = event_thread
        self.logger = newLogger(type(self).__name__)

        self.event_queue = queue.Queue()

        threading.Thread.__init__(self)
예제 #4
0
    def __init__(self, start_group, start_subgroup):
        self.logger = newLogger(type(self).__name__)

        # Doesn't need to know what group it's in, just the text info.
        self.id_to_selector = {}

        # set groups without validating (can't use set_group() yet)
        self.group = start_group
        self.subgroup = start_subgroup
예제 #5
0
    def __init__(self, event_thread):

        self.event_thread = event_thread

        self.logger = newLogger(type(self).__name__)

        self.time_queue = queue.Queue()
        self.handler_list = {}

        threading.Thread.__init__(self)
예제 #6
0
    def __init__(self, in_stream, component_list, event_thread, time_thread):

        self.in_stream = in_stream
        # This is updated by hicp, so only read from it, no iterating.
        self.component_list = component_list
        self.event_thread = event_thread
        self.time_thread = time_thread

        self.logger = newLogger(type(self).__name__)
        self.disconnect_handler = None

        threading.Thread.__init__(self)
예제 #7
0
    def __init__(self,
                 in_stream,
                 out_stream,
                 app_list,
                 default_app=None,
                 text_group=None,
                 text_subgroup=None,
                 authenticator=None):

        # These must be specified for this to work.
        if in_stream is None:
            raise UnboundLocalError("in_stream required, not defined")

        if out_stream is None:
            raise UnboundLocalError("out_stream required, not defined")

        self.logger = newLogger(type(self).__name__)
        self.text_manager = TextManager(text_group, text_subgroup)

        self.in_stream = in_stream
        self.out_stream = out_stream
        self.__default_app = default_app
        self.__app_list = app_list

        if text_group is None:
            # Default language. If they don't specify, make it awkward enough
            # so they make the effort.
            # Canadian English: Remember the "our"s, but not the "ise"s.
            text_group = "en"
            text_subgroup = "ca"

        self.__text_group = text_group
        self.__text_subgroup = text_subgroup
        self.__authenticator = authenticator

        # Things for this object
        self.__gui_id = 0
        self.__component_list = {}
예제 #8
0
    def __init__(self,
                 hicp,
                 write_thread,
                 default_app,
                 app_list=None,
                 authenticator=None):

        self.logger = newLogger(type(self).__name__)

        self.hicp = hicp
        self.write_thread = write_thread
        self.default_app = default_app
        self.app_list = app_list
        self.authenticator = authenticator

        # Used later before starting an app.
        self.start_path = pathlib.Path(os.getcwd())

        self.suspend_app = False
        self.event_queue = queue.Queue()
        self.connect_event = None

        threading.Thread.__init__(self)
예제 #9
0
    def __init__(self, in_stream=None):
        # These may be null.
        self.logger = newLogger(type(self).__name__)

        self.disconnected = False

        # May be EVENT or COMMAND.
        self.__type = None

        # "event: " or "command: " value.
        self.__type_value = None

        self.__headers = {}

        if in_stream is None:
            # No message to read in - probably making one to send.
            return

        # Read headers into the header dict.
        line_cnt = 0
        try:
            while True:
                line = self.readline(in_stream)
                if line == "\r\n" or line == "":
                    # End of message or EOF.
                    if 0 >= line_cnt:
                        # Message not even started, nothing to read.
                        # Probably disconnected.
                        self.disconnected = True
                        self.set_type(self.EVENT, self.DISCONNECT)
                        return
                    break

                line_cnt = line_cnt + 1

                # Split into key and value.
                header_key = ""
                header_value = ""

                # Check for ":: " multi-line data section.
                header_split_idx = line.find(":: ")
                if 0 < header_split_idx:
                    header_key = line[0:header_split_idx]
                    # Skip ":: " 3 chracters.
                    termination_criterion = line[header_split_idx + 3:]

                    # Length or boundary termination criterion?
                    if 0 <= termination_criterion.find("length"):
                        length_match = \
                            self.LENGTH_RE.search(termination_criterion)
                        length = int(length_match.group(2), 10)

                        # header_value is the next length bytes (unless
                        # EOF is encountered).
                        header_value = in_stream.read(length)

                        # There must be a terminating CR LF, so read to
                        # the end of the input line (extra is discarded).
                        self.readline(in_stream)

                    elif 0 <= termination_criterion.find("boundary"):
                        boundary_match = \
                            self.BOUNDARY_RE.search(termination_criterion)
                        boundary = boundary_match.group(2)

                        # Boundary is either CR LF <text> or <text>.
                        if '' == boundary:
                            # Boundary is CR LF plus next line.
                            # The boundary excludes the next CR LF in the
                            # string returned by readline(), but it's
                            # easier to find the boundary if they are
                            # included.
                            boundary = self.readline(in_stream)

                            # This lets us compare the full line to the
                            # boundary string, so indicate that.
                            full_line_boundary = True
                        else:
                            full_line_boundary = False

                        # Read until boundary + CR LF is read.
                        header_value_list = []
                        prev_line_eol_esc = False
                        while 1:
                            header_value_part = self.readline(in_stream)

                            # Remove any escapes, but keep track of
                            # index of last one.
                            (header_value_unescaped, esc_cnt) = \
                                self.ESC_RE.subn("\\2", header_value_part)

                            if 0 < esc_cnt:
                                # String had escapes.
                                last_esc_match = \
                                    self.LAST_ESC_RE.search(header_value_part)
                                after_last_esc_index = last_esc_match.end(2)
                            else:
                                # No esc in string.
                                after_last_esc_index = 0

                            if full_line_boundary:
                                if header_value_unescaped == boundary \
                                    and False == prev_line_eol_esc \
                                    and 0 == esc_cnt:

                                    # Found the boundary. header value doesn't
                                    # include this line.
                                    # The final CR LF is also not included,
                                    # Remove it from the last header value list
                                    # string.
                                    header_value_list[-1] = \
                                        header_value_list[-1][:-2]
                                    break
                            else:
                                # Check for boundary. Should always be at end
                                # of the line, but accept it if not - discard
                                # rest of line.
                                boundary_index = \
                                    header_value_unescaped.find(boundary)

                                if 0 <= boundary_index \
                                    and after_last_esc_index <= boundary_index:

                                    # Found end of line boundary. Remove
                                    # boundary and add to header value list.
                                    header_value_no_boundary = \
                                        header_value_unescaped[ : boundary_index]
                                    header_value_list = \
                                        header_value_list + [header_value_no_boundary]
                                    break

                            # No boundary found, add to header value list
                            header_value_list = \
                                header_value_list + [header_value_unescaped]

                            prev_line_eol_esc = \
                                (after_last_esc_index >= len(header_value_part) - 2)

                        # Convert list to single string.
                        header_value = ''.join(header_value_list)

                    else:
                        # No termination criterion. Leave header value
                        # blank.
                        pass
                else:
                    # Check for ": " single line data value.
                    header_split_idx = line.find(": ")
                    if 0 < header_split_idx:
                        # This is a valid header.
                        header_key = line[:header_split_idx]

                        # Skip ": " 2 chracters, and omit CR LF at the end.
                        header_value = line[header_split_idx + 2:-2]
                    else:
                        # No ": " or ":: ". Let header key be input line
                        # (without CR LF) and leave value as "".
                        header_key = line[:-2]

                if header_key:
                    if 1 == line_cnt:
                        # First line always "event: " or "command: "
                        self.set_type(header_key, header_value)
                    else:
                        self.add_header(header_key, header_value)
                else:
                    # Ignore non headers. Maybe log an error in the
                    # future.
                    self.logger.debug("non-header")  # debug
                    pass
        except ConnectionResetError:
            # Connection closed, interpret as diconnect event.
            self.disconnected = True
            self.set_type(self.EVENT, self.DISCONNECT)
예제 #10
0
    def __init__(self, control):
        self.logger = newLogger(type(self).__name__)

        self.control = control
        self.__text_id = None  # Number