Commit 8efdc1ac authored by Nicolas Delaby's avatar Nicolas Delaby

Use replace hasattr by getattr, force reconnection when loosed

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18945 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ac2a4cf1
No related merge requests found
...@@ -261,8 +261,7 @@ class LDAPMethod(Aqueduct.BaseQuery, ...@@ -261,8 +261,7 @@ class LDAPMethod(Aqueduct.BaseQuery,
def _connection(self): def _connection(self):
' return actual ZLDAP Connection Object ' ' return actual ZLDAP Connection Object '
if hasattr(self,'connection_id') and hasattr(self,self.connection_id): return getattr(self, self.connection_id, None)
return getattr(self, self.connection_id)
def _getConn(self): def _getConn(self):
return self._connection().GetConnection() return self._connection().GetConnection()
...@@ -316,13 +315,13 @@ class LDAPMethod(Aqueduct.BaseQuery, ...@@ -316,13 +315,13 @@ class LDAPMethod(Aqueduct.BaseQuery,
if REQUEST is None: if REQUEST is None:
if kw: REQUEST = kw if kw: REQUEST = kw
else: else:
if hasattr(self, 'REQUEST'): REQUEST=self.REQUEST if getattr(self, 'REQUEST', None) is not None: REQUEST=self.REQUEST
else: REQUEST={} else: REQUEST={}
c = self._getConn() c = self._getConn()
if not c: if not c:
raise "LDAPError", "LDAP Connection not open" raise "LDAPError", "LDAP Connection not open"
if hasattr(self, 'aq_parent'): if getattr(self, 'aq_parent', None) is not None:
p = self.aq_parent p = self.aq_parent
else: p = None else: p = None
...@@ -497,6 +496,19 @@ class LDIFMethod(LDAPMethod): ...@@ -497,6 +496,19 @@ class LDIFMethod(LDAPMethod):
l = ERP5LDIFRecordList(file) l = ERP5LDIFRecordList(file)
l.parse() l.parse()
res = l.all_records res = l.all_records
def delete(c, dn):
try:
c.delete_s(dn)
except ldap.NO_SUCH_OBJECT:
pass
def add(c, dn, mod_list):
try:
c.add_s(dn, mod_list)
except ldap.ALREADY_EXISTS:
pass
for record in res: for record in res:
dn = record[0] dn = record[0]
entry = record[1] entry = record[1]
...@@ -507,26 +519,20 @@ class LDIFMethod(LDAPMethod): ...@@ -507,26 +519,20 @@ class LDIFMethod(LDAPMethod):
tuple_list = entry[key] tuple_list = entry[key]
if key == 'delete': if key == 'delete':
try: try:
c.delete_s(dn) delete(c, dn)
except ldap.NO_SUCH_OBJECT: except ldap.SERVER_DOWN:
pass c = self._connection().GetConnection()
#LOG('LDIFMethod can\'t delete NO SUCH OBJECT',0,dn) delete(c, dn)
else: else:
for mod_tuple in tuple_list: for mod_tuple in tuple_list:
c.modify_s(dn, mod_tuple) c.modify_s(dn, mod_tuple)
else: else:
mod_list = modlist.addModlist(entry) mod_list = modlist.addModlist(entry)
try: try:
c.add_s(dn, mod_list) add(c, dn, mod_list)
except ldap.ALREADY_EXISTS: except ldap.SERVER_DOWN:
pass c = self._connection().GetConnection()
#LOG('LDIFMethod can\'t add, entry allready exists',0,dn) add(c, dn, mod_list)
#except ldap.SERVER_DOWN:
#c = self._connection().GetConnection()
#try:
#c.add_s(dn, mod_list)
#except ldap.ALREADY_EXISTS:
#pass
else: else:
LOG('LDIFMethod Type unknow',0,'') LOG('LDIFMethod Type unknow',0,'')
return res return res
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment