summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2019-08-26 15:58:50 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2019-08-26 15:58:50 +0200
commitdaab3079f0192d9c2ad7c9321e6ecc2d42cd384d (patch)
tree1ab8ff960cbe6766f42bc511cf968805f1e05f8c
parent00080f3bb1e232ddb647e619ba41dca0284772de (diff)
downloadpykolab-daab3079f0192d9c2ad7c9321e6ecc2d42cd384d.tar.gz
Ensure a missing setting isn't treated as a string
-rw-r--r--pykolab/auth/ldap/__init__.py17
-rw-r--r--pykolab/auth/ldap/cache.py28
-rw-r--r--pykolab/conf/__init__.py4
3 files changed, 31 insertions, 18 deletions
diff --git a/pykolab/auth/ldap/__init__.py b/pykolab/auth/ldap/__init__.py
index 466f425..f43d183 100644
--- a/pykolab/auth/ldap/__init__.py
+++ b/pykolab/auth/ldap/__init__.py
@@ -1298,15 +1298,20 @@ class LDAP(pykolab.base.Base):
if not conf.resync:
modified_after = self.get_latest_sync_timestamp()
else:
- modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format').replace('%%', '%')
- if modifytimestamp_format == None:
- modifytimestamp_format = "%Y%m%d%H%M%SZ"
+ modifytimestamp_format = conf.get_raw(
+ 'ldap',
+ 'modifytimestamp_format',
+ default="%Y%m%d%H%M%SZ"
+ ).replace('%%', '%')
+
+ modified_after = datetime.datetime(1900, 01, 01, 00, 00, 00).strftime(
+ modifytimestamp_format
+ )
- modified_after = datetime.datetime(1900, 01, 01, 00, 00, 00).strftime(modifytimestamp_format)
else:
modified_after = self.get_latest_sync_timestamp()
- _filter = "(&%s(modifytimestamp>=%s))" % (_filter,modified_after)
+ _filter = "(&%s(modifytimestamp>=%s))" % (_filter, modified_after)
log.debug(_("Synchronization is using filter %r") % (_filter), level=8)
@@ -1318,7 +1323,7 @@ class LDAP(pykolab.base.Base):
config_base_dn = self.config_get('base_dn')
ldap_base_dn = self._kolab_domain_root_dn(self.domain)
- if not ldap_base_dn == None and not ldap_base_dn == config_base_dn:
+ if ldap_base_dn is not None and not ldap_base_dn == config_base_dn:
base_dn = ldap_base_dn
else:
base_dn = config_base_dn
diff --git a/pykolab/auth/ldap/cache.py b/pykolab/auth/ldap/cache.py
index b72e5ab..23b4e07 100644
--- a/pykolab/auth/ldap/cache.py
+++ b/pykolab/auth/ldap/cache.py
@@ -65,14 +65,16 @@ class Entry(object):
self.uniqueid = uniqueid
self.result_attribute = result_attr
- modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format').replace('%%', '%')
- if modifytimestamp_format == None:
- modifytimestamp_format = "%Y%m%d%H%M%SZ"
+ modifytimestamp_format = conf.get_raw(
+ 'ldap',
+ 'modifytimestamp_format',
+ default="%Y%m%d%H%M%SZ"
+ ).replace('%%', '%')
self.last_change = datetime.datetime.strptime(
last_change,
- modifytimestamp_format
- )
+ modifytimestamp_format
+ )
##
## Tables
@@ -148,9 +150,11 @@ def get_entry(domain, entry, update=True):
db.commit()
_entry = db.query(Entry).filter_by(uniqueid=_uniqueid).first()
else:
- modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format').replace('%%', '%')
- if modifytimestamp_format == None:
- modifytimestamp_format = "%Y%m%d%H%M%SZ"
+ modifytimestamp_format = conf.get_raw(
+ 'ldap',
+ 'modifytimestamp_format',
+ default="%Y%m%d%H%M%SZ"
+ ).replace('%%', '%')
if not _entry.last_change.strftime(modifytimestamp_format) == entry['modifytimestamp']:
log.debug(_("Updating timestamp for cache entry %r") % (_uniqueid), level=8)
@@ -198,9 +202,11 @@ def init_db(domain,reinit=False):
return db[domain]
def last_modify_timestamp(domain):
- modifytimestamp_format = conf.get_raw('ldap', 'modifytimestamp_format').replace('%%', '%')
- if modifytimestamp_format == None:
- modifytimestamp_format = "%Y%m%d%H%M%SZ"
+ modifytimestamp_format = conf.get_raw(
+ 'ldap',
+ 'modifytimestamp_format',
+ "%Y%m%d%H%M%SZ"
+ ).replace('%%', '%')
try:
db = init_db(domain)
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py
index c5ed1d5..9ea503b 100644
--- a/pykolab/conf/__init__.py
+++ b/pykolab/conf/__init__.py
@@ -505,13 +505,15 @@ class Conf(object):
return values
- def get_raw(self, section, key):
+ def get_raw(self, section, key, default=None):
if not self.cfg_parser:
self.read_config()
if self.cfg_parser.has_option(section, key):
return self.cfg_parser.get(section,key, 1)
+ return default
+
def get(self, section, key, quiet=False):
"""
Get a configuration option from our store, the configuration file,