mirror of https://github.com/jesopo/ircrobots
add start of hostmask matching: mask collapsing
This commit is contained in:
parent
024deb8d0f
commit
8afadd1fdf
|
@ -0,0 +1,20 @@
|
|||
|
||||
def _collapse(pattern: str) -> str:
|
||||
out = ""
|
||||
i = 0
|
||||
while i < len(pattern):
|
||||
seen_ast = False
|
||||
while pattern[i:] and pattern[i] in ["*", "?"]:
|
||||
if pattern[i] == "?":
|
||||
out += "?"
|
||||
elif pattern[i] == "*":
|
||||
seen_ast = True
|
||||
i += 1
|
||||
if seen_ast:
|
||||
out += "*"
|
||||
|
||||
if pattern[i:]:
|
||||
out += pattern[i]
|
||||
i += 1
|
||||
return out
|
||||
|
|
@ -0,0 +1 @@
|
|||
from .glob import *
|
|
@ -0,0 +1,16 @@
|
|||
import unittest
|
||||
from ircrobots import glob
|
||||
|
||||
class GlobTestCollapse(unittest.TestCase):
|
||||
def test(self):
|
||||
c1 = glob._collapse("**?*")
|
||||
self.assertEqual(c1, "?*")
|
||||
|
||||
c2 = glob._collapse("a**?a*")
|
||||
self.assertEqual(c2, "a?*a*")
|
||||
|
||||
c3 = glob._collapse("?*?*?*?*a")
|
||||
self.assertEqual(c3, "????*a")
|
||||
|
||||
c4 = glob._collapse("a*?*a?**")
|
||||
self.assertEqual(c4, "a?*a?*")
|
Loading…
Reference in New Issue