Martin von Löwis avatar Martin von Löwis committed ed3cd06

Replace BeautifulSoup with htmllib.
Replace setuptools with distutils.

Comments (0)

Files changed (4)

-include testapp.py
+include MANIFEST.in testapp.py
+recursive-include doc *
 * Specify that response parameters are always literal QUERY_STRINGs;
   parse_qs results are still supported for compatibility.
 * Split test application into separate file testapp.py
+* Drop BeautifulSoup dependency, drop setuptools usage
 
 1.2 (2010-07-02):
 
 # This library implements OpenID Authentication 2.0,
 # in the role of a relying party
 
-import urlparse, urllib, httplib, BeautifulSoup, time, cgi
+import urlparse, urllib, httplib, time, cgi, htmllib, formatter
 import cStringIO, base64, hmac, hashlib, datetime, re, random
 import itertools, cPickle, sys
 
         res[k] = v
     return res
 
+class OpenIDParser(htmllib.HTMLParser):
+    def __init__(self):
+        htmllib.HTMLParser.__init__(self, formatter.NullFormatter())
+        self.links = {}
+        self.xrds_location=None
+
+    def do_link(self, attrs):
+        attrs = dict(attrs)
+        self.links[attrs['rel']] = attrs['href']
+
+    def do_meta(self, attrs):
+        attrs = dict(attrs)
+        # Yadis 6.2.5 option 1: meta tag
+        if attrs['http-equiv'].lower() == 'x-xrds-location':
+            self.xrds_location = attrs['content']
+
 def discover(url):
     '''Perform service discovery on the OP URL.
     Return list of service types, and the auth/2.0 URL,
         return discover(xrds_loc)
 
     if content_type in ('text/html', 'application/xhtml+xml'):
-        soup = BeautifulSoup.BeautifulSoup(data)
+        parser = OpenIDParser()
+        parser.feed(data)
+        parser.close()
         # Yadis 6.2.5 option 1: meta tag
-        meta = soup.find('meta', {'http-equiv':lambda v:v and v.lower()=='x-xrds-location'})
-        if meta:
-            xrds_loc = meta['content']
-            return discover(xrds_loc)
+        if parser.xrds_location:
+            return discover(parser.xrds_location)
         # OpenID 7.3.3: attempt html based discovery
-        op_endpoint = soup.find('link', {'rel':lambda v:v and 'openid2.provider' in v.lower()})
+        op_endpoint = parser.links.get('openid2.provider')
         if op_endpoint:
-            op_endpoint = op_endpoint['href']
-            op_local = soup.find('link', {'rel':lambda v:v and 'openid2.local_id' in v.lower()})
-            if op_local:
-                op_local = op_local['href']
-            else:
-                op_local = None
+            op_local = parser.links.get('openid2.local_id')
             return ['http://specs.openid.net/auth/2.0/signon'], op_endpoint, op_local
         # 14.2.1: 1.1 compatibility
-        op_endpoint = soup.find('link', {'rel':lambda v:v and 'openid.server' in v.lower()})
+        op_endpoint = parser.links.get('openid.server')
         if op_endpoint:
-            op_endpoint = op_endpoint['href']
-            op_local = soup.find('link', {'rel':lambda v:v and 'openid.delegate' in v.lower()})
-            if op_local:
-                op_local = op_local['href']
-            else:
-                op_local = None
+            op_local = parser.links.get('openid.delegate')
             return ['http://openid.net/signon/1.1'], op_endpoint, op_local
         # Discovery failed
         return None
 # -*- coding: utf-8 -*-
-try:
-    from setuptools import setup
-    is_setuptools = True
-except ImportError:
-    from distutils.core import setup
-    is_setuptools = False
-
-extra_args = {}
-if is_setuptools:
-    extra_args['install_requires'] = ['BeautifulSoup']
-
+from distutils.core import setup
 try:
     from distutils.command.build_py import build_py_2to3 as build_py
 except ImportError:
         ],
       py_modules=['openid2rp'],
       cmdclass = {'build_py': build_py},
-      **extra_args
       )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.