[Pypi-checkins] r980 - trunk/pypi
martin.von.loewis
python-checkins at python.org
Thu Sep 15 22:48:32 CEST 2011
Author: martin.von.loewis
Date: Thu Sep 15 22:48:31 2011
New Revision: 980
Modified:
trunk/pypi/config.py
trunk/pypi/standalone.py
trunk/pypi/webui.py
Log:
Enable /id URLs.
Modified: trunk/pypi/config.py
==============================================================================
--- trunk/pypi/config.py (original)
+++ trunk/pypi/config.py Thu Sep 15 22:48:31 2011
@@ -1,4 +1,5 @@
import ConfigParser
+from urlparse import urlsplit, urlunsplit
class Config:
''' Read in the config and set up the vars with the correct type.
@@ -26,6 +27,7 @@
self.adminemail = c.get('webui', 'adminemail')
self.replyto = c.get('webui', 'replyto')
self.url = c.get('webui', 'url')
+ self.scheme_host = urlunsplit(urlsplit(self.url)[:2]+('','',''))
self.orig_pydotorg = self.pydotorg = c.get('webui', 'pydotorg')
self.simple_script = c.get('webui', 'simple_script')
self.files_url = c.get('webui', 'files_url')
Modified: trunk/pypi/standalone.py
==============================================================================
--- trunk/pypi/standalone.py (original)
+++ trunk/pypi/standalone.py Thu Sep 15 22:48:31 2011
@@ -13,7 +13,8 @@
self.send_response(301)
self.send_header('Location', '/pypi')
return
- for scriptname in ('/mirrors', '/simple', '/pypi', '/serversig', '/daytime'):
+ for scriptname in ('/mirrors', '/simple', '/pypi',
+ '/serversig', '/daytime', '/id'):
if self.path.startswith(scriptname):
rest = self.path[len(scriptname):]
break
@@ -119,7 +120,7 @@
elif opt in ('-p', '--port'):
port = int(val)
if port:
- httpd = BaseHTTPServer.HTTPServer(('',8000), RequestHandler)
+ httpd = BaseHTTPServer.HTTPServer(('',port), RequestHandler)
httpd.serve_forever()
else:
StdinoutHandler(remote_user)
Modified: trunk/pypi/webui.py
==============================================================================
--- trunk/pypi/webui.py (original)
+++ trunk/pypi/webui.py Thu Sep 15 22:48:31 2011
@@ -463,6 +463,8 @@
return self.mirrors()
if script_name == '/daytime':
return self.daytime()
+ if script_name == '/id':
+ return self.run_id()
# see if the user has provided a username/password
auth = self.env.get('HTTP_CGI_AUTHORIZATION', '').strip()
@@ -563,8 +565,7 @@
password_reset role role_form list_classifiers login logout files
file_upload show_md5 doc_upload claim openid openid_return dropid
clear_auth addkey delkey lasthour json gae_file about delete_user
- rss_regen openid_discovery openid_endpoint openid_decide_post
- openid_user'''.split():
+ rss_regen openid_endpoint openid_decide_post'''.split():
getattr(self, action)()
else:
#raise NotFound, 'Unknown action %s' % action
@@ -710,6 +711,13 @@
self.handler.end_headers()
self.wfile.write(sig)
+ def run_id(self):
+ path = self.env.get('PATH_INFO')
+ if not path:
+ return self.openid_discovery()
+ else:
+ return self.openid_user(path)
+
def home(self, nav_current='home'):
self.write_template('home.pt', title='PyPI - the Python Package Index')
@@ -2963,7 +2971,7 @@
self.handler.end_headers()
self.handler.wfile.write(payload)
- def openid_user(self):
+ def openid_user(self, user):
"""Return an XRDS document containing an OpenID provider endpoint URL."""
payload = '''<xrds:XRDS
xmlns:xrds="xri://$xrds"
@@ -3015,7 +3023,7 @@
"""
if not self.authenticated:
self.write_template('openid_notloggedin.pt',
- title="OpenId landing page")
+ title="OpenID login attempt")
return
if orequest.identity == "http://specs.openid.net/auth/2.0/identifier_select":
@@ -3084,8 +3092,10 @@
return False
if identity == 'http://specs.openid.net/auth/2.0/identifier_select':
return False
- qs = urlparse.urlparse(identity).query
- username = urlparse.parse_qs(qs).get("username",[None])[0]
+ id_prefix = self.config.scheme_host + "/id/"
+ if not identity.startswith(id_prefix):
+ return False
+ username = identity[len(id_prefix):]
if username == self.username:
if self.store.check_openid_trustedroot(self.username, orequest.trust_root):
return True
@@ -3097,7 +3107,7 @@
def openid_user_url(self):
if self.authenticated:
- return "%s?:action=openid_user&username=%s" % (self.config.url, self.username)
+ return "%s/id/%s" % (self.config.scheme_host, self.username)
else:
return None
More information about the Pypi-checkins
mailing list