python: move method escaped_claim_id from test to samba.sd_utils
[dmulder/samba-autobuild/.git] / python / samba / sd_utils.py
index 67d89ef29fe1daa53299edb877cd54b39abaf289..2bddfe518d2c1ecc9db1bea13fba318d362bdfeb 100644 (file)
@@ -28,6 +28,14 @@ from samba.ntstatus import (
 )
 
 
+def escaped_claim_id(claim_id):
+    escapes = '\x00\t\n\x0b\x0c\r !"%&()<=>|'
+    return ''.join(c
+                   if c not in escapes
+                   else f'%{ord(c):04x}'
+                   for c in claim_id)
+
+
 class SDUtils(object):
     """Some utilities for manipulation of security descriptors on objects."""