summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Jarrett <celttechie@gmail.com>2014-07-10 18:17:10 -0600
committerBrian Jarrett <celttechie@gmail.com>2014-07-12 13:17:56 -0600
commit9f94a353b19a78e528e41279709bc961e877d1aa (patch)
tree6b728175faed56e846c5a42c930249a6cc47f5df
parent600e6bfb3fa261b98b1ae7237080c8f5e757d09a (diff)
downloadsqlalchemy-pr/105.tar.gz
PEP8 Style fixes for lib/sqlalchemy/*.pypr/105
-rw-r--r--lib/sqlalchemy/__init__.py5
-rw-r--r--lib/sqlalchemy/events.py60
-rw-r--r--lib/sqlalchemy/exc.py39
-rw-r--r--lib/sqlalchemy/inspection.py6
-rw-r--r--lib/sqlalchemy/interfaces.py7
-rw-r--r--lib/sqlalchemy/log.py8
-rw-r--r--lib/sqlalchemy/pool.py214
-rw-r--r--lib/sqlalchemy/processors.py22
-rw-r--r--lib/sqlalchemy/types.py15
9 files changed, 200 insertions, 176 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index d55b8ba66..2ab717996 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -119,6 +119,7 @@ from .engine import create_engine, engine_from_config
__version__ = '1.0.0'
+
def __go(lcls):
global __all__
@@ -128,7 +129,7 @@ def __go(lcls):
import inspect as _inspect
__all__ = sorted(name for name, obj in lcls.items()
- if not (name.startswith('_') or _inspect.ismodule(obj)))
+ if not (name.startswith('_') or _inspect.ismodule(obj)))
_sa_util.dependencies.resolve_all("sqlalchemy")
-__go(locals()) \ No newline at end of file
+__go(locals())
diff --git a/lib/sqlalchemy/events.py b/lib/sqlalchemy/events.py
index 3f7a48304..42bbbfc0f 100644
--- a/lib/sqlalchemy/events.py
+++ b/lib/sqlalchemy/events.py
@@ -12,6 +12,7 @@ from .pool import Pool
from .engine import Connectable, Engine, Dialect
from .sql.base import SchemaEventTarget
+
class DDLEvents(event.Events):
"""
Define event listeners for schema objects,
@@ -221,7 +222,6 @@ class DDLEvents(event.Events):
"""
-
class PoolEvents(event.Events):
"""Available events for :class:`.Pool`.
@@ -291,9 +291,9 @@ class PoolEvents(event.Events):
:class:`.Pool` refers to a single "creator" function (which in terms
of a :class:`.Engine` refers to the URL and connection options used),
it is typically valid to make observations about a single connection
- that can be safely assumed to be valid about all subsequent connections,
- such as the database version, the server and client encoding settings,
- collation settings, and many others.
+ that can be safely assumed to be valid about all subsequent
+ connections, such as the database version, the server and client
+ encoding settings, collation settings, and many others.
:param dbapi_connection: a DBAPI connection.
@@ -311,8 +311,8 @@ class PoolEvents(event.Events):
DBAPI connection.
:param connection_proxy: the :class:`._ConnectionFairy` object which
- will proxy the public interface of the DBAPI connection for the lifespan
- of the checkout.
+ will proxy the public interface of the DBAPI connection for the
+ lifespan of the checkout.
If you raise a :class:`~sqlalchemy.exc.DisconnectionError`, the current
connection will be disposed and a fresh connection retrieved.
@@ -372,8 +372,8 @@ class PoolEvents(event.Events):
This event is called any time the :meth:`._ConnectionRecord.invalidate`
method is invoked, either from API usage or via "auto-invalidation".
- The event occurs before a final attempt to call ``.close()`` on the connection
- occurs.
+ The event occurs before a final attempt to call ``.close()`` on the
+ connection occurs.
:param dbapi_connection: a DBAPI connection.
@@ -467,7 +467,6 @@ class ConnectionEvents(event.Events):
_target_class_doc = "SomeEngine"
_dispatch_target = Connectable
-
@classmethod
def _listen(cls, event_key, retval=False):
target, identifier, fn = \
@@ -480,7 +479,7 @@ class ConnectionEvents(event.Events):
orig_fn = fn
def wrap_before_execute(conn, clauseelement,
- multiparams, params):
+ multiparams, params):
orig_fn(conn, clauseelement, multiparams, params)
return clauseelement, multiparams, params
fn = wrap_before_execute
@@ -488,19 +487,20 @@ class ConnectionEvents(event.Events):
orig_fn = fn
def wrap_before_cursor_execute(conn, cursor, statement,
- parameters, context, executemany):
+ parameters, context,
+ executemany):
orig_fn(conn, cursor, statement,
- parameters, context, executemany)
+ parameters, context, executemany)
return statement, parameters
fn = wrap_before_cursor_execute
elif retval and \
identifier not in ('before_execute',
- 'before_cursor_execute', 'handle_error'):
+ 'before_cursor_execute', 'handle_error'):
raise exc.ArgumentError(
- "Only the 'before_execute', "
- "'before_cursor_execute' and 'handle_error' engine "
- "event listeners accept the 'retval=True' "
- "argument.")
+ "Only the 'before_execute', "
+ "'before_cursor_execute' and 'handle_error' engine "
+ "event listeners accept the 'retval=True' "
+ "argument.")
event_key.with_wrapper(fn).base_listen()
def before_execute(self, conn, clauseelement, multiparams, params):
@@ -546,7 +546,7 @@ class ConnectionEvents(event.Events):
"""
def before_cursor_execute(self, conn, cursor, statement,
- parameters, context, executemany):
+ parameters, context, executemany):
"""Intercept low-level cursor execute() events before execution,
receiving the string
SQL statement and DBAPI-specific parameter list to be invoked
@@ -588,7 +588,7 @@ class ConnectionEvents(event.Events):
"""
def after_cursor_execute(self, conn, cursor, statement,
- parameters, context, executemany):
+ parameters, context, executemany):
"""Intercept low-level cursor execute() events after execution.
:param conn: :class:`.Connection` object
@@ -607,7 +607,7 @@ class ConnectionEvents(event.Events):
"""
def dbapi_error(self, conn, cursor, statement, parameters,
- context, exception):
+ context, exception):
"""Intercept a raw DBAPI error.
This event is called with the DBAPI exception instance
@@ -750,8 +750,8 @@ class ConnectionEvents(event.Events):
It also differs from the :meth:`.PoolEvents.checkout` event
in that it is specific to the :class:`.Connection` object, not the
DBAPI connection that :meth:`.PoolEvents.checkout` deals with, although
- this DBAPI connection is available here via the :attr:`.Connection.connection`
- attribute. But note there can in fact
+ this DBAPI connection is available here via the
+ :attr:`.Connection.connection` attribute. But note there can in fact
be multiple :meth:`.PoolEvents.checkout` events within the lifespan
of a single :class:`.Connection` object, if that :class:`.Connection`
is invalidated and re-established. There can also be multiple
@@ -773,8 +773,8 @@ class ConnectionEvents(event.Events):
:meth:`.PoolEvents.checkout` the lower-level pool checkout event
for an individual DBAPI connection
- :meth:`.ConnectionEvents.set_connection_execution_options` - a copy of a
- :class:`.Connection` is also made when the
+ :meth:`.ConnectionEvents.set_connection_execution_options` - a copy
+ of a :class:`.Connection` is also made when the
:meth:`.Connection.execution_options` method is called.
"""
@@ -828,7 +828,8 @@ class ConnectionEvents(event.Events):
.. seealso::
:meth:`.ConnectionEvents.set_connection_execution_options` - event
- which is called when :meth:`.Connection.execution_options` is called.
+ which is called when :meth:`.Connection.execution_options` is
+ called.
"""
@@ -941,10 +942,10 @@ class DialectEvents(event.Events):
:class:`.DialectEvents` hooks should be considered **semi-public**
and experimental.
- These hooks are not for general use and are only for those situations where
- intricate re-statement of DBAPI mechanics must be injected onto an existing
- dialect. For general-use statement-interception events, please
- use the :class:`.ConnectionEvents` interface.
+ These hooks are not for general use and are only for those situations
+ where intricate re-statement of DBAPI mechanics must be injected onto
+ an existing dialect. For general-use statement-interception events,
+ please use the :class:`.ConnectionEvents` interface.
.. seealso::
@@ -1010,4 +1011,3 @@ class DialectEvents(event.Events):
place within the event handler.
"""
-
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index 965e55692..7d333fc01 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -27,10 +27,12 @@ class ArgumentError(SQLAlchemyError):
"""
+
class NoSuchModuleError(ArgumentError):
"""Raised when a dynamically-loaded module (usually a database dialect)
of a particular name cannot be located."""
+
class NoForeignKeysError(ArgumentError):
"""Raised when no foreign keys can be located between two selectables
during a join."""
@@ -70,12 +72,13 @@ class CircularDependencyError(SQLAlchemyError):
def __reduce__(self):
return self.__class__, (None, self.cycles,
- self.edges, self.args[0])
+ self.edges, self.args[0])
class CompileError(SQLAlchemyError):
"""Raised when an error occurs during SQL compilation"""
+
class UnsupportedCompilationError(CompileError):
"""Raised when an operation is not supported by the given compiler.
@@ -86,8 +89,9 @@ class UnsupportedCompilationError(CompileError):
def __init__(self, compiler, element_type):
super(UnsupportedCompilationError, self).__init__(
- "Compiler %r can't render element of type %s" %
- (compiler, element_type))
+ "Compiler %r can't render element of type %s" %
+ (compiler, element_type))
+
class IdentifierError(SQLAlchemyError):
"""Raised when a schema name is beyond the max character limit"""
@@ -160,7 +164,7 @@ class NoReferencedColumnError(NoReferenceError):
def __reduce__(self):
return self.__class__, (self.args[0], self.table_name,
- self.column_name)
+ self.column_name)
class NoSuchTableError(InvalidRequestError):
@@ -237,11 +241,11 @@ class StatementError(SQLAlchemyError):
params_repr = util._repr_params(self.params, 10)
return ' '.join([
- "(%s)" % det for det in self.detail
- ] + [
- SQLAlchemyError.__str__(self),
- repr(self.statement), repr(params_repr)
- ])
+ "(%s)" % det for det in self.detail
+ ] + [
+ SQLAlchemyError.__str__(self),
+ repr(self.statement), repr(params_repr)
+ ])
def __unicode__(self):
return self.__str__()
@@ -272,9 +276,8 @@ class DBAPIError(StatementError):
@classmethod
def instance(cls, statement, params,
- orig,
- dbapi_base_err,
- connection_invalidated=False):
+ orig, dbapi_base_err,
+ connection_invalidated=False):
# Don't ever wrap these, just return them directly as if
# DBAPIError didn't exist.
if isinstance(orig, (KeyboardInterrupt, SystemExit, DontWrapMixin)):
@@ -299,7 +302,7 @@ class DBAPIError(StatementError):
def __reduce__(self):
return self.__class__, (self.statement, self.params,
- self.orig, self.connection_invalidated)
+ self.orig, self.connection_invalidated)
def __init__(self, statement, params, orig, connection_invalidated=False):
try:
@@ -309,11 +312,11 @@ class DBAPIError(StatementError):
except Exception as e:
text = 'Error in str() of DB-API-generated exception: ' + str(e)
StatementError.__init__(
- self,
- '(%s) %s' % (orig.__class__.__name__, text),
- statement,
- params,
- orig
+ self,
+ '(%s) %s' % (orig.__class__.__name__, text),
+ statement,
+ params,
+ orig
)
self.connection_invalidated = connection_invalidated
diff --git a/lib/sqlalchemy/inspection.py b/lib/sqlalchemy/inspection.py
index dcd3b441d..ab9f2ae38 100644
--- a/lib/sqlalchemy/inspection.py
+++ b/lib/sqlalchemy/inspection.py
@@ -68,7 +68,7 @@ def inspect(subject, raiseerr=True):
if raiseerr and (
reg is None or ret is None
- ):
+ ):
raise exc.NoInspectionAvailable(
"No inspection system is "
"available for object of type %s" %
@@ -81,8 +81,8 @@ def _inspects(*types):
for type_ in types:
if type_ in _registrars:
raise AssertionError(
- "Type %s is already "
- "registered" % type_)
+ "Type %s is already "
+ "registered" % type_)
_registrars[type_] = fn_or_cls
return fn_or_cls
return decorate
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py
index f09a3ff81..ae11d1930 100644
--- a/lib/sqlalchemy/interfaces.py
+++ b/lib/sqlalchemy/interfaces.py
@@ -80,8 +80,9 @@ class PoolListener(object):
"""
- listener = util.as_interface(listener, methods=('connect',
- 'first_connect', 'checkout', 'checkin'))
+ listener = util.as_interface(listener,
+ methods=('connect', 'first_connect',
+ 'checkout', 'checkin'))
if hasattr(listener, 'connect'):
event.listen(self, 'connect', listener.connect)
if hasattr(listener, 'first_connect'):
@@ -206,7 +207,7 @@ class ConnectionProxy(object):
statement,
parameters,
context,
- ):
+ ):
return statement, parameters
return listener.cursor_execute(
diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py
index 88d6de089..b3c9ae024 100644
--- a/lib/sqlalchemy/log.py
+++ b/lib/sqlalchemy/log.py
@@ -47,6 +47,7 @@ def class_logger(cls):
_logged_classes.add(cls)
return cls
+
class Identified(object):
logging_name = None
@@ -91,7 +92,7 @@ class InstanceLogger(object):
# if echo flag is enabled and no handlers,
# add a handler to the list
if self._echo_map[echo] <= logging.INFO \
- and not self.logger.handlers:
+ and not self.logger.handlers:
_add_default_handler(self.logger)
#
@@ -174,10 +175,11 @@ def instance_logger(instance, echoflag=None):
if instance.logging_name:
name = "%s.%s.%s" % (instance.__class__.__module__,
- instance.__class__.__name__, instance.logging_name)
+ instance.__class__.__name__,
+ instance.logging_name)
else:
name = "%s.%s" % (instance.__class__.__module__,
- instance.__class__.__name__)
+ instance.__class__.__name__)
instance._echo = echoflag
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index 7150ce81f..d26bbf32c 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -67,7 +67,9 @@ reset_rollback = util.symbol('reset_rollback')
reset_commit = util.symbol('reset_commit')
reset_none = util.symbol('reset_none')
+
class _ConnDialect(object):
+
"""partial implementation of :class:`.Dialect`
which provides DBAPI connection methods.
@@ -76,6 +78,7 @@ class _ConnDialect(object):
:class:`.Dialect`.
"""
+
def do_rollback(self, dbapi_connection):
dbapi_connection.rollback()
@@ -85,20 +88,22 @@ class _ConnDialect(object):
def do_close(self, dbapi_connection):
dbapi_connection.close()
+
class Pool(log.Identified):
+
"""Abstract base class for connection pools."""
_dialect = _ConnDialect()
def __init__(self,
- creator, recycle=-1, echo=None,
- use_threadlocal=False,
- logging_name=None,
- reset_on_return=True,
- listeners=None,
- events=None,
- _dispatch=None,
- _dialect=None):
+ creator, recycle=-1, echo=None,
+ use_threadlocal=False,
+ logging_name=None,
+ reset_on_return=True,
+ listeners=None,
+ events=None,
+ _dispatch=None,
+ _dialect=None):
"""
Construct a Pool.
@@ -134,10 +139,10 @@ class Pool(log.Identified):
.. warning:: The :paramref:`.Pool.use_threadlocal` flag
**does not affect the behavior** of :meth:`.Engine.connect`.
- :meth:`.Engine.connect` makes use of the :meth:`.Pool.unique_connection`
- method which **does not use thread local context**.
- To produce a :class:`.Connection` which refers to the
- :meth:`.Pool.connect` method, use
+ :meth:`.Engine.connect` makes use of the
+ :meth:`.Pool.unique_connection` method which **does not use thread
+ local context**. To produce a :class:`.Connection` which refers
+ to the :meth:`.Pool.connect` method, use
:meth:`.Engine.contextual_connect`.
Note that other SQLAlchemy connectivity systems such as
@@ -221,8 +226,8 @@ class Pool(log.Identified):
self._reset_on_return = reset_commit
else:
raise exc.ArgumentError(
- "Invalid value for 'reset_on_return': %r"
- % reset_on_return)
+ "Invalid value for 'reset_on_return': %r"
+ % reset_on_return)
self.echo = echo
if _dispatch:
@@ -234,8 +239,8 @@ class Pool(log.Identified):
event.listen(self, target, fn)
if listeners:
util.warn_deprecated(
- "The 'listeners' argument to Pool (and "
- "create_engine()) is deprecated. Use event.listen().")
+ "The 'listeners' argument to Pool (and "
+ "create_engine()) is deprecated. Use event.listen().")
for l in listeners:
self.add_listener(l)
@@ -247,7 +252,7 @@ class Pool(log.Identified):
raise
except:
self.logger.error("Exception closing connection %r",
- connection, exc_info=True)
+ connection, exc_info=True)
@util.deprecated(
2.7, "Pool.add_listener is deprecated. Use event.listen()")
@@ -267,8 +272,9 @@ class Pool(log.Identified):
This method is equivalent to :meth:`.Pool.connect` when the
:paramref:`.Pool.use_threadlocal` flag is not set to True.
- When :paramref:`.Pool.use_threadlocal` is True, the :meth:`.Pool.unique_connection`
- method provides a means of bypassing the threadlocal context.
+ When :paramref:`.Pool.use_threadlocal` is True, the
+ :meth:`.Pool.unique_connection` method provides a means of bypassing
+ the threadlocal context.
"""
return _ConnectionFairy._checkout(self)
@@ -295,7 +301,6 @@ class Pool(log.Identified):
if getattr(connection, 'is_valid', False):
connection.invalidate(exception)
-
def recreate(self):
"""Return a new :class:`.Pool`, of the same class as this one
and configured with identical creation arguments.
@@ -371,6 +376,7 @@ class Pool(log.Identified):
class _ConnectionRecord(object):
+
"""Internal object which maintains an individual DBAPI connection
referenced by a :class:`.Pool`.
@@ -406,8 +412,8 @@ class _ConnectionRecord(object):
self.finalize_callback = deque()
pool.dispatch.first_connect.\
- for_modify(pool.dispatch).\
- exec_once(self.connection, self)
+ for_modify(pool.dispatch).\
+ exec_once(self.connection, self)
pool.dispatch.connect(self.connection, self)
connection = None
@@ -439,16 +445,16 @@ class _ConnectionRecord(object):
raise
fairy = _ConnectionFairy(dbapi_connection, rec)
rec.fairy_ref = weakref.ref(
- fairy,
- lambda ref: _finalize_fairy and \
- _finalize_fairy(
- dbapi_connection,
- rec, pool, ref, pool._echo)
- )
+ fairy,
+ lambda ref: _finalize_fairy and
+ _finalize_fairy(
+ dbapi_connection,
+ rec, pool, ref, pool._echo)
+ )
_refs.add(rec)
if pool._echo:
pool.logger.debug("Connection %r checked out from pool",
- dbapi_connection)
+ dbapi_connection)
return fairy
def checkin(self):
@@ -462,7 +468,6 @@ class _ConnectionRecord(object):
pool.dispatch.checkin(connection, self)
pool._return_conn(self)
-
def close(self):
if self.connection is not None:
self.__close()
@@ -471,9 +476,9 @@ class _ConnectionRecord(object):
"""Invalidate the DBAPI connection held by this :class:`._ConnectionRecord`.
This method is called for all connection invalidations, including
- when the :meth:`._ConnectionFairy.invalidate` or :meth:`.Connection.invalidate`
- methods are called, as well as when any so-called "automatic invalidation"
- condition occurs.
+ when the :meth:`._ConnectionFairy.invalidate` or
+ :meth:`.Connection.invalidate` methods are called, as well as when any
+ so-called "automatic invalidation" condition occurs.
.. seealso::
@@ -504,14 +509,15 @@ class _ConnectionRecord(object):
elif self.__pool._recycle > -1 and \
time.time() - self.starttime > self.__pool._recycle:
self.__pool.logger.info(
- "Connection %r exceeded timeout; recycling",
- self.connection)
+ "Connection %r exceeded timeout; recycling",
+ self.connection)
recycle = True
elif self.__pool._invalidate_time > self.starttime:
self.__pool.logger.info(
- "Connection %r invalidated due to pool invalidation; recycling",
- self.connection
- )
+ "Connection %r invalidated due to pool invalidation; " +
+ "recycling",
+ self.connection
+ )
recycle = True
if recycle:
@@ -536,7 +542,8 @@ class _ConnectionRecord(object):
raise
-def _finalize_fairy(connection, connection_record, pool, ref, echo, fairy=None):
+def _finalize_fairy(connection, connection_record,
+ pool, ref, echo, fairy=None):
"""Cleanup for a :class:`._ConnectionFairy` whether or not it's already
been garbage collected.
@@ -544,13 +551,13 @@ def _finalize_fairy(connection, connection_record, pool, ref, echo, fairy=None):
_refs.discard(connection_record)
if ref is not None and \
- connection_record.fairy_ref is not ref:
+ connection_record.fairy_ref is not ref:
return
if connection is not None:
if connection_record and echo:
pool.logger.debug("Connection %r being returned to pool",
- connection)
+ connection)
try:
fairy = fairy or _ConnectionFairy(connection, connection_record)
@@ -561,7 +568,8 @@ def _finalize_fairy(connection, connection_record, pool, ref, echo, fairy=None):
if not connection_record:
pool._close_connection(connection)
except Exception as e:
- pool.logger.error("Exception during reset or similar", exc_info=True)
+ pool.logger.error(
+ "Exception during reset or similar", exc_info=True)
if connection_record:
connection_record.invalidate(e=e)
if isinstance(e, (SystemExit, KeyboardInterrupt)):
@@ -575,6 +583,7 @@ _refs = set()
class _ConnectionFairy(object):
+
"""Proxies a DBAPI connection and provides return-on-dereference
support.
@@ -582,10 +591,11 @@ class _ConnectionFairy(object):
to provide context management to a DBAPI connection delivered by
that :class:`.Pool`.
- The name "fairy" is inspired by the fact that the :class:`._ConnectionFairy`
- object's lifespan is transitory, as it lasts only for the length of a
- specific DBAPI connection being checked out from the pool, and additionally
- that as a transparent proxy, it is mostly invisible.
+ The name "fairy" is inspired by the fact that the
+ :class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
+ only for the length of a specific DBAPI connection being checked out from
+ the pool, and additionally that as a transparent proxy, it is mostly
+ invisible.
.. seealso::
@@ -611,8 +621,8 @@ class _ConnectionFairy(object):
_reset_agent = None
"""Refer to an object with a ``.commit()`` and ``.rollback()`` method;
if non-None, the "reset-on-return" feature will call upon this object
- rather than directly against the dialect-level do_rollback() and do_commit()
- methods.
+ rather than directly against the dialect-level do_rollback() and
+ do_commit() methods.
In practice, a :class:`.Connection` assigns a :class:`.Transaction` object
to this variable when one is in scope so that the :class:`.Transaction`
@@ -649,8 +659,8 @@ class _ConnectionFairy(object):
while attempts > 0:
try:
pool.dispatch.checkout(fairy.connection,
- fairy._connection_record,
- fairy)
+ fairy._connection_record,
+ fairy)
return fairy
except exc.DisconnectionError as e:
pool.logger.info(
@@ -668,7 +678,7 @@ class _ConnectionFairy(object):
def _checkin(self):
_finalize_fairy(self.connection, self._connection_record,
- self._pool, None, self._echo, fairy=self)
+ self._pool, None, self._echo, fairy=self)
self.connection = None
self._connection_record = None
@@ -680,9 +690,9 @@ class _ConnectionFairy(object):
if pool._reset_on_return is reset_rollback:
if echo:
pool.logger.debug("Connection %s rollback-on-return%s",
- self.connection,
- ", via agent"
- if self._reset_agent else "")
+ self.connection,
+ ", via agent"
+ if self._reset_agent else "")
if self._reset_agent:
self._reset_agent.rollback()
else:
@@ -690,9 +700,9 @@ class _ConnectionFairy(object):
elif pool._reset_on_return is reset_commit:
if echo:
pool.logger.debug("Connection %s commit-on-return%s",
- self.connection,
- ", via agent"
- if self._reset_agent else "")
+ self.connection,
+ ", via agent"
+ if self._reset_agent else "")
if self._reset_agent:
self._reset_agent.commit()
else:
@@ -759,7 +769,6 @@ class _ConnectionFairy(object):
def __getattr__(self, key):
return getattr(self.connection, key)
-
def detach(self):
"""Separate this connection from its Pool.
@@ -788,8 +797,8 @@ class _ConnectionFairy(object):
self._checkin()
-
class SingletonThreadPool(Pool):
+
"""A Pool that maintains one connection per thread.
Maintains one connection per each thread, never moving a connection to a
@@ -816,14 +825,14 @@ class SingletonThreadPool(Pool):
def recreate(self):
self.logger.info("Pool recreating")
return self.__class__(self._creator,
- pool_size=self.size,
- recycle=self._recycle,
- echo=self.echo,
- logging_name=self._orig_logging_name,
- use_threadlocal=self._use_threadlocal,
- reset_on_return=self._reset_on_return,
- _dispatch=self.dispatch,
- _dialect=self._dialect)
+ pool_size=self.size,
+ recycle=self._recycle,
+ echo=self.echo,
+ logging_name=self._orig_logging_name,
+ use_threadlocal=self._use_threadlocal,
+ reset_on_return=self._reset_on_return,
+ _dispatch=self.dispatch,
+ _dialect=self._dialect)
def dispose(self):
"""Dispose of this pool."""
@@ -847,7 +856,7 @@ class SingletonThreadPool(Pool):
def status(self):
return "SingletonThreadPool id:%d size: %d" % \
- (id(self), len(self._all_conns))
+ (id(self), len(self._all_conns))
def _do_return_conn(self, conn):
pass
@@ -868,6 +877,7 @@ class SingletonThreadPool(Pool):
class QueuePool(Pool):
+
"""A :class:`.Pool` that imposes a limit on the number of open connections.
:class:`.QueuePool` is the default pooling implementation used for
@@ -908,9 +918,10 @@ class QueuePool(Pool):
:param timeout: The number of seconds to wait before giving up
on returning a connection. Defaults to 30.
- :param \**kw: Other keyword arguments including :paramref:`.Pool.recycle`,
- :paramref:`.Pool.echo`, :paramref:`.Pool.reset_on_return` and others
- are passed to the :class:`.Pool` constructor.
+ :param \**kw: Other keyword arguments including
+ :paramref:`.Pool.recycle`, :paramref:`.Pool.echo`,
+ :paramref:`.Pool.reset_on_return` and others are passed to the
+ :class:`.Pool` constructor.
"""
Pool.__init__(self, creator, **kw)
@@ -941,9 +952,9 @@ class QueuePool(Pool):
return self._do_get()
else:
raise exc.TimeoutError(
- "QueuePool limit of size %d overflow %d reached, "
- "connection timed out, timeout %d" %
- (self.size(), self.overflow(), self._timeout))
+ "QueuePool limit of size %d overflow %d reached, "
+ "connection timed out, timeout %d" %
+ (self.size(), self.overflow(), self._timeout))
if self._inc_overflow():
try:
@@ -976,14 +987,14 @@ class QueuePool(Pool):
def recreate(self):
self.logger.info("Pool recreating")
return self.__class__(self._creator, pool_size=self._pool.maxsize,
- max_overflow=self._max_overflow,
- timeout=self._timeout,
- recycle=self._recycle, echo=self.echo,
- logging_name=self._orig_logging_name,
- use_threadlocal=self._use_threadlocal,
- reset_on_return=self._reset_on_return,
- _dispatch=self.dispatch,
- _dialect=self._dialect)
+ max_overflow=self._max_overflow,
+ timeout=self._timeout,
+ recycle=self._recycle, echo=self.echo,
+ logging_name=self._orig_logging_name,
+ use_threadlocal=self._use_threadlocal,
+ reset_on_return=self._reset_on_return,
+ _dispatch=self.dispatch,
+ _dialect=self._dialect)
def dispose(self):
while True:
@@ -998,11 +1009,11 @@ class QueuePool(Pool):
def status(self):
return "Pool size: %d Connections in pool: %d "\
- "Current Overflow: %d Current Checked out "\
- "connections: %d" % (self.size(),
- self.checkedin(),
- self.overflow(),
- self.checkedout())
+ "Current Overflow: %d Current Checked out "\
+ "connections: %d" % (self.size(),
+ self.checkedin(),
+ self.overflow(),
+ self.checkedout())
def size(self):
return self._pool.maxsize
@@ -1018,6 +1029,7 @@ class QueuePool(Pool):
class NullPool(Pool):
+
"""A Pool which does not pool connections.
Instead it literally opens and closes the underlying DB-API connection
@@ -1046,19 +1058,20 @@ class NullPool(Pool):
self.logger.info("Pool recreating")
return self.__class__(self._creator,
- recycle=self._recycle,
- echo=self.echo,
- logging_name=self._orig_logging_name,
- use_threadlocal=self._use_threadlocal,
- reset_on_return=self._reset_on_return,
- _dispatch=self.dispatch,
- _dialect=self._dialect)
+ recycle=self._recycle,
+ echo=self.echo,
+ logging_name=self._orig_logging_name,
+ use_threadlocal=self._use_threadlocal,
+ reset_on_return=self._reset_on_return,
+ _dispatch=self.dispatch,
+ _dialect=self._dialect)
def dispose(self):
pass
class StaticPool(Pool):
+
"""A Pool of exactly one connection, used for all requests.
Reconnect-related functions such as ``recycle`` and connection
@@ -1106,6 +1119,7 @@ class StaticPool(Pool):
class AssertionPool(Pool):
+
"""A :class:`.Pool` that allows at most one checked out connection at
any given time.
@@ -1119,6 +1133,7 @@ class AssertionPool(Pool):
this in the assertion error raised.
"""
+
def __init__(self, *args, **kw):
self._conn = None
self._checked_out = False
@@ -1143,9 +1158,9 @@ class AssertionPool(Pool):
def recreate(self):
self.logger.info("Pool recreating")
return self.__class__(self._creator, echo=self.echo,
- logging_name=self._orig_logging_name,
- _dispatch=self.dispatch,
- _dialect=self._dialect)
+ logging_name=self._orig_logging_name,
+ _dispatch=self.dispatch,
+ _dialect=self._dialect)
def _do_get(self):
if self._checked_out:
@@ -1166,6 +1181,7 @@ class AssertionPool(Pool):
class _DBProxy(object):
+
"""Layers connection pooling behavior on top of a standard DB-API module.
Proxies a DB-API 2.0 connect() call to a connection pool keyed to the
@@ -1211,8 +1227,8 @@ class _DBProxy(object):
try:
if key not in self.pools:
kw.pop('sa_pool_key', None)
- pool = self.poolclass(lambda:
- self.module.connect(*args, **kw), **self.kw)
+ pool = self.poolclass(
+ lambda: self.module.connect(*args, **kw), **self.kw)
self.pools[key] = pool
return pool
else:
diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py
index 0f47f4e66..3794b01f5 100644
--- a/lib/sqlalchemy/processors.py
+++ b/lib/sqlalchemy/processors.py
@@ -33,15 +33,17 @@ def str_to_datetime_processor_factory(regexp, type_):
m = rmatch(value)
except TypeError:
raise ValueError("Couldn't parse %s string '%r' "
- "- value is not a string." %
- (type_.__name__, value))
+ "- value is not a string." %
+ (type_.__name__, value))
if m is None:
raise ValueError("Couldn't parse %s string: "
- "'%s'" % (type_.__name__, value))
+ "'%s'" % (type_.__name__, value))
if has_named_groups:
groups = m.groupdict(0)
- return type_(**dict(list(zip(iter(groups.keys()),
- list(map(int, iter(groups.values())))))))
+ return type_(**dict(list(zip(
+ iter(groups.keys()),
+ list(map(int, iter(groups.values())))
+ ))))
else:
return type_(*list(map(int, m.groups(0))))
return process
@@ -112,7 +114,7 @@ def py_fallback():
return value and True or False
DATETIME_RE = re.compile(
- "(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?")
+ "(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)(?:\.(\d+))?")
TIME_RE = re.compile("(\d+):(\d+):(\d+)(?:\.(\d+))?")
DATE_RE = re.compile("(\d+)-(\d+)-(\d+)")
@@ -124,10 +126,10 @@ def py_fallback():
try:
from sqlalchemy.cprocessors import UnicodeResultProcessor, \
- DecimalResultProcessor, \
- to_float, to_str, int_to_boolean, \
- str_to_datetime, str_to_time, \
- str_to_date
+ DecimalResultProcessor, \
+ to_float, to_str, int_to_boolean, \
+ str_to_datetime, str_to_time, \
+ str_to_date
def to_unicode_processor_factory(encoding, errors=None):
if errors is not None:
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 75fabcad8..b49e389ac 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -10,13 +10,13 @@
"""
__all__ = ['TypeEngine', 'TypeDecorator', 'UserDefinedType',
- 'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'NVARCHAR', 'TEXT', 'Text',
- 'FLOAT', 'NUMERIC', 'REAL', 'DECIMAL', 'TIMESTAMP', 'DATETIME',
- 'CLOB', 'BLOB', 'BINARY', 'VARBINARY', 'BOOLEAN', 'BIGINT',
- 'SMALLINT', 'INTEGER', 'DATE', 'TIME', 'String', 'Integer',
- 'SmallInteger', 'BigInteger', 'Numeric', 'Float', 'DateTime',
- 'Date', 'Time', 'LargeBinary', 'Binary', 'Boolean', 'Unicode',
- 'Concatenable', 'UnicodeText', 'PickleType', 'Interval', 'Enum']
+ 'INT', 'CHAR', 'VARCHAR', 'NCHAR', 'NVARCHAR', 'TEXT', 'Text',
+ 'FLOAT', 'NUMERIC', 'REAL', 'DECIMAL', 'TIMESTAMP', 'DATETIME',
+ 'CLOB', 'BLOB', 'BINARY', 'VARBINARY', 'BOOLEAN', 'BIGINT',
+ 'SMALLINT', 'INTEGER', 'DATE', 'TIME', 'String', 'Integer',
+ 'SmallInteger', 'BigInteger', 'Numeric', 'Float', 'DateTime',
+ 'Date', 'Time', 'LargeBinary', 'Binary', 'Boolean', 'Unicode',
+ 'Concatenable', 'UnicodeText', 'PickleType', 'Interval', 'Enum']
from .sql.type_api import (
adapt_type,
@@ -75,4 +75,3 @@ from .sql.sqltypes import (
VARCHAR,
_type_map
)
-