From 852f04dc513bd3f718b8d3339d0867e28428ae9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 12 Jul 2011 00:16:15 +0200 Subject: [PATCH] Remove support of Python2.5 and fix py3 warnings --- CHANGELOG | 1 + doc/topics/install.rst | 2 +- setup.py | 7 +------ trytond/backend/mysql/database.py | 1 - trytond/backend/postgresql/database.py | 1 - trytond/backend/sqlite/database.py | 7 +++++-- trytond/backend/sqlite/table.py | 2 +- trytond/config.py | 1 - trytond/convert.py | 1 - trytond/ir/action.py | 1 - trytond/ir/attachment.py | 1 - trytond/ir/cron.py | 1 - trytond/ir/gen_time_locale.py | 1 - trytond/ir/lang.py | 1 - trytond/ir/module/module.py | 1 - trytond/ir/property.py | 1 - trytond/ir/rule.py | 1 - trytond/ir/sequence.py | 1 - trytond/ir/translation.py | 2 +- trytond/ir/ui/icon.py | 1 - trytond/ir/ui/menu.py | 1 - trytond/ir/ui/view.py | 1 - trytond/model/browse.py | 1 - trytond/model/fields/one2many.py | 2 +- trytond/model/fields/reference.py | 1 - trytond/model/model.py | 13 ++++++++----- trytond/model/modelsql.py | 4 ++-- trytond/model/modelstorage.py | 8 ++++++-- trytond/model/modelview.py | 5 ++--- trytond/model/modelworkflow.py | 1 - trytond/modules/__init__.py | 10 ++++++---- trytond/pool.py | 1 - trytond/protocols/datatype.py | 3 +++ trytond/protocols/dispatcher.py | 1 - trytond/pysocket.py | 4 ++-- trytond/pyson.py | 3 ++- trytond/res/user.py | 1 - trytond/security.py | 7 +++---- trytond/server.py | 1 - trytond/tests/test_access.py | 1 - trytond/tests/test_exportdata.py | 1 - trytond/tests/test_fields.py | 1 - trytond/tests/test_importdata.py | 1 - trytond/tests/test_modelsingleton.py | 1 - trytond/tests/test_mptt.py | 8 +++----- trytond/tests/test_sequence.py | 1 - trytond/tests/test_trigger.py | 1 - trytond/tests/test_tryton.py | 8 -------- trytond/workflow/workflow.py | 1 - 49 files changed, 48 insertions(+), 79 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 82469db2eb..28aae47f2c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Drop support of Python 2.5 * Remove support of Many2Many field in record XML * Change Pool into a Singleton * Remove support of zipped modules diff --git a/doc/topics/install.rst b/doc/topics/install.rst index e44100ed6a..ed496ac66a 100644 --- a/doc/topics/install.rst +++ b/doc/topics/install.rst @@ -7,7 +7,7 @@ How to install Tryton Prerequisites ============= - * Python 2.5 or later (http://www.python.org/) + * Python 2.6 or later (http://www.python.org/) * lxml 2.0 or later (http://codespeak.net/lxml/) * relatorio 0.2.0 or later (http://relatorio.openhex.org/) * python-dateutil (http://labix.org/python-dateutil) diff --git a/setup.py b/setup.py index 5bb69db1e5..e21a377c6b 100644 --- a/setup.py +++ b/setup.py @@ -8,10 +8,6 @@ import sys execfile(os.path.join('trytond', 'version.py')) -SIMPLEJSON = [] -if sys.version_info < (2, 6): - SIMPLEJSON = ['simplejson'] - def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() @@ -52,7 +48,6 @@ setup(name=PACKAGE, 'Natural Language :: Russian', 'Natural Language :: Spanish', 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.5', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Topic :: Software Development :: Libraries :: Application Frameworks', @@ -63,7 +58,7 @@ setup(name=PACKAGE, 'relatorio >= 0.2.0', 'Genshi', 'python-dateutil', - ] + SIMPLEJSON, + ], extras_require={ 'PostgreSQL': ['psycopg2 >= 2.0'], 'MySQL': ['MySQL-python'], diff --git a/trytond/backend/mysql/database.py b/trytond/backend/mysql/database.py index de7fc52785..c01a3030cc 100644 --- a/trytond/backend/mysql/database.py +++ b/trytond/backend/mysql/database.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.backend.database import DatabaseInterface, CursorInterface from trytond.config import CONFIG import MySQLdb diff --git a/trytond/backend/postgresql/database.py b/trytond/backend/postgresql/database.py index c432fa9673..be7f01d7ec 100644 --- a/trytond/backend/postgresql/database.py +++ b/trytond/backend/postgresql/database.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.backend.database import DatabaseInterface, CursorInterface from trytond.config import CONFIG from trytond.session import Session diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index d0baee3221..e4d04a2b65 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.backend.database import DatabaseInterface, CursorInterface from trytond.config import CONFIG from trytond.session import Session @@ -9,6 +8,7 @@ import re from decimal import Decimal import datetime import time +import sys _FIX_ROWCOUNT = False try: @@ -357,7 +357,10 @@ class Cursor(CursorInterface): return select sqlite.register_converter('NUMERIC', lambda val: Decimal(val)) -sqlite.register_adapter(Decimal, lambda val: buffer(str(val))) +if sys.version_info[0] == 2: + sqlite.register_adapter(Decimal, lambda val: buffer(str(val))) +else: + sqlite.register_adapter(Decimal, lambda val: bytes(str(val))) sqlite.register_adapter(Session, int) def adapt_datetime(val): return val.replace(tzinfo=None).isoformat(" ") diff --git a/trytond/backend/sqlite/table.py b/trytond/backend/sqlite/table.py index 6d942b7962..2a18b038b6 100644 --- a/trytond/backend/sqlite/table.py +++ b/trytond/backend/sqlite/table.py @@ -127,7 +127,7 @@ class TableHandler(TableHandlerInterface): match = re.match(r'(\w+)(\((.*?)\))?', type_) if match: typname = match.group(1).upper() - size = match.group(3) and int(match.group(3)) or None + size = match.group(3) and int(match.group(3)) or 0 else: typname = type_.upper() size = -1 diff --git a/trytond/config.py b/trytond/config.py index cf0d8d11ff..39e772c0ad 100644 --- a/trytond/config.py +++ b/trytond/config.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import ConfigParser, os, sys diff --git a/trytond/convert.py b/trytond/convert.py index 406708be55..3b2eea2fd6 100644 --- a/trytond/convert.py +++ b/trytond/convert.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import time from xml import sax from decimal import Decimal diff --git a/trytond/ir/action.py b/trytond/ir/action.py index 5af846d398..cbd5cbd750 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import base64 import os from trytond.model import ModelView, ModelSQL, ModelStorage, fields diff --git a/trytond/ir/attachment.py b/trytond/ir/attachment.py index a8432da0bf..4136554184 100644 --- a/trytond/ir/attachment.py +++ b/trytond/ir/attachment.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import os try: import hashlib diff --git a/trytond/ir/cron.py b/trytond/ir/cron.py index d55355d38e..99ed8d329b 100644 --- a/trytond/ir/cron.py +++ b/trytond/ir/cron.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib import datetime from dateutil.relativedelta import relativedelta diff --git a/trytond/ir/gen_time_locale.py b/trytond/ir/gen_time_locale.py index 72f8f298d1..2aca343d09 100644 --- a/trytond/ir/gen_time_locale.py +++ b/trytond/ir/gen_time_locale.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import time import locale import os diff --git a/trytond/ir/lang.py b/trytond/ir/lang.py index f218f0dc8f..2e74373943 100644 --- a/trytond/ir/lang.py +++ b/trytond/ir/lang.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import time import datetime from trytond.model import ModelView, ModelSQL, fields diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index da232c5676..701a7a0834 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import os from trytond.model import ModelView, ModelSQL, fields import trytond.tools as tools diff --git a/trytond/ir/property.py b/trytond/ir/property.py index a9bbb9698d..ec08703131 100644 --- a/trytond/ir/property.py +++ b/trytond/ir/property.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from decimal import Decimal from trytond.model import ModelView, ModelSQL, fields from trytond.transaction import Transaction diff --git a/trytond/ir/rule.py b/trytond/ir/rule.py index 824a2ee467..678c8d01bf 100644 --- a/trytond/ir/rule.py +++ b/trytond/ir/rule.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib import time from trytond.model import ModelView, ModelSQL, fields diff --git a/trytond/ir/sequence.py b/trytond/ir/sequence.py index 3c2c97d00b..9371bb102b 100644 --- a/trytond/ir/sequence.py +++ b/trytond/ir/sequence.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from string import Template import datetime import time diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index 6d1d355fc0..8cf89f4996 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib import base64 try: @@ -17,6 +16,7 @@ try: from hashlib import md5 except ImportError: from md5 import md5 +from functools import reduce from trytond.model import ModelView, ModelSQL, fields from trytond.model.cacheable import Cacheable from trytond.wizard import Wizard diff --git a/trytond/ir/ui/icon.py b/trytond/ir/ui/icon.py index ef64c96599..fdbbd83638 100644 --- a/trytond/ir/ui/icon.py +++ b/trytond/ir/ui/icon.py @@ -1,6 +1,5 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of this # repository contains the full copyright notices and license terms. -from __future__ import with_statement import os diff --git a/trytond/ir/ui/menu.py b/trytond/ir/ui/menu.py index 0f58cc80bb..547964e693 100644 --- a/trytond/ir/ui/menu.py +++ b/trytond/ir/ui/menu.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.model import ModelView, ModelSQL, fields from trytond.transaction import Transaction from trytond.pool import Pool diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 544fbe6676..9c83c7c6d6 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import os import logging from lxml import etree diff --git a/trytond/model/browse.py b/trytond/model/browse.py index 83d69cec96..c7e5f86814 100644 --- a/trytond/model/browse.py +++ b/trytond/model/browse.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib from itertools import islice, ifilter, ifilterfalse, chain from trytond.model import fields diff --git a/trytond/model/fields/one2many.py b/trytond/model/fields/one2many.py index fac141c8be..9f4a72b33b 100644 --- a/trytond/model/fields/one2many.py +++ b/trytond/model/fields/one2many.py @@ -98,7 +98,7 @@ class One2Many(Field): index_of_ids2 = dict((i, index) for index, i in enumerate(chain(*ids2))) for val in res.values(): - val.sort(lambda x, y: cmp(index_of_ids2[x], index_of_ids2[y])) + val.sort(key=lambda x: index_of_ids2[x]) return res def set(self, ids, model, name, values): diff --git a/trytond/model/fields/reference.py b/trytond/model/fields/reference.py index d4ef42dc4c..c185829627 100644 --- a/trytond/model/fields/reference.py +++ b/trytond/model/fields/reference.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib from trytond.model.fields.field import Field from trytond.tools import safe_eval diff --git a/trytond/model/model.py b/trytond/model/model.py index 19cddf66ea..d9415a832b 100644 --- a/trytond/model/model.py +++ b/trytond/model/model.py @@ -2,6 +2,7 @@ #this repository contains the full copyright notices and license terms. import copy +import collections from trytond.model import fields from trytond.error import WarningErrorMixin from trytond.pool import Pool @@ -53,7 +54,7 @@ class Model(WarningErrorMixin): fields_names += self._inherit_fields.keys() for field_name in fields_names: default_method = getattr(self, 'default_%s' % field_name, False) - if callable(default_method): + if isinstance(default_method, collections.Callable): res[field_name] = default_method self.__defaults = res return res @@ -97,7 +98,8 @@ class Model(WarningErrorMixin): for attribute in ('on_change', 'on_change_with', 'autocomplete'): function_name = '%s_%s' % (attribute, field_name) if (getattr(field, attribute, False) - and callable(getattr(self, function_name, False))): + and isinstance(getattr(self, function_name, False), + collections.Callable)): self._rpc.setdefault(function_name, False) def __getattr__(self, name): @@ -105,9 +107,10 @@ class Model(WarningErrorMixin): # Search if a function exists in inherits parents for model_name, field_name in self._inherits.iteritems(): model_obj = pool.get(model_name) - if hasattr(model_obj, name) and \ - callable(getattr(model_obj, name)): - return getattr(model_obj, name) + if (hasattr(model_obj, name) + and isinstance(getattr(model_obj, name), + collections.Callable)): + return getattr(model_obj, name) raise AttributeError(name) def _inherits_reload(self): diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 4261e521bb..89e7cba646 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -1,9 +1,9 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import contextlib import datetime import re +from functools import reduce from decimal import Decimal from itertools import islice from trytond.model import ModelStorage @@ -766,7 +766,7 @@ class ModelSQL(ModelStorage): cursor.execute("SELECT id " \ 'FROM "' + self._table + '" ' \ 'WHERE ' + ' OR '.join( - (clause,) * (len(args)/2)), args) + (clause,) * (len(args) // 2)), args) if cursor.fetchone(): raise Exception('ConcurrencyException', 'Records were modified in the meanwhile') diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 49b5202426..43039a2d3e 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -1,7 +1,6 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import datetime import time from decimal import Decimal @@ -12,6 +11,9 @@ try: except ImportError: import StringIO import csv +from functools import reduce +import traceback +import sys from trytond.model import Model from trytond.model import fields from trytond.model.browse import BrowseRecordList, BrowseRecord, \ @@ -848,7 +850,9 @@ class ModelStorage(Model): logger.error(exp) # XXX should raise Exception Transaction().cursor.rollback() - warning = '\n'.join(map(str, exp[1:]) + [warning]) + tb_s = reduce(lambda x, y: x + y, + traceback.format_exception(*sys.exc_info())) + warning = '%s\n%s' % (tb_s, warning) return (-1, res, exp, warning) done += 1 return (done, 0, 0, 0) diff --git a/trytond/model/modelview.py b/trytond/model/modelview.py index f153b272dd..5fc87ef476 100644 --- a/trytond/model/modelview.py +++ b/trytond/model/modelview.py @@ -169,9 +169,8 @@ class ModelView(Model): raise_p = False while True: try: - sql_inherit.sort(lambda x, y: \ - cmp(self._modules_list.index(x[2] or None), - self._modules_list.index(y[2] or None))) + sql_inherit.sort(key=lambda x: + self._modules_list.index(x[2] or None)) break except ValueError: if raise_p: diff --git a/trytond/model/modelworkflow.py b/trytond/model/modelworkflow.py index f3f722d8bc..fb2f2fd815 100644 --- a/trytond/model/modelworkflow.py +++ b/trytond/model/modelworkflow.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.model import ModelStorage from trytond.transaction import Transaction from trytond.pool import Pool diff --git a/trytond/modules/__init__.py b/trytond/modules/__init__.py index d3082b0f1b..11ba764384 100644 --- a/trytond/modules/__init__.py +++ b/trytond/modules/__init__.py @@ -1,11 +1,13 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import os, sys, imp import itertools import traceback import logging import contextlib +from functools import reduce +import imp +import operator from trytond.backend import Database import trytond.tools as tools from trytond.config import CONFIG @@ -91,7 +93,7 @@ class Node(Singleton): for attr in ('init', 'update'): if hasattr(self, attr): setattr(node, attr, True) - self.childs.sort(lambda x, y: cmp(x.name, y.name)) + self.childs.sort(key=operator.attrgetter('name')) def all_childs(self): res = [] @@ -334,7 +336,7 @@ def register_classes(reload_p=False): if i.startswith(module) \ and i != module: del sys.modules[i] - reload(sys.modules[module]) + imp.reload(sys.modules[module]) logger = logging.getLogger('modules') @@ -352,7 +354,7 @@ def register_classes(reload_p=False): and i != 'trytond.modules.' + module \ and getattr(sys.modules[i], '_TRYTON_RELOAD', True): del sys.modules[i] - reload(sys.modules['trytond.modules.' + module]) + imp.reload(sys.modules['trytond.modules.' + module]) continue if os.path.isdir(OPJ(MODULES_PATH, module)): diff --git a/trytond/pool.py b/trytond/pool.py index b431b73260..d19d144b44 100644 --- a/trytond/pool.py +++ b/trytond/pool.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from threading import RLock import logging from trytond.modules import load_modules, register_classes diff --git a/trytond/protocols/datatype.py b/trytond/protocols/datatype.py index ce2e9a84c9..5c55a19e28 100644 --- a/trytond/protocols/datatype.py +++ b/trytond/protocols/datatype.py @@ -55,6 +55,9 @@ class Float(float): return self.decimal.__eq__(other) return super(Float, self).__eq__(other) + def __hash__(self): + return super(Float, self).__hash__() + def __floordiv__(self, other, context=None): if isinstance(other, Decimal): return self.decimal.__floordiv__(other, context=context) diff --git a/trytond/protocols/dispatcher.py b/trytond/protocols/dispatcher.py index 3767b2799d..4a185ddb96 100644 --- a/trytond/protocols/dispatcher.py +++ b/trytond/protocols/dispatcher.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import traceback import logging import time diff --git a/trytond/pysocket.py b/trytond/pysocket.py index 9d03cd6bc1..abbcf7daae 100644 --- a/trytond/pysocket.py +++ b/trytond/pysocket.py @@ -111,8 +111,8 @@ class PySocket: except socket.error: peercert = None def format_hash(value): - return reduce(lambda x, (i, y): x + y.upper() + - ((i % 2 and i + 1 < len(value)) and ':' or ''), + return reduce(lambda x, y: x + y[1].upper() + + ((y[0] % 2 and y[0] + 1 < len(value)) and ':' or ''), enumerate(value), '') if peercert and hashlib: fingerprint = format_hash(hashlib.sha1(peercert).hexdigest()) diff --git a/trytond/pyson.py b/trytond/pyson.py index b3d375bb30..817161da24 100644 --- a/trytond/pyson.py +++ b/trytond/pyson.py @@ -6,6 +6,7 @@ if sys.version_info < (2, 6): else: import json import datetime +from functools import reduce class PYSON(object): @@ -405,7 +406,7 @@ class Date(PYSON): date = date.replace(year=year) if dct['dM']: month = date.month + dct['dM'] - year = date.year + month / 12 + year = date.year + month // 12 month = month % 12 date = date.replace(year=year, month=month) if dct['dd']: diff --git a/trytond/res/user.py b/trytond/res/user.py index ba5c002a9b..b71a9d2fa7 100644 --- a/trytond/res/user.py +++ b/trytond/res/user.py @@ -1,7 +1,6 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. "User" -from __future__ import with_statement import copy import string import random diff --git a/trytond/security.py b/trytond/security.py index 1f2ed492a0..4fa49aa0e5 100644 --- a/trytond/security.py +++ b/trytond/security.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement from trytond.backend import Database from trytond.session import Session from trytond.pool import Pool @@ -41,7 +40,7 @@ def login(dbname, loginname, password, cache=True): def logout(dbname, user, session): name = '' - if _USER_CACHE.get(dbname, {}).has_key(user): + if user in _USER_CACHE.get(dbname, {}): for i, real_session \ in enumerate(_USER_CACHE[dbname][user]): if real_session.session == session: @@ -62,7 +61,7 @@ def check(dbname, user, session): result = None now = time.time() timeout = int(CONFIG['session_timeout']) - if _USER_CACHE.get(dbname, {}).has_key(user): + if user in _USER_CACHE.get(dbname, {}): to_del = [] for i, real_session \ in enumerate(_USER_CACHE[dbname][user]): @@ -81,7 +80,7 @@ def get_connections(dbname, user): res = 0 now = time.time() timeout = int(CONFIG['session_timeout']) - if _USER_CACHE.get(dbname, {}).has_key(int(user)): + if int(user) in _USER_CACHE.get(dbname, {}): for _, session in enumerate(_USER_CACHE[dbname][int(user)]): if abs(session.timestamp - now) < timeout: res += 1 diff --git a/trytond/server.py b/trytond/server.py index d502d05813..ccb5f96a32 100644 --- a/trytond/server.py +++ b/trytond/server.py @@ -3,7 +3,6 @@ """ %prog [options] """ -from __future__ import with_statement import logging import logging.handlers import sys, os, signal diff --git a/trytond/tests/test_access.py b/trytond/tests/test_access.py index 7a21a2521a..3d9c7d0282 100644 --- a/trytond/tests/test_access.py +++ b/trytond/tests/test_access.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ install_module diff --git a/trytond/tests/test_exportdata.py b/trytond/tests/test_exportdata.py index 8f35fbf670..04524309b4 100644 --- a/trytond/tests/test_exportdata.py +++ b/trytond/tests/test_exportdata.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest from decimal import Decimal import datetime diff --git a/trytond/tests/test_fields.py b/trytond/tests/test_fields.py index fd44d29eee..f92b58cc4e 100644 --- a/trytond/tests/test_fields.py +++ b/trytond/tests/test_fields.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest import datetime from decimal import Decimal diff --git a/trytond/tests/test_importdata.py b/trytond/tests/test_importdata.py index 0ea271dcaf..ec7bccbb05 100644 --- a/trytond/tests/test_importdata.py +++ b/trytond/tests/test_importdata.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ install_module diff --git a/trytond/tests/test_modelsingleton.py b/trytond/tests/test_modelsingleton.py index b94a8f19d6..752dd4e061 100644 --- a/trytond/tests/test_modelsingleton.py +++ b/trytond/tests/test_modelsingleton.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest from datetime import datetime from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ diff --git a/trytond/tests/test_mptt.py b/trytond/tests/test_mptt.py index b50462bd64..0dc276a65a 100644 --- a/trytond/tests/test_mptt.py +++ b/trytond/tests/test_mptt.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ install_module @@ -23,8 +22,7 @@ class MPTTTestCase(unittest.TestCase): ('parent', '=', parent_id), ]) childs = self.mptt.read(child_ids, ['left', 'right']) - childs.sort(lambda x, y: cmp(child_ids.index(x['id']), - child_ids.index(y['id']))) + childs.sort(key=lambda x: child_ids.index(x['id'])) for child in childs: assert child['left'] > left, \ 'Record (%d): left %d <= parent left %d' % \ @@ -152,7 +150,7 @@ class MPTTTestCase(unittest.TestCase): with Transaction().start(DB_NAME, USER, CONTEXT) as transaction: record_ids = self.mptt.search([]) - self.mptt.write(record_ids[:len(record_ids)/2], { + self.mptt.write(record_ids[:len(record_ids) // 2], { 'active': False }) self.CheckTree() @@ -186,7 +184,7 @@ class MPTTTestCase(unittest.TestCase): with Transaction().start(DB_NAME, USER, CONTEXT) as transaction: record_ids = self.mptt.search([]) - self.mptt.delete(record_ids[:len(record_ids)/2]) + self.mptt.delete(record_ids[:len(record_ids) // 2]) self.CheckTree() transaction.cursor.rollback() diff --git a/trytond/tests/test_sequence.py b/trytond/tests/test_sequence.py index 8a07b671fc..aa5e44c9f2 100644 --- a/trytond/tests/test_sequence.py +++ b/trytond/tests/test_sequence.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest import datetime from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \ diff --git a/trytond/tests/test_trigger.py b/trytond/tests/test_trigger.py index c2834524bd..fe53103a04 100644 --- a/trytond/tests/test_trigger.py +++ b/trytond/tests/test_trigger.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import unittest import sys import time diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index 9ecd460d3f..e7c65a0366 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import logging logging.basicConfig(level=logging.ERROR) import sys, os @@ -11,13 +10,6 @@ DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, if os.path.isdir(DIR): sys.path.insert(0, os.path.dirname(DIR)) -if sys.version_info[:2] <= (2, 5): - # ugly monkeypatch to make doctests work. For the reasons see - # http://mail.python.org/pipermail/python-dev/2008-July/081420.html - # It can go away once we drop Python 2.5 - import decimal - decimal.Decimal.__repr__ = lambda s: "Decimal('%s')" % str(s) - import unittest import doctest from lxml import etree diff --git a/trytond/workflow/workflow.py b/trytond/workflow/workflow.py index ef91314733..c8969d93f9 100644 --- a/trytond/workflow/workflow.py +++ b/trytond/workflow/workflow.py @@ -1,6 +1,5 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of #this repository contains the full copyright notices and license terms. -from __future__ import with_statement import os import expr import base64