Skip to content

Commit baa046e

Browse files
committed
Indent s2repoze correctly
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 1e12f42 commit baa046e

File tree

5 files changed

+232
-207
lines changed

5 files changed

+232
-207
lines changed

src/saml2/s2repoze/plugins/challenge_decider.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,74 +9,78 @@
99
import re
1010

1111
_DAV_METHODS = (
12-
'OPTIONS',
13-
'PROPFIND',
14-
'PROPPATCH',
15-
'MKCOL',
16-
'LOCK',
17-
'UNLOCK',
18-
'TRACE',
19-
'DELETE',
20-
'COPY',
21-
'MOVE'
22-
)
12+
"OPTIONS",
13+
"PROPFIND",
14+
"PROPPATCH",
15+
"MKCOL",
16+
"LOCK",
17+
"UNLOCK",
18+
"TRACE",
19+
"DELETE",
20+
"COPY",
21+
"MOVE",
22+
)
2323

2424
_DAV_USERAGENTS = (
25-
'Microsoft Data Access Internet Publishing Provider',
26-
'WebDrive',
27-
'Zope External Editor',
28-
'WebDAVFS',
29-
'Goliath',
30-
'neon',
31-
'davlib',
32-
'wsAPI',
33-
'Microsoft-WebDAV'
34-
)
25+
"Microsoft Data Access Internet Publishing Provider",
26+
"WebDrive",
27+
"Zope External Editor",
28+
"WebDAVFS",
29+
"Goliath",
30+
"neon",
31+
"davlib",
32+
"wsAPI",
33+
"Microsoft-WebDAV",
34+
)
35+
3536

3637
def my_request_classifier(environ):
3738
""" Returns one of the classifiers 'dav', 'xmlpost', or 'browser',
3839
depending on the imperative logic below"""
3940
request_method = REQUEST_METHOD(environ)
4041
if request_method in _DAV_METHODS:
41-
return 'dav'
42+
return "dav"
4243
useragent = USER_AGENT(environ)
4344
if useragent:
4445
for agent in _DAV_USERAGENTS:
4546
if useragent.find(agent) != -1:
46-
return 'dav'
47-
if request_method == 'POST':
48-
if CONTENT_TYPE(environ) == 'text/xml':
49-
return 'xmlpost'
47+
return "dav"
48+
if request_method == "POST":
49+
if CONTENT_TYPE(environ) == "text/xml":
50+
return "xmlpost"
5051
elif CONTENT_TYPE(environ) == "application/soap+xml":
51-
return 'soap'
52-
return 'browser'
52+
return "soap"
53+
return "browser"
54+
5355

5456
zope.interface.directlyProvides(my_request_classifier, IRequestClassifier)
5557

58+
5659
class MyChallengeDecider:
5760
def __init__(self, path_login="", path_logout=""):
5861
self.path_login = path_login
5962
self.path_logout = path_logout
63+
6064
def __call__(self, environ, status, _headers):
61-
if status.startswith('401 '):
65+
if status.startswith("401 "):
6266
return True
6367
else:
64-
if environ.has_key('samlsp.pending'):
68+
if environ.has_key("samlsp.pending"):
6569
return True
6670

67-
uri = environ.get('REQUEST_URI', None)
71+
uri = environ.get("REQUEST_URI", None)
6872
if uri is None:
6973
uri = construct_url(environ)
7074

7175
# require and challenge for logout and inform the challenge plugin that it is a logout we want
7276
for regex in self.path_logout:
7377
if regex.match(uri) is not None:
74-
environ['samlsp.logout'] = True
78+
environ["samlsp.logout"] = True
7579
return True
7680

7781
# If the user is already authent, whatever happens(except logout),
7882
# don't make a challenge
79-
if environ.has_key('repoze.who.identity'):
83+
if environ.has_key("repoze.who.identity"):
8084
return False
8185

8286
# require a challenge for login
@@ -87,27 +91,24 @@ def __call__(self, environ, status, _headers):
8791
return False
8892

8993

