Skip to content

Commit 4b6a0ce

Browse files
Fixing for python2
1 parent 87913a1 commit 4b6a0ce

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Pilot/proxyTools.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import sys
1010
import os
1111

12+
try:
13+
IsADirectoryError # pylint: disable=used-before-assignment
14+
except NameError:
15+
IsADirectoryError = OSError
1216

1317
try:
1418
from urllib.parse import urlencode
@@ -22,7 +26,7 @@
2226
VOMS_FQANS_OID = b"1.3.6.1.4.1.8005.100.100.4"
2327
VOMS_EXTENSION_OID = b"1.3.6.1.4.1.8005.100.100.5"
2428

25-
RE_OPENSSL_ANS1_FORMAT = re.compile(rb"^\s*\d+:d=(\d+)\s+hl=")
29+
RE_OPENSSL_ANS1_FORMAT = re.compile(br"^\s*\d+:d=(\d+)\s+hl=")
2630

2731

2832
def parseASN1(data):
@@ -42,7 +46,7 @@ def findExtension(oid, lines):
4246

4347
def getVO(proxy_data):
4448

45-
chain = re.findall(rb"-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----", proxy_data, flags=re.DOTALL)
49+
chain = re.findall(br"-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----", proxy_data, flags=re.DOTALL)
4650
for cert in chain:
4751
proc = Popen(["openssl", "x509", "-outform", "der"], stdin=PIPE, stdout=PIPE)
4852
out, _ = proc.communicate(cert)
@@ -62,13 +66,13 @@ def getVO(proxy_data):
6266
if depth <= initial_depth:
6367
break
6468
# Look for a role, if it exists the VO is the first element
65-
match = re.search(rb"OCTET STRING\s+:/([a-zA-Z0-9]+)/Role=", line)
69+
match = re.search(br"OCTET STRING\s+:/([a-zA-Z0-9]+)/Role=", line)
6670
if match:
6771
return match.groups()[0].decode()
6872
raise NotImplementedError("Something went very wrong")
6973

7074

71-
class BaseConnectedRequest:
75+
class BaseConnectedRequest(object):
7276
"""This class helps supporting multiple kinds of requests that requires connections"""
7377

7478
def __init__(self, url, caPath, name="unknown"):
@@ -126,21 +130,21 @@ class TokenBasedRequest(BaseConnectedRequest):
126130
"""Connected Request with JWT support"""
127131

128132
def __init__(self, url, caPath, jwtData):
129-
super().__init__(url, caPath, "TokenBasedConnection")
133+
super(TokenBasedRequest, self).__init__(url, caPath, "TokenBasedConnection")
130134

131135
self.jwtData = jwtData
132136

133137
def executeRequest(self, raw_data, headers={"User-Agent": "Dirac Pilot [Unknown ID]"}):
134138
# Adds the JWT in the HTTP request (in the Bearer field)
135139
headers["Bearer"] = self.jwtData
136-
return super().executeRequest(raw_data, headers)
140+
return super(TokenBasedRequest, self).executeRequest(raw_data, headers)
137141

138142

139143
class X509BasedRequest(BaseConnectedRequest):
140144
"""Connected Request with X509 support"""
141145

142146
def __init__(self, url, caPath, certEnv):
143-
super().__init__(url, caPath, "X509BasedConnection")
147+
super(X509BasedRequest, self).__init__(url, caPath, "X509BasedConnection")
144148

145149
self.certEnv = certEnv
146150
self._hasExtraCredentials = False
@@ -158,4 +162,4 @@ def executeRequest(self, raw_data, headers={"User-Agent": "Dirac Pilot [Unknown
158162
# Adds a flag if the passed cert is a Directory
159163
if self._hasExtraCredentials:
160164
raw_data["extraCredentials"] = '"hosts"'
161-
return super().executeRequest(raw_data, headers)
165+
return super(X509BasedRequest, self).executeRequest(raw_data, headers)

0 commit comments

Comments
 (0)