Remove support of Python2.5 and fix py3 warnings

This commit is contained in:
Cédric Krier
2011-07-12 00:16:15 +02:00
parent 981e3dca65
commit 852f04dc51
49 changed files with 48 additions and 79 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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)
+1 -6
View File
@@ -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'],
-1
View File
@@ -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
-1
View File
@@ -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
+5 -2
View File
@@ -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(" ")
+1 -1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
+1 -1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
+1 -1
View File
@@ -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):
-1
View File
@@ -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
+8 -5
View File
@@ -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):
+2 -2
View File
@@ -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')
+6 -2
View File
@@ -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)
+2 -3
View File
@@ -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:
-1
View File
@@ -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
+6 -4
View File
@@ -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)):
-1
View File
@@ -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
+3
View File
@@ -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)
-1
View File
@@ -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
+2 -2
View File
@@ -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())
+2 -1
View File
@@ -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']:
-1
View File
@@ -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
+3 -4
View File
@@ -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
-1
View File
@@ -3,7 +3,6 @@
"""
%prog [options]
"""
from __future__ import with_statement
import logging
import logging.handlers
import sys, os, signal
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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
-1
View File
@@ -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, \
+3 -5
View File
@@ -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()
-1
View File
@@ -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, \
-1
View File
@@ -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
-8
View File
@@ -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
-1
View File
@@ -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