As Nathaniel found while implementing OTP, weird super() calls in get_args make it difficult to customize the get_args behavior in LDAP CRUD methods.

This patch makes the super() calls properly follow the inheritance chain.


I've sent a previous version of the patch, which only corrected one occurrence to the problem, to Nathaniel's thread: http://www.redhat.com/archives/freeipa-devel/2013-October/msg00020.html


--
PetrĀ³

~ "if you need to add a pylint exception for it, it might be a bad idea"
From 11b3cdfc113ada64d0b64dd184caf771b29ac041 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Wed, 2 Oct 2013 15:16:38 +0200
Subject: [PATCH] Use correct super-calls in get_args() methods

The get_args methods in ipalib.crud and ipalib.plugins.baseldap used
super() calls that skipped some of the classes in the inheritance
chain, and contained code that reimplemented some of the skipped
functionality.
This made it difficult to customize the get_args behavior.

Use proper super() calls.
---
 ipalib/crud.py             | 15 +++++++++++++--
 ipalib/plugins/baseldap.py | 30 ++++++++----------------------
 2 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/ipalib/crud.py b/ipalib/crud.py
index d54b91fd7a927dda363f983d68fe732616663a82..72ea142da74e2f088bda36a06653f9e201f5dcc8 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -120,7 +120,10 @@ class created them for us:
 """
 
 from frontend import Method, Object
-import backend, frontend, parameters, output
+import backend
+import parameters
+import output
+from ipalib.text import _
 
 
 class Create(Method):
@@ -133,6 +136,8 @@ class Create(Method):
     def get_args(self):
         if self.obj.primary_key:
             yield self.obj.primary_key.clone(attribute=True)
+        for arg in super(Create, self).get_args():
+            yield arg
 
     def get_options(self):
         if self.extra_options_first:
@@ -164,6 +169,8 @@ def get_args(self):
             # Don't enforce rules on the primary key so we can reference
             # any stored entry, legal or not
             yield self.obj.primary_key.clone(attribute=True, query=True)
+        for arg in super(PKQuery, self).get_args():
+            yield arg
 
 
 class Retrieve(PKQuery):
@@ -230,7 +237,11 @@ class Search(Method):
     has_output = output.standard_list_of_entries
 
     def get_args(self):
-        yield parameters.Str('criteria?', noextrawhitespace=False)
+        yield parameters.Str(
+            'criteria?', noextrawhitespace=False,
+            doc=_('A string searched in all relevant object attributes'))
+        for arg in super(Search, self).get_args():
+            yield arg
 
     def get_options(self):
         if self.extra_options_first:
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 4a79502708c358dd20ede017037b16f691b76766..6d734d0254917fc8b7931690c9f6324760d1b7ac 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -991,12 +991,9 @@ class LDAPCreate(BaseLDAPCommand, crud.Create):
     takes_options = (BaseLDAPCommand.setattr_option, BaseLDAPCommand.addattr_option)
 
     def get_args(self):
-        #pylint: disable=E1003
         for key in self.obj.get_ancestor_primary_keys():
             yield key
-        if self.obj.primary_key:
-            yield self.obj.primary_key.clone(attribute=True)
-        for arg in super(crud.Create, self).get_args():
+        for arg in super(LDAPCreate, self).get_args():
             yield arg
 
     has_output_params = global_output_params
@@ -1135,12 +1132,9 @@ class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
     Base class for commands that need to retrieve an existing entry.
     """
     def get_args(self):
-        #pylint: disable=E1003
         for key in self.obj.get_ancestor_primary_keys():
             yield key
-        if self.obj.primary_key:
-            yield self.obj.primary_key.clone(attribute=True, query=True)
-        for arg in super(crud.PKQuery, self).get_args():
+        for arg in super(LDAPQuery, self).get_args():
             yield arg
 
     # list of attributes we want exported to JSON
@@ -1167,15 +1161,11 @@ class LDAPMultiQuery(LDAPQuery):
     )
 
     def get_args(self):
-        #pylint: disable=E1003
-        for key in self.obj.get_ancestor_primary_keys():
-            yield key
-        if self.obj.primary_key:
-            yield self.obj.primary_key.clone(
-                attribute=True, query=True, multivalue=True
-            )
-        for arg in super(crud.PKQuery, self).get_args():
-            yield arg
+        for arg in super(LDAPMultiQuery, self).get_args():
+            if self.obj.primary_key and arg.name == self.obj.primary_key.name:
+                yield arg.clone(multivalue=True)
+            else:
+                yield arg
 
 
 class LDAPRetrieve(LDAPQuery):
@@ -1758,13 +1748,9 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
     )
 
     def get_args(self):
-        #pylint: disable=E1003
         for key in self.obj.get_ancestor_primary_keys():
             yield key
-        yield Str('criteria?',
-                  noextrawhitespace=False,
-                  doc=_('A string searched in all relevant object attributes'))
-        for arg in super(crud.Search, self).get_args():
+        for arg in super(LDAPSearch, self).get_args():
             yield arg
 
     def get_member_options(self, attr):
-- 
1.8.3.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to