SyntaxError: invalid syntax in mfs.cgi

520 views Asked by At

I run MooseFS CGI Server based on Python in my RedHat server, and I get an weird syntax error:

Traceback (most recent call last):
    File "/usr/sbin/mfscgiserv", line 300, in run_cgi
    execfile(self.file_name)
File "/usr/share/mfscgi/mfs.cgi", line 129
    return "%s%.1f%s" % (("~" if n != rn else ""),rn,s)
                            ^
SyntaxError: invalid syntax

It is just the right file downloaded from moosefs offical site, and I can't find any error about it. My python's version is 2.4.3.

2

There are 2 answers

2
Bakuriu On BEST ANSWER

As Abhijit already said you can't use the conditional expression in python<2.5, but you can work around this in two simple ways:

(r != rn and "~") or ""

Or:

"~" * (r != rn)

The first one is safe because "~" is considered True and thus if r != rn then it is guaranteed that the and will succeed and thus the or will not evaluate the second expression.

The second one uses the fact that a string multiplied by 1(or True) returns the string itself, while the string multiplied by 0(or False) returns ""(the empty string).


Edit: Since the error is generated by a file that is not in your control, you shouldn't modify its source code. The fact that the library uses Python's2.5 syntax simply means that it does not support Python 2.4.3 and you either have to change library or to upgrade your python installation.

Since python2.4.x was last released in the 2008, I think it'd a good idea to upgrade your python installation to python2.7.3. This should solve your problem and you'll get all the benefits of the newer version of python.

0
Abhijit On

The failing expression uses python conditional_expression, which was added in Python 2.5.

Your best bet is to upgrade to a supported Python Version