]> gitweb.pimeys.fr Git - bots/parrot.git/blobdiff - quotes.py
Regexp avec le flag UNICODE histoire de matcher correctement les espaces insécables
[bots/parrot.git] / quotes.py
index 35f486081a546736312b68d0bd082362050ed097..1365b1211868bc51a235c4e9f2d50d6aa4cdb93e 100644 (file)
--- a/quotes.py
+++ b/quotes.py
@@ -11,6 +11,9 @@ import random
 
 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)
+
 def get_now():
     """ Renvoie la date actuelle """
     return datetime.datetime(*time.localtime()[:6])
@@ -42,7 +45,6 @@ class Quote(object):
             Indépendamment de la date. """
         return [self.author, self.content] == [otherquote.author, otherquote.content]
 
-quote_matcher = re.compile(config.quote_regexp)
 
 def parse(text, date=None):
     """ Parse le ``text`` et renvoie une quote ou None. """
@@ -113,8 +115,7 @@ def restore(dump_file=None):
     with open(dump_file) as f:
         t = f.read()
     t = t.decode("utf-8") # Oui, ça peut fail, mais on ne doit alors pas continuer
-    regex = re.compile(config.quote_regexp_with_timestamp)
-    l = [m.groupdict() for m in regex.finditer(t)]
+    l = [m.groupdict() for m in quote_matcher_with_timestamp.finditer(t)]
     # On instancie les quotes grâce aux dicos qui ont déjà la bonne tronche
     l = [Quote(**q) for q in l]
     newquotedb = QuoteDB()