mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
parent
d982710bec
commit
a6833222ff
@ -1487,3 +1487,30 @@ def is_fips_enabled():
|
|||||||
# Consider that the host is not fips-enabled if the file does not exist
|
# Consider that the host is not fips-enabled if the file does not exist
|
||||||
pass
|
pass
|
||||||
return False
|
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)
|
||||||
|
@ -8,6 +8,8 @@ classes/utils for Kerberos principal name validation/manipulation
|
|||||||
import re
|
import re
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from ipapython.ipautil import escape_seq, unescape_seq
|
||||||
|
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
unicode = str
|
unicode = str
|
||||||
|
|
||||||
@ -58,33 +60,6 @@ def split_principal_name(principal_name):
|
|||||||
return tuple(COMPONENT_SPLIT_RE.split(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
|
@six.python_2_unicode_compatible
|
||||||
class Principal(object):
|
class Principal(object):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user