Hello guys,

Maybe some of you already know, we are trying to adapt our Spacewalk python's 
code to version 3.x and in the same time save backward compatibility with 
version 2.x. (we have to support Python from version 2.4). Pavel Studenik is 
adapting client-side code (rhncfg at this moment) and I server-side. The main 
question for me is to extract all version-dependent code into mini-library or 
check a version of python in if-clauses and try-except blocks within the code. 
Actually I've tried to extract code in a library, but actually, it contained 
only few functions and set of data-types and I removed it. 

How does it look likes now, for example:

import sys

try:
    PY3 = sys.version_info.major >= 3
except AttributeError:
    PY3 = False


.
.
.

if PY3:
    raise InvalidAction(str(pnf)).with_traceback(sys.exc_info()[2])
else:
    raise InvalidAction(str(pnf)), None, sys.exc_info()[2]


At the same moment I can adapt some data-types in the same try-block:

try:
    PY3 = sys.version_info.major >= 3
    import xmlrpc.client as xmlrpclib
except AttributeError:
    PY3 = False
    import xmlrpclib

Honestly, I'm not happy with many of this 'if PY3:', and I would like to see 
clean and simple code. What advantages and disadvantages do you see for both of 
this cases? And If you have any questions you can ask me.

PS Yes, I know about 'six' module, but I'm not sure we will use it.

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to