90-
91-
def make_plugin(path_login = None, path_logout = None):
94+
def make_plugin(path_login=None, path_logout=None):
9295
if path_login is None:
93-
raise ValueError(
94-
'must include path_login in configuration')
96+
raise ValueError("must include path_login in configuration")
9597

96-
# make regexp out of string passed via the config file
98+
# make regexp out of string passed via the config file
9799
list_login = []
98100
for arg in path_login.splitlines():
99101
carg = arg.lstrip()
100-
if carg != '':
102+
if carg != "":
101103
list_login.append(re.compile(carg))
102104

103105
list_logout = []
104106
if path_logout is not None:
105107
for arg in path_logout.splitlines():
106108
carg = arg.lstrip()
107-
if carg != '':
109+
if carg != "":
108110
list_logout.append(re.compile(carg))
109111

110112
plugin = MyChallengeDecider(list_login, list_logout)
111113

112114
return plugin
113-

src/saml2/s2repoze/plugins/entitlement.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
from zope.interface import implements
55

6-
#from repoze.who.interfaces import IChallenger, IIdentifier, IAuthenticator
6+
# from repoze.who.interfaces import IChallenger, IIdentifier, IAuthenticator
77
from repoze.who.interfaces import IMetadataProvider
88

9+
910
class EntitlementMetadataProvider(object):
1011

1112
implements(IMetadataProvider)
@@ -43,7 +44,7 @@ def get_entitlement(self, user, virtualorg):
4344

4445
def store_entitlement(self, user, virtualorg, entitlement=None):
4546
if user not in self._store:
46-
self._store[user] = {"entitlement":{}}
47+
self._store[user] = {"entitlement": {}}
4748
elif "entitlement" not in self._store[user]:
4849
self._store[user]["entitlement"] = {}
4950

@@ -53,18 +54,17 @@ def store_entitlement(self, user, virtualorg, entitlement=None):
5354
self._store.sync()
5455

5556
def add_metadata(self, environ, identity):
56-
#logger = environ.get('repoze.who.logger','')
57+
# logger = environ.get('repoze.who.logger','')
5758
try:
58-
user = self._store[identity.get('repoze.who.userid')]
59+
user = self._store[identity.get("repoze.who.userid")]
5960
except KeyError:
6061
return
6162

6263
try:
6364
vorg = environ["myapp.vo"]
6465
try:
6566
ents = user["entitlement"][vorg]
66-
identity["user"] = {
67-
"entitlement": ["%s:%s" % (vorg,e) for e in ents]}
67+
identity["user"] = {"entitlement": ["%s:%s" % (vorg, e) for e in ents]}
6868
except KeyError:
6969
pass
7070
except KeyError:
@@ -73,5 +73,6 @@ def add_metadata(self, environ, identity):
7373
res.extend(["%s:%s" % (vorg, e) for e in ents])
7474
identity["user"] = res
7575

76+
7677
def make_plugin(filename, key_attribute=""):
7778
return EntitlementMetadataProvider(filename, key_attribute)

src/saml2/s2repoze/plugins/formswithhidden.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,26 @@
3737

3838
HIDDEN_PRE_LINE = """<input type=hidden name="%s" value="%s">"""
3939

40+
4041
class FormHiddenPlugin(FormPlugin):
4142

4243
implements(IChallenger, IIdentifier)
4344

