summaryrefslogtreecommitdiff
path: root/source4/scripting/python/samba/samba3.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-12-21 23:05:35 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-12-21 23:05:35 +0100
commit2227860a793dbde0b41e6ba1a720ac0d161ad784 (patch)
tree31e9701e978e4355362c199863d11ce52c04d5db /source4/scripting/python/samba/samba3.py
parentd75c51eef34836f9eb5fa3449cef31f6463ce470 (diff)
downloadsamba-2227860a793dbde0b41e6ba1a720ac0d161ad784.tar.gz
samba-2227860a793dbde0b41e6ba1a720ac0d161ad784.tar.bz2
samba-2227860a793dbde0b41e6ba1a720ac0d161ad784.zip
Fix more tests, improve repr() functions for various Python types.
Diffstat (limited to 'source4/scripting/python/samba/samba3.py')
-rw-r--r--source4/scripting/python/samba/samba3.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/source4/scripting/python/samba/samba3.py b/source4/scripting/python/samba/samba3.py
index 1dc90bfcf3..c8ddbc8864 100644
--- a/source4/scripting/python/samba/samba3.py
+++ b/source4/scripting/python/samba/samba3.py
@@ -666,12 +666,15 @@ class ParamFile(object):
Does not use a parameter table, unlike the "normal".
"""
- def __init__(self):
- self._sections = {}
+ def __init__(self, sections=None):
+ self._sections = sections or {}
def _sanitize_name(self, name):
return name.strip().lower().replace(" ","")
+ def __repr__(self):
+ return "ParamFile(%r)" % self._sections
+
def read(self, filename):
"""Read a file.
@@ -683,7 +686,7 @@ class ParamFile(object):
if not l:
continue
if l[0] == "[" and l[-1] == "]":
- section = self._sanitize_name(l[1:-2])
+ section = self._sanitize_name(l[1:-1])
self._sections.setdefault(section, {})
elif "=" in l:
(k, v) = l.split("=", 1)
@@ -704,7 +707,9 @@ class ParamFile(object):
if not section in self._sections:
return None
param = self._sanitize_name(param)
- return self._sections[section].get(param)
+ if not param in self._sections[section]:
+ return None
+ return self._sections[section][param].strip()
def __getitem__(self, section):
return self._sections[section]
@@ -745,7 +750,7 @@ class Samba3(object):
def get_sam_db(self):
lp = self.get_conf()
- backends = str(lp.get("passdb backend")).split(" ")
+ backends = (lp.get("passdb backend") or "").split(" ")
if ":" in backends[0]:
(name, location) = backends[0].split(":", 2)
else: