Skip to content

Commit 13fdda5

Browse files
author
Roland Hedberg
committed
PEP-8
1 parent 095f8db commit 13fdda5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+456
-449
lines changed

src/s2repoze/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# -*- coding: utf-8 -*-
2-
# Created by Roland Hedberg
2+
# Created by Roland Hedberg

src/s2repoze/plugins/challenge_decider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from paste.httpheaders import CONTENT_TYPE
77
from paste.httpheaders import USER_AGENT
88

9-
import re
9+
import re
1010

1111
_DAV_METHODS = (
1212
'OPTIONS',
@@ -74,9 +74,9 @@ def __call__(self, environ, status, _headers):
7474
environ['samlsp.logout'] = True
7575
return True
7676

77-
# If the user is already authent, whatever happens(except logout),
77+
# If the user is already authent, whatever happens(except logout),
7878
# don't make a challenge
79-
if environ.has_key('repoze.who.identity'):
79+
if environ.has_key('repoze.who.identity'):
8080
return False
8181

8282
# require a challenge for login

src/s2repoze/plugins/entitlement.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
from repoze.who.interfaces import IMetadataProvider
88

99
class EntitlementMetadataProvider(object):
10-
10+
1111
implements(IMetadataProvider)
12-
12+
1313
def __init__(self, filename, key_attribute):
1414
# Means I have to do explicit syncs on writes, but also
1515
# that it's faster on reads since it will cache data
1616
self._store = shelve.open(filename, writeback=True)
1717
self.key_attribute = key_attribute
18-
18+
1919
def keys(self):
2020
return self._store.keys()
21-
21+
2222
def get(self, user, attribute):
2323
return self._store[user][attribute]
2424

@@ -28,19 +28,19 @@ def set(self, user, attribute, value):
2828

2929
self._store[user][attribute] = value
3030
self._store.sync()
31-
31+
3232
def part_of(self, user, virtualorg):
3333
if virtualorg in self._store[user]["entitlement"]:
3434
return True
3535
else:
3636
return False
37-
37+
3838
def get_entitlement(self, user, virtualorg):
3939
try:
4040
return self._store[user]["entitlement"][virtualorg]
4141
except KeyError:
4242
return []
43-
43+
4444
def store_entitlement(self, user, virtualorg, entitlement=None):
4545
if user not in self._store:
4646
self._store[user] = {"entitlement":{}}
@@ -51,14 +51,14 @@ def store_entitlement(self, user, virtualorg, entitlement=None):
5151
entitlement = []
5252
self._store[user]["entitlement"][virtualorg] = entitlement
5353
self._store.sync()
54-
54+
5555
def add_metadata(self, environ, identity):
5656
#logger = environ.get('repoze.who.logger','')
5757
try:
5858
user = self._store[identity.get('repoze.who.userid')]
5959
except KeyError:
6060
return
61-
61+
6262
try:
6363
vorg = environ["myapp.vo"]
6464
try:
@@ -72,6 +72,6 @@ def add_metadata(self, environ, identity):
7272
for vorg, ents in user["entitlement"].items():
7373
res.extend(["%s:%s" % (vorg, e) for e in ents])
7474
identity["user"] = res
75-
75+
7676
def make_plugin(filename, key_attribute=""):
7777
return EntitlementMetadataProvider(filename, key_attribute)

src/s2repoze/plugins/formswithhidden.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
class FormHiddenPlugin(FormPlugin):
4141

4242
implements(IChallenger, IIdentifier)
43-
43+
4444
# IIdentifier
4545
def identify(self, environ):
4646
logger = environ.get('repoze.who.logger','')
@@ -49,7 +49,7 @@ def identify(self, environ):
4949
query = parse_dict_querystring(environ)
5050
# If the extractor finds a special query string on any request,
5151
# it will attempt to find the values in the input body.
52-
if query.get(self.login_form_qs):
52+
if query.get(self.login_form_qs):
5353
form = parse_formvars(environ)
5454
from StringIO import StringIO
5555
# we need to replace wsgi.input because we've read it
@@ -89,7 +89,7 @@ def challenge(self, environ, status, app_headers, forget_headers):
8989
if location:
9090
headers = list(app_headers) + list(forget_headers)
9191
return HTTPFound(headers = headers)
92-
92+
9393
query = parse_dict_querystring(environ)
9494
hidden = []
9595
for key, val in query.items():
@@ -98,7 +98,7 @@ def challenge(self, environ, status, app_headers, forget_headers):
9898
logger.info("hidden: %s" % (hidden,))
9999
form = self.formbody or _DEFAULT_FORM
100100
form = form % "\n".join(hidden)
101-
101+
102102
if self.formcallable is not None:
103103
form = self.formcallable(environ)
104104
def auth_form(environ, start_response):

src/s2repoze/plugins/ini.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from repoze.who.interfaces import IMetadataProvider
77

88
class INIMetadataProvider(object):
9-
9+
1010
implements(IMetadataProvider)
11-
11+
1212
def __init__(self, ini_file, key_attribute):
1313

1414
self.users = ConfigParser.ConfigParser()
1515
self.users.readfp(open(ini_file))
1616
self.key_attribute = key_attribute
17-
17+
1818
def add_metadata(self, _environ, identity):
1919
#logger = environ.get('repoze.who.logger','')
2020

@@ -30,6 +30,6 @@ def add_metadata(self, _environ, identity):
3030
identity["user"] = dict(self.users.items(key))
3131
except ValueError:
3232
pass
33-
33+
3434
def make_plugin(ini_file, key_attribute=""):
3535
return INIMetadataProvider(ini_file, key_attribute)

src/s2repoze/plugins/sp.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from saml2.config import config_factory
4141
from saml2.profile import paos
4242

43-
#from saml2.population import Population
43+
# from saml2.population import Population
4444
#from saml2.attribute_resolver import AttributeResolver
4545

4646
logger = logging.getLogger(__name__)
@@ -58,6 +58,7 @@ def construct_came_from(environ):
5858
came_from += '?' + qstr
5959
return came_from
6060

61+
6162
def exception_trace(tag, exc, log):
6263
message = traceback.format_exception(*sys.exc_info())
6364
log.error("[%s] ExcList: %s" % (tag, "".join(message),))
@@ -79,12 +80,11 @@ def __call__(self, environ, start_response):
7980

8081

8182
class SAML2Plugin(object):
82-
8383
implements(IChallenger, IIdentifier, IAuthenticator, IMetadataProvider)
8484

8585
def __init__(self, rememberer_name, config, saml_client, wayf, cache,
8686
sid_store=None, discovery="", idp_query_param="",
87-
sid_store_cert=None,):
87+
sid_store_cert=None, ):
8888
self.rememberer_name = rememberer_name
8989
self.wayf = wayf
9090
self.saml_client = saml_client
@@ -130,17 +130,20 @@ def _get_post(self, environ):
130130
:param environ: A dictionary with environment variables
131131
"""
132132

133-
body= ''
133+
body = ''
134134
try:
135-
length= int(environ.get('CONTENT_LENGTH', '0'))
135+
length = int(environ.get('CONTENT_LENGTH', '0'))
136136
except ValueError:
137-
length= 0
138-
if length!=0:
137+
length = 0
138+
if length != 0:
139139
body = environ['wsgi.input'].read(length) # get the POST variables
140-
environ['s2repoze.body'] = body # store the request body for later use by pysaml2
141-
environ['wsgi.input'] = StringIO(body) # restore the request body as a stream so that everything seems untouched
140+
environ[
141+
's2repoze.body'] = body # store the request body for later
142+
# use by pysaml2
143+
environ['wsgi.input'] = StringIO(body) # restore the request body
144+
# as a stream so that everything seems untouched
142145

143-
post = parse_qs(body) # parse the POST fields into a dict
146+
post = parse_qs(body) # parse the POST fields into a dict
144147

145148
logger.debug('identify post: %s' % (post,))
146149

@@ -161,10 +164,11 @@ def _pick_idp(self, environ, came_from):
161164
"""
162165

163166
# check headers to see if it's an ECP request
164-
# headers = {
165-
# 'Accept' : 'text/html; application/vnd.paos+xml',
166-
# 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE, SERVICE)
167-
# }
167+
# headers = {
168+
# 'Accept' : 'text/html; application/vnd.paos+xml',
169+
# 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE,
170+
# SERVICE)
171+
# }
168172

169173
_cli = self.saml_client
170174

@@ -262,7 +266,6 @@ def challenge(self, environ, _status, _app_headers, _forget_headers):
262266

263267
_cli = self.saml_client
264268

265-
266269
if 'REMOTE_USER' in environ:
267270
name_id = decode(environ["REMOTE_USER"])
268271

@@ -360,7 +363,7 @@ def challenge(self, environ, _status, _app_headers, _forget_headers):
360363

361364
try:
362365
ret = _cli.config.getattr(
363-
"endpoints","sp")["discovery_response"][0][0]
366+
"endpoints", "sp")["discovery_response"][0][0]
364367
if (environ["PATH_INFO"]) in ret and ret.split(
365368
environ["PATH_INFO"])[1] == "":
366369
query = parse_qs(environ["QUERY_STRING"])
@@ -439,8 +442,10 @@ def identify(self, environ):
439442
#logger = environ.get('repoze.who.logger', '')
440443

441444
query = parse_dict_querystring(environ)
442-
if ("CONTENT_LENGTH" not in environ or not environ["CONTENT_LENGTH"]) and \
443-
"SAMLResponse" not in query and "SAMLRequest" not in query:
445+
if ("CONTENT_LENGTH" not in environ or not environ[
446+
"CONTENT_LENGTH"]) and \
447+
"SAMLResponse" not in query and "SAMLRequest" not in \
448+
query:
444449
logger.debug('[identify] get or empty post')
445450
return None
446451

@@ -483,6 +488,7 @@ def identify(self, environ):
483488
return {}
484489
except:
485490
import traceback
491+
486492
traceback.print_exc()
487493
elif "SAMLResponse" not in post:
488494
logger.info("[sp.identify] --- NOT SAMLResponse ---")
@@ -498,7 +504,8 @@ def identify(self, environ):
498504
#if self.debug:
499505
try:
500506
if logout:
501-
response = self.saml_client.parse_logout_request_response(
507+
response = \
508+
self.saml_client.parse_logout_request_response(
502509
post["SAMLResponse"][0], binding)
503510
if response:
504511
action = self.saml_client.handle_logout_response(
@@ -548,7 +555,8 @@ def add_metadata(self, environ, identity):
548555
name_id = identity['repoze.who.userid']
549556
if isinstance(name_id, basestring):
550557
try:
551-
# Make sure that userids authenticated by another plugin don't cause problems here.
558+
# Make sure that userids authenticated by another plugin
559+
# don't cause problems here.
552560
name_id = decode(name_id)
553561
except:
554562
pass
@@ -602,7 +610,9 @@ def _service_url(environ, qstr=None):
602610
#noinspection PyUnusedLocal
603611
def authenticate(self, environ, identity=None):
604612
if identity:
605-
if identity.get('user') and environ.get('s2repoze.sessioninfo') and identity.get('user') == environ.get('s2repoze.sessioninfo').get('ava'):
613+
if identity.get('user') and environ.get(
614+
's2repoze.sessioninfo') and identity.get(
615+
'user') == environ.get('s2repoze.sessioninfo').get('ava'):
606616
return identity.get('login')
607617
tktuser = identity.get('repoze.who.plugins.auth_tkt.userid', None)
608618
if tktuser and self.saml_client.is_logged_in(decode(tktuser)):
@@ -634,8 +644,7 @@ def make_plugin(remember_name=None, # plugin for remember
634644
identity_cache="",
635645
discovery="",
636646
idp_query_param=""
637-
):
638-
647+
):
639648
if saml_conf is "":
640649
raise ValueError(
641650
'must include saml_conf in configuration')

0 commit comments

Comments
 (0)