Blob Blame History Raw
From 4c6f15013559c469b9f98dc1ed94ec6549cf8cd9 Mon Sep 17 00:00:00 2001
From: Ralph Bean <rbean@redhat.com>
Date: Sat, 19 Sep 2015 21:36:02 -0400
Subject: [PATCH] remove ming

---
 TurboGears2.egg-info/SOURCES.txt   |   1 -
 TurboGears2.egg-info/requires.txt  |   4 +-
 TurboGears2.egg-info/top_level.txt |   2 +-
 setup.py                           |   6 --
 tests/test_configuration.py        | 212 -------------------------------------
 tg/appwrappers/mingflush.py        |  59 -----------
 tg/configuration/app_config.py     |  63 +----------
 7 files changed, 6 insertions(+), 341 deletions(-)
 delete mode 100644 tg/appwrappers/mingflush.py

diff --git a/TurboGears2.egg-info/SOURCES.txt b/TurboGears2.egg-info/SOURCES.txt
index 6b46abe..00b1979 100644
--- a/TurboGears2.egg-info/SOURCES.txt
+++ b/TurboGears2.egg-info/SOURCES.txt
@@ -87,7 +87,6 @@ tg/appwrappers/caching.py
 tg/appwrappers/errorpage.py
 tg/appwrappers/i18n.py
 tg/appwrappers/identity.py
-tg/appwrappers/mingflush.py
 tg/appwrappers/session.py
 tg/appwrappers/transaction_manager.py
 tg/configuration/__init__.py
diff --git a/TurboGears2.egg-info/requires.txt b/TurboGears2.egg-info/requires.txt
index 6bd1732..83ead20 100644
--- a/TurboGears2.egg-info/requires.txt
+++ b/TurboGears2.egg-info/requires.txt
@@ -22,7 +22,5 @@ Beaker
 Kajiki >= 0.4.4
 routes
 jinja2
-ming > 0.5.0
 TurboKid >= 1.0.4
-tgming
-tw.forms
\ No newline at end of file
+tw.forms
diff --git a/TurboGears2.egg-info/top_level.txt b/TurboGears2.egg-info/top_level.txt
index 38e51fc..d89021e 100644
--- a/TurboGears2.egg-info/top_level.txt
+++ b/TurboGears2.egg-info/top_level.txt
@@ -1,2 +1,2 @@
-tg
 tests
+tg
diff --git a/setup.py b/setup.py
index 3ee621f..4e9e8f2 100644
--- a/setup.py
+++ b/setup.py
@@ -38,14 +38,8 @@ else:
     test_requirements.append('jinja2')
 
 
