]> gitweb.pimeys.fr Git - bots/parrot.git/commitdiff
On droppe les espaces insécables dans les auteurs
authorVincent Le Gallic <legallic@crans.org>
Mon, 14 Apr 2014 06:58:20 +0000 (08:58 +0200)
committerVincent Le Gallic <legallic@crans.org>
Mon, 14 Apr 2014 06:58:20 +0000 (08:58 +0200)
quotes.py

index fa9ac0afdedf3c8dfc6b945150d46533b4b03f72..08cac11f11368a8dec06db4f2bce6cd1ae0d8e54 100644 (file)
--- 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)
 
 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 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):
 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])
             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
     
         self.content = content
         self.timestamp = timestamp