示例#1
0
    def _parse(self, string):
        buf = self._buffer + string

        split = []
        prev = 0
        for match in self._prompt.finditer(buf):
            if match.groups()[0]:
                t = datetime.time(int(match.groups()[0]),
                                  int(match.groups()[1]),
                                  tzinfo=TZINFO)
            else:
                t = None
            split.append((buf[prev:match.start()], t))
            prev = match.end()

        # The last item in list is not yet complete.
        self._buffer = buf[prev:]

        # loop through all the outputs and match each with all regexes, after
        # checking for blocks.
        for ics_output, t in split:
            self.fics_time = t
            # Now FICS has a bad habit of (at least for error messages because
            # of no ID) not doing quite prompt to prompt sending with blocking.
            # so we first split along \x17.
            outputs = ics_output.split('\x17')
            for block in outputs:
                # Delete annoying whitespaces.
                block_match = self._block_regex.match(block)
                if block_match:
                    info = block_match.groupdict()
                    data = info['data'].strip()
                    id_ = int(info['id'])
                    self.block_code = int(info['code'])
                    if self._block_funcs.has_key(id_):
                        handler = self._block_funcs[id_]
                        self.send(handler[0](data, *handler[1], **handler[2]))
                        del self._block_funcs[id_]
                        self._used_blocks.remove(id_)
                else:
                    data = block.strip()
                    self.block_code = None

                for (regex, function) in self._registered:
                    match = regex.match(data)
                    if match:
                        self.send(function(match))
                        break

                if self.unmatched_log is not None:
                    self.unmatched_log.write(block)
示例#2
0
    def _parse(self, string):
        buf = self._buffer + string
        
        split = []
        prev = 0
        for match in self._prompt.finditer(buf):
            if match.groups()[0]:
                t = datetime.time(int(match.groups()[0]), int(match.groups()[1]), tzinfo=TZINFO)
            else:
                t = None
            split.append((buf[prev:match.start()], t))
            prev = match.end()
        
        # The last item in list is not yet complete.
        self._buffer = buf[prev:]

        # loop through all the outputs and match each with all regexes, after
        # checking for blocks.
        for ics_output, t in split:
            self.fics_time = t
            # Now FICS has a bad habit of (at least for error messages because
            # of no ID) not doing quite prompt to prompt sending with blocking.
            # so we first split along \x17.
            outputs = ics_output.split('\x17')
            for block in outputs:
                # Delete annoying whitespaces.
                block_match = self._block_regex.match(block)
                if block_match:
                    info = block_match.groupdict()
                    data = info['data'].strip()
                    id_ = int(info['id'])
                    self.block_code = int(info['code'])
                    if self._block_funcs.has_key(id_):
                        handler = self._block_funcs[id_]
                        self.send(handler[0](data, *handler[1], **handler[2]))
                        del self._block_funcs[id_]
                        self._used_blocks.remove(id_)
                else:
                    data = block.strip()
                    self.block_code = None
                                                
                for (regex, function) in self._registered:
                    match = regex.match(data)
                    if match:
                        # print function, match
                        self.send(function(match))
                        break
                
                if self.unmatched_log is not None:
                    self.unmatched_log.write(block)
示例#3
0
 def parse_block(self, data):
     """This function can be used to get a snipplet from FICS parsed alone,
     which was garbage to some other parsing function.
     
     IE. before (and after) style 12 info there can be quite a bit of spam
     which is basically unrelated to style 12. I don't know if this can be
     needed, but I provide the possibility anyways.
     """
     data = data.strip()
     if not data:
         return
     for (regex, function) in self._registered:
         match = regex.match(data)
         if match:
             self.send(function(match))
             break
     
     if self.unmatched_log is not None:
         self.unmatched_log.write(data)
示例#4
0
    def parse_block(self, data):
        """This function can be used to get a snipplet from FICS parsed alone,
        which was garbage to some other parsing function.
        
        IE. before (and after) style 12 info there can be quite a bit of spam
        which is basically unrelated to style 12. I don't know if this can be
        needed, but I provide the possibility anyways.
        """
        data = data.strip()
        if not data:
            return
        for (regex, function) in self._registered:
            match = regex.match(data)
            if match:
                self.send(function(match))
                break

        if self.unmatched_log is not None:
            self.unmatched_log.write(data)