4445
# IIdentifier
4546
def identify(self, environ):
46-
logger = environ.get('repoze.who.logger','')
47+
logger = environ.get("repoze.who.logger", "")
4748
logger.info("formplugin identify")
48-
#logger and logger.info("environ keys: %s", environ.keys())
49+
# logger and logger.info("environ keys: %s", environ.keys())
4950
query = parse_dict_querystring(environ)
5051
# If the extractor finds a special query string on any request,
5152
# it will attempt to find the values in the input body.
5253
if query.get(self.login_form_qs):
5354
form = parse_formvars(environ)
5455
from StringIO import StringIO
56+
5557
# we need to replace wsgi.input because we've read it
5658
# this smells funny
57-
environ['wsgi.input'] = StringIO()
59+
environ["wsgi.input"] = StringIO()
5860
form.update(query)
5961
qinfo = {}
6062
for key, val in form.items():
@@ -63,32 +65,31 @@ def identify(self, environ):
6365
if qinfo:
6466
environ["s2repoze.qinfo"] = qinfo
6567
try:
66-
login = form['login']
67-
password = form['password']
68+
login = form["login"]
69+
password = form["password"]
6870
except KeyError:
6971
return None
7072
del query[self.login_form_qs]
7173
query.update(qinfo)
72-
environ['QUERY_STRING'] = urllib.urlencode(query)
73-
environ['repoze.who.application'] = HTTPFound(
74-
construct_url(environ))
75-
credentials = {'login':login, 'password':password}
76-
max_age = form.get('max_age', None)
74+
environ["QUERY_STRING"] = urllib.urlencode(query)
75+
environ["repoze.who.application"] = HTTPFound(construct_url(environ))
76+
credentials = {"login": login, "password": password}
77+
max_age = form.get("max_age", None)
7778
if max_age is not None:
78-
credentials['max_age'] = max_age
79+
credentials["max_age"] = max_age
7980
return credentials
8081

8182
return None
8283

8384
# IChallenger
8485
def challenge(self, environ, status, app_headers, forget_headers):
85-
logger = environ.get('repoze.who.logger','')
86+
logger = environ.get("repoze.who.logger", "")
8687
logger.info("formplugin challenge")
8788
if app_headers:
8889
location = LOCATION(app_headers)
8990
if location:
9091
headers = list(app_headers) + list(forget_headers)
91-
return HTTPFound(headers = headers)
92+
return HTTPFound(headers=headers)
9293

9394
query = parse_dict_querystring(environ)
9495
hidden = []
@@ -101,23 +102,24 @@ def challenge(self, environ, status, app_headers, forget_headers):
101102

102103
if self.formcallable is not None:
103104
form = self.formcallable(environ)
105+
104106
def auth_form(environ, start_response):
105107
content_length = CONTENT_LENGTH.tuples(str(len(form)))
106-
content_type = CONTENT_TYPE.tuples('text/html')
108+
content_type = CONTENT_TYPE.tuples("text/html")
107109
headers = content_length + content_type + forget_headers
108-
start_response('200 OK', headers)
110+
start_response("200 OK", headers)
109111
return [form]
110112

111113
return auth_form
112114

113115

114-
def make_plugin(login_form_qs='__do_login', rememberer_name=None, form=None):
116+
def make_plugin(login_form_qs="__do_login", rememberer_name=None, form=None):
115117
if rememberer_name is None:
116118
raise ValueError(
117-
'must include rememberer key (name of another IIdentifier plugin)')
119+
"must include rememberer key (name of another IIdentifier plugin)"
120+
)
118121
if form is not None:
119-
with open(form, 'r') as f:
122+
with open(form, "r") as f:
120123
form = f.read()
121124
plugin = FormHiddenPlugin(login_form_qs, rememberer_name, form)
122125
return plugin
123-

src/saml2/s2repoze/plugins/ini.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
from zope.interface import implements
44

5-
#from repoze.who.interfaces import IChallenger, IIdentifier, IAuthenticator
5+
# from repoze.who.interfaces import IChallenger, IIdentifier, IAuthenticator
66
from repoze.who.interfaces import IMetadataProvider
77

8+
89
class INIMetadataProvider(object):
910

1011
implements(IMetadataProvider)
@@ -16,9 +17,9 @@ def __init__(self, ini_file, key_attribute):
1617
self.key_attribute = key_attribute
1718

1819
def add_metadata(self, _environ, identity):
19-
#logger = environ.get('repoze.who.logger','')
20+
# logger = environ.get('repoze.who.logger','')
2021

21-
key = identity.get('repoze.who.userid')
22+
key = identity.get("repoze.who.userid")
2223
try:
2324
if self.key_attribute:
2425
for sec in self.users.sections():
@@ -31,5 +32,6 @@ def add_metadata(self, _environ, identity):
3132
except ValueError:
3233
pass
3334

35+
3436
def make_plugin(ini_file, key_attribute=""):
3537
return INIMetadataProvider(ini_file, key_attribute)

0 commit comments

Comments
 (0)