Ejemplo n.º 1
0
 def _glob_match(self, pattern, string):
     """
     Match given string, by escaping regex characters
     """
     # regex flags Multi-line, Unicode, Locale
     return bool(re_match(glob_trans(pattern), string,
                          re.M | re.U | re.L))
Ejemplo n.º 2
0
 def _glob_match(self, pattern, string):
     """
     Match given string, by escaping regex characters
     """
     # regex flags Multi-line, Unicode, Locale
     return bool(re_match(glob_trans(pattern), string,
                          re.M | re.U | re.L))
Ejemplo n.º 3
0
 def _compareAttribute(self, node1, node2, attr):
     attr1 = node1.getAttribute(attr)
     attr2 = node2.getAttribute(attr)
     if attr2.startswith("regexp:"):
         return bool(re_match(attr2[7:], attr1))
     elif attr2.startswith("glob:"):
         return bool(re_match(glob_trans(attr2[5:]), attr1))
     else:
         return attr1 == attr2
Ejemplo n.º 4
0
    def poll_server(self):
        if not self._callback:
            # If callback not registered, don't proceed further
            # Sleep a sleep_time and then return
            time.sleep(self.sleep_time)
            return True
        try:
            event = poll_events()
        except socket.error:
            log(traceback.format_exc())
            # Connection to server might be failed
            return False

        if not event:
            # No event in queue, sleep a sleep_time
            time.sleep(self.sleep_time)
            return True

        # Event format:
        # window:create-Untitled Document 1 - gedit
        event = event.split('-', 1)  # Split first -
        data = event[1]  # Rest of data
        event_type = event[0]  # event type
        # self._callback[name][0] - Event type
        # self._callback[name][1] - Callback function
        # self._callback[name][2] - Arguments to callback function
        for name in self._callback:
            # Window created event
            # User registered window events
            # Keyboard event
            if (event_type == "onwindowcreate" and \
                re.match(glob_trans(name), data, re.M | re.U | re.L)) or \
                (event_type != "onwindowcreate" and \
                 self._callback[name][0] == event_type) or \
                 event_type == 'kbevent':
                if event_type == 'kbevent':
                    # Special case
                    keys, modifiers = data.split('-')
                    fname = 'kbevent%s%s' % (keys, modifiers)
                else:
                    fname = name
                # Get the callback function
                callback = self._callback[fname][1]
                if not callable(callback):
                    # If not callable, ignore the event
                    continue
                args = self._callback[fname][2]
                try:
                    if len(args) and args[0]:
                        # Spawn a new thread, for each event
                        # If one or more arguments to the callback function
                        _t = threading.Thread(target=callback, args=args)
                    else:
                        # Spawn a new thread, for each event
                        # No arguments to the callback function
                        _t = threading.Thread(target=callback, args=())
                    _t.start()
                except:
                    # Log trace incase of exception
                    log(traceback.format_exc())
                    # Silently ignore !?! any exception thrown
                    pass
                # When multiple kb events registered, the for
                # loop keeps iterating, so just break the loop
                break
        return True
Ejemplo n.º 5
0
    def poll_server(self):
        if not self._callback:
            # If callback not registered, don't proceed further
            # Sleep a second and then return
            time.sleep(1)
            return True
        try:
            event = poll_events()
        except socket.error:
            log(traceback.format_exc())
            # Connection to server might be failed
            return False

        if not event:
            # No event in queue, sleep a second
            time.sleep(1)
            return True

        # Event format:
        # window:create-Untitled Document 1 - gedit
        event = event.split('-', 1) # Split first -
        data = event[1] # Rest of data
        event_type = event[0] # event type
        # self._callback[name][0] - Event type
        # self._callback[name][1] - Callback function
        # self._callback[name][2] - Arguments to callback function
        for name in self._callback:
            # Window created event
            # User registered window events
            # Keyboard event
            if (event_type == "onwindowcreate" and \
                re.match(glob_trans(name), data, re.M | re.U | re.L)) or \
                (event_type != "onwindowcreate" and \
                 self._callback[name][0] == event_type) or \
                 event_type == 'kbevent':
                if event_type == 'kbevent':
                    # Special case
                    keys, modifiers = data.split('-')
                    fname = 'kbevent%s%s' % (keys, modifiers)
                else:
                    fname = name
                # Get the callback function
                callback = self._callback[fname][1]
                if not callable(callback):
                    # If not callable, ignore the event
                    continue
                args = self._callback[fname][2]
                try:
                    if len(args) and args[0]:
                        # Spawn a new thread, for each event
                        # If one or more arguments to the callback function
                        thread.start_new_thread(callback, args)
                    else:
                        # Spawn a new thread, for each event
                        # No arguments to the callback function
                        thread.start_new_thread(callback, ())
                except:
                    # Log trace incase of exception
                    log(traceback.format_exc())
                    # Silently ignore !?! any exception thrown
                    pass
                # When multiple kb events registered, the for
                # loop keeps iterating, so just break the loop
                break
        return True
Ejemplo n.º 6
0
 def _glob_match(self, pattern, string):
     return bool(re_match(glob_trans(pattern), string))