Exemple #1
0
    def parse(self, content, resources):

        for line in content:
            match = self.regex.match(line)
            if match is not None:

                date = match.group(1)
                time = match.group(2)
                name = match.group(4)
                message = match.group(5)

                if name:
                    mediamatch = self.mediaregex.match(message)
                    locationmatch = self.locationregex.match(message)
                    contactmatch = self.contactregex.match(message)

                    if mediamatch:
                        try:
                            src = mediamatch.group(1)
                            message = parse_media(resources, src).getObject()
                        except IOError:
                            message = "<strong>File not found: </strong>{}".format(
                                src)
                    elif locationmatch:
                        message = parse_media(
                            resources, locationmatch.group(2)).getObject()

                    elif contactmatch:
                        message = parse_media(
                            resources, contactmatch.group(1)).getObject()

                    yield (date, Bubble(name, message, time, name != self.me))

                else:
                    # Broadcast message
                    yield (date, Broadcast(message))
            else:
                # It's an image with a message
                yield (None, line)
Exemple #2
0
 def test_single(self):
     self.assertEqual(
         parse_media('@media screen, print { }').media, ['screen', 'print'])
Exemple #3
0
 def test_multi(self):
     self.assertEqual(parse_media('@media screen { }').media, ['screen'])