Chain iterators and extend when excluding links from quirks
This commit is contained in:
parent
d3c9b8eedf
commit
8e3f5410b7
1 changed files with 14 additions and 16 deletions
30
dataobjs.py
30
dataobjs.py
|
@ -1,4 +1,8 @@
|
||||||
|
import re
|
||||||
|
import random
|
||||||
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
PchumLog = logging.getLogger("pchumLogger")
|
PchumLog = logging.getLogger("pchumLogger")
|
||||||
try:
|
try:
|
||||||
|
@ -6,9 +10,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("PyQt5 fallback (dataobjs.py)")
|
print("PyQt5 fallback (dataobjs.py)")
|
||||||
from PyQt5 import QtGui
|
from PyQt5 import QtGui
|
||||||
from datetime import datetime
|
|
||||||
import re
|
|
||||||
import random
|
|
||||||
|
|
||||||
from mood import Mood
|
from mood import Mood
|
||||||
from parsetools import (
|
from parsetools import (
|
||||||
|
@ -167,20 +168,17 @@ class pesterQuirks:
|
||||||
if checkstate == 2:
|
if checkstate == 2:
|
||||||
# Check for substring that should be excluded.
|
# Check for substring that should be excluded.
|
||||||
excludes = []
|
excludes = []
|
||||||
# Check for links, store in list.
|
# Return matches for links, smilies, handles, memos.
|
||||||
for match in re.finditer(_urlre, string):
|
# Chain the iterators and add to excludes list.
|
||||||
excludes.append(match)
|
matches = itertools.chain(
|
||||||
# Check for smilies, store in list.
|
re.finditer(_urlre, string),
|
||||||
for match in re.finditer(_smilere, string):
|
re.finditer(_smilere, string),
|
||||||
excludes.append(match)
|
re.finditer(_handlere, string),
|
||||||
# Check for @handles, store in list.
|
re.finditer(_memore, string),
|
||||||
for match in re.finditer(_handlere, string):
|
)
|
||||||
excludes.append(match)
|
excludes.extend(matches)
|
||||||
# Check for #memos, store in list.
|
|
||||||
for match in re.finditer(_memore, string):
|
|
||||||
excludes.append(match)
|
|
||||||
|
|
||||||
if len(excludes) >= 1:
|
if excludes:
|
||||||
# SORT !!!
|
# SORT !!!
|
||||||
excludes.sort(key=lambda exclude: exclude.start())
|
excludes.sort(key=lambda exclude: exclude.start())
|
||||||
# Recursion check.
|
# Recursion check.
|
||||||
|
|
Loading…
Reference in a new issue