2
2
3
3
from .utils import basestring
4
4
5
+ try :
6
+ PatternType = re ._pattern_type
7
+ except AttributeError :
8
+ PatternType = re .Pattern
9
+
5
10
6
11
class Event (object ):
7
12
match_regex = re .compile ('^Event: .*' , re .IGNORECASE )
@@ -76,8 +81,8 @@ def __call__(self, key, value):
76
81
77
82
class EventListener (object ):
78
83
def __init__ (self , on_event = None , white_list = None , black_list = [], ** kwargs ):
79
- self .white_list = [white_list ] if isinstance (white_list , (basestring , re . _pattern_type )) else white_list
80
- self .black_list = [black_list ] if isinstance (black_list , (basestring , re . _pattern_type )) else black_list
84
+ self .white_list = [white_list ] if isinstance (white_list , (basestring , PatternType )) else white_list
85
+ self .black_list = [black_list ] if isinstance (black_list , (basestring , PatternType )) else black_list
81
86
for k in list (kwargs .keys ()):
82
87
if k .startswith ('on_' ):
83
88
setattr (self , k , kwargs .pop (k ))
@@ -93,25 +98,25 @@ def check_white_list(self, event_name):
93
98
for rule in self .white_list :
94
99
if isinstance (rule , basestring ) and event_name == rule :
95
100
return True
96
- if isinstance (rule , re . _pattern_type ) and rule .search (event_name ) is not None :
101
+ if isinstance (rule , PatternType ) and rule .search (event_name ) is not None :
97
102
return True
98
103
return False
99
104
100
105
def check_black_list (self , event_name ):
101
106
for rule in self .black_list :
102
107
if isinstance (rule , basestring ) and event_name == rule :
103
108
return False
104
- if isinstance (rule , re . _pattern_type ) and rule .match (event_name ) is not None :
109
+ if isinstance (rule , PatternType ) and rule .match (event_name ) is not None :
105
110
return False
106
111
return True
107
112
108
113
def check_attribute (self , rules , value ):
109
- if isinstance (rules , (re . _pattern_type , basestring )):
114
+ if isinstance (rules , (PatternType , basestring )):
110
115
rules = [rules ]
111
116
for rule in rules :
112
117
if isinstance (rule , basestring ) and rule == value :
113
118
return True
114
- if isinstance (rule , re . _pattern_type ) and rule .search (value ):
119
+ if isinstance (rule , PatternType ) and rule .search (value ):
115
120
return True
116
121
return False
117
122
0 commit comments