]> gitweb.pimeys.fr Git - bots/parrot.git/commitdiff
Regexp avec le flag UNICODE histoire de matcher correctement les espaces insécables
authorVincent Le Gallic <legallic@crans.org>
Wed, 9 Apr 2014 20:24:52 +0000 (22:24 +0200)
committerVincent Le Gallic <legallic@crans.org>
Wed, 9 Apr 2014 20:24:52 +0000 (22:24 +0200)
config.py
parrot.py
quotes.py

index 25347ca2544ea21085ccdd2d9aa44804f291df17..ad2d89751c20e03ca3e01b6f3d6a09a4f07c884e 100644 (file)
--- a/config.py
+++ b/config.py
@@ -117,7 +117,7 @@ helpmsg_overops = u" SAY DO STAY NOSTAY OPS OVEROPS KICK DIE CRASH RESTORE"
 blacklisted_masks = [("Flo!*@*", [])]
 
 #: Regexp utilisée pour parser des quotes
 blacklisted_masks = [("Flo!*@*", [])]
 
 #: Regexp utilisée pour parser des quotes
-quote_regexp = ur"""\s*(?:"|«|')\s*(?P<content>.+?)\s*(?:"|»|') ?~ ?(?P<author>.+?)\s*(?:$|\n)"""
+quote_regexp = ur"""\s*(?:"|«|')\s*(?P<content>.+?)\s*(?:"|»|')\s*~\s*(?P<author>.+?)\s*(?:$|\n)"""
 
 #: Regexp utlisée pour parser une quote avec timestamp
 quote_regexp_with_timestamp = ur"(?P<timestamp>.{19}) " + quote_regexp
 
 #: Regexp utlisée pour parser une quote avec timestamp
 quote_regexp_with_timestamp = ur"(?P<timestamp>.{19}) " + quote_regexp
index a507663bc0d9e6dcdbc76fd402e49e3a3910bd0d..17d99c199e9dc70a50ff735ed9aa5e0707cc551b 100755 (executable)
--- a/parrot.py
+++ b/parrot.py
@@ -426,7 +426,7 @@ class Parrot(ircbot.SingleServerIRCBot):
                 self.serv.privmsg(canal, "%s: %s" % (auteur, config.quote_display_url.encode("utf-8")))
         else:
             # Vu que ce bot est prévu pour parser des quotes il va falloir bosser ici
                 self.serv.privmsg(canal, "%s: %s" % (auteur, config.quote_display_url.encode("utf-8")))
         else:
             # Vu que ce bot est prévu pour parser des quotes il va falloir bosser ici
-            match = quote_pattern.match(message)
+            match = self.quote_pattern.match(message)
             if match:
                 d = match.groupdict()
                 if self.quotedb.store(d["author"], d["content"]):
             if match:
                 d = match.groupdict()
                 if self.quotedb.store(d["author"], d["content"]):
index 35f486081a546736312b68d0bd082362050ed097..1365b1211868bc51a235c4e9f2d50d6aa4cdb93e 100644 (file)
--- a/quotes.py
+++ b/quotes.py
@@ -11,6 +11,9 @@ import random
 
 import config
 
 
 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])
 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]
 
             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. """
 
 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
     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()
     # On instancie les quotes grâce aux dicos qui ont déjà la bonne tronche
     l = [Quote(**q) for q in l]
     newquotedb = QuoteDB()