24
24
from decimal import Decimal
25
25
from bitarray import bitarray
26
26
import uuid
27
- import re
27
+ import regex
28
28
import collections
29
29
import copy
30
30
import six
31
31
32
32
# For Python3
33
33
if six .PY3 :
34
34
unicode = str
35
-
35
+ basestring = str
36
36
# Words that could turn up in YANG definition files that are actually
37
37
# reserved names in Python, such as being builtin types. This list is
38
38
# not complete, but will probably continue to grow.
@@ -139,7 +139,7 @@ def RestrictedClassType(*args, **kwargs):
139
139
# this gives deserialisers some hints as to how to encode/decode this value
140
140
# it must be a list since a restricted class can encapsulate a restricted
141
141
# class
142
- current_restricted_class_type = re .sub ("<(type|class) '(?P<class>.*)'>" ,
142
+ current_restricted_class_type = regex .sub ("<(type|class) '(?P<class>.*)'>" ,
143
143
"\g<class>" , str (base_type ))
144
144
if hasattr (base_type , "_restricted_class_base" ):
145
145
restricted_class_hint = getattr (base_type , "_restricted_class_base" )
@@ -179,9 +179,9 @@ def __new__(self, *args, **kwargs):
179
179
_restriction_test method so that it can be called by other functions.
180
180
"""
181
181
182
- range_regex = re .compile ("(?P<low>\-?[0-9\.]+|min)([ ]+)?\.\.([ ]+)?" +
182
+ range_regex = regex .compile ("(?P<low>\-?[0-9\.]+|min)([ ]+)?\.\.([ ]+)?" +
183
183
"(?P<high>(\-?[0-9\.]+|max))" )
184
- range_single_value_regex = re .compile ("(?P<value>\-?[0-9\.]+)" )
184
+ range_single_value_regex = regex .compile ("(?P<value>\-?[0-9\.]+)" )
185
185
186
186
def convert_regexp (pattern ):
187
187
@@ -203,6 +203,7 @@ def convert_regexp(pattern):
203
203
pattern = "^%s" % pattern
204
204
if not pattern [len (pattern ) - 1 ] == "$" :
205
205
pattern = "%s$" % pattern
206
+
206
207
return pattern
207
208
208
209
def build_length_range_tuples (range , length = False , multiplier = 1 ):
@@ -253,7 +254,7 @@ def match_pattern_check(regexp):
253
254
def mp_check (value ):
254
255
if not isinstance (value , basestring ):
255
256
return False
256
- if re .match (convert_regexp (regexp ), value ):
257
+ if regex .match (convert_regexp (regexp ), value ):
257
258
return True
258
259
return False
259
260
return mp_check
@@ -947,7 +948,7 @@ class YANGBaseClass(base_type):
947
948
if yang_type in ["container" , "list" ] or is_container == "container" :
948
949
__slots__ = tuple (clsslots )
949
950
950
- _pybind_base_class = re .sub ("<(type|class) '(?P<class>.*)'>" , "\g<class>" ,
951
+ _pybind_base_class = regex .sub ("<(type|class) '(?P<class>.*)'>" , "\g<class>" ,
951
952
str (base_type ))
952
953
953
954
def __new__ (self , * args , ** kwargs ):
@@ -1211,7 +1212,7 @@ def __init__(self, *args, **kwargs):
1211
1212
1212
1213
if value is not None :
1213
1214
set_method (value )
1214
- self ._type = re .sub ("<(type|class) '(?P<class>.*)'>" , "\g<class>" ,
1215
+ self ._type = regex .sub ("<(type|class) '(?P<class>.*)'>" , "\g<class>" ,
1215
1216
str (get_method ()._base_type ))
1216
1217
1217
1218
self ._utype = get_method ()._base_type
0 commit comments