From d2edf940c5e7cf78465954534040ff2406cc0c7a Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 14 Apr 2014 08:58:20 +0200 Subject: [PATCH] =?utf8?q?On=20droppe=20les=20espaces=20ins=C3=A9cables=20?= =?utf8?q?dans=20les=20auteurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- quotes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/quotes.py b/quotes.py index fa9ac0a..08cac11 100644 --- a/quotes.py +++ b/quotes.py @@ -13,11 +13,16 @@ import config quote_matcher = re.compile(config.quote_regexp, flags=re.UNICODE) quote_matcher_with_timestamp = re.compile(config.quote_regexp_with_timestamp, flags=re.UNICODE) +spaces_matcher = re.compile(u"\s", flags=re.U) def get_now(): """ Renvoie la date actuelle """ return datetime.datetime(*time.localtime()[:6]) +def sanitize_author(raw): + """Proprifie l'auteur : enlève les espaces insécables.""" + return spaces_matcher.sub(u" ", raw) + class Quote(object): """ Une citation """ def __init__(self, author, content, timestamp=None): @@ -25,7 +30,7 @@ class Quote(object): timestamp = get_now() elif isinstance(timestamp, basestring): timestamp = datetime.datetime(*time.strptime(timestamp, u"%Y-%m-%d_%H:%M:%S")[:6]) - self.author = author + self.author = sanitize_author(author) self.content = content self.timestamp = timestamp -- 2.39.2