[Python-modules-commits] [python3-openid] 01/02: Import python3-openid_3.0.9.orig.tar.gz
Barry Warsaw
barry at moszumanska.debian.org
Tue Nov 10 02:53:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
barry pushed a commit to branch master
in repository python3-openid.
commit 17f415bf47331d83ae6e41ddd299a8721d1a8625
Author: Barry Warsaw <barry at python.org>
Date: Mon Nov 9 21:28:16 2015 -0500
Import python3-openid_3.0.9.orig.tar.gz
---
.gitignore | 8 -
.travis.yml | 10 --
CHANGES.md | 43 -----
PKG-INFO | 26 +++
README.md | 53 -------
admin/runtests | 39 +++--
contrib/upgrade-store-1.1-to-2.0 | 12 +-
...-store-1.1-to-2.0 => upgrade-store-1.1-to-2.0~} | 6 +-
dev-requirements.txt | 3 -
examples/README | 91 -----------
examples/djopenid/README | 54 -------
examples/djopenid/server/tests.py | 22 +--
examples/djopenid/settings.py | 1 +
examples/djopenid/util.py | 7 +-
openid/__init__.py | 2 +-
openid/fetchers.py | 2 +-
openid/oidutil.py | 30 +++-
openid/store/sqlstore.py | 37 ++---
openid/test/__init__.py | 4 +-
openid/test/storetest.py | 70 ++++----
openid/test/test_examples.py | 4 +-
openid/test/test_fetchers.py | 3 +-
openid/test/test_parsehtml.py | 3 -
openid/test/test_rpverify.py | 7 +
openid/yadis/etxrd.py | 26 +--
openid/yadis/parsehtml.py | 15 +-
pylintrc | 40 -----
python3_openid.egg-info/PKG-INFO | 26 +++
python3_openid.egg-info/SOURCES.txt | 176 +++++++++++++++++++++
python3_openid.egg-info/dependency_links.txt | 1 +
python3_openid.egg-info/requires.txt | 1 +
python3_openid.egg-info/top_level.txt | 1 +
run_tests.sh | 6 -
setup.cfg | 10 +-
setup.py | 5 +-
tox.ini | 14 --
36 files changed, 407 insertions(+), 451 deletions(-)
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 2425b0a..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-*~
-*.pyc
-*.swp
-.tox
-MANIFEST
-dist/
-.envrc
-.direnv
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index bdb9711..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,10 +0,0 @@
-language: python
-
-python:
- - 3.3
- - 3.2
-
-install:
- - pip install --use-mirrors Django==1.5
- - python setup.py install
-script: ./run_tests.sh
diff --git a/CHANGES.md b/CHANGES.md
deleted file mode 100644
index eb107a3..0000000
--- a/CHANGES.md
+++ /dev/null
@@ -1,43 +0,0 @@
-
-As of 3.0.0:
-
-* API changes
- * SQLStore implementations no longer create or use a 'settings'
- table
- * SRegResponse.fromSuccessResponse returns None when no signed
- arguments were found
- * Added functions to generate request/response HTML forms with
- auto-submission javascript
- * Consumer (relying party) API: AuthRequest.htmlMarkup
- * Server API: server.OpenIDResponse.toHTML
- * PAPE (Provider Authentication Policy Extension) module
- * Updated extension for specification draft 2
- * Request.fromSuccessResponse returns None if PAPE response
- arguments were not signed
-
-* New features
- * Demo server now supports OP-driven identifier selection
- * Demo consumer now has a "stateless" option
- * Fetchers now only read/request first megabyte of response
-
-* Bug fixes
- * NOT NULL constraints were added to SQLStore tables where
- appropriate
- * message.fromPostArgs: use query.items() instead of iteritems(),
- fixes #161 (Affects Django users)
- * check_authentication requests: copy entire response, not just
- signed fields. Fixes missing namespace in check_authentication
- requests
- * Consumer._verifyDiscoveryResults: fall back to OpenID 1.0 type if
- 1.1 endpoint cannot be found; fixes discovery verification bug for
- certain OpenID 1 identifiers
- * SQLStore._execSQL: convert unicode arguments to str to avoid
- postgresql api bug with unicode objects (Thanks to Marek Kuziel.)
- * MySQLStore: Use ENGINE instead of TYPE when creating tables
- * server.OpenIDResponse.toFormMarkup: Use return_to from the
- request, not the response fields (Not all responses (i.e. cancel,
- setup_needed) include a return_to field.)
- * server.AssociationRequest.answer: include session_type in
- no-encryption assoc responses
- * OpenIDServiceEndpoint.getDisplayIdentifier: Don't include the
- fragment in display identifiers.
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..e7a66b8
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,26 @@
+Metadata-Version: 1.1
+Name: python3-openid
+Version: 3.0.9
+Summary: OpenID support for modern servers and consumers.
+Home-page: http://github.com/necaris/python3-openid
+Author: Rami Chowdhury
+Author-email: rami.chowdhury at gmail.com
+License: UNKNOWN
+Download-URL: http://github.com/necaris/python3-openid/tarball/v3.0.9
+Description: This is a set of Python packages to support use of
+ the OpenID decentralized identity system in your application, update to Python
+ 3. Want to enable single sign-on for your web site? Use the openid.consumer
+ package. Want to run your own OpenID server? Check out openid.server.
+ Includes example code and support for a variety of storage back-ends.
+Platform: UNKNOWN
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: Environment :: Web Environment
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: Apache Software License
+Classifier: Operating System :: POSIX
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 3
+Classifier: Topic :: Internet :: WWW/HTTP
+Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
+Classifier: Topic :: Software Development :: Libraries :: Python Modules
+Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
diff --git a/README.md b/README.md
deleted file mode 100644
index a1691c8..0000000
--- a/README.md
+++ /dev/null
@@ -1,53 +0,0 @@
-*NOTE*: This started out as a fork of the Python OpenID library, with changes
-to make it Python 3 compatible. It's now a port of that library, including
-cleanups and updates to the code in general.
-
-[![Build Status](https://travis-ci.org/necaris/python3-openid.png?branch=master)](https://travis-ci.org/necaris/python3-openid)
-
-# REQUIREMENTS
-
- - Python 3.x (tested on 3.2, 3.3, 3.4)
-
-# INSTALLATION
-
-The recommended way is to install from PyPI with `pip`:
-
- pip install python3-openid
-
-Alternatively, you can run the following command:
-
- python setup.py install
-
-
-# GETTING STARTED
-
-The library should follow the existing `python-openid` API as closely as possible.
-
-*NOTE*: documentation will be auto-generated as soon as I can figure out how to update the documentation tools.
-
-*NOTE*: The examples directory includes an example server and consumer
-implementation. See the README file in that directory for more
-information on running the examples.
-
-# LOGGING
-
-This library offers a logging hook that will record unexpected
-conditions that occur in library code. If a condition is recoverable,
-the library will recover and issue a log message. If it is not
-recoverable, the library will raise an exception. See the
-documentation for the `openid.oidutil` module for more on the logging
-hook.
-
-# DOCUMENTATION
-
-The documentation in this library is in Epydoc format, which is
-detailed at:
-
- http://epydoc.sourceforge.net/
-
-# CONTACT
-
-Going forward, the plan is to maintain this library on GitHub, so any bug
-reports, suggestions, and feature requests should be raised [here](issues).
-
-There are also the `#python-openid` and `#openid` channels on FreeNode IRC.
diff --git a/admin/runtests b/admin/runtests
index b2a3a79..1343ea1 100755
--- a/admin/runtests
+++ b/admin/runtests
@@ -1,5 +1,8 @@
#!/usr/bin/env python
-import os.path, sys, warnings
+import os.path
+import sys
+import unittest
+
test_modules = [
'cryptutil',
@@ -14,19 +17,19 @@ def fixpath():
d = os.path.dirname(sys.argv[0])
parent = os.path.normpath(os.path.join(d, '..'))
if parent not in sys.path:
- print "putting %s in sys.path" % (parent,)
+ print ("putting %s in sys.path" % (parent,))
sys.path.insert(0, parent)
def otherTests():
failed = []
for module_name in test_modules:
- print 'Testing %s...' % (module_name,) ,
+ print ('Testing %s...' % (module_name,))
sys.stdout.flush()
module_name = 'openid.test.' + module_name
try:
test_mod = __import__(module_name, {}, {}, [None])
except ImportError:
- print 'Failed to import test %r' % (module_name,)
+ print ('Failed to import test %r' % (module_name,))
failed.append(module_name)
else:
try:
@@ -37,7 +40,7 @@ def otherTests():
sys.excepthook(*sys.exc_info())
failed.append(module_name)
else:
- print 'Succeeded.'
+ print ('Succeeded.')
return failed
@@ -72,9 +75,10 @@ def pyunitTests():
try:
from openid.test import test_examples
- except ImportError, e:
+ except ImportError as e:
if 'twill' in str(e):
- warnings.warn("Could not import twill; skipping test_examples.")
+ raise unittest.SkipTest('Skipping test_examples. '
+ 'Could not import twill.')
else:
raise
else:
@@ -110,10 +114,10 @@ def pyunitTests():
m = __import__('openid.test.%s' % (name,), {}, {}, ['unused'])
try:
s.addTest(m.pyUnitTests())
- except AttributeError, ex:
+ except AttributeError as ex:
# because the AttributeError doesn't actually say which
# object it was.
- print "Error loading tests from %s:" % (name,)
+ print ("Error loading tests from %s:" % (name,))
raise
runner = unittest.TextTestRunner() # verbosity=2)
@@ -125,7 +129,7 @@ def pyunitTests():
def splitDir(d, count):
# in python2.4 and above, it's easier to spell this as
# d.rsplit(os.sep, count)
- for i in xrange(count):
+ for i in range(count):
d = os.path.dirname(d)
return d
@@ -144,7 +148,9 @@ def _import_djopenid():
djinit = os.path.join(djdir, '__init__.py')
djopenid = types.ModuleType('djopenid')
- execfile(djinit, djopenid.__dict__)
+ with open(djinit) as f:
+ code = compile(f.read(), djinit, 'exec')
+ exec(code, djopenid.__dict__)
djopenid.__file__ = djinit
# __path__ is the magic that makes child modules of the djopenid package
@@ -167,12 +173,11 @@ def django_tests():
try:
import django.test.simple
- except ImportError, e:
- warnings.warn("django.test.simple not found; "
- "django examples not tested.")
- return 0
+ except ImportError as e:
+ raise unittest.SkipTest("django.test.simple not found; "
+ "django examples not tested.")
import djopenid.server.models, djopenid.consumer.models
- print "Testing Django examples:"
+ print ("Testing Django examples:")
# These tests do get put in to a pyunit test suite, so we could run them
# with the other pyunit tests, but django also establishes a test database
@@ -193,7 +198,7 @@ def main():
django_failures = django_tests()
if other_failed:
- print 'Failures:', ', '.join(other_failed)
+ print ('Failures:', ', '.join(other_failed))
failed = (bool(other_failed) or
bool(not pyunit_result.wasSuccessful()) or
diff --git a/contrib/upgrade-store-1.1-to-2.0 b/contrib/upgrade-store-1.1-to-2.0
index 1f587c3..6a34682 100644
--- a/contrib/upgrade-store-1.1-to-2.0
+++ b/contrib/upgrade-store-1.1-to-2.0
@@ -119,13 +119,17 @@ def main(argv=None):
return 1
password = askForPassword()
try:
- import psycopg
+ import psycopg2
except ImportError:
- print "You need psycopg installed to update a postgres DB."
- return 1
+ try:
+ from psycopg2cffi import compat
+ compat.register()
+ except:
+ print "You need psycopg2 installed to update a postgres DB."
+ return 1
try:
- db_conn = psycopg.connect(database = options.postgres_db_name,
+ db_conn = psycopg2.connect(database = options.postgres_db_name,
user = options.username,
host = options.db_host,
password = password)
diff --git a/contrib/upgrade-store-1.1-to-2.0 b/contrib/upgrade-store-1.1-to-2.0~
similarity index 96%
copy from contrib/upgrade-store-1.1-to-2.0
copy to contrib/upgrade-store-1.1-to-2.0~
index 1f587c3..2f6f0eb 100644
--- a/contrib/upgrade-store-1.1-to-2.0
+++ b/contrib/upgrade-store-1.1-to-2.0~
@@ -119,13 +119,13 @@ def main(argv=None):
return 1
password = askForPassword()
try:
- import psycopg
+ import psycopg2
except ImportError:
- print "You need psycopg installed to update a postgres DB."
+ print "You need psycopg2 installed to update a postgres DB."
return 1
try:
- db_conn = psycopg.connect(database = options.postgres_db_name,
+ db_conn = psycopg2.connect(database = options.postgres_db_name,
user = options.username,
host = options.db_host,
password = password)
diff --git a/dev-requirements.txt b/dev-requirements.txt
deleted file mode 100644
index d6792cc..0000000
--- a/dev-requirements.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-#
-nose==1.3.1
-Django
diff --git a/examples/README b/examples/README
deleted file mode 100644
index 87c0831..0000000
--- a/examples/README
+++ /dev/null
@@ -1,91 +0,0 @@
-Python OpenID library example code
-==================================
-
-The examples directory contains working code illustrating the use of
-the library for performing OpenID authentication, both as a consumer
-and a server. There are two kinds of examples, one that can run
-without any external dependencies, and one that uses the Django Web
-framework. The examples do not illustrate how to use all of the
-features of the library, but they should be a good starting point to
-see how to use this library with your code.
-
-Both the Django libraries and the BaseHTTPServer examples require that
-the OpenID library is installed or that it has been added to Python's
-search path (PYTHONPATH environment variable or sys.path).
-
-The Django example is probably a good place to start reading the
-code. There is little that is Django-specific about the OpenID logic
-in the example, and it should be easy to port to any framework. To run
-the django examples, see the README file in the djopenid subdirectory.
-
-The other examples use Python's built-in BaseHTTPServer and have a
-good deal of ad-hoc dispatching and rendering code mixed in
-
-Using the BaseHTTPServer examples
-=================================
-
-This directory contains a working server and consumer that use this
-OpenID library. They are both written using python's standard
-BaseHTTPServer.
-
-
-To run the example system:
-
-1. Make sure you've installed the library, as explained in the
- installation instructions.
-
-2. Start the consumer server:
-
- python consumer.py --port 8001
-
-
-3. In another terminal, start the identity server:
-
- python server.py --port 8000
-
- (Hit Ctrl-C in either server's window to stop that server.)
-
-
-4. Open your web broswer, and go to the consumer server:
-
- http://localhost:8001/
-
- Note that all pages the consumer server shows will have "Python OpenID
- Consumer Example" across the top.
-
-
-5. Enter an identity url managed by the sample identity server:
-
- http://localhost:8000/id/bob
-
-
-6. The browser will be redirected to the sample server, which will be
- requesting that you log in to proceed. Enter the username for the
- identity URL into the login box:
-
- bob
-
- Note that all pages the identity server shows will have "Python
- OpenID Server Example" across the top.
-
-
-7. After you log in as bob, the server example will ask you if you
- want to allow http://localhost:8001/ to know your identity. Say
- yes.
-
-
-8. You should end up back on the consumer site, at a page indicating
- you've logged in successfully.
-
-
-That's a basic OpenID login procedure. You can continue through it,
-playing with variations to see how they work. The python code is
-intended to be a straightforward example of how to use the python
-OpenID library to function as either an identity server or consumer.
-
-Getting help
-============
-
-Please send bug reports, patches, and other feedback to
-
- http://openid.net/developers/dev-mailing-lists/
diff --git a/examples/djopenid/README b/examples/djopenid/README
deleted file mode 100644
index 2d28b47..0000000
--- a/examples/djopenid/README
+++ /dev/null
@@ -1,54 +0,0 @@
-DJANGO EXAMPLE PACKAGE
-======================
-
-This package implements an example consumer and server for the Django
-Python web framework. You can get Django (and learn more about it) at
-
- http://www.djangoproject.com/
-
-SETUP
-=====
-
- 1. Install the OpenID library
-
- 2. Install Django >= 1.5 (with Python 3 support)
-
- 3. Modify djopenid/settings.py appropriately; you may wish to change
- the database type or path, although the default settings should be
- sufficient for most systems.
-
- 4. In examples/djopenid/ run:
-
- python manage.py syncdb
-
- 5. To run the example consumer or server, run
-
- python manage.py runserver PORT
-
- where PORT is the port number on which to listen.
-
- Note that if you want to try both the consumer and server at the
- same time, run the command twice with two different values for
- PORT.
-
- 6. Point your web browser at the server at
-
- http://localhost:PORT/
-
- to begin.
-
-ABOUT THE CODE
-==============
-
-The example server and consumer code provided in this package are
-intended to be instructional in the use of this OpenID library. While
-it is not recommended to use the example code in production, the code
-should be sufficient to explain the general use of the library.
-
-If you aren't familiar with the Django web framework, you can quickly
-start looking at the important code by looking in the 'views' modules:
-
- djopenid.consumer.views
- djopenid.server.views
-
-Each view is a python callable that responds to an HTTP request.
diff --git a/examples/djopenid/server/tests.py b/examples/djopenid/server/tests.py
index 8ac86fa..de5f1e9 100644
--- a/examples/djopenid/server/tests.py
+++ b/examples/djopenid/server/tests.py
@@ -43,22 +43,22 @@ class TestProcessTrustResult(TestCase):
response = views.processTrustResult(self.request)
- self.failUnlessEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
finalURL = response['location']
- self.failUnless('openid.mode=id_res' in finalURL, finalURL)
- self.failUnless('openid.identity=' in finalURL, finalURL)
- self.failUnless('openid.sreg.postcode=12345' in finalURL, finalURL)
+ self.assertIn('openid.mode=id_res', finalURL)
+ self.assertIn('openid.identity=', finalURL)
+ self.assertIn('openid.sreg.postcode=12345', finalURL)
def test_cancel(self):
self.request.POST['cancel'] = 'Yes'
response = views.processTrustResult(self.request)
- self.failUnlessEqual(response.status_code, 302)
+ self.assertEqual(response.status_code, 302)
finalURL = response['location']
- self.failUnless('openid.mode=cancel' in finalURL, finalURL)
- self.failIf('openid.identity=' in finalURL, finalURL)
- self.failIf('openid.sreg.postcode=12345' in finalURL, finalURL)
+ self.assertIn('openid.mode=cancel', finalURL)
+ self.assertNotIn('openid.identity=', finalURL)
+ self.assertNotIn('openid.sreg.postcode=12345', finalURL)
class TestShowDecidePage(TestCase):
@@ -98,6 +98,6 @@ class TestGenericXRDS(TestCase):
requested_url = 'http://requested.invalid/'
(endpoint,) = applyFilter(requested_url, response.content)
- self.failUnlessEqual(YADIS_CONTENT_TYPE, response['Content-Type'])
- self.failUnlessEqual(type_uris, endpoint.type_uris)
- self.failUnlessEqual(endpoint_url, endpoint.uri)
+ self.assertEqual(YADIS_CONTENT_TYPE, response['Content-Type'])
+ self.assertEqual(type_uris, endpoint.type_uris)
+ self.assertEqual(endpoint_url, endpoint.uri)
diff --git a/examples/djopenid/settings.py b/examples/djopenid/settings.py
index 1a33dcf..b1ccc26 100644
--- a/examples/djopenid/settings.py
+++ b/examples/djopenid/settings.py
@@ -38,6 +38,7 @@ TIME_ZONE = 'Europe/London'
# http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
# http://blogs.law.harvard.edu/tech/stories/storyReader$15
LANGUAGE_CODE = 'en-us.UTF-8'
+USE_I18N = False
SITE_ID = 1
diff --git a/examples/djopenid/util.py b/examples/djopenid/util.py
index f37a4d0..fc21ceb 100644
--- a/examples/djopenid/util.py
+++ b/examples/djopenid/util.py
@@ -2,7 +2,6 @@
"""
Utility code for the Django example consumer and server.
"""
-
from urllib.parse import urljoin
from django.db import connection
@@ -15,6 +14,12 @@ from django.shortcuts import render_to_response
from django.conf import settings
+try:
+ import psycopg2
+except ImportError:
+ from psycopg2cffi import compat
+ compat.register()
+
from openid.store.filestore import FileOpenIDStore
from openid.store import sqlstore
from openid.yadis.constants import YADIS_CONTENT_TYPE
diff --git a/openid/__init__.py b/openid/__init__.py
index 25eaaaa..8577355 100644
--- a/openid/__init__.py
+++ b/openid/__init__.py
@@ -23,7 +23,7 @@ module.
and limitations under the License.
"""
-version_info = (3, 0, 4)
+version_info = (3, 0, 9)
__version__ = ".".join(str(x) for x in version_info)
diff --git a/openid/fetchers.py b/openid/fetchers.py
index 469e733..68ff069 100644
--- a/openid/fetchers.py
+++ b/openid/fetchers.py
@@ -496,7 +496,7 @@ class HTTPLib2Fetcher(HTTPFetcher):
final_url = url
return HTTPResponse(
- body=content,
+ body=content.decode(), # TODO Don't assume ASCII
final_url=final_url,
headers=dict(list(httplib2_response.items())),
status=httplib2_response.status,
diff --git a/openid/oidutil.py b/openid/oidutil.py
index dbbba12..70637c4 100644
--- a/openid/oidutil.py
+++ b/openid/oidutil.py
@@ -11,12 +11,17 @@ __all__ = ['log', 'appendArgs', 'toBase64', 'fromBase64', 'autoSubmitHTML',
import binascii
import logging
-import urllib.parse as urlparse
+# import urllib.parse as urlparse
from urllib.parse import urlencode
+xxe_safe_elementtree_modules = [
+ 'defusedxml.cElementTree',
+ 'defusedxml.ElementTree',
+ ]
+
+
elementtree_modules = [
- 'lxml.etree',
'xml.etree.cElementTree',
'xml.etree.ElementTree',
'cElementTree',
@@ -61,6 +66,27 @@ for (var i = 0; i < elements.length; i++) {
return html
+def importSafeElementTree(module_names=None):
+ """Find a working ElementTree implementation that is not vulnerable
+ to XXE, using `defusedxml`.
+
+ >>> XXESafeElementTree = importSafeElementTree()
+
+ @param module_names: The names of modules to try to use as
+ a safe ElementTree. Defaults to C{L{xxe_safe_elementtree_modules}}
+
+ @returns: An ElementTree module that is not vulnerable to XXE.
+ """
+ if module_names is None:
+ module_names = xxe_safe_elementtree_modules
+ try:
+ return importElementTree(module_names)
+ except ImportError:
+ raise ImportError('Unable to find a ElementTree module '
+ 'that is not vulnerable to XXE. '
+ 'Tried importing %r' % (module_names,))
+
+
def importElementTree(module_names=None):
"""Find a working ElementTree implementation, trying the standard
places that such a thing might show up.
diff --git a/openid/store/sqlstore.py b/openid/store/sqlstore.py
index 2c6e408..690ed19 100644
--- a/openid/store/sqlstore.py
+++ b/openid/store/sqlstore.py
@@ -10,6 +10,12 @@ python -c 'from openid.store import sqlstore; import pysqlite2.dbapi2;'
import re
import time
+try:
+ import psycopg2
+except ImportError:
+ from psycopg2cffi import compat
+ compat.register()
+
from openid.association import Association
from openid.store.interface import OpenIDStore
from openid.store import nonce
@@ -228,6 +234,8 @@ class SQLStore(OpenIDStore):
else:
associations = []
for values in rows:
+ values = list(values)
+ values[1] = self.blobDecode(values[1])
assoc = Association(*values)
if assoc.expiresIn == 0:
self.txn_removeAssociation(server_url, assoc.handle)
@@ -339,9 +347,6 @@ class SQLiteStore(SQLStore):
clean_nonce_sql = 'DELETE FROM %(nonces)s WHERE timestamp < ?;'
- def blobDecode(self, buf):
- return str(buf)
-
def blobEncode(self, s):
return memoryview(s)
@@ -417,13 +422,6 @@ class MySQLStore(SQLStore):
clean_nonce_sql = 'DELETE FROM %(nonces)s WHERE timestamp < %%s;'
- def blobDecode(self, blob):
- if type(blob) is str:
- # Versions of MySQLdb >= 1.2.2
- return blob
- else:
- # Versions of MySQLdb prior to 1.2.2 (as far as we can tell)
- return blob.tostring()
class PostgreSQLStore(SQLStore):
"""
@@ -434,16 +432,7 @@ class PostgreSQLStore(SQLStore):
All other methods are implementation details.
"""
-
- try:
- import psycopg as exceptions
- except ImportError:
- # psycopg2 has the dbapi extension where the exception classes
- # are available on the connection object. A psycopg2
- # connection will use the correct exception classes because of
- # this, and a psycopg connection will fall through to use the
- # psycopg imported above.
- exceptions = None
+ exceptions = None
create_nonce_sql = """
CREATE TABLE %(nonces)s (
@@ -510,9 +499,9 @@ class PostgreSQLStore(SQLStore):
clean_nonce_sql = 'DELETE FROM %(nonces)s WHERE timestamp < %%s;'
def blobEncode(self, blob):
- try:
- from psycopg2 import Binary
- except ImportError:
- from psycopg import Binary
+ from psycopg2 import Binary
return Binary(blob)
+
+ def blobDecode(self, blob):
+ return blob.tobytes()
diff --git a/openid/test/__init__.py b/openid/test/__init__.py
index 2669297..cb3c3b2 100644
--- a/openid/test/__init__.py
+++ b/openid/test/__init__.py
@@ -154,8 +154,8 @@ def djangoExampleTests():
try:
import django.test.simple
except ImportError:
- warnings.warn("django.test.simple not found; skipping django examples.")
- return 0
+ raise unittest.SkipTest("Skipping django examples. "
+ "django.test.simple not found.")
import djopenid.server.models
import djopenid.consumer.models
diff --git a/openid/test/storetest.py b/openid/test/storetest.py
index 159e424..9aadb24 100644
--- a/openid/test/storetest.py
+++ b/openid/test/storetest.py
@@ -1,16 +1,21 @@
import unittest
import string
import time
-import socket
-import random
import os
-import warnings
+import uuid
+
+try:
+ import psycopg2
+except ImportError:
+ from psycopg2cffi import compat
+ compat.register()
from openid.association import Association
from openid.cryptutil import randomString
from openid.store.nonce import mkNonce, split
-db_host = 'dbtest'
+
+db_host = os.environ.get('TEST_DB_HOST', 'dbtest')
allowed_handle = []
for c in string.printable:
@@ -27,12 +32,12 @@ generateSecret = randomString
def getTmpDbName():
- hostname = socket.gethostname()
- hostname = hostname.replace('.', '_')
- hostname = hostname.replace('-', '_')
- return "%s_%d_%s_openid_test" % \
- (hostname, os.getpid(), \
- random.randrange(1, int(time.time())))
+ """Returns a name suitable for creating a temporary database.
+
+ Restrictions:
+ - Maximum length 64 characters (MySQL)
+ """
+ return "openid_test_%s" % uuid.uuid4().hex
def testStore(store):
@@ -55,7 +60,7 @@ def testStore(store):
def checkRetrieve(url, handle=None, expected=None):
retrieved_assoc = store.getAssociation(url, handle)
- assert retrieved_assoc == expected, (retrieved_assoc, expected)
+ assert retrieved_assoc == expected, (retrieved_assoc.__dict__, expected.__dict__)
if expected is not None:
if retrieved_assoc is expected:
print ('Unexpected: retrieved a reference to the expected '
@@ -250,15 +255,15 @@ def test_sqlite():
def test_mysql():
- # TODO fix
from openid.store import sqlstore
try:
import MySQLdb
except ImportError:
- warnings.warn("Could not import MySQLdb. Skipping MySQL store tests.")
- pass
+ raise unittest.SkipTest('Skipping MySQL store tests. '
+ 'Could not import MySQLdb.')
+
else:
- db_user = 'openid_test'
+ db_user = os.environ.get('TEST_MYSQL_USER', 'openid_test')
db_passwd = ''
db_name = getTmpDbName()
@@ -269,10 +274,10 @@ def test_mysql():
conn = MySQLdb.connect(user=db_user, passwd=db_passwd,
host=db_host)
except MySQLdb.OperationalError as why:
- if int(why) == 2005:
- print(('Skipping MySQL store test (cannot connect '
- 'to test server on host %r)' % (db_host,)))
- return
+ if why.args[0] == 2005:
+ raise unittest.SkipTest('Skipping MySQL store test. '
+ 'Cannot connect to server on host %r.'
+ % (db_host,))
else:
raise
@@ -298,7 +303,7 @@ def test_postgresql():
Tests the PostgreSQLStore on a locally-hosted PostgreSQL database
cluster, version 7.4 or later. To run this test, you must have:
- - The 'psycopg' python module (version 1.1) installed
+ - The 'psycopg2' python module (version 1.1) installed
- PostgreSQL running locally
@@ -321,19 +326,24 @@ def test_postgresql():
"""
from openid.store import sqlstore
try:
- import psycopg
+ import psycopg2
except ImportError:
- warnings.warn("Could not import psycopg. Skipping PostgreSQL store tests.")
- pass
+ raise unittest.SkipTest('Skipping PostgreSQL store tests. '
+ 'Could not import psycopg2.')
else:
db_name = getTmpDbName()
- db_user = 'openid_test'
+ db_user = os.environ.get('TEST_POSTGRES_USER', 'openid_test')
# Connect once to create the database; reconnect to access the
# new database.
- conn_create = psycopg.connect(database='template1', user=db_user,
- host=db_host)
- conn_create.autocommit()
+ try:
+ conn_create = psycopg2.connect(database='template1', user=db_user,
+ host=db_host)
+ except psycopg2.OperationalError as why:
+ raise unittest.SkipTest('Skipping PostgreSQL store test: %s'
+ % why)
+
+ conn_create.autocommit = True
# Create the test database.
cursor = conn_create.cursor()
@@ -341,7 +351,7 @@ def test_postgresql():
conn_create.close()
# Connect to the test database.
- conn_test = psycopg.connect(database=db_name, user=db_user,
+ conn_test = psycopg2.connect(database=db_name, user=db_user,
host=db_host)
# OK, we're in the right environment. Create the store
@@ -363,9 +373,9 @@ def test_postgresql():
time.sleep(1)
# Remove the database now that the test is over.
- conn_remove = psycopg.connect(database='template1', user=db_user,
+ conn_remove = psycopg2.connect(database='template1', user=db_user,
host=db_host)
- conn_remove.autocommit()
+ conn_remove.autocommit = True
cursor = conn_remove.cursor()
cursor.execute('DROP DATABASE %s;' % (db_name,))
diff --git a/openid/test/test_examples.py b/openid/test/test_examples.py
index 16ab8d3..9ddbfde 100644
--- a/openid/test/test_examples.py
+++ b/openid/test/test_examples.py
@@ -7,6 +7,8 @@ import sys
import time
from io import StringIO
+# TODO: Replace twill with MechanicalSoup or similar
+'''
import twill.commands
import twill.parse
import twill.unit
@@ -177,7 +179,7 @@ class TestServer(unittest.TestCase):
def tearDown(self):
twill.set_output(None)
twill.set_errout(None)
-
+'''
if __name__ == '__main__':
unittest.main()
diff --git a/openid/test/test_fetchers.py b/openid/test/test_fetchers.py
index 8e9f5de..c97ffba 100644
--- a/openid/test/test_fetchers.py
+++ b/openid/test/test_fetchers.py
@@ -107,10 +107,9 @@ def run_fetcher_tests(server):
try:
__import__(library_name)
except ImportError:
- warnings.warn(
+ raise unittest.SkipTest(
'Skipping tests for %r fetcher because '
'the library did not import.' % (library_name,))
- pass
else:
assert False, ('%s present but not detected' % (
library_name,))
diff --git a/openid/test/test_parsehtml.py b/openid/test/test_parsehtml.py
index b3c6475..387ddc5 100644
... 480 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python3-openid.git
More information about the Python-modules-commits
mailing list