[mod_python] Getting mod_python version

Michael S. Fischer michael at dynamine.net
Tue Dec 2 11:59:05 EST 2003


I agree that the code looks a little cleaner, but I still think it's 
less robust due to the phenomenon I described.

(Python also makes you use 'elif's instead of 'case' statements, and 
there's something to be said about the ugliness of the former as well. 
Eye of the beholder, I guess.)

Best,

--Michael

Michael C. Neel wrote:

> What if something changed every major version, 2 - 5?
> 
> with __version__ you could:
> 
> 	if m.__version__.startswidth('2.'):
> 		user = m.get2_user()
> 	elif m.__version__.startswidth('3.'):
> 		user = m.get3_user()
> 	elif m.__version__.startswidth('4.'):
> 		user = m.get4_user()
> 	elif m.__version__.startswidth('5.'):
> 		user = m.get5_user()
> 	else:
> 		#unsupported version
> 
> with try/except:
> 
> 	try:
> 		user = m.get2_user()
> 	except:
> 		try:
> 			user = m.get3_user()
> 		except:
> 			try:
> 				user = m.get4_user()
> 			except:
> 				try:
> 					user = m.get5_user()
> 				except:
> 					#unsupported version
> 
> I'm failing to see why it is supposed to be easier to code/easier to
> read with multiple try/except blocks, which are just going to get deeper
> as we go.
> 
> Mike
> 
> 
>>-----Original Message-----
>>From: Michael S. Fischer [mailto:michael at dynamine.net] 
>>Sent: Tuesday, December 02, 2003 2:41 PM
>>To: Michael C. Neel
>>Cc: Gustavo Córdova Avila; mod_python at modpython.org
>>Subject: Re: [mod_python] Getting mod_python version
>>
>>
>>Regardless of whether or not __version__ is implemented, 
>>using exception 
>>handling is more robust in the long run, I think.
>>
>>Forgetting to change the interface version number when a 
>>compatibility 
>>detail has changed is not an unknown phenomenon -- if not with 
>>mod_python, then certainly with other SDKs.
>>
>>--Michael
>>
>>Michael C. Neel wrote:
>>
>>
>>>Most modules have a __version__ member, and the help() 
>>
>>built-in method
>>
>>>even looks for this variable and uses it to display the 
>>
>>version of the
>>
>>>file:
>>>
>>>
>>>
>>>>>>import cgi
>>>>>>cgi.__version__
>>>
>>>'2.6'
>>>
>>>
>>>>>>help(cgi)
>>>
>>>...skipping...
>>>DATA
>>>    __all__ = ['MiniFieldStorage', 'FieldStorage', 
>>
>>'FormContentDict',
>>
>>>'SvF...
>>>    __version__ = '2.6'
>>>    logfile = ''
>>>    logfp = None
>>>    maxlen = 0
>>>
>>>VERSION
>>>    2.6
>>>
>>>
>>>
>>>I have not read or seen anything saying the "pythonic" way 
>>
>>of versioning
>>
>>>a module is by try/except blocks testing to see if variable 
>>
>>exist.  I
>>
>>>have however seen this from PEP 8:
>>>
>>>Version Bookkeeping
>>>
>>>    If you have to have RCS or CVS crud in your source 
>>
>>file, do it as
>>
>>>    follows.
>>>
>>>        __version__ = "$Revision: 1.20 $"
>>>        # $Source: 
>>
>>/cvsroot/python/python/nondist/peps/pep-0008.txt,v $
>>
>>>    These lines should be included after the module's docstring,
>>>    before any other code, separated by a blank line above and
>>>    below.
>>>
>>>Which implies to me that __version__ is a pythonic way of 
>>
>>versioning a
>>
>>>module/code file, though it doesn't seem to be as standard 
>>
>>as __doc__.
>>
>>>Mike
>>>
>>>
>>>
>>>>-----Original Message-----
>>>>From: Gustavo Córdova Avila [mailto:gustavo.cordova at q-voz.com] 
>>>>Sent: Tuesday, December 02, 2003 1:47 PM
>>>>To: Michael C. Neel
>>>>Cc: mod_python at modpython.org
>>>>Subject: Re: [mod_python] Getting mod_python version
>>>>
>>>>
>>>>This is the correct, "pythonic" way of doing things.
>>>>
>>>>I'd recommend using "except AttributeError:" instead of a naked 
>>>>"except:" btw.
>>>>
>>>>-gustavo
>>>>
>>>>Michael C. Neel wrote:
>>>>
>>>>
>>>>
>>>>>Hi all,
>>>>>
>>>>>	I don't know if it's not there, or I'm just overlooking it, but
>>>>>I can seem for a way in code to get the version of 
>>>>
>>>>mod_python.  I have
>>>>
>>>>
>>>>>some "default" modules I use, and I am trying to make them 
>>>>
>>>>work with any
>>>>
>>>>
>>>>>mod_python version.  Right now I'm doing try block, like such:
>>>>>
>>>>>  # Get username/password from client
>>>>>  pw = req.get_basic_auth_pw()
>>>>>  try:
>>>>>      # mod_python 2.x
>>>>>      user = req.connection.user
>>>>>  except:
>>>>>      # mod_python 3.x
>>>>>      user = req.user
>>>>>
>>>>>	...but I'd rather be able to get the version directly.
>>>>>
>>>>>Mike
>>>>>
>>>>>_______________________________________________
>>>>>Mod_python mailing list
>>>>>Mod_python at modpython.org
>>>>>http://mailman.modpython.org/mailman/listinfo/mod_python
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>_______________________________________________
>>>Mod_python mailing list
>>>Mod_python at modpython.org
>>>http://mailman.modpython.org/mailman/listinfo/mod_python
>>>
>>
>>
> 



More information about the Mod_python mailing list