Patch to replace tuple() with tuple([])

Peter Hawkins peter at hawkins.emu.id.au
Fri Apr 11 13:23:19 CEST 2003


Hi...

Attached is a patch against 2.0.0pre07 which replaces instances of tuple()
with tuple([]). This is necessary since tuple() is not valid under
python 2.1.

For example, under python 2.1:

 >>> print tuple()
 Traceback (most recent call last):
   File "<stdin>", line 1, in ?
 TypeError: tuple() takes exactly 1 argument (0 given)
 >>> print tuple([])
 ()
 >>>

Under python 2.2:

 >>> print tuple()
 ()
 >>> print tuple([])
 ()
 >>>


Could you please apply this? I realise that you may think python 2.1 is
old/deprecated, but it seems like not much work is required to keep it
functional for a little bit longer (ideally, I'd like it to work until
the next debian release).

=)
Peter
-------------- next part --------------
diff -urN Lib.old/ldap/schema/models.py Lib/ldap/schema/models.py
--- Lib.old/ldap/schema/models.py	2003-04-11 21:17:07.000000000 +1000
+++ Lib/ldap/schema/models.py	2003-04-11 21:17:26.000000000 +1000
@@ -57,7 +57,7 @@
       return ''
 
   def key_list(self,key,values,sep=' ',quoted=0):
-    assert type(values)==type(tuple()),TypeError("values has to be of ListType")
+    assert type(values)==type(tuple([])),TypeError("values has to be of ListType")
     if not values:
       return ''
     if quoted:
@@ -91,14 +91,14 @@
   """
   schema_attribute = 'objectClasses'
   token_defaults = {
-    'NAME':tuple(),
+    'NAME':tuple([]),
     'DESC':(None,),
     'OBSOLETE':None,
-    'SUP':tuple(),
+    'SUP':tuple([]),
     'STRUCTURAL':None,
     'AUXILIARY':None,
     'ABSTRACT':None,
-    'MUST':tuple(),
+    'MUST':tuple([]),
     'MAY':()
   }
 
@@ -115,13 +115,13 @@
       self.kind = 1
     elif d['AUXILIARY']!=None:
       self.kind = 2
-    assert type(self.names)==type(tuple())
+    assert type(self.names)==type(tuple([]))
     assert self.desc is None or type(self.desc)==type('')
     assert type(self.obsolete)==type(0) and (self.obsolete==0 or self.obsolete==1)
-    assert type(self.sup)==type(tuple())
+    assert type(self.sup)==type(tuple([]))
     assert type(self.kind)==type(0)
-    assert type(self.must)==type(tuple())
-    assert type(self.may)==type(tuple())
+    assert type(self.must)==type(tuple([]))
+    assert type(self.may)==type(tuple([]))
     return # ObjectClass.__init__()
 
   def __str__(self):
@@ -172,10 +172,10 @@
   """
   schema_attribute = 'attributeTypes'
   token_defaults = {
-    'NAME':tuple(),
+    'NAME':tuple([]),
     'DESC':(None,),
     'OBSOLETE':None,
-    'SUP':tuple(),
+    'SUP':tuple([]),
     'EQUALITY':(None,),
     'ORDERING':(None,),
     'SUBSTR':(None,),
@@ -217,9 +217,9 @@
     except KeyError:
       raise
     self.usage = AttributeUsage.get(d['USAGE'][0],0)
-    assert type(self.names)==type(tuple())
+    assert type(self.names)==type(tuple([]))
     assert self.desc is None or type(self.desc)==type('')
-    assert type(self.sup)==type(tuple()),'attribute sup has type %s' % (type(self.sup))
+    assert type(self.sup)==type(tuple([])),'attribute sup has type %s' % (type(self.sup))
     assert type(self.obsolete)==type(0) and (self.obsolete==0 or self.obsolete==1)
     assert type(self.single_value)==type(0) and (self.single_value==0 or self.single_value==1)
     assert type(self.no_user_mod)==type(0) and (self.no_user_mod==0 or self.no_user_mod==1)
@@ -295,7 +295,7 @@
   """
   schema_attribute = 'matchingRules'
   token_defaults = {
-    'NAME':tuple(),
+    'NAME':tuple([]),
     'DESC':(None,),
     'OBSOLETE':None,
     'SYNTAX':(None,),
@@ -306,7 +306,7 @@
     self.desc = d['DESC'][0]
     self.obsolete = d['OBSOLETE']!=None
     self.syntax = d['SYNTAX'][0]
-    assert type(self.names)==type(tuple())
+    assert type(self.names)==type(tuple([]))
     assert self.desc is None or type(self.desc)==type('')
     assert type(self.obsolete)==type(0) and (self.obsolete==0 or self.obsolete==1)
     assert self.syntax is None or type(self.syntax)==type('')
@@ -334,10 +334,10 @@
   """
   schema_attribute = 'matchingRuleUse'
   token_defaults = {
-       'NAME':tuple(),
+       'NAME':tuple([]),
        'DESC':(None,),
        'OBSOLETE':None,
-       'APPLIES':tuple(),
+       'APPLIES':tuple([]),
   }
 
   def _set_attrs(self,l,d):
@@ -345,10 +345,10 @@
     self.desc = d['DESC'][0]
     self.obsolete = d['OBSOLETE']!=None
     self.applies = d['APPLIES']
-    assert type(self.names)==type(tuple())
+    assert type(self.names)==type(tuple([]))
     assert self.desc is None or type(self.desc)==type('')
     assert type(self.obsolete)==type(0) and (self.obsolete==0 or self.obsolete==1)
-    assert type(self.applies)==type(tuple())
+    assert type(self.applies)==type(tuple([]))
     return # MatchingRuleUse.__init__()
 
   def __str__(self):
diff -urN Lib.old/ldap/schema/tokenizer.py Lib/ldap/schema/tokenizer.py
--- Lib.old/ldap/schema/tokenizer.py	2003-04-11 21:17:07.000000000 +1000
+++ Lib/ldap/schema/tokenizer.py	2003-04-11 21:17:45.000000000 +1000
@@ -66,7 +66,7 @@
       if i<l_len:
         if result_has_key(l[i]):
           # non-valued
-          result[token] = tuple()
+          result[token] = tuple([])
         elif l[i]=="(":
           # multi-valued
           i += 1 # Consume left parentheses


More information about the python-ldap mailing list