diff --git a/.gitignore b/.gitignore index d78118b8..88f3c787 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ MANIFEST *.pidb *.pyc *.sw[po] +*.egg-info/ dist/* build/* doc/src/_build/* diff --git a/doc/src/tools/stitch_text.py b/doc/src/tools/stitch_text.py index b36727b5..dca745bd 100755 --- a/doc/src/tools/stitch_text.py +++ b/doc/src/tools/stitch_text.py @@ -19,10 +19,7 @@ def main(): def iter_file_base(fn): f = open(fn) - if sys.version_info[0] >= 3: - have_line = iter(f).__next__ - else: - have_line = iter(f).next + have_line = iter(f).__next__ while not have_line().startswith('.. toctree'): pass diff --git a/examples/dialtone.py b/examples/dialtone.py index 8654ffde..f20d6fe7 100644 --- a/examples/dialtone.py +++ b/examples/dialtone.py @@ -17,13 +17,6 @@ from datetime import datetime import psycopg2 from psycopg2.extensions import adapt, register_adapter -try: - sorted() -except: - def sorted(seq): - seq.sort() - return seq - # Here is the adapter for every object that we may ever need to # insert in the database. It receives the original object and does # its job on that instance diff --git a/lib/extras.py b/lib/extras.py index 3308f78f..a6c025e1 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -110,16 +110,16 @@ class DictCursorBase(_cursor): try: if self._prefetch: res = super(DictCursorBase, self).__iter__() - first = res.next() + first = next(res) if self._query_executed: self._build_index() if not self._prefetch: res = super(DictCursorBase, self).__iter__() - first = res.next() + first = next(res) yield first while 1: - yield res.next() + yield next(res) except StopIteration: return @@ -349,7 +349,7 @@ class NamedTupleCursor(_cursor): def __iter__(self): try: it = super(NamedTupleCursor, self).__iter__() - t = it.next() + t = next(it) nt = self.Record if nt is None: @@ -358,7 +358,7 @@ class NamedTupleCursor(_cursor): yield nt._make(t) while 1: - yield nt._make(it.next()) + yield nt._make(next(it)) except StopIteration: return @@ -1144,7 +1144,7 @@ def _paginate(seq, page_size): while 1: try: for i in xrange(page_size): - page.append(it.next()) + page.append(next(it)) yield page page = [] except StopIteration: diff --git a/lib/sql.py b/lib/sql.py index 5dfe7c8b..849b25fb 100644 --- a/lib/sql.py +++ b/lib/sql.py @@ -276,7 +276,7 @@ class SQL(Composable): rv = [] it = iter(seq) try: - rv.append(it.next()) + rv.append(next(it)) except StopIteration: pass else: diff --git a/tests/__init__.py b/tests/__init__.py index 6cb6c7ba..fa7e3939 100755 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -29,7 +29,7 @@ warnings.simplefilter('error') # noqa import sys from testconfig import dsn -from testutils import unittest +import unittest import test_async import test_bugX000 diff --git a/tests/test_async.py b/tests/test_async.py index 4eb5e6a2..2c4bfa3b 100755 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -23,7 +23,8 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. -from testutils import unittest, skip_before_postgres, slow +import unittest +from testutils import skip_before_postgres, slow import psycopg2 from psycopg2 import extensions as ext diff --git a/tests/test_async_keyword.py b/tests/test_async_keyword.py index ddf43266..e08c2750 100755 --- a/tests/test_async_keyword.py +++ b/tests/test_async_keyword.py @@ -29,7 +29,8 @@ import psycopg2 from psycopg2 import extras from testconfig import dsn -from testutils import ConnectingTestCase, unittest, skip_before_postgres, slow +import unittest +from testutils import ConnectingTestCase, skip_before_postgres, slow from test_replication import ReplicationTestCase, skip_repl_if_green from psycopg2.extras import LogicalReplicationConnection, StopReplication diff --git a/tests/test_cancel.py b/tests/test_cancel.py index 529c4ba4..7888bbff 100755 --- a/tests/test_cancel.py +++ b/tests/test_cancel.py @@ -31,7 +31,8 @@ import psycopg2.extensions from psycopg2 import extras from testconfig import dsn -from testutils import unittest, ConnectingTestCase, skip_before_postgres, slow +import unittest +from testutils import ConnectingTestCase, skip_before_postgres, slow class CancelTests(ConnectingTestCase): diff --git a/tests/test_connection.py b/tests/test_connection.py index f13df18d..369c204c 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -35,7 +35,7 @@ import psycopg2.errorcodes from psycopg2 import extensions as ext from testutils import ( - script_to_py3, unittest, decorate_all_tests, skip_if_no_superuser, + unittest, decorate_all_tests, skip_if_no_superuser, skip_before_postgres, skip_after_postgres, skip_before_libpq, ConnectingTestCase, skip_if_tpc_disabled, skip_if_windows, slow) @@ -1566,7 +1566,7 @@ while True: cur.execute(%(query)r, ("Hello, world!",)) """ % {'dsn': dsn, 'query': query}) - proc = sp.Popen([sys.executable, '-c', script_to_py3(script)], + proc = sp.Popen([sys.executable, '-c', script], stdout=sp.PIPE, stderr=sp.PIPE) (out, err) = proc.communicate() self.assertNotEqual(proc.returncode, 0) diff --git a/tests/test_copy.py b/tests/test_copy.py index c5e79138..3201fb27 100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -24,7 +24,8 @@ import sys import string -from testutils import (unittest, ConnectingTestCase, decorate_all_tests, +import unittest +from testutils import (ConnectingTestCase, decorate_all_tests, skip_before_postgres, slow) from cStringIO import StringIO from itertools import cycle, izip @@ -32,7 +33,7 @@ from subprocess import Popen, PIPE import psycopg2 import psycopg2.extensions -from testutils import skip_copy_if_green, script_to_py3 +from testutils import skip_copy_if_green from testconfig import dsn @@ -324,7 +325,7 @@ except psycopg2.ProgrammingError: conn.close() """ % {'dsn': dsn}) - proc = Popen([sys.executable, '-c', script_to_py3(script)]) + proc = Popen([sys.executable, '-c', script]) proc.communicate() self.assertEqual(0, proc.returncode) @@ -343,7 +344,7 @@ except psycopg2.ProgrammingError: conn.close() """ % {'dsn': dsn}) - proc = Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE) + proc = Popen([sys.executable, '-c', script], stdout=PIPE) proc.communicate() self.assertEqual(0, proc.returncode) diff --git a/tests/test_cursor.py b/tests/test_cursor.py index c5ce70fa..e896ef94 100755 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -26,7 +26,8 @@ import time import pickle import psycopg2 import psycopg2.extensions -from testutils import (unittest, ConnectingTestCase, skip_before_postgres, +import unittest +from testutils import (ConnectingTestCase, skip_before_postgres, skip_if_no_getrefcount, slow, skip_if_no_superuser, skip_if_windows) @@ -334,9 +335,9 @@ class CursorTests(ConnectingTestCase): # timestamp will not be influenced by the pause in Python world. curs.execute("""select clock_timestamp() from generate_series(1,2)""") i = iter(curs) - t1 = (i.next())[0] # the brackets work around a 2to3 bug + t1 = next(i)[0] time.sleep(0.2) - t2 = (i.next())[0] + t2 = next(i)[0] self.assert_((t2 - t1).microseconds * 1e-6 < 0.1, "named cursor records fetched in 2 roundtrips (delta: %s)" % (t2 - t1)) diff --git a/tests/test_dates.py b/tests/test_dates.py index 9ce74d88..ccfdc20a 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -25,7 +25,8 @@ import math import psycopg2 from psycopg2.tz import FixedOffsetTimezone, ZERO -from testutils import unittest, ConnectingTestCase, skip_before_postgres +import unittest +from testutils import ConnectingTestCase, skip_before_postgres def total_seconds(d): diff --git a/tests/test_errcodes.py b/tests/test_errcodes.py index d651b227..0fdf8e59 100755 --- a/tests/test_errcodes.py +++ b/tests/test_errcodes.py @@ -22,7 +22,8 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. -from testutils import unittest, ConnectingTestCase, slow +import unittest +from testutils import ConnectingTestCase, slow try: reload diff --git a/tests/test_extras_dictcursor.py b/tests/test_extras_dictcursor.py index 2c867d38..b014a81b 100755 --- a/tests/test_extras_dictcursor.py +++ b/tests/test_extras_dictcursor.py @@ -18,7 +18,8 @@ import time from datetime import timedelta import psycopg2 import psycopg2.extras -from testutils import unittest, ConnectingTestCase, skip_before_postgres +import unittest +from testutils import ConnectingTestCase, skip_before_postgres class ExtrasDictCursorTests(ConnectingTestCase): @@ -310,22 +311,22 @@ class NamedTupleCursorTest(ConnectingTestCase): i = iter(curs) self.assertEqual(curs.rownumber, 0) - t = i.next() + t = next(i) self.assertEqual(t.i, 1) self.assertEqual(t.s, 'foo') self.assertEqual(curs.rownumber, 1) self.assertEqual(curs.rowcount, 3) - t = i.next() + t = next(i) self.assertEqual(t.i, 2) self.assertEqual(t.s, 'bar') self.assertEqual(curs.rownumber, 2) self.assertEqual(curs.rowcount, 3) - t = i.next() + t = next(i) self.assertEqual(t.i, 3) self.assertEqual(t.s, 'baz') - self.assertRaises(StopIteration, i.next) + self.assertRaises(StopIteration, next, i) self.assertEqual(curs.rownumber, 3) self.assertEqual(curs.rowcount, 3) diff --git a/tests/test_fast_executemany.py b/tests/test_fast_executemany.py index ad7a5b12..32b34545 100755 --- a/tests/test_fast_executemany.py +++ b/tests/test_fast_executemany.py @@ -17,7 +17,7 @@ from datetime import date import testutils -from testutils import unittest +import unittest import psycopg2 import psycopg2.extras diff --git a/tests/test_ipaddress.py b/tests/test_ipaddress.py index bfeaae44..ea193bf8 100755 --- a/tests/test_ipaddress.py +++ b/tests/test_ipaddress.py @@ -20,7 +20,7 @@ import sys from functools import wraps import testutils -from testutils import unittest +import unittest import psycopg2 import psycopg2.extras diff --git a/tests/test_lobject.py b/tests/test_lobject.py index 8eafabc9..7e91fe7a 100755 --- a/tests/test_lobject.py +++ b/tests/test_lobject.py @@ -29,7 +29,8 @@ from functools import wraps import psycopg2 import psycopg2.extensions -from testutils import (unittest, decorate_all_tests, skip_if_tpc_disabled, +import unittest +from testutils import (decorate_all_tests, skip_if_tpc_disabled, ConnectingTestCase, skip_if_green, slow) diff --git a/tests/test_module.py b/tests/test_module.py index 4a4941c1..e0533ac8 100755 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -26,8 +26,9 @@ import os import sys from subprocess import Popen -from testutils import (unittest, skip_before_postgres, - ConnectingTestCase, skip_copy_if_green, script_to_py3, slow) +import unittest +from testutils import (skip_before_postgres, + ConnectingTestCase, skip_copy_if_green, slow) import psycopg2 @@ -322,7 +323,7 @@ sys.path.insert(0, %r) import _psycopg """ % (pardir, pkgdir)) - proc = Popen([sys.executable, '-c', script_to_py3(script)]) + proc = Popen([sys.executable, '-c', script]) proc.communicate() self.assertEqual(0, proc.returncode) diff --git a/tests/test_notify.py b/tests/test_notify.py index 0e74e1d5..64835efb 100755 --- a/tests/test_notify.py +++ b/tests/test_notify.py @@ -22,11 +22,11 @@ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public # License for more details. -from testutils import unittest +import unittest import psycopg2 from psycopg2 import extensions -from testutils import ConnectingTestCase, script_to_py3, slow +from testutils import ConnectingTestCase, slow from testconfig import dsn import sys @@ -61,7 +61,7 @@ import %(module)s as psycopg2 import %(module)s.extensions as ext conn = psycopg2.connect(%(dsn)r) conn.set_isolation_level(ext.ISOLATION_LEVEL_AUTOCOMMIT) -print conn.get_backend_pid() +print(conn.get_backend_pid()) curs = conn.cursor() curs.execute("NOTIFY " %(name)r %(payload)r) curs.close() @@ -70,7 +70,7 @@ conn.close() 'module': psycopg2.__name__, 'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload}) - return Popen([sys.executable, '-c', script_to_py3(script)], stdout=PIPE) + return Popen([sys.executable, '-c', script], stdout=PIPE) @slow def test_notifies_received_on_poll(self): diff --git a/tests/test_psycopg2_dbapi20.py b/tests/test_psycopg2_dbapi20.py index c780d506..3bcedc41 100755 --- a/tests/test_psycopg2_dbapi20.py +++ b/tests/test_psycopg2_dbapi20.py @@ -25,7 +25,8 @@ import dbapi20 import dbapi20_tpc from testutils import skip_if_tpc_disabled -from testutils import unittest, decorate_all_tests +import unittest +from testutils import decorate_all_tests import psycopg2 from testconfig import dsn diff --git a/tests/test_quote.py b/tests/test_quote.py index 1ced845c..0f60dd9f 100755 --- a/tests/test_quote.py +++ b/tests/test_quote.py @@ -24,7 +24,8 @@ import sys import testutils -from testutils import unittest, ConnectingTestCase +import unittest +from testutils import ConnectingTestCase import psycopg2 import psycopg2.extensions diff --git a/tests/test_replication.py b/tests/test_replication.py index d03c6566..444dd111 100755 --- a/tests/test_replication.py +++ b/tests/test_replication.py @@ -27,7 +27,8 @@ from psycopg2.extras import ( PhysicalReplicationConnection, LogicalReplicationConnection, StopReplication) import testconfig -from testutils import unittest, ConnectingTestCase +import unittest +from testutils import ConnectingTestCase from testutils import skip_before_postgres, skip_if_green skip_repl_if_green = skip_if_green("replication not supported in green mode") diff --git a/tests/test_sql.py b/tests/test_sql.py index 2e12ba63..566cc281 100755 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -24,7 +24,8 @@ import datetime as dt from cStringIO import StringIO -from testutils import (unittest, ConnectingTestCase, +import unittest +from testutils import (ConnectingTestCase, skip_before_postgres, skip_before_python, skip_copy_if_green) import psycopg2 @@ -344,11 +345,11 @@ class ComposedTest(ConnectingTestCase): def test_iter(self): obj = sql.Composed([sql.SQL("foo"), sql.SQL('bar')]) it = iter(obj) - i = it.next() + i = next(it) self.assertEqual(i, sql.SQL('foo')) - i = it.next() + i = next(it) self.assertEqual(i, sql.SQL('bar')) - self.assertRaises(StopIteration, it.next) + self.assertRaises(StopIteration, next, it) class PlaceholderTest(ConnectingTestCase): diff --git a/tests/test_transaction.py b/tests/test_transaction.py index dd487c05..26704d8f 100755 --- a/tests/test_transaction.py +++ b/tests/test_transaction.py @@ -23,7 +23,8 @@ # License for more details. import threading -from testutils import unittest, ConnectingTestCase, skip_before_postgres, slow +import unittest +from testutils import ConnectingTestCase, skip_before_postgres, slow import psycopg2 from psycopg2.extensions import ( diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py index b0af6daa..cd1a4f6b 100755 --- a/tests/test_types_basic.py +++ b/tests/test_types_basic.py @@ -27,7 +27,8 @@ import decimal import sys from functools import wraps import testutils -from testutils import unittest, ConnectingTestCase, decorate_all_tests +import unittest +from testutils import ConnectingTestCase, decorate_all_tests import psycopg2 diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py index f50b1b5e..576e13c8 100755 --- a/tests/test_types_extras.py +++ b/tests/test_types_extras.py @@ -22,7 +22,8 @@ from datetime import date, datetime from functools import wraps from pickle import dumps, loads -from testutils import (unittest, skip_if_no_uuid, skip_before_postgres, +import unittest +from testutils import (skip_if_no_uuid, skip_before_postgres, ConnectingTestCase, decorate_all_tests, py3_raises_typeerror, slow) import psycopg2 @@ -812,30 +813,6 @@ class AdaptTypeTestCase(ConnectingTestCase): return oid -def skip_if_json_module(f): - """Skip a test if a Python json module *is* available""" - @wraps(f) - def skip_if_json_module_(self): - if psycopg2.extras.json is not None: - return self.skipTest("json module is available") - - return f(self) - - return skip_if_json_module_ - - -def skip_if_no_json_module(f): - """Skip a test if no Python json module is available""" - @wraps(f) - def skip_if_no_json_module_(self): - if psycopg2.extras.json is None: - return self.skipTest("json module not available") - - return f(self) - - return skip_if_no_json_module_ - - def skip_if_no_json_type(f): """Skip a test if PostgreSQL json type is not available""" @wraps(f) @@ -851,23 +828,6 @@ def skip_if_no_json_type(f): class JsonTestCase(ConnectingTestCase): - @skip_if_json_module - def test_module_not_available(self): - from psycopg2.extras import Json - self.assertRaises(ImportError, Json(None).getquoted) - - @skip_if_json_module - def test_customizable_with_module_not_available(self): - from psycopg2.extras import Json - - class MyJson(Json): - def dumps(self, obj): - assert obj is None - return "hi" - - self.assertEqual(MyJson(None).getquoted(), "'hi'") - - @skip_if_no_json_module def test_adapt(self): from psycopg2.extras import json, Json @@ -879,7 +839,6 @@ class JsonTestCase(ConnectingTestCase): self.assertQuotedEqual(curs.mogrify("%s", (Json(obj),)), psycopg2.extensions.QuotedString(json.dumps(obj)).getquoted()) - @skip_if_no_json_module def test_adapt_dumps(self): from psycopg2.extras import json, Json @@ -897,7 +856,6 @@ class JsonTestCase(ConnectingTestCase): self.assertQuotedEqual(curs.mogrify("%s", (Json(obj, dumps=dumps),)), b"'123.45'") - @skip_if_no_json_module def test_adapt_subclass(self): from psycopg2.extras import json, Json @@ -915,7 +873,6 @@ class JsonTestCase(ConnectingTestCase): obj = Decimal('123.45') self.assertQuotedEqual(curs.mogrify("%s", (MyJson(obj),)), b"'123.45'") - @skip_if_no_json_module def test_register_on_dict(self): from psycopg2.extras import Json psycopg2.extensions.register_adapter(dict, Json) @@ -937,7 +894,6 @@ class JsonTestCase(ConnectingTestCase): self.assertRaises(psycopg2.ProgrammingError, psycopg2.extras.register_json, self.conn) - @skip_if_no_json_module @skip_before_postgres(9, 2) def test_default_cast(self): curs = self.conn.cursor() @@ -948,7 +904,6 @@ class JsonTestCase(ConnectingTestCase): curs.execute("""select array['{"a": 100.0, "b": null}']::json[]""") self.assertEqual(curs.fetchone()[0], [{'a': 100.0, 'b': None}]) - @skip_if_no_json_module @skip_if_no_json_type def test_register_on_connection(self): psycopg2.extras.register_json(self.conn) @@ -956,7 +911,6 @@ class JsonTestCase(ConnectingTestCase): curs.execute("""select '{"a": 100.0, "b": null}'::json""") self.assertEqual(curs.fetchone()[0], {'a': 100.0, 'b': None}) - @skip_if_no_json_module @skip_if_no_json_type def test_register_on_cursor(self): curs = self.conn.cursor() @@ -964,7 +918,6 @@ class JsonTestCase(ConnectingTestCase): curs.execute("""select '{"a": 100.0, "b": null}'::json""") self.assertEqual(curs.fetchone()[0], {'a': 100.0, 'b': None}) - @skip_if_no_json_module @skip_if_no_json_type def test_register_globally(self): old = psycopg2.extensions.string_types.get(114) @@ -982,7 +935,6 @@ class JsonTestCase(ConnectingTestCase): if olda: psycopg2.extensions.register_type(olda) - @skip_if_no_json_module @skip_if_no_json_type def test_loads(self): json = psycopg2.extras.json @@ -996,7 +948,6 @@ class JsonTestCase(ConnectingTestCase): self.assert_(isinstance(data['a'], Decimal)) self.assertEqual(data['a'], Decimal('100.0')) - @skip_if_no_json_module @skip_if_no_json_type def test_no_conn_curs(self): from psycopg2._json import _get_json_oids @@ -1023,7 +974,6 @@ class JsonTestCase(ConnectingTestCase): if olda: psycopg2.extensions.register_type(olda) - @skip_if_no_json_module @skip_before_postgres(9, 2) def test_register_default(self): curs = self.conn.cursor() @@ -1042,7 +992,6 @@ class JsonTestCase(ConnectingTestCase): self.assert_(isinstance(data[0]['a'], Decimal)) self.assertEqual(data[0]['a'], Decimal('100.0')) - @skip_if_no_json_module @skip_if_no_json_type def test_null(self): psycopg2.extras.register_json(self.conn) @@ -1052,7 +1001,6 @@ class JsonTestCase(ConnectingTestCase): curs.execute("""select NULL::json[]""") self.assertEqual(curs.fetchone()[0], None) - @skip_if_no_json_module def test_no_array_oid(self): curs = self.conn.cursor() t1, t2 = psycopg2.extras.register_json(curs, oid=25) @@ -1064,7 +1012,6 @@ class JsonTestCase(ConnectingTestCase): self.assertEqual(data['a'], 100) self.assertEqual(data['b'], None) - @skip_if_no_json_module def test_str(self): snowman = u"\u2603" obj = {'a': [1, 2, snowman]} @@ -1075,7 +1022,6 @@ class JsonTestCase(ConnectingTestCase): self.assert_(s.startswith("'")) self.assert_(s.endswith("'")) - @skip_if_no_json_module @skip_before_postgres(8, 2) def test_scs(self): cnn_on = self.connect(options="-c standard_conforming_strings=on") @@ -1188,7 +1134,6 @@ class JsonbTestCase(ConnectingTestCase): curs.execute("""select NULL::jsonb[]""") self.assertEqual(curs.fetchone()[0], None) -decorate_all_tests(JsonbTestCase, skip_if_no_json_module) decorate_all_tests(JsonbTestCase, skip_if_no_jsonb_type) @@ -1619,7 +1564,7 @@ class RangeCasterTestCase(ConnectingTestCase): from psycopg2.tz import FixedOffsetTimezone cur = self.conn.cursor() - d1 = date(2012, 01, 01) + d1 = date(2012, 1, 1) d2 = date(2012, 12, 31) r = DateRange(d1, d2) cur.execute("select %s", (r,)) diff --git a/tests/test_with.py b/tests/test_with.py index 53dfa464..83612dec 100755 --- a/tests/test_with.py +++ b/tests/test_with.py @@ -25,7 +25,8 @@ import psycopg2 import psycopg2.extensions as ext -from testutils import unittest, ConnectingTestCase +import unittest +from testutils import ConnectingTestCase class WithTestCase(ConnectingTestCase): diff --git a/tests/testutils.py b/tests/testutils.py index bd08d6c7..2ee07af2 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -371,34 +371,6 @@ def skip_if_windows(f): return skip_if_windows_ -def script_to_py3(script): - """Convert a script to Python3 syntax if required.""" - if sys.version_info[0] < 3: - return script - - import tempfile - f = tempfile.NamedTemporaryFile(suffix=".py", delete=False) - f.write(script.encode()) - f.flush() - filename = f.name - f.close() - - # 2to3 is way too chatty - import logging - logging.basicConfig(filename=os.devnull) - - from lib2to3.main import main - if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]): - raise Exception('py3 conversion failed') - - f2 = open(filename) - try: - return f2.read() - finally: - f2.close() - os.remove(filename) - - class py3_raises_typeerror(object): def __enter__(self): pass