summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-05 06:33:09 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-05 06:33:09 +0000
commit56fa454fdd229524999127a5b89cc7c9077b9bd6 (patch)
tree1e3b2ee0e60ccc5d31e109947a332bb682c271bb /ipalib/plugable.py
parentd134b483066ae9d3a7e76d6e491f0f91eba6a954 (diff)
downloadfreeipa.git-56fa454fdd229524999127a5b89cc7c9077b9bd6.tar.gz
freeipa.git-56fa454fdd229524999127a5b89cc7c9077b9bd6.tar.xz
freeipa.git-56fa454fdd229524999127a5b89cc7c9077b9bd6.zip
47: Added plugable.check_identifier() function; added corresponding unit tests
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r--ipalib/plugable.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 70743f5a..8f2cbc27 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -21,6 +21,7 @@
Utility classes for registering plugins, base classes for writing plugins.
"""
+import re
import inspect
import errors
@@ -43,6 +44,16 @@ def from_cli(cli_name):
return cli_name.replace('-', '_').replace('.', '__')
+def check_identifier(name):
+ """
+ Raises errors.NameSpaceError if `name` is not a valid Python identifier
+ suitable for use in a NameSpace.
+ """
+ regex = r'^[a-z][_a-z0-9]*[a-z0-9]$'
+ if re.match(regex, name) is None:
+ raise errors.NameSpaceError(name, regex)
+
+
class Plugin(object):
"""
Base class for all plugins.