-if py_version != (3, 2):
-    # Ming is not compatible with Python3.2
-    test_requirements.append('ming > 0.5.0')
-
-
 if py_version[0] == 2:
     test_requirements.extend(['TurboKid >= 1.0.4',
-                              'tgming',
                               'tw.forms'])
 
 install_requires=[
diff --git a/tests/test_configuration.py b/tests/test_configuration.py
index 4ee5248..5b2f16f 100644
--- a/tests/test_configuration.py
+++ b/tests/test_configuration.py
@@ -8,7 +8,6 @@ from datetime import datetime
 from tg.configuration.hooks import _TGGlobalHooksNamespace
 
 from tg.appwrappers.errorpage import ErrorPageApplicationWrapper
-from tg.appwrappers.mingflush import MingApplicationWrapper
 from tg.appwrappers.transaction_manager import TransactionApplicationWrapper
 
 from tg.util import Bunch
@@ -140,13 +139,6 @@ class TestPylonsConfigWrapper:
         assert 'tg.app_globals' in k
 
 
-def test_coerce_config():
-    opts = {'ming.connection.max_pool_size': '5'}
-    conf = coerce_config(opts, 'ming.connection.', {'max_pool_size':asint})
-    assert conf['max_pool_size'] == 5
-    assert opts['ming.connection.max_pool_size'] == '5'
-
-
 def test_coerce_options():
     opts = {'connection': 'false'}
     conf = coerce_options(opts, {'connection': asbool})
@@ -613,184 +605,6 @@ class TestAppConfig:
             self.config.use_sqlalchemy = False
             config.pop('sqlalchemy.master.url')
 
-    def test_setup_ming_persistance(self):
-        class RootController(TGController):
-            @expose()
-            def test(self):
-                return 'HI!'
-
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=RootController())
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mim://'
-        conf['ming.db'] = 'inmemdb'
-
-        app = conf.make_wsgi_app()
-
-        tgapp = app.application
-        while not isinstance(tgapp, TGApp):
-            tgapp = tgapp.app
-
-        ming_handler = tgapp.wrapped_dispatch
-        while ming_handler != tgapp.dispatch:
-            if isinstance(ming_handler, MingApplicationWrapper):
-                break
-            ming_handler = ming_handler.next_handler
-        assert isinstance(ming_handler, MingApplicationWrapper), ming_handler
-
-        class FakeMingSession(object):
-            actions = []
-
-            def flush_all(self):
-                self.actions.append('FLUSH')
-
-            def close_all(self):
-                self.actions.append('CLOSE')
-
-        ming_handler.ThreadLocalODMSession = FakeMingSession()
-
-        app = TestApp(app)
-        resp = app.get('/test')
-        assert 'HI' in resp
-
-        assert ming_handler.ThreadLocalODMSession.actions == ['FLUSH']
-
-    def test_setup_ming_persistance_closes_on_failure(self):
-        class RootController(TGController):
-            @expose()
-            def test(self):
-                raise Exception('CRASH!')
-
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=RootController())
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mim://'
-        conf['ming.db'] = 'inmemdb'
-
-        app = conf.make_wsgi_app()
-
-        tgapp = app.application
-        while not isinstance(tgapp, TGApp):
-            tgapp = tgapp.app
-
-        ming_handler = tgapp.wrapped_dispatch
-        while ming_handler != tgapp.dispatch:
-            if isinstance(ming_handler, MingApplicationWrapper):
-                break
-            ming_handler = ming_handler.next_handler
-        assert isinstance(ming_handler, MingApplicationWrapper), ming_handler
-
-        class FakeMingSession(object):
-            actions = []
-
-            def flush_all(self):
-                self.actions.append('FLUSH')
-
-            def close_all(self):
-                self.actions.append('CLOSE')
-
-        ming_handler.ThreadLocalODMSession = FakeMingSession()
-
-        app = TestApp(app)
-
-        try:
-            app.get('/test', status=500)
-        except:
-            assert ming_handler.ThreadLocalODMSession.actions == ['CLOSE']
-        else:
-            assert False, 'Should have raised exception'
-
-    def test_setup_ming_persistance_with_url_alone(self):
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=None)
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mim://inmemdb'
-
-        app = conf.make_wsgi_app()
-        assert app is not None
-
-        dstore = config['tg.app_globals'].ming_datastore
-        dstore_name = dstore.name
-        # Looks like ming has empty dstore.name when using MIM.
-        assert dstore_name == '', dstore
-
-    def test_setup_ming_persistance_with_url_and_db(self):
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=None)
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mim://inmemdb'
-        conf['ming.db'] = 'realinmemdb'
-
-        app = conf.make_wsgi_app()
-        assert app is not None
-
-        dstore = config['tg.app_globals'].ming_datastore
-        dstore_name = dstore.name
-        assert dstore_name == 'realinmemdb', dstore
-
-    def test_setup_ming_persistance_advanced_options(self):
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=None)
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mim://inmemdb'
-        conf['ming.connection.read_preference'] = 'PRIMARY'
-
-        app = conf.make_wsgi_app()
-        assert app is not None
-
-    def test_setup_ming_persistance_replica_set(self):
-        if sys.version_info[:2] == (2, 6):
-            raise SkipTest()
-
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=None)
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mongodb://localhost:27017,localhost:27018/testdb?replicaSet=test'
-        conf['ming.db'] = ''
-
-        app = conf.make_wsgi_app()
-        assert app is not None
-
-        expected_url = 'mongodb://localhost:27017,localhost:27018/?replicaSet=test'
-        expected_db = 'testdb'
-
-        dstore = config['tg.app_globals'].ming_datastore
-        assert expected_db == dstore.name, dstore.name
-        assert expected_url == dstore.bind._conn_args[0], dstore.bind._conn_args
-
-    def test_setup_mig_persistance_replica_set_option(self):
-        package = PackageWithModel()
-        conf = AppConfig(minimal=True, root_controller=None)
-        conf.package = package
-        conf.model = package.model
-        conf.use_ming = True
-        conf['ming.url'] = 'mongodb://localhost:27017,localhost:27018/testdb'
-        conf['ming.connection.replicaSet'] = 'test'
-        conf['ming.db'] = ''
-
-        app = conf.make_wsgi_app()
-        assert app is not None
-
-        expected_url = 'mongodb://localhost:27017,localhost:27018/'
-        expected_db = 'testdb'
-
-        dstore = config['tg.app_globals'].ming_datastore
-        assert expected_db == dstore.name, dstore.name
-        assert expected_url == dstore.bind._conn_args[0], dstore.bind._conn_args
-        assert 'test' == dstore.bind._conn_kwargs.get('replicaSet'), dstore.bind._conn_kwargs
-
     def test_add_auth_middleware(self):
         class Dummy:pass
 
