1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-09 20:59:11 +03:00

Fix more tests, improve repr() functions for various Python types.

This commit is contained in:
Jelmer Vernooij
2008-12-21 23:05:35 +01:00
parent d75c51eef3
commit 2227860a79
9 changed files with 32 additions and 60 deletions

View File

@ -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: