99import 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
3637def 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
5456zope .interface .directlyProvides (my_request_classifier , IRequestClassifier )
5557
58+
5659class 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-
0 commit comments