A somewhat usable and tested version.
[django-ssify.git] / tests / tests_utils.py
1 # -*- coding: utf-8 -*-
2 # This file is part of django-ssify, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
4 #
5 from __future__ import unicode_literals
6
7 import re
8
9
10 splitter = re.compile(br'(?<=-->)\s*(?=<!--#)')
11
12 def split_ssi(ssi_text):
13     """re.split won't split on empty sequence, so we need that."""
14     ssi_text = ssi_text.strip()
15     start = 0
16     for match in re.finditer(splitter, ssi_text):
17         yield ssi_text[start:match.start()]
18         start = match.end()
19     yield ssi_text[start:]