diff options
Diffstat (limited to 'lib/sqlalchemy')
21 files changed, 25 insertions, 631 deletions
diff --git a/lib/sqlalchemy/connectors/zxJDBC.py b/lib/sqlalchemy/connectors/zxJDBC.py deleted file mode 100644 index 36c3fbc67..000000000 --- a/lib/sqlalchemy/connectors/zxJDBC.py +++ /dev/null @@ -1,68 +0,0 @@ -# connectors/zxJDBC.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -import sys - -from . import Connector - - -class ZxJDBCConnector(Connector): - driver = "zxjdbc" - - supports_sane_rowcount = False - supports_sane_multi_rowcount = False - - supports_unicode_binds = True - supports_unicode_statements = sys.version > "2.5.0+" - description_encoding = None - default_paramstyle = "qmark" - - jdbc_db_name = None - jdbc_driver_name = None - - @classmethod - def dbapi(cls): - from com.ziclix.python.sql import zxJDBC - - return zxJDBC - - def _driver_kwargs(self): - """Return kw arg dict to be sent to connect().""" - return {} - - def _create_jdbc_url(self, url): - """Create a JDBC url from a :class:`~sqlalchemy.engine.url.URL`""" - return "jdbc:%s://%s%s/%s" % ( - self.jdbc_db_name, - url.host, - url.port is not None and ":%s" % url.port or "", - url.database, - ) - - def create_connect_args(self, url): - opts = self._driver_kwargs() - opts.update(url.query) - return [ - [ - self._create_jdbc_url(url), - url.username, - url.password, - self.jdbc_driver_name, - ], - opts, - ] - - def is_disconnect(self, e, connection, cursor): - if not isinstance(e, self.dbapi.ProgrammingError): - return False - e = str(e) - return "connection is closed" in e or "cursor is closed" in e - - def _get_server_version_info(self, connection): - # use connection.connection.dbversion, and parse appropriately - # to get a tuple - raise NotImplementedError() diff --git a/lib/sqlalchemy/dialects/mssql/__init__.py b/lib/sqlalchemy/dialects/mssql/__init__.py index d8d577a65..67830affe 100644 --- a/lib/sqlalchemy/dialects/mssql/__init__.py +++ b/lib/sqlalchemy/dialects/mssql/__init__.py @@ -10,7 +10,6 @@ from . import base # noqa from . import mxodbc # noqa from . import pymssql # noqa from . import pyodbc # noqa -from . import zxjdbc # noqa from .base import BIGINT from .base import BINARY from .base import BIT diff --git a/lib/sqlalchemy/dialects/mssql/zxjdbc.py b/lib/sqlalchemy/dialects/mssql/zxjdbc.py deleted file mode 100644 index 98666445f..000000000 --- a/lib/sqlalchemy/dialects/mssql/zxjdbc.py +++ /dev/null @@ -1,71 +0,0 @@ -# mssql/zxjdbc.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -""" -.. dialect:: mssql+zxjdbc - :name: zxJDBC for Jython - :dbapi: zxjdbc - :connectstring: mssql+zxjdbc://user:pass@host:port/dbname[?key=value&key=value...] - :driverurl: http://jtds.sourceforge.net/ - - .. note:: Jython is not supported by current versions of SQLAlchemy. The - zxjdbc dialect should be considered as experimental. - -""" # noqa -from .base import MSDialect -from .base import MSExecutionContext -from ... import engine -from ...connectors.zxJDBC import ZxJDBCConnector - - -class MSExecutionContext_zxjdbc(MSExecutionContext): - - _embedded_scope_identity = False - - def pre_exec(self): - super(MSExecutionContext_zxjdbc, self).pre_exec() - # scope_identity after the fact returns null in jTDS so we must - # embed it - if self._select_lastrowid and self.dialect.use_scope_identity: - self._embedded_scope_identity = True - self.statement += "; SELECT scope_identity()" - - def post_exec(self): - if self._embedded_scope_identity: - while True: - try: - row = self.cursor.fetchall()[0] - break - except self.dialect.dbapi.Error: - self.cursor.nextset() - self._lastrowid = int(row[0]) - - if ( - self.isinsert or self.isupdate or self.isdelete - ) and self.compiled.returning: - self._result_proxy = engine.FullyBufferedResultProxy(self) - - if self._enable_identity_insert: - table = self.dialect.identifier_preparer.format_table( - self.compiled.statement.table - ) - self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table) - - -class MSDialect_zxjdbc(ZxJDBCConnector, MSDialect): - jdbc_db_name = "jtds:sqlserver" - jdbc_driver_name = "net.sourceforge.jtds.jdbc.Driver" - - execution_ctx_cls = MSExecutionContext_zxjdbc - - def _get_server_version_info(self, connection): - return tuple( - int(x) for x in connection.connection.dbversion.split(".") - ) - - -dialect = MSDialect_zxjdbc diff --git a/lib/sqlalchemy/dialects/mysql/__init__.py b/lib/sqlalchemy/dialects/mysql/__init__.py index c9f3b43b4..f1f1cce37 100644 --- a/lib/sqlalchemy/dialects/mysql/__init__.py +++ b/lib/sqlalchemy/dialects/mysql/__init__.py @@ -13,7 +13,6 @@ from . import mysqldb # noqa from . import oursql # noqa from . import pymysql # noqa from . import pyodbc # noqa -from . import zxjdbc # noqa from .base import BIGINT from .base import BINARY from .base import BIT diff --git a/lib/sqlalchemy/dialects/mysql/zxjdbc.py b/lib/sqlalchemy/dialects/mysql/zxjdbc.py deleted file mode 100644 index cf947b905..000000000 --- a/lib/sqlalchemy/dialects/mysql/zxjdbc.py +++ /dev/null @@ -1,120 +0,0 @@ -# mysql/zxjdbc.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -r""" - -.. dialect:: mysql+zxjdbc - :name: zxjdbc for Jython - :dbapi: zxjdbc - :connectstring: mysql+zxjdbc://<user>:<password>@<hostname>[:<port>]/<database> - :driverurl: http://dev.mysql.com/downloads/connector/j/ - - .. note:: Jython is not supported by current versions of SQLAlchemy. The - zxjdbc dialect should be considered as experimental. - -Character Sets --------------- - -SQLAlchemy zxjdbc dialects pass unicode straight through to the -zxjdbc/JDBC layer. To allow multiple character sets to be sent from the -MySQL Connector/J JDBC driver, by default SQLAlchemy sets its -``characterEncoding`` connection property to ``UTF-8``. It may be -overridden via a ``create_engine`` URL parameter. - -""" # noqa -import re - -from .base import BIT -from .base import MySQLDialect -from .base import MySQLExecutionContext -from ... import types as sqltypes -from ... import util -from ...connectors.zxJDBC import ZxJDBCConnector - - -class _ZxJDBCBit(BIT): - def result_processor(self, dialect, coltype): - """Converts boolean or byte arrays from MySQL Connector/J to longs.""" - - def process(value): - if value is None: - return value - if isinstance(value, bool): - return int(value) - v = 0 - for i in value: - v = v << 8 | (i & 0xFF) - value = v - return value - - return process - - -class MySQLExecutionContext_zxjdbc(MySQLExecutionContext): - def get_lastrowid(self): - cursor = self.create_cursor() - cursor.execute("SELECT LAST_INSERT_ID()") - lastrowid = cursor.fetchone()[0] - cursor.close() - return lastrowid - - -class MySQLDialect_zxjdbc(ZxJDBCConnector, MySQLDialect): - jdbc_db_name = "mysql" - jdbc_driver_name = "com.mysql.jdbc.Driver" - - execution_ctx_cls = MySQLExecutionContext_zxjdbc - - colspecs = util.update_copy( - MySQLDialect.colspecs, {sqltypes.Time: sqltypes.Time, BIT: _ZxJDBCBit} - ) - - def _detect_charset(self, connection): - """Sniff out the character set in use for connection results.""" - # Prefer 'character_set_results' for the current connection over the - # value in the driver. SET NAMES or individual variable SETs will - # change the charset without updating the driver's view of the world. - # - # If it's decided that issuing that sort of SQL leaves you SOL, then - # this can prefer the driver value. - rs = connection.execute("SHOW VARIABLES LIKE 'character_set%%'") - opts = {row[0]: row[1] for row in self._compat_fetchall(rs)} - for key in ("character_set_connection", "character_set"): - if opts.get(key, None): - return opts[key] - - util.warn( - "Could not detect the connection character set. " - "Assuming latin1." - ) - return "latin1" - - def _driver_kwargs(self): - """return kw arg dict to be sent to connect().""" - return dict(characterEncoding="UTF-8", yearIsDateType="false") - - def _extract_error_code(self, exception): - # e.g.: DBAPIError: (Error) Table 'test.u2' doesn't exist - # [SQLCode: 1146], [SQLState: 42S02] 'DESCRIBE `u2`' () - m = re.compile(r"\[SQLCode\: (\d+)\]").search(str(exception.args)) - c = m.group(1) - if c: - return int(c) - - def _get_server_version_info(self, connection): - dbapi_con = connection.connection - version = [] - r = re.compile(r"[.\-]") - for n in r.split(dbapi_con.dbversion): - try: - version.append(int(n)) - except ValueError: - version.append(n) - return tuple(version) - - -dialect = MySQLDialect_zxjdbc diff --git a/lib/sqlalchemy/dialects/oracle/__init__.py b/lib/sqlalchemy/dialects/oracle/__init__.py index 849dd6924..a4dee02ff 100644 --- a/lib/sqlalchemy/dialects/oracle/__init__.py +++ b/lib/sqlalchemy/dialects/oracle/__init__.py @@ -7,7 +7,6 @@ from . import base # noqa from . import cx_oracle # noqa -from . import zxjdbc # noqa from .base import BFILE from .base import BINARY_DOUBLE from .base import BINARY_FLOAT diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index abf3af821..9cb25b934 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -575,7 +575,7 @@ class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval): Note that only DAY TO SECOND intervals are currently supported. This is due to a lack of support for YEAR TO MONTH intervals - within available DBAPIs (cx_oracle and zxjdbc). + within available DBAPIs. :param day_precision: the day precision value. this is the number of digits to store for the day field. Defaults to "2" diff --git a/lib/sqlalchemy/dialects/oracle/zxjdbc.py b/lib/sqlalchemy/dialects/oracle/zxjdbc.py deleted file mode 100644 index 66878b25f..000000000 --- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py +++ /dev/null @@ -1,254 +0,0 @@ -# oracle/zxjdbc.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -""" -.. dialect:: oracle+zxjdbc - :name: zxJDBC for Jython - :dbapi: zxjdbc - :connectstring: oracle+zxjdbc://user:pass@host/dbname - :driverurl: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html - - .. note:: Jython is not supported by current versions of SQLAlchemy. The - zxjdbc dialect should be considered as experimental. - -""" # noqa -import collections -import decimal -import re - -from .base import OracleCompiler -from .base import OracleDialect -from .base import OracleExecutionContext -from ... import sql -from ... import types as sqltypes -from ... import util -from ...connectors.zxJDBC import ZxJDBCConnector -from ...engine import result as _result -from ...sql import expression - - -SQLException = zxJDBC = None - - -class _ZxJDBCDate(sqltypes.Date): - def result_processor(self, dialect, coltype): - def process(value): - if value is None: - return None - else: - return value.date() - - return process - - -class _ZxJDBCNumeric(sqltypes.Numeric): - def result_processor(self, dialect, coltype): - # XXX: does the dialect return Decimal or not??? - # if it does (in all cases), we could use a None processor as well as - # the to_float generic processor - if self.asdecimal: - - def process(value): - if isinstance(value, decimal.Decimal): - return value - else: - return decimal.Decimal(str(value)) - - else: - - def process(value): - if isinstance(value, decimal.Decimal): - return float(value) - else: - return value - - return process - - -class OracleCompiler_zxjdbc(OracleCompiler): - def returning_clause(self, stmt, returning_cols): - self.returning_cols = list( - expression._select_iterables(returning_cols) - ) - - # within_columns_clause=False so that labels (foo AS bar) don't render - columns = [ - self.process(c, within_columns_clause=False) - for c in self.returning_cols - ] - - if not hasattr(self, "returning_parameters"): - self.returning_parameters = [] - - binds = [] - for i, col in enumerate(self.returning_cols): - dbtype = col.type.dialect_impl(self.dialect).get_dbapi_type( - self.dialect.dbapi - ) - self.returning_parameters.append((i + 1, dbtype)) - - bindparam = sql.bindparam( - "ret_%d" % i, value=ReturningParam(dbtype) - ) - self.binds[bindparam.key] = bindparam - binds.append( - self.bindparam_string(self._truncate_bindparam(bindparam)) - ) - - return "RETURNING " + ", ".join(columns) + " INTO " + ", ".join(binds) - - -class OracleExecutionContext_zxjdbc(OracleExecutionContext): - def pre_exec(self): - if hasattr(self.compiled, "returning_parameters"): - # prepare a zxJDBC statement so we can grab its underlying - # OraclePreparedStatement's getReturnResultSet later - self.statement = self.cursor.prepare(self.statement) - - def get_result_proxy(self): - if hasattr(self.compiled, "returning_parameters"): - rrs = None - try: - try: - rrs = self.statement.__statement__.getReturnResultSet() - next(rrs) - except SQLException as sqle: - msg = "%s [SQLCode: %d]" % ( - sqle.getMessage(), - sqle.getErrorCode(), - ) - if sqle.getSQLState() is not None: - msg += " [SQLState: %s]" % sqle.getSQLState() - raise zxJDBC.Error(msg) - else: - row = tuple( - self.cursor.datahandler.getPyObject(rrs, index, dbtype) - for index, dbtype in self.compiled.returning_parameters - ) - return ReturningResultProxy(self, row) - finally: - if rrs is not None: - try: - rrs.close() - except SQLException: - pass - self.statement.close() - - return _result.ResultProxy(self) - - def create_cursor(self): - cursor = self._dbapi_connection.cursor() - cursor.datahandler = self.dialect.DataHandler(cursor.datahandler) - return cursor - - -class ReturningResultProxy(_result.FullyBufferedResultProxy): - - """ResultProxy backed by the RETURNING ResultSet results.""" - - def __init__(self, context, returning_row): - self._returning_row = returning_row - super(ReturningResultProxy, self).__init__(context) - - def _cursor_description(self): - ret = [] - for c in self.context.compiled.returning_cols: - if hasattr(c, "name"): - ret.append((c.name, c.type)) - else: - ret.append((c.anon_label, c.type)) - return ret - - def _buffer_rows(self): - return collections.deque([self._returning_row]) - - -class ReturningParam(object): - - """A bindparam value representing a RETURNING parameter. - - Specially handled by OracleReturningDataHandler. - """ - - def __init__(self, type_): - self.type = type_ - - def __eq__(self, other): - if isinstance(other, ReturningParam): - return self.type == other.type - return NotImplemented - - def __ne__(self, other): - if isinstance(other, ReturningParam): - return self.type != other.type - return NotImplemented - - def __repr__(self): - kls = self.__class__ - return "<%s.%s object at 0x%x type=%s>" % ( - kls.__module__, - kls.__name__, - id(self), - self.type, - ) - - -class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect): - jdbc_db_name = "oracle" - jdbc_driver_name = "oracle.jdbc.OracleDriver" - - statement_compiler = OracleCompiler_zxjdbc - execution_ctx_cls = OracleExecutionContext_zxjdbc - - colspecs = util.update_copy( - OracleDialect.colspecs, - {sqltypes.Date: _ZxJDBCDate, sqltypes.Numeric: _ZxJDBCNumeric}, - ) - - def __init__(self, *args, **kwargs): - super(OracleDialect_zxjdbc, self).__init__(*args, **kwargs) - global SQLException, zxJDBC - from java.sql import SQLException - from com.ziclix.python.sql import zxJDBC - from com.ziclix.python.sql.handler import OracleDataHandler - - class OracleReturningDataHandler(OracleDataHandler): - """zxJDBC DataHandler that specially handles ReturningParam.""" - - def setJDBCObject(self, statement, index, object_, dbtype=None): - if type(object_) is ReturningParam: - statement.registerReturnParameter(index, object_.type) - elif dbtype is None: - OracleDataHandler.setJDBCObject( - self, statement, index, object_ - ) - else: - OracleDataHandler.setJDBCObject( - self, statement, index, object_, dbtype - ) - - self.DataHandler = OracleReturningDataHandler - - def initialize(self, connection): - super(OracleDialect_zxjdbc, self).initialize(connection) - self.implicit_returning = connection.connection.driverversion >= "10.2" - - def _create_jdbc_url(self, url): - return "jdbc:oracle:thin:@%s:%s:%s" % ( - url.host, - url.port or 1521, - url.database, - ) - - def _get_server_version_info(self, connection): - version = re.search( - r"Release ([\d\.]+)", connection.connection.dbversion - ).group(1) - return tuple(int(x) for x in version.split(".")) - - -dialect = OracleDialect_zxjdbc diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index 80875916a..06d22872a 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -11,7 +11,6 @@ from . import psycopg2 # noqa from . import psycopg2cffi # noqa from . import pygresql # noqa from . import pypostgresql # noqa -from . import zxjdbc # noqa from .array import All from .array import Any from .array import ARRAY diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 0f08d1f40..cbc750066 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1156,9 +1156,6 @@ class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval): """PostgreSQL INTERVAL type. - The INTERVAL type may not be supported on all DBAPIs. - It is known to work on psycopg2 and not pg8000 or zxjdbc. - """ __visit_name__ = "INTERVAL" diff --git a/lib/sqlalchemy/dialects/postgresql/zxjdbc.py b/lib/sqlalchemy/dialects/postgresql/zxjdbc.py deleted file mode 100644 index 6ca7fcf98..000000000 --- a/lib/sqlalchemy/dialects/postgresql/zxjdbc.py +++ /dev/null @@ -1,48 +0,0 @@ -# postgresql/zxjdbc.py -# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors -# <see AUTHORS file> -# -# This module is part of SQLAlchemy and is released under -# the MIT License: http://www.opensource.org/licenses/mit-license.php - -""" -.. dialect:: postgresql+zxjdbc - :name: zxJDBC for Jython - :dbapi: zxjdbc - :connectstring: postgresql+zxjdbc://scott:tiger@localhost/db - :driverurl: http://jdbc.postgresql.org/ - - -""" -from .base import PGDialect -from .base import PGExecutionContext -from ...connectors.zxJDBC import ZxJDBCConnector - - -class PGExecutionContext_zxjdbc(PGExecutionContext): - def create_cursor(self): - cursor = self._dbapi_connection.cursor() - cursor.datahandler = self.dialect.DataHandler(cursor.datahandler) - return cursor - - -class PGDialect_zxjdbc(ZxJDBCConnector, PGDialect): - jdbc_db_name = "postgresql" - jdbc_driver_name = "org.postgresql.Driver" - - execution_ctx_cls = PGExecutionContext_zxjdbc - - supports_native_decimal = True - - def __init__(self, *args, **kwargs): - super(PGDialect_zxjdbc, self).__init__(*args, **kwargs) - from com.ziclix.python.sql.handler import PostgresqlDataHandler - - self.DataHandler = PostgresqlDataHandler - - def _get_server_version_info(self, connection): - parts = connection.connection.dbversion.split(".") - return tuple(int(x) for x in parts) - - -dialect = PGDialect_zxjdbc diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index cc65a0c49..1c995f05f 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -410,9 +410,7 @@ class DefaultDialect(interfaces.Dialect): return results == {True} def _check_unicode_description(self, connection): - # all DBAPIs on Py2K return cursor.description as encoded, - # until pypy2.1beta2 with sqlite, so let's just check it - - # it's likely others will start doing this too in Py2k. + # all DBAPIs on Py2K return cursor.description as encoded if util.py2k and not self.supports_unicode_statements: cast_to = util.binary_type diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py index 45a777a56..05fcc3fc9 100644 --- a/lib/sqlalchemy/orm/__init__.py +++ b/lib/sqlalchemy/orm/__init__.py @@ -233,12 +233,8 @@ def clear_mappers(): """ with mapperlib._CONFIGURE_MUTEX: while _mapper_registry: - try: - # can't even reliably call list(weakdict) in jython - mapper, b = _mapper_registry.popitem() - mapper.dispose() - except KeyError: - pass + mapper, b = _mapper_registry.popitem() + mapper.dispose() joinedload = strategy_options.joinedload._unbound_fn diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py index 6d0d00409..52b9fa1a9 100644 --- a/lib/sqlalchemy/sql/sqltypes.py +++ b/lib/sqlalchemy/sql/sqltypes.py @@ -41,10 +41,6 @@ from ..util import compat from ..util import pickle -if util.jython: - import array - - class _LookupExpressionAdapter(object): """Mixin expression adaptations based on lookup tables. @@ -923,19 +919,7 @@ class _Binary(TypeEngine): if util.py2k: def result_processor(self, dialect, coltype): - if util.jython: - - def process(value): - if value is not None: - if isinstance(value, array.array): - return value.tostring() - return str(value) - else: - return None - - else: - process = processors.to_str - return process + return processors.to_str else: diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py index 4aa5560bf..ff4f89606 100644 --- a/lib/sqlalchemy/testing/engines.py +++ b/lib/sqlalchemy/testing/engines.py @@ -58,7 +58,7 @@ class ConnectionKiller(object): # this can cause a deadlock with pg8000 - pg8000 acquires # prepared statement lock inside of rollback() - if async gc # is collecting in finalize_fairy, deadlock. - # not sure if this should be if pypy/jython only. + # not sure if this should be for non-cpython only. # note that firebird/fdb definitely needs this though for conn, rec in list(self.conns): if rec.connection is None: diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py index 14a6fc4ac..cc6557018 100644 --- a/lib/sqlalchemy/testing/profiling.py +++ b/lib/sqlalchemy/testing/profiling.py @@ -15,13 +15,13 @@ in a more fine-grained way than nose's profiling plugin. import collections import contextlib import os +import platform import pstats import sys from . import config from .util import gc_collect -from ..util import jython -from ..util import pypy +from ..util import cpython from ..util import win32 @@ -91,12 +91,12 @@ class ProfileStatsFile(object): # keep it at 2.7, 3.1, 3.2, etc. for now. py_version = ".".join([str(v) for v in sys.version_info[0:2]]) - platform_tokens = [py_version] + if not cpython: + platform_tokens = [platform.python_implementation(), py_version] + else: + platform_tokens = [py_version] platform_tokens.append(dbapi_key) - if jython: - platform_tokens.append("jython") - if pypy: - platform_tokens.append("pypy") + if win32: platform_tokens.append("win") platform_tokens.append( diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py index 4088c0cb1..b3375f6d5 100644 --- a/lib/sqlalchemy/testing/requirements.py +++ b/lib/sqlalchemy/testing/requirements.py @@ -1034,7 +1034,7 @@ class SuiteRequirements(Requirements): from sqlalchemy.util import pickle return exclusions.only_if( - lambda: not util.pypy + lambda: util.cpython and pickle.__name__ == "cPickle" or sys.version_info >= (3, 2), "Needs cPickle+cPython or newer Python 3 pickle", diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py index fc535aa23..2cc8761b8 100644 --- a/lib/sqlalchemy/testing/suite/test_insert.py +++ b/lib/sqlalchemy/testing/suite/test_insert.py @@ -56,10 +56,6 @@ class LastrowidTest(fixtures.TablesTest): pk = config.db.scalar(select([self.tables.autoinc_pk.c.id])) eq_(r.inserted_primary_key, [pk]) - # failed on pypy1.9 but seems to be OK on pypy 2.1 - # @exclusions.fails_if(lambda: util.pypy, - # "lastrowid not maintained after " - # "connection close") @requirements.dbapi_lastrowid def test_native_lastrowid_autoinc(self): r = config.db.execute( diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index de20bb794..c52dc4a19 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -9,36 +9,22 @@ import decimal import gc import random import sys -import time import types from . import mock from ..util import decorator from ..util import defaultdict +from ..util import has_refcount_gc from ..util import inspect_getfullargspec -from ..util import jython from ..util import py2k -from ..util import pypy -if jython: +if not has_refcount_gc: - def jython_gc_collect(*args): - """aggressive gc.collect for tests.""" - gc.collect() - time.sleep(0.1) - gc.collect() - gc.collect() - return 0 - - # "lazy" gc, for VM's that don't GC on refcount == 0 - gc_collect = lazy_gc = jython_gc_collect -elif pypy: - - def pypy_gc_collect(*args): + def non_refcount_gc_collect(*args): gc.collect() gc.collect() - gc_collect = lazy_gc = pypy_gc_collect + gc_collect = lazy_gc = non_refcount_gc_collect else: # assume CPython - straight gc.collect, lazy_gc() is a pass gc_collect = gc.collect diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index a19636f62..30e384027 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -53,12 +53,12 @@ from .compat import cmp # noqa from .compat import cpython # noqa from .compat import decode_backslashreplace # noqa from .compat import dottedgetter # noqa +from .compat import has_refcount_gc # noqa from .compat import inspect_getfullargspec # noqa from .compat import int_types # noqa from .compat import iterbytes # noqa from .compat import itertools_filter # noqa from .compat import itertools_filterfalse # noqa -from .compat import jython # noqa from .compat import namedtuple # noqa from .compat import nested # noqa from .compat import next # noqa @@ -69,7 +69,6 @@ from .compat import py2k # noqa from .compat import py33 # noqa from .compat import py36 # noqa from .compat import py3k # noqa -from .compat import pypy # noqa from .compat import quote_plus # noqa from .compat import raise_from_cause # noqa from .compat import reduce # noqa diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py index 2cb5db5d4..ea9ac0f11 100644 --- a/lib/sqlalchemy/util/compat.py +++ b/lib/sqlalchemy/util/compat.py @@ -11,6 +11,7 @@ import collections import contextlib import inspect import operator +import platform import sys @@ -21,10 +22,12 @@ py32 = sys.version_info >= (3, 2) py3k = sys.version_info >= (3, 0) py2k = sys.version_info < (3, 0) py265 = sys.version_info >= (2, 6, 5) -jython = sys.platform.startswith("java") -pypy = hasattr(sys, "pypy_version_info") + + +cpython = platform.python_implementation() == "CPython" win32 = sys.platform.startswith("win") -cpython = not pypy and not jython # TODO: something better for this ? + +has_refcount_gc = bool(cpython) contextmanager = contextlib.contextmanager dottedgetter = operator.attrgetter |