@@ -834,14 +648,6 @@ class TestAppConfig:
 
         self.config.auth_backend = None
 
-    def test_setup_ming_auth(self):
-        self.config.auth_backend = 'ming'
-
-        self.config.setup_auth()
-        assert 'sa_auth' in config
-
-        self.config.auth_backend = None
-
     def test_deprecated_register_hooks(self):
         def dummy(*args):
             pass
@@ -1427,24 +1233,6 @@ class TestAppConfig:
         self.config.auth_backend = None
         config.sa_auth = past_config_sa_auth
 
-    def test_ming_auth_middleware(self):
-        if PY3: raise SkipTest()
-
-        self.config.auth_backend = 'ming'
-        self.config['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(),
-                                  'user_class':None,
-                                  'cookie_secret':'12345',
-                                  'authenticators':UncopiableList([('default', None)])}
-        self.config.setup_auth()
-        self.config.add_auth_middleware(None, True)
-
-        authenticators = [x[0] for x in self.config['sa_auth']['authenticators']]
-        assert 'cookie' in authenticators
-        assert 'mingauth' in authenticators
-
-        self.config['sa_auth'] = {}
-        self.config.auth_backend = None
-
     @raises(KeyError)
     def test_sqla_auth_middleware_no_backend(self):
         #This is expected to raise error as no authenticators are specified for a custom backend
diff --git a/tg/appwrappers/mingflush.py b/tg/appwrappers/mingflush.py
deleted file mode 100644
index 56ae551..0000000
--- a/tg/appwrappers/mingflush.py
+++ /dev/null
@@ -1,59 +0,0 @@
-import logging
-from tg.configuration.utils import coerce_config
-from tg.support.converters import asbool, asint
-from .base import ApplicationWrapper
-
-log = logging.getLogger(__name__)
-
-
-class MingApplicationWrapper(ApplicationWrapper):
-    """Automatically flushes the Ming ODMSession.
-
-    In case an exception raised during excution it won't flush the session and it will
-    instead close it throwing away any change.
-
-    Supported options which can be provided by config are:
-
-        - ``ming.autoflush``: Whenever to flush session at end of request if no exceptions happened.
-
-    """
-    def __init__(self, handler, config):
-        super(MingApplicationWrapper, self).__init__(handler, config)
-
-        options = {
-            'autoflush': False,
-        }
-        options.update(coerce_config(config, 'ming.',  {
-            'autoflush': asbool,
-        }))
-
-        self.ThreadLocalODMSession = None
-        self.enabled = options['autoflush']
-
-        if self.enabled:
-            try:
-                from ming.odm import ThreadLocalODMSession
-                self.ThreadLocalODMSession = ThreadLocalODMSession
-            except ImportError:  # pragma: no cover
-                log.exception('Unable to Enable Ming Application Wrapper')
-                self.enabled = False
-
-        log.debug('MingSessionFlush enabled: %s -> %s',
-                  self.enabled, options)
-
-    @property
-    def injected(self):
-        return self.enabled
-
-    def __call__(self, controller, environ, context):
-        session = self.ThreadLocalODMSession
-
-        try:
-            resp = self.next_handler(controller, environ, context)
-        except:
-            session.close_all()
-            raise
-
-        log.debug('MingSessionFlush flushing changes...')
-        session.flush_all()
-        return resp
diff --git a/tg/configuration/app_config.py b/tg/configuration/app_config.py
index 65671ec..0608a11 100644
--- a/tg/configuration/app_config.py
+++ b/tg/configuration/app_config.py
@@ -30,7 +30,6 @@ from tg.appwrappers.caching import CacheApplicationWrapper
 from tg.appwrappers.session import SessionApplicationWrapper
 from tg.appwrappers.errorpage import ErrorPageApplicationWrapper
 from tg.appwrappers.transaction_manager import TransactionApplicationWrapper
-from tg.appwrappers.mingflush import MingApplicationWrapper
 
 log = logging.getLogger(__name__)
 
@@ -239,7 +238,6 @@ class AppConfig(Bunch):
         self.register_wrapper(IdentityApplicationWrapper, after=True)
         self.register_wrapper(SessionApplicationWrapper, after=True)
         self.register_wrapper(CacheApplicationWrapper, after=True)
-        self.register_wrapper(MingApplicationWrapper, after=True)
         self.register_wrapper(TransactionApplicationWrapper, after=True)
         self.register_wrapper(ErrorPageApplicationWrapper, after=True)
 
