summaryrefslogtreecommitdiffstats
path: root/ipalib/plugable.py
diff options
context:
space:
mode:
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.