chore(cas): make script both python2 and 3 compatible

This commit is contained in:
Hivert Quentin
2023-09-09 10:15:34 +02:00
parent f2df405616
commit 041bb98e9d

View File

@@ -33,9 +33,11 @@ import sys
config = { "cas-addr": "127.0.0.1",
"memcached-addrs": ["127.0.0.1:11211"] }
class CASProxyValidator:
def run(self):
if os.environ.has_key("GATEWAY_INTERFACE"):
if "GATEWAY_INTERFACE" in os.environ:
self._runAsCGI()
else:
self._runAsCmd()
@@ -71,17 +73,14 @@ class CASProxyValidator:
return rc
def _printCGIError(self, message, code = 403):
print("Status: %d\n"
"Content-Type: text/plain; charset=utf-8\n\n%s"
% (code, message))
print("Status: %d\nContent-Type: text/plain; charset=utf-8\n\n%s" % (code, message))
def _runAsCmd(self):
if len(sys.argv) == 3:
self._registerPGTIdAndIou(sys.argv[1], sys.argv[2])
print "set '%s' to '%s'" \
% ("cas-pgtiou:%s" % sys.argv[1], sys.argv[2])
print("set '%s' to '%s'" % ("cas-pgtiou:%s" % sys.argv[1], sys.argv[2]))
else:
raise Exception, "Missing or too many parameters."
raise Exception("Missing or too many parameters.")
def _registerPGTIdAndIou(self, pgtIou, pgtId):
mc = memcache.Client(config["memcached-addrs"])