@@ -381,7 +379,6 @@ class AppConfig(Bunch):
         self._configure_package_paths()
         self._configure_renderers()
         self._configure_error_pages()
-        self._configure_ming()
         self._configure_transaction_manager()
         self._configure_mimetypes()
 
@@ -510,14 +507,6 @@ class AppConfig(Bunch):
         for key, value in lookup.items():
             self.mimetypes.add_type(value, key)
 
-    def _configure_ming(self):
-        try:
-            autoflush_enabled = self['ming.autoflush']
-        except KeyError:
-            autoflush_enabled = True
-
-        self['ming.autoflush'] = self.use_ming and autoflush_enabled
-
     def _configure_error_pages(self):
         if (self.auth_backend is None and 401 not in self['errorpage.status_codes']):
             # If there's no auth backend configured which traps 401
@@ -686,42 +675,7 @@ class AppConfig(Bunch):
         if self.use_sqlalchemy:
             self.setup_sqlalchemy()
         elif self.use_ming:
-            self.setup_ming()
-
-    def setup_ming(self):
-        """Setup MongoDB database engine using Ming"""
-        try:
-            from ming import create_datastore
-            def create_ming_datastore(url, database, **kw):
-                if database and url[-1] != '/':
-                    url += '/'
-                ming_url = url + database
-                return create_datastore(ming_url, **kw)
-        except ImportError: #pragma: no cover
-            from ming.datastore import DataStore
-            def create_ming_datastore(url, database, **kw):
-                return DataStore(url, database=database, **kw)
-
-        def mongo_read_pref(value):
-            from pymongo.read_preferences import ReadPreference
-            return getattr(ReadPreference, value)
-
-        datastore_options = coerce_config(config, 'ming.connection.', {'max_pool_size':asint,
-                                                                       'network_timeout':asint,
-                                                                       'tz_aware':asbool,
-                                                                       'safe':asbool,
-                                                                       'journal':asbool,
-                                                                       'wtimeout':asint,
-                                                                       'fsync':asbool,
-                                                                       'ssl':asbool,
-                                                                       'read_preference':mongo_read_pref})
-        datastore_options.pop('host', None)
-        datastore_options.pop('port', None)
-
-        datastore = create_ming_datastore(config['ming.url'], config.get('ming.db', ''),
-                                          **datastore_options)
-        config['tg.app_globals'].ming_datastore = datastore
-        self.package.model.init_model(datastore)
+            raise NotImplementedError("ming support removed in Fedora")
 
     def setup_sqlalchemy(self):
         """Setup SQLAlchemy database engine.
@@ -963,8 +917,7 @@ class AppConfig(Bunch):
                 from repoze.what.plugins.quickstart import setup_sql_auth
                 app = setup_sql_auth(app, skip_authentication=skip_authentication, **auth_args)
             elif self.auth_backend == "ming":
-                from tgming import setup_ming_auth
-                app = setup_ming_auth(app, skip_authentication=skip_authentication, **auth_args)
+                raise NotImplementedError("ming support removed in Fedora")
         else:
             # Removing authmetadata as is not used by repoze.who:
             tgauthmetadata = auth_args.pop('authmetadata', None)
@@ -989,9 +942,7 @@ class AppConfig(Bunch):
                     auth_args, sqlauth = create_default_authenticator(**auth_args)
                     authenticator = ('sqlauth', sqlauth)
                 elif self.auth_backend == "ming":
-                    from tg.configuration.mongo.auth import create_default_authenticator
-                    auth_args, mingauth = create_default_authenticator(**auth_args)
-                    authenticator = ('mingauth', mingauth)
+                    raise NotImplementedError("ming support removed in Fedora")
                 else:
                     authenticator = None
 
@@ -1187,12 +1138,6 @@ class AppConfig(Bunch):
 
         return TGTransactionManager(app, config)
 
-    def add_ming_middleware(self, app):
-        """Set up the ming middleware for the unit of work"""
-        from tg.support.middlewares import MingSessionRemoverMiddleware
-        from ming.odm import ThreadLocalODMSession
-        return MingSessionRemoverMiddleware(ThreadLocalODMSession, app)
-
     def add_sqlalchemy_middleware(self, app):
         """Set up middleware that cleans up the sqlalchemy session.
 
@@ -1296,7 +1241,7 @@ class AppConfig(Bunch):
                 app = self.add_sqlalchemy_middleware(app)
 
             if self.use_ming:
-                app = self.add_ming_middleware(app)
+                raise NotImplementedError("ming support removed in Fedora")
 
             if config.get('make_body_seekable'):
                 app = SeekableRequestBodyMiddleware(app)
-- 
2.4.3