You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2006/10/27 02:18:08 UTC

svn commit: r468203 - /httpd/mod_python/trunk/lib/python/mod_python/util.py

Author: grahamd
Date: Thu Oct 26 17:18:08 2006
New Revision: 468203

URL: http://svn.apache.org/viewvc?view=rev&rev=468203
Log:
(MODPYTHON-93) Restored a level of backward compatibility for third party
packages which create instances of the Field class directly and insert them
direct into the list of form fields. This should mean that older versions
of Trac will still work.


Modified:
    httpd/mod_python/trunk/lib/python/mod_python/util.py

Modified: httpd/mod_python/trunk/lib/python/mod_python/util.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/trunk/lib/python/mod_python/util.py?view=diff&rev=468203&r1=468202&r2=468203
==============================================================================
--- httpd/mod_python/trunk/lib/python/mod_python/util.py (original)
+++ httpd/mod_python/trunk/lib/python/mod_python/util.py Thu Oct 26 17:18:08 2006
@@ -48,8 +48,38 @@
 """
 
 class Field:
-    def __init__(self, name):
+    def __init__(self, name, *args, **kwargs):
         self.name = name
+
+	# Some third party packages such as Trac create
+	# instances of the Field object and insert it
+	# directly into the list of form fields. To
+	# maintain backward compatibility check for
+	# where more than just a field name is supplied
+	# and invoke an additional initialisation step
+        # to process the arguments. Ideally, third party
+        # code should use the add_field() method of the
+        # form, but if they need to maintain backward
+        # compatibility with older versions of mod_python
+        # they will not have a choice but to use old
+        # way of doing things and thus we need this code
+        # for the forseeable future to cope with that.
+
+        if not args or not kwargs:
+            self.__bc_init__(*args, **kwargs)
+
+    def __bc_init__(self, file, ctype, type_options,
+                    disp, disp_options, headers = {}):
+       self.file = file
+       self.type = ctype
+       self.type_options = type_options
+       self.disposition = disp
+       self.disposition_options = disp_options
+       if disp_options.has_key("filename"):
+           self.filename = disp_options["filename"]
+       else:
+           self.filename = None
+       self.headers = headers
 
     def __repr__(self):
         """Return printable representation."""