Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack LLC # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License.
# maintain a single engine reference for sqlite in-memory
# For exporting to other modules
"""Ensure that the length of string field do not exceed the limit.
This decorator check the initialize arguments, to make sure the length of string field do not exceed the length limit, or raise a 'StringLengthExceeded' exception.
Use decorator instead of inheritance, because the metaclass will check the __tablename__, primary key columns, etc. at the class definition.
""" column.type.length < len(v): #if signing.token_format == 'PKI', the id will #store it's public key which is very long. self.__tablename__ == 'token' and \ k == 'id':
string=v, type=k, length=column.type.length)
global GLOBAL_ENGINE
# Special Fields
def from_dict(cls, d):
if k not in cls.attributes and k != 'extra')
"""Returns the model's attributes as a dictionary.
If include_extra_dict is True, 'extra' attributes are literally included in the resulting dictionary twice, for backwards-compatibility with a broken implementation.
"""
"""Make the model object behave like a dict.""" for k, v in values.iteritems(): setattr(self, k, v)
"""Make the model object behave like a dict.
Includes attributes from joins.
""" #local = dict(self) #joined = dict([(k, v) for k, v in self.__dict__.iteritems() # if not k[0] == '_']) #local.update(joined) #return local.iteritems()
"""Ensures that MySQL connections checked out of the pool are alive.
Borrowed from: http://groups.google.com/group/sqlalchemy/msg/a4ce563d802c929f
Error codes caught: * 2006 MySQL server has gone away * 2013 Lost connection to MySQL server during query * 2014 Commands out of sync; you can't run this command now * 2045 Can't open shared memory; no answer from server (%lu) * 2055 Lost connection to MySQL server at '%s', system error: %d
from http://dev.mysql.com/doc/refman/5.6/en/error-messages-client.html """
try: dbapi_con.cursor().execute('select 1') except dbapi_con.OperationalError as e: if e.args[0] in (2006, 2013, 2014, 2045, 2055): logging.warn(_('Got mysql server has gone away: %s'), e) raise DisconnectionError("Database server went away") else: raise
# Backends
"""Return a SQLAlchemy session.""" self._engine)
"""Return a SQLAlchemy engine.
If allow_global_engine is True and an in-memory sqlite connection string is provided by CONF, all backends will share a global sqlalchemy engine.
"""
'convert_unicode': True, 'echo': CONF.debug and CONF.verbose, 'pool_recycle': CONF.sql.idle_timeout, }
elif 'mysql' in connection_dict.drivername: engine_config['listeners'] = [MySQLPingListener()]
# auto-build the db to support wsgi server w/ in-memory backend
expire_on_commit=False): """Return a SQLAlchemy sessionmaker using the given engine.""" bind=engine, autocommit=autocommit, expire_on_commit=expire_on_commit)
"""Converts IntegrityError into HTTP 409 Conflict.""" def wrapper(*args, **kwargs): |