diff options
Diffstat (limited to 'ipapython')
| -rw-r--r-- | ipapython/ipautil.py | 27 | ||||
| -rw-r--r-- | ipapython/kerberos.py | 29 |
2 files changed, 29 insertions, 27 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index a7fd4edbb..41544a114 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -1486,3 +1486,30 @@ def is_fips_enabled(): # Consider that the host is not fips-enabled if the file does not exist pass return False + + +def unescape_seq(seq, *args): + """ + unescape (remove '\\') all occurences of sequence in input strings. + + :param seq: sequence to unescape + :param args: input string to process + + :returns: tuple of strings with unescaped sequences + """ + unescape_re = re.compile(r'\\{}'.format(seq)) + + return tuple(re.sub(unescape_re, seq, a) for a in args) + + +def escape_seq(seq, *args): + """ + escape (prepend '\\') all occurences of sequence in input strings + + :param seq: sequence to escape + :param args: input string to process + + :returns: tuple of strings with escaped sequences + """ + + return tuple(a.replace(seq, u'\\{}'.format(seq)) for a in args) diff --git a/ipapython/kerberos.py b/ipapython/kerberos.py index 298dbf186..a8ebc0428 100644 --- a/ipapython/kerberos.py +++ b/ipapython/kerberos.py @@ -8,6 +8,8 @@ classes/utils for Kerberos principal name validation/manipulation import re import six +from ipapython.ipautil import escape_seq, unescape_seq + if six.PY3: unicode = str @@ -58,33 +60,6 @@ def split_principal_name(principal_name): return tuple(COMPONENT_SPLIT_RE.split(principal_name)) -def unescape_seq(seq, *args): - """ - unescape (remove '\\') all occurences of sequence in input strings. - - :param seq: sequence to unescape - :param args: input string to process - - :returns: tuple of strings with unescaped sequences - """ - unescape_re = re.compile(r'\\{}'.format(seq)) - - return tuple(re.sub(unescape_re, seq, a) for a in args) - - -def escape_seq(seq, *args): - """ - escape (prepend '\\') all occurences of sequence in input strings - - :param seq: sequence to escape - :param args: input string to process - - :returns: tuple of strings with escaped sequences - """ - - return tuple(a.replace(seq, u'\\{}'.format(seq)) for a in args) - - @six.python_2_unicode_compatible class Principal(object): """ |
