def test_02_app_local_store(self):
        store1 = get_app_local_store()
        store1["hello"] = "world"
        g.test_flag = True

        # We get the same store even if we push another app context for the same app
        with self.app.app_context():
            store2 = get_app_local_store()
            self.assertEqual(store1, store2)
            self.assertEqual(store2["hello"], "world")
            self.assertNotIn("test_flag", g)
            g.test_flag = False

        self.assertEquals(g.test_flag, True)
        g.pop("test_flag")

        # We get a different store if we push a context for another app
        new_app = create_app("testing", "")
        with new_app.app_context():
            store3 = get_app_local_store()
            self.assertNotIn("hello", store3)
            self.assertNotEqual(store3, store1)
            store3["hello"] = "no!"
            store4 = get_app_local_store()
            store3["something"] = "else"
            self.assertEqual(store4["hello"], "no!")
            self.assertEqual(store4["something"], "else")

        self.assertEqual(store1, store2)
        self.assertEqual(store2["hello"], "world")
Esempio n. 2
0
File: db.py Progetto: vhnuuh/pyutil
def close_db(e=None):
    """If this request connected to the database, close the connection.
    """
    db = g.pop('db', None)

    if db is not None:
        db.close()
Esempio n. 3
0
def track_time_changes(auto_extend=False, user=None):
    """Track time changes of event objects.

    This provides a list of changes while the context manager was
    active and also triggers `times_changed` signals.

    If the code running inside the ``with`` block of this context
    manager raises an exception, no signals will be triggered.

    :param auto_extend: Whether entry parents will get their boundaries
                        automatically extended or not. Passing ``'start'`` will
                        extend only start datetime, ``'end'`` to extend only
                        end datetime.
    :param user: The `User` that will trigger time changes.
    """
    if auto_extend:
        assert user is not None
    if 'old_times' in g:
        raise RuntimeError('time change tracking may not be nested')
    g.old_times = defaultdict(dict)
    changes = defaultdict(dict)
    try:
        yield changes
    except:
        del g.old_times
        raise
    else:
        if auto_extend:
            by_start = auto_extend in (True, 'start')
            by_end = auto_extend in (True, 'end')
            initial_changes = set(g.old_times)
            # g.old_times changes during iteration
            for obj in list(g.old_times):
                if not isinstance(obj, Event):
                    obj.extend_parent(by_start=by_start, by_end=by_end)
            cascade_changes = set(g.old_times) - initial_changes
            for obj in cascade_changes:
                if isinstance(obj, Event):
                    if not obj.can_manage(user):
                        # TODO: raise Forbidden exceptions after adding protection check in the UI
                        raise UserValueError(_("Your action requires modification of event boundaries, but you are "
                                               "not authorized to manage the event."))
                elif not obj.object.can_manage(user):
                    # TODO: raise Forbidden exceptions after adding protection check in the UI
                    raise UserValueError(_("Your action requires modification of session block boundaries, but you are "
                                           "not authorized to manage the session block."))
        old_times = g.pop('old_times')
        for obj, info in old_times.iteritems():
            if isinstance(obj, TimetableEntry):
                obj = obj.object
            if obj.start_dt != info['start_dt']:
                changes[obj]['start_dt'] = (info['start_dt'], obj.start_dt)
            if obj.duration != info['duration']:
                changes[obj]['duration'] = (info['duration'], obj.duration)
            if obj.end_dt != info['end_dt']:
                changes[obj]['end_dt'] = (info['end_dt'], obj.end_dt)
        for obj, obj_changes in changes.iteritems():
            entry = None if isinstance(obj, Event) else obj.timetable_entry
            signals.event.times_changed.send(type(obj), entry=entry, obj=obj, changes=obj_changes)
Esempio n. 4
0
def close_db(e=None):
    db = g.pop('db', None)
    if db is not None:
        db.close()
Esempio n. 5
0
def close_db(e=None):
    print("close server")
    db = g.pop('db', None)

    if db is not None:
        db.close()
Esempio n. 6
0
def close_db(e=None):
    click.echo("Runs: close_db")
    cnx = g.pop('db', None)
    if cnx is not None:
        cnx.close()
Esempio n. 7
0
def unauthentication(response):
    if hasattr(g, "session"):
        g.pop("session")
    return response
Esempio n. 8
0
def close_connection(e = None):
    conn = g.pop('conn', None)
    if conn is not None:
        conn.close()
Esempio n. 9
0
def close_db(what):
    db = g.pop('db', None)
    if db is not None:
        db.tearDown()
Esempio n. 10
0
 def logout(self):
     self._clean_session()
     g.pop('user')
Esempio n. 11
0
def close_db(e=None):
    db = g.pop('db', None)

    if db is not None:
        db.close()  # close the connection
Esempio n. 12
0
def close_db(e=None): # close_db checks if a connection was created by checking if g.db was set. If the connection exists, it is closed. Further down you will tell your application about the close_db function in the application factory so that it is called after each request
    db = g.pop('db', None)

    if db is not None:
        db.close()
def close_db():
    db = g.pop('db', None)
    if db is not None:
        if db.open:
            db.close()
Esempio n. 14
0
 def _clear_cache():
     if has_request_context():
         g.pop('global_settings_cache', None)
Esempio n. 15
0
def teardown_db(error):
    if hasattr(g, 'db_conn'):
        print('ON VA FERMER')
        g.db_conn.close()
        g.pop('db_conn', None)
