netcmd/ldapcmp: promote re object to global
authorJoe Guo <joeg@catalyst.net.nz>
Tue, 6 Nov 2018 08:37:47 +0000 (21:37 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 21 Nov 2018 06:46:20 +0000 (07:46 +0100)
Then we can reuse the re obj.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/ldapcmp.py

index 4acabaa..ffa452c 100644 (file)
@@ -37,6 +37,8 @@ from samba.netcmd import (
     Option,
 )
 
+RE_RANGED_RESULT = re.compile("^([^;]+);range=(\d+)-(\d+|\*)$")
+
 
 class LDAPBase(object):
 
@@ -138,9 +140,7 @@ class LDAPBase(object):
             It resolved ranged results e.g. member;range=0-1499
         """
 
-        r = re.compile("^([^;]+);range=(\d+)-(\d+|\*)$")
-
-        m = r.match(key)
+        m = RE_RANGED_RESULT.match(key)
         if m is None:
             return key
 
@@ -151,9 +151,7 @@ class LDAPBase(object):
             It resolved ranged results e.g. member;range=0-1499
         """
 
-        r = re.compile("^([^;]+);range=(\d+)-(\d+|\*)$")
-
-        m = r.match(key)
+        m = RE_RANGED_RESULT.match(key)
         if m is None:
             # no range, just return the values
             return vals
@@ -175,7 +173,7 @@ class LDAPBase(object):
             fvals = None
 
             for key in res.keys():
-                m = r.match(key)
+                m = RE_RANGED_RESULT.match(key)
 
                 if m is None:
                     continue