summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorMartin Babinsky <mbabinsk@redhat.com>2016-09-23 15:53:41 +0200
committerMartin Babinsky <mbabinsk@redhat.com>2016-10-03 13:42:34 +0200
commit4d994bee60560438178ad9f0215f611ca60e32c3 (patch)
treeac2e012dee2525ec550a482c5837678298452ed4 /ipapython
parent95aa9369cb2f84ab71fa84e254d0bb3af264e97e (diff)
downloadfreeipa-4d994bee60560438178ad9f0215f611ca60e32c3.tar.gz
freeipa-4d994bee60560438178ad9f0215f611ca60e32c3.tar.xz
freeipa-4d994bee60560438178ad9f0215f611ca60e32c3.zip
Move character escaping function to ipautil
Functions `escape_seq` and `unescape_seq` have a generic use-case so it makes sense to move them from `kerberos` to ipautil module so that other modules can reuse them more readily. https://fedorahosted.org/freeipa/ticket/5809 Reviewed-By: Tomas Krizek <tkrizek@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py27
-rw-r--r--ipapython/kerberos.py29
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):
"""