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)
def test_single(self): self.assertEqual( parse_media('@media screen, print { }').media, ['screen', 'print'])
def test_multi(self): self.assertEqual(parse_media('@media screen { }').media, ['screen'])