Esempio n. 16
0
def teardown_db(e):  #Stolen directly from Flask's docs
    db = g.pop('db', None)
    if db is not None:
        db.close()
Esempio n. 17
0
def teardown_db(exception):
    db = g.pop('db', None)

    if db is not None:
        app.logger.info('Closing connection...')
        db.close()
Esempio n. 18
0
def close_db(* args):
    db = g.pop('db', None)
    if db is not None:
        db.close()
Esempio n. 19
0
def close_dbConn():
    if 'dbConn' in g:
        g.dbComm.close()
        g.pop('dbConn')
Esempio n. 20
0
def close_db(e=None):
    db = g.pop("db", None)

    if db is not None:
        # Call destructor to run cleanup
        del db
Esempio n. 21
0
def close_db(e=None):
    """If this request connected to the database, close the
    connection.
    """
    db = g.pop("db", None)
Esempio n. 22
0
def close_db():
    db_client = g.pop('db_client', None)
    if db_client is not None:
        db_client.close()
Esempio n. 23
0
def close_oidc(app):
    """ Release okta connection
    """
    oidc = g.pop('oidc', None)
    if oidc is not None:
        oidc.logout()
Esempio n. 24
0
def close_db(e=None):
    db = g.pop(current_app.config['DATABASE'], None)

    if db is not None:
        db.close()
Esempio n. 25
0
def close_db(e=None):
    db = g.pop("db", None)

    if db is not None:
        db.close()
Esempio n. 26
0
 def close_db(_):
     dbp = g.pop("db", None)
     if dbp is not None:
         dbp.close()
Esempio n. 27
0
 def close_db(e = None):
     db_session.remove()
     db = g.pop('db', None)
     if db is not None:
         db.close()
Esempio n. 28
0
def close_db(e=None):
    if e is not None:
        print(f'Closing db: {e}')
    db = g.pop('db', None)
    if db is not None:
        db.close()
Esempio n. 29
0
def close_lijing_db(e=None):
    db = g.pop('lijing_db', None)

    if db is not None:
        db.close()
Esempio n. 30
0
File: db.py Progetto: haraldvt/pls
def close_db(e=None):
    db = g.pop('db', None)

    if db is not None:
        db.close()
Esempio n. 31
0
def track_time_changes(auto_extend=False, user=None):
    """Track time changes of event objects.

    This provides a list of changes while the context manager was
    active and also triggers `times_changed` signals.

    If the code running inside the ``with`` block of this context
    manager raises an exception, no signals will be triggered.

    :param auto_extend: Whether entry parents will get their boundaries
                        automatically extended or not. Passing ``'start'`` will
                        extend only start datetime, ``'end'`` to extend only
                        end datetime.
    :param user: The `User` that will trigger time changes.
    """
    if auto_extend:
        assert user is not None
    if 'old_times' in g:
        raise RuntimeError('time change tracking may not be nested')
    g.old_times = defaultdict(dict)
    changes = defaultdict(dict)
    try:
        yield changes
    except Exception:
        del g.old_times
        raise
    else:
        if auto_extend:
            by_start = auto_extend in (True, 'start')
            by_end = auto_extend in (True, 'end')
            initial_changes = set(g.old_times)
            # g.old_times changes during iteration
            for obj in list(g.old_times):
                if not isinstance(obj, Event):
                    obj.extend_parent(by_start=by_start, by_end=by_end)
            cascade_changes = set(g.old_times) - initial_changes
            for obj in cascade_changes:
                if isinstance(obj, Event):
                    if not obj.can_manage(user):
                        # TODO: raise Forbidden exceptions after adding protection check in the UI
                        raise UserValueError(
                            _("Your action requires modification of event boundaries, but you are "
                              "not authorized to manage the event."))
                elif not obj.object.can_manage(user):
                    # TODO: raise Forbidden exceptions after adding protection check in the UI
                    raise UserValueError(
                        _("Your action requires modification of session block boundaries, but you are "
                          "not authorized to manage the session block."))
        old_times = g.pop('old_times')
        for obj, info in old_times.iteritems():
            if isinstance(obj, TimetableEntry):
                obj = obj.object
            if obj.start_dt != info['start_dt']:
                changes[obj]['start_dt'] = (info['start_dt'], obj.start_dt)
            if obj.duration != info['duration']:
                changes[obj]['duration'] = (info['duration'], obj.duration)
            if obj.end_dt != info['end_dt']:
                changes[obj]['end_dt'] = (info['end_dt'], obj.end_dt)
        for obj, obj_changes in changes.iteritems():
            entry = None if isinstance(obj, Event) else obj.timetable_entry
            signals.event.times_changed.send(type(obj),
                                             entry=entry,
                                             obj=obj,
                                             changes=obj_changes)
Esempio n. 32
0
def close_db(e=None):
	db = g.pop('db', None)

	if(db != None):
		db.close()
Esempio n. 33
0
def close_db(e=None):
    """Checks if a database connection exists and closes it"""
    db = g.pop("db", None)

    if db is not None:
        db.close()
Esempio n. 34
0
def close_db(e=None):
    """close connection"""
    db_client = g.pop('db_client', None)
    if db_client is not None:
        db_client.close()
Esempio n. 35
0
File: base.py Progetto: fph/indico
 def _clear_cache():
     if has_request_context():
         g.pop('global_settings_cache', None)
Esempio n. 36
0
 def teardown_db(self, exc):
     db = g.pop('db', None)
     if db is not None:
         self.close(db)