diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-28 15:50:05 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-07-28 15:50:05 -0400 |
commit | 27913554a85c308d81e6c018669d0246ceecc639 (patch) | |
tree | 191305298ce66000c95c9c8fec1e27350f0d206e /lib/sqlalchemy/dialects/postgresql/psycopg2.py | |
parent | 90571b3a3a4eca329ec14e9bd142ad2b96526d99 (diff) | |
download | sqlalchemy-27913554a85c308d81e6c018669d0246ceecc639.tar.gz |
trailing whitespace bonanza
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/psycopg2.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/psycopg2.py | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 44ed7fc91..8976ca990 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -10,7 +10,7 @@ Driver ------ The psycopg2 driver is available at http://pypi.python.org/pypi/psycopg2/ . -The dialect has several behaviors which are specifically tailored towards compatibility +The dialect has several behaviors which are specifically tailored towards compatibility with this module. Note that psycopg1 is **not** supported. @@ -48,7 +48,7 @@ which specifies Unix-domain communication rather than TCP/IP communication:: create_engine("postgresql+psycopg2://user:password@/dbname") By default, the socket file used is to connect to a Unix-domain socket -in ``/tmp``, or whatever socket directory was specified when PostgreSQL +in ``/tmp``, or whatever socket directory was specified when PostgreSQL was built. This value can be overridden by passing a pathname to psycopg2, using ``host`` as an additional keyword argument:: @@ -61,11 +61,11 @@ See also: Per-Statement/Connection Execution Options ------------------------------------------- -The following DBAPI-specific options are respected when used with +The following DBAPI-specific options are respected when used with :meth:`.Connection.execution_options`, :meth:`.Executable.execution_options`, :meth:`.Query.execution_options`, in addition to those not specific to DBAPIs: -* isolation_level - Set the transaction isolation level for the lifespan of a +* isolation_level - Set the transaction isolation level for the lifespan of a :class:`.Connection` (can only be set on a connection, not a statement or query). This includes the options ``SERIALIZABLE``, ``READ COMMITTED``, ``READ UNCOMMITTED`` and ``REPEATABLE READ``. @@ -79,8 +79,8 @@ By default, the psycopg2 driver uses the ``psycopg2.extensions.UNICODE`` extension, such that the DBAPI receives and returns all strings as Python Unicode objects directly - SQLAlchemy passes these values through without change. Psycopg2 here will encode/decode string values based on the -current "client encoding" setting; by default this is the value in -the ``postgresql.conf`` file, which often defaults to ``SQL_ASCII``. +current "client encoding" setting; by default this is the value in +the ``postgresql.conf`` file, which often defaults to ``SQL_ASCII``. Typically, this can be changed to ``utf-8``, as a more useful default:: #client_encoding = sql_ascii # actually, defaults to database @@ -90,7 +90,7 @@ Typically, this can be changed to ``utf-8``, as a more useful default:: A second way to affect the client encoding is to set it within Psycopg2 locally. SQLAlchemy will call psycopg2's ``set_client_encoding()`` method (see: http://initd.org/psycopg/docs/connection.html#connection.set_client_encoding) -on all new connections based on the value passed to +on all new connections based on the value passed to :func:`.create_engine` using the ``client_encoding`` parameter:: engine = create_engine("postgresql://user:pass@host/dbname", client_encoding='utf8') @@ -102,15 +102,15 @@ This overrides the encoding specified in the Postgresql client configuration. SQLAlchemy can also be instructed to skip the usage of the psycopg2 ``UNICODE`` extension and to instead utilize it's own unicode encode/decode -services, which are normally reserved only for those DBAPIs that don't -fully support unicode directly. Passing ``use_native_unicode=False`` +services, which are normally reserved only for those DBAPIs that don't +fully support unicode directly. Passing ``use_native_unicode=False`` to :func:`.create_engine` will disable usage of ``psycopg2.extensions.UNICODE``. -SQLAlchemy will instead encode data itself into Python bytestrings on the way +SQLAlchemy will instead encode data itself into Python bytestrings on the way in and coerce from bytes on the way back, -using the value of the :func:`.create_engine` ``encoding`` parameter, which +using the value of the :func:`.create_engine` ``encoding`` parameter, which defaults to ``utf-8``. SQLAlchemy's own unicode encode/decode functionality is steadily becoming -obsolete as more DBAPIs support unicode fully along with the approach of +obsolete as more DBAPIs support unicode fully along with the approach of Python 3; in modern usage psycopg2 should be relied upon to handle unicode. Transactions @@ -132,7 +132,7 @@ at the API level what level should be used. NOTICE logging --------------- -The psycopg2 dialect will log Postgresql NOTICE messages via the +The psycopg2 dialect will log Postgresql NOTICE messages via the ``sqlalchemy.dialects.postgresql`` logger:: import logging @@ -220,8 +220,8 @@ class PGExecutionContext_psycopg2(PGExecutionContext): (self.compiled and isinstance(self.compiled.statement, expression.Selectable) \ or \ ( - (not self.compiled or - isinstance(self.compiled.statement, expression.TextClause)) + (not self.compiled or + isinstance(self.compiled.statement, expression.TextClause)) and self.statement and SERVER_SIDE_CURSOR_RE.match(self.statement)) ) ) @@ -249,7 +249,7 @@ class PGExecutionContext_psycopg2(PGExecutionContext): def _log_notices(self, cursor): for notice in cursor.connection.notices: - # NOTICE messages have a + # NOTICE messages have a # newline character at the end logger.info(notice.rstrip()) @@ -291,7 +291,7 @@ class PGDialect_psycopg2(PGDialect): } ) - def __init__(self, server_side_cursors=False, use_native_unicode=True, + def __init__(self, server_side_cursors=False, use_native_unicode=True, client_encoding=None, **kwargs): PGDialect.__init__(self, **kwargs) self.server_side_cursors = server_side_cursors @@ -299,12 +299,12 @@ class PGDialect_psycopg2(PGDialect): self.supports_unicode_binds = use_native_unicode self.client_encoding = client_encoding if self.dbapi and hasattr(self.dbapi, '__version__'): - m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', + m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', self.dbapi.__version__) if m: self.psycopg2_version = tuple( - int(x) - for x in m.group(1, 2, 3) + int(x) + for x in m.group(1, 2, 3) if x is not None) @classmethod @@ -316,8 +316,8 @@ class PGDialect_psycopg2(PGDialect): def _isolation_lookup(self): extensions = __import__('psycopg2.extensions').extensions return { - 'READ COMMITTED':extensions.ISOLATION_LEVEL_READ_COMMITTED, - 'READ UNCOMMITTED':extensions.ISOLATION_LEVEL_READ_UNCOMMITTED, + 'READ COMMITTED':extensions.ISOLATION_LEVEL_READ_COMMITTED, + 'READ UNCOMMITTED':extensions.ISOLATION_LEVEL_READ_UNCOMMITTED, 'REPEATABLE READ':extensions.ISOLATION_LEVEL_REPEATABLE_READ, 'SERIALIZABLE':extensions.ISOLATION_LEVEL_SERIALIZABLE } @@ -328,9 +328,9 @@ class PGDialect_psycopg2(PGDialect): except KeyError: raise exc.ArgumentError( "Invalid value '%s' for isolation_level. " - "Valid isolation levels for %s are %s" % + "Valid isolation levels for %s are %s" % (level, self.name, ", ".join(self._isolation_lookup)) - ) + ) connection.set_isolation_level(level) @@ -370,8 +370,8 @@ class PGDialect_psycopg2(PGDialect): def is_disconnect(self, e, connection, cursor): if isinstance(e, self.dbapi.OperationalError): # these error messages from libpq: interfaces/libpq/fe-misc.c. - # TODO: these are sent through gettext in libpq and we can't - # check within other locales - consider using connection.closed + # TODO: these are sent through gettext in libpq and we can't + # check within other locales - consider using connection.closed return 'closed the connection' in str(e) or \ 'connection not open' in str(e) or \ 'could not receive data from server' in str(e) @@ -380,7 +380,7 @@ class PGDialect_psycopg2(PGDialect): return 'connection already closed' in str(e) or \ 'cursor already closed' in str(e) elif isinstance(e, self.dbapi.ProgrammingError): - # not sure where this path is originally from, it may + # not sure where this path is originally from, it may # be obsolete. It really says "losed", not "closed". return "losed the connection unexpectedly" in str(e) else: |