changeset 9d1c6e94d686 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=9d1c6e94d686
description:
Fix flake8 errors and warnings
We add the flake8 configuration used so we ensure everyone uses the
same.
We remove the usage of __all__ for non public API.
When possible, we rationalize the class name according to its __name__
and module.
issue9082
review297061002
diffstat:
.flake8 | 2 +
setup.py | 3 +-
trytond/admin.py | 4 +-
trytond/application.py | 4 +-
trytond/backend/__init__.py | 4 +-
trytond/backend/postgresql/__init__.py | 8 +-
trytond/backend/postgresql/database.py | 12 +-
trytond/backend/postgresql/table.py | 9 +-
trytond/backend/sqlite/__init__.py | 8 +-
trytond/backend/sqlite/database.py | 8 +-
trytond/backend/sqlite/table.py | 30 ++--
trytond/bus.py | 7 +-
trytond/config.py | 1 +
trytond/convert.py | 6 +-
trytond/filestore.py | 3 +-
trytond/ir/__init__.py | 176 ++++++++++++++++----------------
trytond/ir/action.py | 6 +-
trytond/ir/attachment.py | 1 +
trytond/ir/cron.py | 4 +-
trytond/ir/lang.py | 5 +-
trytond/ir/model.py | 64 ++++++++---
trytond/ir/module.py | 4 +-
trytond/ir/rule.py | 11 +-
trytond/ir/translation.py | 20 ++-
trytond/ir/trigger.py | 8 +-
trytond/ir/ui/__init__.py | 5 +
trytond/ir/ui/menu.py | 8 +-
trytond/model/fields/__init__.py | 45 +++++---
trytond/model/fields/field.py | 12 +-
trytond/model/modelsql.py | 3 +-
trytond/model/modelstorage.py | 12 +-
trytond/model/tree.py | 7 +-
trytond/modules/__init__.py | 1 -
trytond/pool.py | 3 +-
trytond/protocols/jsonrpc.py | 17 ++-
trytond/report/__init__.py | 4 +-
trytond/report/report.py | 15 +-
trytond/res/__init__.py | 24 ++--
trytond/res/group.py | 3 -
trytond/res/user.py | 3 +-
trytond/rpc.py | 3 +-
trytond/tests/run-tests.py | 4 +-
trytond/tests/test_protocols.py | 13 ++-
trytond/tests/test_tools.py | 3 +-
trytond/tools/__init__.py | 11 +-
trytond/tools/misc.py | 8 +-
trytond/tools/multivalue.py | 8 +-
trytond/transaction.py | 4 +-
trytond/wsgi.py | 4 +-
49 files changed, 366 insertions(+), 262 deletions(-)
diffs (1443 lines):
diff -r bfe9c94cfb99 -r 9d1c6e94d686 .flake8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.flake8 Sun Mar 01 12:33:54 2020 +0100
@@ -0,0 +1,2 @@
+[flake8]
+ignore=E123,E124,E126,E128,W503
diff -r bfe9c94cfb99 -r 9d1c6e94d686 setup.py
--- a/setup.py Sat Feb 29 23:50:59 2020 +0100
+++ b/setup.py Sun Mar 01 12:33:54 2020 +0100
@@ -106,7 +106,8 @@
'Environment :: No Input/Output (Daemon)',
'Framework :: Tryton',
'Intended Audience :: Developers',
- 'License :: OSI Approved :: GNU General Public License v3 or later
(GPLv3+)',
+ 'License :: OSI Approved :: '
+ 'GNU General Public License v3 or later (GPLv3+)',
'Natural Language :: Bulgarian',
'Natural Language :: Catalan',
'Natural Language :: Chinese (Simplified)',
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/admin.py
--- a/trytond/admin.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/admin.py Sun Mar 01 12:33:54 2020 +0100
@@ -5,7 +5,7 @@
import logging
from getpass import getpass
-from sql import Table
+from sql import Table, Literal
from trytond import backend
from trytond.transaction import Transaction
@@ -41,7 +41,7 @@
raise Exception('"%s" is not a Tryton database.' % db_name)
lang = Table('ir_lang')
cursor.execute(*lang.select(lang.code,
- where=lang.translatable == True))
+ where=lang.translatable == Literal(True)))
lang = set([x[0] for x in cursor.fetchall()])
lang.add(main_lang)
else:
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/application.py
--- a/trytond/application.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/application.py Sun Mar 01 12:33:54 2020 +0100
@@ -25,8 +25,8 @@
from gevent import monkey
monkey.patch_all()
-from trytond.pool import Pool
-from trytond.wsgi import app
+from trytond.pool import Pool # noqa: E402
+from trytond.wsgi import app # noqa: E402
Pool.start()
# TRYTOND_CONFIG it's managed by importing config
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/__init__.py
--- a/trytond/backend/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -9,7 +9,9 @@
from trytond.config import config
-__all__ = ['name', 'Database', 'DatabaseIntegrityError', 'TableHandler']
+__all__ = [
+ 'name', 'Database', 'DatabaseIntegrityError',
+ 'DatabaseOperationalError', 'TableHandler']
name = urllib.parse.urlparse(config.get('database', 'uri', default='')).scheme
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/postgresql/__init__.py
--- a/trytond/backend/postgresql/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/postgresql/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,5 +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 .database import *
-from .table import *
+from .database import (
+ Database, DatabaseIntegrityError, DatabaseOperationalError)
+from .table import TableHandler
+
+__all__ = [
+ Database, DatabaseIntegrityError, DatabaseOperationalError, TableHandler]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/postgresql/database.py
--- a/trytond/backend/postgresql/database.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/postgresql/database.py Sun Mar 01 12:33:54 2020 +0100
@@ -4,7 +4,7 @@
import time
import logging
import os
-import urllib.request, urllib.parse, urllib.error
+import urllib.parse
import json
from datetime import datetime
from decimal import Decimal
@@ -533,15 +533,15 @@
increment, = cursor.fetchone()
cursor.execute(
'SELECT CASE WHEN NOT is_called THEN last_value '
- 'ELSE last_value + %s '
- 'END '
+ 'ELSE last_value + %s '
+ 'END '
'FROM "%s"' % (self.flavor.param, name),
(increment,))
else:
cursor.execute(
'SELECT CASE WHEN NOT is_called THEN last_value '
- 'ELSE last_value + increment_by '
- 'END '
+ 'ELSE last_value + increment_by '
+ 'END '
'FROM "%s"' % name)
return cursor.fetchone()[0]
@@ -583,6 +583,8 @@
def convert_json(value):
from trytond.protocols.jsonrpc import JSONDecoder
return json.loads(value, object_hook=JSONDecoder())
+
+
register_default_json(loads=convert_json)
register_default_jsonb(loads=convert_json)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/postgresql/table.py
--- a/trytond/backend/postgresql/table.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/postgresql/table.py Sun Mar 01 12:33:54 2020 +0100
@@ -9,7 +9,7 @@
__all__ = ['TableHandler']
logger = logging.getLogger(__name__)
-VARCHAR_SIZE_RE = re.compile('VARCHAR\(([0-9]+)\)')
+VARCHAR_SIZE_RE = re.compile(r'VARCHAR\(([0-9]+)\)')
class TableHandler(TableHandlerInterface):
@@ -74,9 +74,10 @@
'ALTER __id SET DEFAULT %s'
% (self.table_name, default))
if self._columns['id']['default'] != default:
- cursor.execute('ALTER TABLE "%s" '
- 'ALTER id SET DEFAULT %s'
- % (self.table_name, default))
+ cursor.execute(
+ 'ALTER TABLE "%s" '
+ 'ALTER id SET DEFAULT %s'
+ % (self.table_name, default))
self._update_definitions()
@staticmethod
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/sqlite/__init__.py
--- a/trytond/backend/sqlite/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/sqlite/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,5 +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 .database import *
-from .table import *
+from .database import (
+ Database, DatabaseIntegrityError, DatabaseOperationalError)
+from .table import TableHandler
+
+__all__ = [
+ Database, DatabaseIntegrityError, DatabaseOperationalError, TableHandler]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/sqlite/database.py
--- a/trytond/backend/sqlite/database.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/sqlite/database.py Sun Mar 01 12:33:54 2020 +0100
@@ -10,13 +10,10 @@
from decimal import Decimal
from weakref import WeakKeyDictionary
-_FIX_ROWCOUNT = False
try:
from pysqlite2 import dbapi2 as sqlite
from pysqlite2.dbapi2 import IntegrityError as DatabaseIntegrityError
from pysqlite2.dbapi2 import OperationalError as DatabaseOperationalError
- # pysqlite2 < 2.5 doesn't return correct rowcount
- _FIX_ROWCOUNT = sqlite.version_info < (2, 5, 0)
except ImportError:
import sqlite3 as sqlite
from sqlite3 import IntegrityError as DatabaseIntegrityError
@@ -554,12 +551,15 @@
column = JSONExtract(column, '$.%s' % key)
return NullIf(JSONQuote(column), JSONQuote(Null))
+
sqlite.register_converter('NUMERIC', lambda val: Decimal(val.decode('utf-8')))
sqlite.register_adapter(Decimal, lambda val: str(val).encode('utf-8'))
def adapt_datetime(val):
return val.replace(tzinfo=None).isoformat(" ")
+
+
sqlite.register_adapter(datetime.datetime, adapt_datetime)
sqlite.register_adapter(datetime.time, lambda val: val.isoformat())
sqlite.register_converter('TIME',
@@ -575,6 +575,8 @@
elif value <= _interval_min:
return datetime.timedelta.min
return datetime.timedelta(seconds=value)
+
+
_interval_max = datetime.timedelta.max.total_seconds()
_interval_min = datetime.timedelta.min.total_seconds()
sqlite.register_converter('INTERVAL', convert_interval)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/backend/sqlite/table.py
--- a/trytond/backend/sqlite/table.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/backend/sqlite/table.py Sun Mar 01 12:33:54 2020 +0100
@@ -10,7 +10,7 @@
__all__ = ['TableHandler']
logger = logging.getLogger(__name__)
-VARCHAR_SIZE_RE = re.compile('VARCHAR\(([0-9]+)\)')
+VARCHAR_SIZE_RE = re.compile(r'VARCHAR\(([0-9]+)\)')
class TableHandler(TableHandlerInterface):
@@ -58,16 +58,16 @@
in cursor.fetchall()]
cursor.execute(('INSERT INTO "_temp_%s" '
'(' + ','.join(columns) + ') '
- 'SELECT ' + ','.join(columns) +
- ' FROM "%s"') % (table_name, table_name))
+ 'SELECT ' + ','.join(columns)
+ + ' FROM "%s"') % (table_name, table_name))
cursor.execute('DROP TABLE "%s"' % table_name)
new_sql = sql.replace('PRIMARY KEY',
'PRIMARY KEY AUTOINCREMENT')
cursor.execute(new_sql)
cursor.execute(('INSERT INTO "%s" '
'(' + ','.join(columns) + ') '
- 'SELECT ' + ','.join(columns) +
- ' FROM "_temp_%s"') % (table_name, table_name))
+ 'SELECT ' + ','.join(columns)
+ + ' FROM "_temp_%s"') % (table_name, table_name))
cursor.execute('DROP TABLE "_temp_%s"' % table_name)
return True
@@ -106,11 +106,11 @@
new_column, database.sql_type(typname), field_size=size)
columns.append(new_column)
old_columns.append(column)
- cursor.execute(('INSERT INTO "%s" (' +
- ','.join('"%s"' % x for x in columns) +
- ') SELECT ' +
- ','.join('"%s"' % x for x in old_columns) + ' ' +
- 'FROM "%s"') % (self.table_name, temp_table))
+ cursor.execute(('INSERT INTO "%s" ('
+ + ','.join('"%s"' % x for x in columns)
+ + ') SELECT '
+ + ','.join('"%s"' % x for x in old_columns) + ' '
+ + 'FROM "%s"') % (self.table_name, temp_table))
cursor.execute('DROP TABLE "%s"' % temp_table)
self._update_definitions()
@@ -332,11 +332,11 @@
new_table._add_raw_column(
name, database.sql_type(typname), field_size=size)
columns_name = list(new_table._columns.keys())
- cursor.execute(('INSERT INTO "%s" (' +
- ','.join('"%s"' % c for c in columns_name) +
- ') SELECT ' +
- ','.join('"%s"' % c for c in columns_name) + ' ' +
- 'FROM "%s"') % (self.table_name, temp_table))
+ cursor.execute(('INSERT INTO "%s" ('
+ + ','.join('"%s"' % c for c in columns_name)
+ + ') SELECT '
+ + ','.join('"%s"' % c for c in columns_name) + ' '
+ + 'FROM "%s"') % (self.table_name, temp_table))
cursor.execute('DROP TABLE "%s"' % temp_table)
self._update_definitions()
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/bus.py
--- a/trytond/bus.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/bus.py Sun Mar 01 12:33:54 2020 +0100
@@ -16,7 +16,8 @@
from werkzeug.utils import redirect
from werkzeug.wrappers import Response
-from werkzeug.exceptions import NotImplemented, BadRequest
+from werkzeug.exceptions import (
+ NotImplemented as NotImplementedException, BadRequest)
from trytond import backend
from trytond.wsgi import app
@@ -142,7 +143,7 @@
def _listen(cls, database):
db = backend.Database(database)
if not db.has_channel():
- raise NotImplemented
+ raise NotImplementedException
logger.info("listening on channel '%s'", cls._channel)
conn = db.get_connection()
@@ -222,7 +223,7 @@
@app.auth_required
def subscribe(request, database_name):
if not _allow_subscribe:
- raise NotImplemented
+ raise NotImplementedException
if _url_host and _url_host != request.host_url:
response = redirect(
urljoin(_url_host, request.path), HTTPStatus.PERMANENT_REDIRECT)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/config.py
--- a/trytond/config.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/config.py Sun Mar 01 12:33:54 2020 +0100
@@ -149,4 +149,5 @@
AttributeError):
return default
+
config = TrytonConfigParser()
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/convert.py
--- a/trytond/convert.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/convert.py Sun Mar 01 12:33:54 2020 +0100
@@ -16,8 +16,8 @@
logger = logging.getLogger(__name__)
-CDATA_START = re.compile('^\s*\<\!\[cdata\[', re.IGNORECASE)
-CDATA_END = re.compile('\]\]\>\s*$', re.IGNORECASE)
+CDATA_START = re.compile(r'^\s*\<\!\[cdata\[', re.IGNORECASE)
+CDATA_END = re.compile(r'\]\]\>\s*$', re.IGNORECASE)
class DummyTagHandler:
@@ -279,7 +279,7 @@
self.cdata = 'done'
value = self.values[self.current_field]
- match = re.findall('[^%]%\((.*?)\)[ds]', value)
+ match = re.findall(r'[^%]%\((.*?)\)[ds]', value)
xml_ids = {}
for xml_id in match:
xml_ids[xml_id] = self.mh.get_id(xml_id)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/filestore.py
--- a/trytond/filestore.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/filestore.py Sun Mar 01 12:33:54 2020 +0100
@@ -62,6 +62,7 @@
def _id(self, data):
return hashlib.md5(data).hexdigest()
+
if config.get('database', 'class'):
- FileStore = resolve(config.get('database', 'class'))
+ FileStore = resolve(config.get('database', 'class')) # noqa: F811
filestore = FileStore()
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/__init__.py
--- a/trytond/ir/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,25 +1,23 @@
# 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 ..pool import Pool
-from .configuration import *
-from .translation import *
-from .sequence import *
-from .ui.menu import *
-from .ui.view import *
-from .ui.icon import *
-from .action import *
-from .model import *
-from .attachment import *
-from .note import *
-from .cron import *
-from .lang import *
+from . import configuration
+from . import translation
+from . import sequence
+from . import ui
+from . import action
+from . import model
+from . import attachment
+from . import note
+from . import cron
+from . import lang
from . import export
-from .rule import *
-from .module import *
-from .cache import *
-from .date import *
-from .trigger import *
-from .session import *
+from . import rule
+from . import module
+from . import cache
+from . import date
+from . import trigger
+from . import session
from . import queue
from . import calendar_
from . import message
@@ -30,85 +28,85 @@
def register():
Pool.register(
- Configuration,
- Translation,
- TranslationSetStart,
- TranslationSetSucceed,
- TranslationCleanStart,
- TranslationCleanSucceed,
- TranslationUpdateStart,
- TranslationExportStart,
- TranslationExportResult,
- SequenceType,
- Sequence,
- SequenceStrict,
- UIMenu,
- UIMenuFavorite,
- View,
- ShowViewStart,
- ViewTreeWidth,
- ViewTreeState,
- ViewSearch,
- Icon,
- Action,
- ActionKeyword,
- ActionReport,
- ActionActWindow,
- ActionActWindowView,
- ActionActWindowDomain,
- ActionWizard,
- ActionURL,
- Model,
- ModelField,
- ModelAccess,
- ModelFieldAccess,
- ModelButton,
- ModelButtonRule,
- ModelButtonClick,
- ModelButtonReset,
- ModelData,
- PrintModelGraphStart,
- Attachment,
- Note,
- NoteRead,
- Cron,
- Lang,
+ configuration.Configuration,
+ translation.Translation,
+ translation.TranslationSetStart,
+ translation.TranslationSetSucceed,
+ translation.TranslationCleanStart,
+ translation.TranslationCleanSucceed,
+ translation.TranslationUpdateStart,
+ translation.TranslationExportStart,
+ translation.TranslationExportResult,
+ sequence.SequenceType,
+ sequence.Sequence,
+ sequence.SequenceStrict,
+ ui.menu.UIMenu,
+ ui.menu.UIMenuFavorite,
+ ui.view.View,
+ ui.view.ShowViewStart,
+ ui.view.ViewTreeWidth,
+ ui.view.ViewTreeState,
+ ui.view.ViewSearch,
+ ui.icon.Icon,
+ action.Action,
+ action.ActionKeyword,
+ action.ActionReport,
+ action.ActionActWindow,
+ action.ActionActWindowView,
+ action.ActionActWindowDomain,
+ action.ActionWizard,
+ action.ActionURL,
+ model.Model,
+ model.ModelField,
+ model.ModelAccess,
+ model.ModelFieldAccess,
+ model.ModelButton,
+ model.ModelButtonRule,
+ model.ModelButtonClick,
+ model.ModelButtonReset,
+ model.ModelData,
+ model.PrintModelGraphStart,
+ attachment.Attachment,
+ note.Note,
+ note.NoteRead,
+ cron.Cron,
+ lang.Lang,
export.Export,
export.ExportLine,
- RuleGroup,
- Rule,
- Module,
- ModuleDependency,
- ModuleConfigWizardItem,
- ModuleConfigWizardFirst,
- ModuleConfigWizardOther,
- ModuleConfigWizardDone,
- ModuleActivateUpgradeStart,
- ModuleActivateUpgradeDone,
- Cache,
- Date,
- Trigger,
- TriggerLog,
- Session,
- SessionWizard,
+ rule.RuleGroup,
+ rule.Rule,
+ module.Module,
+ module.ModuleDependency,
+ module.ModuleConfigWizardItem,
+ module.ModuleConfigWizardFirst,
+ module.ModuleConfigWizardOther,
+ module.ModuleConfigWizardDone,
+ module.ModuleActivateUpgradeStart,
+ module.ModuleActivateUpgradeDone,
+ cache.Cache,
+ date.Date,
+ trigger.Trigger,
+ trigger.TriggerLog,
+ session.Session,
+ session.SessionWizard,
queue.Queue,
calendar_.Month,
calendar_.Day,
message.Message,
module='ir', type_='model')
Pool.register(
- TranslationSet,
- TranslationClean,
- TranslationUpdate,
- TranslationExport,
- TranslationReport,
- ShowView,
- PrintModelGraph,
- ModuleConfigWizard,
- ModuleActivateUpgrade,
- ModuleConfig,
+ translation.TranslationSet,
+ translation.TranslationClean,
+ translation.TranslationUpdate,
+ translation.TranslationExport,
+ translation.TranslationReport,
+ ui.view.ShowView,
+ model.PrintModelGraph,
+ module.ModuleConfigWizard,
+ module.ModuleActivateUpgrade,
+ module.ModuleConfig,
module='ir', type_='wizard')
Pool.register(
- ModelGraph,
- ModelWorkflowGraph,
+ model.ModelGraph,
+ model.ModelWorkflowGraph,
module='ir', type_='report')
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/action.py
--- a/trytond/ir/action.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/action.py Sun Mar 01 12:33:54 2020 +0100
@@ -290,13 +290,15 @@
@classmethod
def get_action(cls, ids, names):
+ def identical(v):
+ return v
records = cls.browse(ids)
result = {}
for name in names:
result[name] = values = {}
for record in records:
value = getattr(record, 'action')
- convert = lambda v: v
+ convert = identical
if value is not None:
value = getattr(value, name)
if isinstance(value, ModelStorage):
@@ -305,7 +307,7 @@
else:
convert = int
elif isinstance(value, (list, tuple)):
- convert = lambda v: [r.id for r in v]
+ convert = partial(map, int)
values[record.id] = convert(value)
return result
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/attachment.py
--- a/trytond/ir/attachment.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/attachment.py Sun Mar 01 12:33:54 2020 +0100
@@ -20,6 +20,7 @@
except StopIteration:
return ''
+
if config.getboolean('attachment', 'filestore', default=True):
file_id = 'file_id'
store_prefix = config.get('attachment', 'store_prefix', default=None)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/cron.py
--- a/trytond/ir/cron.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/cron.py Sun Mar 01 12:33:54 2020 +0100
@@ -85,8 +85,8 @@
@classmethod
def view_attributes(cls):
- return [
- ('//label[@id="time_label"]', 'states', {
+ return [(
+ '//label[@id="time_label"]', 'states', {
'invisible': Eval('interval_type') == 'minutes',
}),
]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/lang.py
--- a/trytond/ir/lang.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/lang.py Sun Mar 01 12:33:54 2020 +0100
@@ -2,10 +2,7 @@
# this repository contains the full copyright notices and license terms.
import datetime
-import warnings
-warnings.filterwarnings('ignore', "", ImportWarning)
from locale import CHAR_MAX
-warnings.resetwarnings()
from ast import literal_eval
from sql import Table
@@ -518,4 +515,6 @@
for sep in ['@', '_']:
if sep in code:
return code.rsplit(sep, 1)[0]
+
+
_parents = {}
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/model.py
--- a/trytond/ir/model.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/model.py Sun Mar 01 12:33:54 2020 +0100
@@ -5,7 +5,7 @@
import logging
import re
-from sql import Null
+from sql import Null, Literal
from sql.aggregate import Max
from sql.conditionals import Case
from collections import defaultdict
@@ -98,7 +98,8 @@
cursor.execute(*ir_model.insert(
[ir_model.model, ir_model.name, ir_model.info,
ir_model.module],
- [[model.__name__, model._get_name(), model.__doc__,
+ [[
+ model.__name__, model._get_name(), model.__doc__,
module_name]]))
cursor.execute(*ir_model.select(ir_model.id,
where=ir_model.model == model.__name__))
@@ -282,8 +283,11 @@
ir_model_field.field_description,
ir_model_field.ttype, ir_model_field.relation,
ir_model_field.help, ir_model_field.module],
- [[model_id, field_name, field.string, field._type,
- relation, field.help, module_name]]))
+ [[
+ model_id, field_name,
+ field.string,
+ field._type, relation,
+ field.help, module_name]]))
elif (model_fields[field_name]['field_description'] != field.string
or model_fields[field_name]['ttype'] != field._type
or model_fields[field_name]['relation'] != relation
@@ -293,8 +297,8 @@
ir_model_field.ttype, ir_model_field.relation,
ir_model_field.help],
[field.string, field._type, relation, field.help],
- where=ir_model_field.id ==
- model_fields[field_name]['id']))
+ where=(ir_model_field.id
+ == model_fields[field_name]['id'])))
@classmethod
def clean(cls):
@@ -519,14 +523,23 @@
condition=model_access.group == group.id
).select(
ir_model.model,
- Max(Case((model_access.perm_read == True, 1), else_=0)),
- Max(Case((model_access.perm_write == True, 1), else_=0)),
- Max(Case((model_access.perm_create == True, 1), else_=0)),
- Max(Case((model_access.perm_delete == True, 1), else_=0)),
+ Max(Case(
+ (model_access.perm_read == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (model_access.perm_write == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (model_access.perm_create == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (model_access.perm_delete == Literal(True), 1),
+ else_=0)),
where=ir_model.model.in_(models)
- & (model_access.active == True)
- & (((user_group.user == user)
- & (group.active == True))
+ & (model_access.active == Literal(True))
+ & ((
+ (user_group.user == user)
+ & (group.active == Literal(True)))
| (model_access.group == Null)),
group_by=ir_model.model))
access.update(dict(
@@ -700,14 +713,23 @@
).select(
ir_model.model,
model_field.name,
- Max(Case((field_access.perm_read == True , 1), else_=0)),
- Max(Case((field_access.perm_write == True, 1), else_=0)),
- Max(Case((field_access.perm_create == True, 1), else_=0)),
- Max(Case((field_access.perm_delete == True, 1), else_=0)),
+ Max(Case(
+ (field_access.perm_read == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (field_access.perm_write == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (field_access.perm_create == Literal(True), 1),
+ else_=0)),
+ Max(Case(
+ (field_access.perm_delete == Literal(True), 1),
+ else_=0)),
where=ir_model.model.in_(models)
- & (field_access.active == True)
- & (((user_group.user == user)
- & (group.active == True))
+ & (field_access.active == Literal(True))
+ & ((
+ (user_group.user == user)
+ & (group.active == Literal(True)))
| (field_access.group == Null)),
group_by=[ir_model.model, model_field.name]))
for m, f, r, w, c, d in cursor.fetchall():
@@ -1372,7 +1394,7 @@
for model in models:
if filter and re.search(filter, model.model):
- continue
+ continue
label = '"{' + model.model + '\\n'
if model.fields:
label += '|'
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/module.py
--- a/trytond/ir/module.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/module.py Sun Mar 01 12:33:54 2020 +0100
@@ -403,8 +403,8 @@
cursor.execute(*model_data.update(
columns=[model_data.model],
values=[cls.__name__],
- where=(model_data.model ==
- 'ir.module.module.config_wizard.item')))
+ where=(model_data.model
+ == 'ir.module.module.config_wizard.item')))
super(ModuleConfigWizardItem, cls).__register__(module_name)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/rule.py
--- a/trytond/ir/rule.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/rule.py Sun Mar 01 12:33:54 2020 +0100
@@ -2,6 +2,8 @@
# this repository contains the full copyright notices and license terms.
from collections import defaultdict
+from sql import Literal
+
from trytond.i18n import gettext
from trytond.model.exceptions import ValidationError
from ..model import ModelView, ModelSQL, fields, EvalEnvironment, Check
@@ -50,7 +52,8 @@
t = cls.__table__()
cls._sql_constraints += [
('global_default_exclusive',
- Check(t, (t.global_p == False) | (t.default_p == False)),
+ Check(t, (t.global_p == Literal(False))
+ | (t.default_p == Literal(False))),
'Global and Default are mutually exclusive!'),
]
@@ -179,7 +182,7 @@
condition=rule_group.model == model.id
).select(rule_table.id,
where=(model.model == model_name)
- & (getattr(rule_group, 'perm_%s' % mode) == True)
+ & (getattr(rule_group, 'perm_%s' % mode) == Literal(True))
& (rule_group.id.in_(
rule_group_group.join(
user_group,
@@ -188,8 +191,8 @@
).select(rule_group_group.rule_group,
where=user_group.user == user_id)
)
- | (rule_group.default_p == True)
- | (rule_group.global_p == True)
+ | (rule_group.default_p == Literal(True))
+ | (rule_group.global_p == Literal(True))
)))
ids = [x for x, in cursor]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/translation.py
--- a/trytond/ir/translation.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/translation.py Sun Mar 01 12:33:54 2020 +0100
@@ -216,7 +216,8 @@
ir_translation.type, ir_translation.src,
ir_translation.value, ir_translation.module,
ir_translation.fuzzy, ir_translation.res_id],
- [[trans_name, 'en',
+ [[
+ trans_name, 'en',
'wizard_button', button.string,
'', module_name,
False, -1]]))
@@ -224,8 +225,8 @@
cursor.execute(*ir_translation.update(
[ir_translation.src],
[button.string],
- where=ir_translation.id ==
- trans_buttons[trans_name]['id']))
+ where=ir_translation.id
+ == trans_buttons[trans_name]['id']))
for state_name, state in wizard.states.items():
if not isinstance(state, StateView):
@@ -264,7 +265,8 @@
Operator = fields.SQL_OPERATORS[operator]
return [('id', 'in', table.select(table.id,
where=Operator(Substring(table.name, 1,
- Case((Position(',', table.name) > 0,
+ Case((
+ Position(',', table.name) > 0,
Position(',', table.name) - 1),
else_=0)), value)))]
@@ -1016,7 +1018,8 @@
translation.type, translation.src,
translation.value, translation.module,
translation.fuzzy, translation.res_id],
- [[report.report_name, 'en',
+ [[
+ report.report_name, 'en',
'report', string,
'', module,
False, -1]]))
@@ -1103,8 +1106,8 @@
[translation.src,
translation.fuzzy],
[string, True],
- where=(translation.id ==
- trans_views[string_trans]['id'])))
+ where=(translation.id
+ == trans_views[string_trans]['id'])))
del trans_views[string_trans]
done = True
break
@@ -1114,7 +1117,8 @@
translation.type, translation.src,
translation.value, translation.module,
translation.fuzzy, translation.res_id],
- [[view.model, 'en',
+ [[
+ view.model, 'en',
'view', string,
'', view.module,
False, -1]]))
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/trigger.py
--- a/trytond/ir/trigger.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/trigger.py Sun Mar 01 12:33:54 2020 +0100
@@ -64,10 +64,10 @@
t = cls.__table__()
cls._sql_constraints += [
('on_exclusive',
- Check(t, ~((t.on_time == True)
- & ((t.on_create == True)
- | (t.on_write == True)
- | (t.on_delete == True)))),
+ Check(t, ~((t.on_time == Literal(True))
+ & ((t.on_create == Literal(True))
+ | (t.on_write == Literal(True))
+ | (t.on_delete == Literal(True))))),
'"On Time" and others are mutually exclusive!'),
]
cls._order.insert(0, ('name', 'ASC'))
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/ui/__init__.py
--- a/trytond/ir/ui/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/ui/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,2 +1,7 @@
# 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 . import menu
+from . import view
+from . import icon
+
+__all__ = ['menu', 'view', 'icon']
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/ir/ui/menu.py
--- a/trytond/ir/ui/menu.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/ir/ui/menu.py Sun Mar 01 12:33:54 2020 +0100
@@ -162,9 +162,11 @@
with Transaction().set_context(active_test=False):
menus = cls.browse(menus)
action_keywords = sum((list(m.action_keywords) for m in menus), [])
- key = lambda k: k.action.type
- action_keywords.sort(key=key)
- for type, action_keywords in groupby(action_keywords, key=key):
+
+ def action_type(keyword):
+ return keyword.action.type
+ action_keywords.sort(key=action_type)
+ for type, action_keywords in groupby(action_keywords, key=action_type):
action_keywords = list(action_keywords)
for action_keyword in action_keywords:
model = action_keyword.model
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/model/fields/__init__.py
--- a/trytond/model/fields/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/model/fields/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,21 +1,30 @@
# 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 .field import *
-from .boolean import *
-from .integer import *
-from .char import *
-from .text import *
-from .float import *
-from .numeric import *
-from .date import *
-from .binary import *
-from .selection import *
-from .reference import *
-from .many2one import *
-from .one2many import *
-from .many2many import *
-from .function import *
-from .one2one import *
-from .dict import *
-from .multiselection import *
+from .field import (
+ depends, with_inactive_records, SQL_OPERATORS, on_change_result,
+ get_eval_fields, states_validate, domain_validate, context_validate, Field)
+from .boolean import Boolean
+from .integer import Integer, BigInteger
+from .char import Char
+from .text import Text
+from .float import Float
+from .numeric import Numeric
+from .date import Date, Timestamp, DateTime, Time, TimeDelta
+from .binary import Binary
+from .selection import Selection
+from .reference import Reference
+from .many2one import Many2One
+from .one2many import One2Many
+from .many2many import Many2Many
+from .function import Function, MultiValue
+from .one2one import One2One
+from .dict import Dict
+from .multiselection import MultiSelection
+
+__all__ = [
+ depends, with_inactive_records, SQL_OPERATORS, on_change_result,
+ get_eval_fields, states_validate, domain_validate, context_validate, Field,
+ Boolean, Integer, BigInteger, Char, Text, Float, Numeric, Date, Timestamp,
+ DateTime, Time, TimeDelta, Binary, Selection, Reference, Many2One,
+ One2Many, Many2Many, Function, MultiValue, One2One, Dict, MultiSelection]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/model/fields/field.py
--- a/trytond/model/fields/field.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/model/fields/field.py Sun Mar 01 12:33:54 2020 +0100
@@ -29,9 +29,11 @@
elif (isinstance(arg, tuple)
or (isinstance(arg, list)
and len(arg) > 2
- and ((isinstance(arg[1], str)
+ and ((
+ isinstance(arg[1], str)
and arg[1] in OPERATORS)
- or (isinstance(arg[1], PYSON)
+ or (
+ isinstance(arg[1], PYSON)
and arg[1].types() == set([str]))))):
pass
elif isinstance(arg, list):
@@ -484,7 +486,7 @@
& (translation.res_id == -1)
& (translation.lang == language)
& (translation.type == 'model')
- & (translation.fuzzy == False))
+ & (translation.fuzzy == Literal(False)))
elif Model.__name__ == 'ir.model.field':
if name == 'field_description':
type_ = 'field'
@@ -498,14 +500,14 @@
& (translation.res_id == -1)
& (translation.lang == language)
& (translation.type == type_)
- & (translation.fuzzy == False))
+ & (translation.fuzzy == Literal(False)))
else:
return from_.join(translation, 'LEFT',
condition=(translation.res_id == table.id)
& (translation.name == '%s,%s' % (Model.__name__, name))
& (translation.lang == language)
& (translation.type == 'model')
- & (translation.fuzzy == False))
+ & (translation.fuzzy == Literal(False)))
def convert_domain(self, domain, tables, Model):
from trytond.ir.lang import get_parent_language
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/model/modelsql.py
--- a/trytond/model/modelsql.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/model/modelsql.py Sun Mar 01 12:33:54 2020 +0100
@@ -370,7 +370,8 @@
target_records = Model.search([
('id', '=', field.sql_format(values[field_name])),
], order=[])
- if not ((target_records
+ if not ((
+ target_records
or (values[field_name] in create_records))
and (values[field_name] not in delete_records)):
error_args = cls.__names__(field_name)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/model/modelstorage.py
--- a/trytond/model/modelstorage.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/model/modelstorage.py Sun Mar 01 12:33:54 2020 +0100
@@ -297,7 +297,8 @@
# Clean transaction cache
for cache in list(Transaction().cache.values()):
- for cache in (cache, list(cache.get('_language_cache',
{}).values())):
+ for cache in (cache, list(
+ cache.get('_language_cache', {}).values())):
if cls.__name__ in cache:
for record in records:
if record.id in cache[cls.__name__]:
@@ -647,8 +648,8 @@
value = getattr(value, field_name)
if isinstance(value, (list, tuple)):
first = True
- child_fields_names = [(x[:i + 1] == fields_tree[:i + 1] and
- x[i + 1:]) or [] for x in fields_names]
+ child_fields_names = [(x[:i + 1] == fields_tree[:i + 1]
+ and x[i + 1:]) or [] for x in fields_names]
if child_fields_names in done:
break
done.append(child_fields_names)
@@ -1184,7 +1185,8 @@
validate_domain(field)
def required_test(value, field_name, field):
- if ((isinstance(value,
+ if ((
+ isinstance(value,
(type(None), bool, list, tuple, str, dict))
and not value)
or (field._type == 'reference'
@@ -1689,7 +1691,7 @@
if to_write:
cls.write(*sum(
(([r], save_values[r]) for r in to_write), ()))
- except:
+ except Exception:
for record in to_create + to_write:
record._values = values[record]
raise
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/model/tree.py
--- a/trytond/model/tree.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/model/tree.py Sun Mar 01 12:33:54 2020 +0100
@@ -55,7 +55,8 @@
for value in values:
domain.append((field, clause[1], value.strip()))
field = parent + '.' + field
- if ((clause[1].endswith('like')
+ if ((
+ clause[1].endswith('like')
and not clause[2].replace(
'%%', '__').startswith('%'))
or not clause[1].endswith('like')):
@@ -68,8 +69,8 @@
domain.append((top_parent, operator, None))
if (clause[1].endswith('like')
and clause[2].replace('%%', '__').endswith('%')):
- ids = list(map(int, cls.search(domain, order=[])))
- domain = [(parent, 'child_of', ids)]
+ ids = list(map(int, cls.search(domain, order=[])))
+ domain = [(parent, 'child_of', ids)]
return domain
@classmethod
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/modules/__init__.py
--- a/trytond/modules/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/modules/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -81,7 +81,6 @@
return module
-
def get_module_info(name):
"Return the content of the tryton.cfg"
module_config = configparser.ConfigParser()
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/pool.py
--- a/trytond/pool.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/pool.py Sun Mar 01 12:33:54 2020 +0100
@@ -231,7 +231,8 @@
if classes is None:
classes = {}
for type_ in self._pool[self.database_name]:
- classes[type_] =
list(self._pool[self.database_name][type_].values())
+ classes[type_] = list(
+ self._pool[self.database_name][type_].values())
for type_, lst in classes.items():
for cls in lst:
cls.__setup__()
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/protocols/jsonrpc.py
--- a/trytond/protocols/jsonrpc.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/protocols/jsonrpc.py Sun Mar 01 12:33:54 2020 +0100
@@ -31,6 +31,7 @@
return self.decoders[dct['__class__']](dct)
return dct
+
JSONDecoder.register('datetime',
lambda dct: datetime.datetime(dct['year'], dct['month'], dct['day'],
dct['hour'], dct['minute'], dct['second'], dct['microsecond']))
@@ -46,6 +47,8 @@
def _bytes_decoder(dct):
cast = bytearray if bytes == str else bytes
return cast(base64.decodebytes(dct['base64'].encode('utf-8')))
+
+
JSONDecoder.register('bytes', _bytes_decoder)
JSONDecoder.register('Decimal', lambda dct: Decimal(dct['decimal']))
@@ -64,6 +67,7 @@
super(JSONEncoder, self).default)
return marshaller(obj)
+
JSONEncoder.register(datetime.datetime,
lambda o: {
'__class__': 'datetime',
@@ -95,10 +99,15 @@
'__class__': 'timedelta',
'seconds': o.total_seconds(),
})
-_bytes_encoder = lambda o: {
- '__class__': 'bytes',
- 'base64': base64.encodebytes(o).decode('utf-8'),
- }
+
+
+def _bytes_encoder(o):
+ return {
+ '__class__': 'bytes',
+ 'base64': base64.encodebytes(o).decode('utf-8'),
+ }
+
+
JSONEncoder.register(bytes, _bytes_encoder)
JSONEncoder.register(bytearray, _bytes_encoder)
JSONEncoder.register(Decimal,
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/report/__init__.py
--- a/trytond/report/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/report/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,3 +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 .report import *
+from .report import Report, get_email
+
+__all__ = [Report, get_email]
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/report/report.py
--- a/trytond/report/report.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/report/report.py Sun Mar 01 12:33:54 2020 +0100
@@ -22,13 +22,6 @@
except ImportError:
weasyprint = None
-warnings.simplefilter("ignore")
-import relatorio.reporting
-warnings.resetwarnings()
-try:
- from relatorio.templates.opendocument import Manifest, MANIFEST
-except ImportError:
- Manifest, MANIFEST = None, None
from genshi.filters import Translator
from trytond.i18n import gettext
@@ -38,6 +31,14 @@
from trytond.rpc import RPC
from trytond.exceptions import UserError
+warnings.simplefilter("ignore")
+import relatorio.reporting # noqa: E402
+warnings.resetwarnings()
+try:
+ from relatorio.templates.opendocument import Manifest, MANIFEST
+except ImportError:
+ Manifest, MANIFEST = None, None
+
logger = logging.getLogger(__name__)
MIMETYPES = {
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/res/__init__.py
--- a/trytond/res/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/res/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -2,8 +2,8 @@
# this repository contains the full copyright notices and license terms.
from ..pool import Pool
-from .group import *
-from .user import *
+from . import group
+from . import user
from . import ir
from . import routes
@@ -12,14 +12,14 @@
def register():
Pool.register(
- Group,
- User,
- LoginAttempt,
- UserAction,
- UserGroup,
- Warning_,
- UserApplication,
- UserConfigStart,
+ group.Group,
+ user.User,
+ user.LoginAttempt,
+ user.UserAction,
+ user.UserGroup,
+ user.Warning_,
+ user.UserApplication,
+ user.UserConfigStart,
ir.UIMenuGroup,
ir.ActionGroup,
ir.ModelButtonGroup,
@@ -37,8 +37,8 @@
ir.Export_Write_Group,
module='res', type_='model')
Pool.register(
- UserConfig,
+ user.UserConfig,
module="res", type_='wizard')
Pool.register(
- EmailResetPassword,
+ user.EmailResetPassword,
module='res', type_='report')
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/res/group.py
--- a/trytond/res/group.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/res/group.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,13 +1,10 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
-"Group"
from itertools import chain
from ..model import ModelView, ModelSQL, DeactivableMixin, fields, Unique
from ..pool import Pool
from ..tools import grouped_slice
-__all__ = ['Group']
-
class MenuMany2Many(fields.Many2Many):
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/res/user.py
--- a/trytond/res/user.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/res/user.py Sun Mar 01 12:33:54 2020 +0100
@@ -602,7 +602,8 @@
(table.password_reset_expire > CurrentTimestamp(),
table.password_reset),
else_=None),
- where=(table.login == login) & (table.active == True)))
+ where=(table.login == login)
+ & (table.active == Literal(True))))
result = cursor.fetchone() or (None, None, None)
cls._get_login_cache.set(login, result)
return result
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/rpc.py
--- a/trytond/rpc.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/rpc.py Sun Mar 01 12:33:54 2020 +0100
@@ -27,7 +27,8 @@
self.readonly = readonly
self.instantiate = instantiate
if result is None:
- result = lambda r: r
+ def result(r):
+ return r
self.result = result
self.check_access = check_access
self.fresh_session = fresh_session
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tests/run-tests.py
--- a/trytond/tests/run-tests.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tests/run-tests.py Sun Mar 01 12:33:54 2020 +0100
@@ -35,14 +35,14 @@
config.update_etc(opt.config)
# Import after application is configured
-from trytond import backend
+from trytond import backend # noqa: E402
if backend.name == 'sqlite':
database_name = ':memory:'
else:
database_name = 'test_' + str(int(time.time()))
os.environ.setdefault('DB_NAME', database_name)
-from trytond.tests.test_tryton import all_suite, modules_suite
+from trytond.tests.test_tryton import all_suite, modules_suite # noqa: E402
if not opt.modules:
suite = all_suite(opt.tests)
else:
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tests/test_protocols.py
--- a/trytond/tests/test_protocols.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tests/test_protocols.py Sun Mar 01 12:33:54 2020 +0100
@@ -55,7 +55,18 @@
def test_xml_request(self):
req = XMLRequest.from_values(
- data=b"<?xml
version='1.0'?>\n<methodCall>\n<methodName>method</methodName>\n<params>\n<param>\n<value><string>foo</string></value>\n</param>\n<param>\n<value><string>bar</string></value>\n</param>\n</params>\n</methodCall>\n",
+ data=b"""<?xml version='1.0'?>
+ <methodCall>
+ <methodName>method</methodName>
+ <params>
+ <param>
+ <value><string>foo</string></value>
+ </param>
+ <param>
+ <value><string>bar</string></value>
+ </param>
+ </params>
+ </methodCall>""",
content_type='text/xml')
self.assertEqual(req.parsed_data, (('foo', 'bar'), 'method'))
self.assertEqual(req.rpc_method, 'method')
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tests/test_tools.py
--- a/trytond/tests/test_tools.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tests/test_tools.py Sun Mar 01 12:33:54 2020 +0100
@@ -35,7 +35,8 @@
def test_reduce_ids_one_hole(self):
'Test reduce_ids continue list with one hole'
- self.assertEqual(reduce_ids(self.table.id, list(range(10)) +
list(range(20, 30))),
+ self.assertEqual(reduce_ids(
+ self.table.id, list(range(10)) + list(range(20, 30))),
((self.table.id >= 0) & (self.table.id <= 9))
| ((self.table.id >= 20) & (self.table.id <= 29)))
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tools/__init__.py
--- a/trytond/tools/__init__.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tools/__init__.py Sun Mar 01 12:33:54 2020 +0100
@@ -1,9 +1,16 @@
# 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 .misc import (
+ file_open, get_smtp_server, memoize, reduce_ids, reduce_domain,
+ grouped_slice, is_instance_method, resolve, strip_wildcard,
+ lstrip_wildcard, rstrip_wildcard, slugify)
+from .decimal_ import decistmt
-from .misc import *
-from .decimal_ import *
+__all__ = ['file_open', 'get_smtp_server', 'memoize', 'reduce_ids',
+ 'reduce_domain', 'grouped_slice', 'is_instance_method', 'resolve',
+ 'strip_wildcard', 'lstrip_wildcard', 'rstrip_wildcard', 'slugify',
+ 'decistmt', 'ClassProperty', 'cursor_dict']
class ClassProperty(property):
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tools/misc.py
--- a/trytond/tools/misc.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tools/misc.py Sun Mar 01 12:33:54 2020 +0100
@@ -203,10 +203,10 @@
domain = domain[1:]
result = [operator]
for arg in domain:
- if (isinstance(arg, tuple) or
- (isinstance(arg, list) and
- len(arg) > 2 and
- arg[1] in OPERATORS)):
+ if (isinstance(arg, tuple)
+ or (isinstance(arg, list)
+ and len(arg) > 2
+ and arg[1] in OPERATORS)):
# clause
result.append(arg)
elif isinstance(arg, list) and arg:
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/tools/multivalue.py
--- a/trytond/tools/multivalue.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/tools/multivalue.py Sun Mar 01 12:33:54 2020 +0100
@@ -88,15 +88,17 @@
pcolumns = []
vcolumns = [Column(table, f) for f in fields]
values = []
- l = len(value_names)
+ length = len(value_names)
for row in cursor.fetchall():
value = [c(v) for v, c in zip(row, casts)]
if parent:
- value.append(int(row[l].split(',')[1]) if row[l] else None)
+ value.append(
+ int(row[length].split(',')[1])
+ if row[length] else None)
i = 1
else:
i = 0
- value.extend(row[l + i:])
+ value.extend(row[length + i:])
values.append(value)
if (values and not (
# No property defined
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/transaction.py
--- a/trytond/transaction.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/transaction.py Sun Mar 01 12:33:54 2020 +0100
@@ -221,14 +221,14 @@
self.started_at = self.monotonic_time()
Cache.commit(self)
self.connection.commit()
- except:
+ except Exception:
self.rollback()
raise
else:
try:
for datamanager in self._datamanagers:
datamanager.tpc_finish(self)
- except:
+ except Exception:
logger.critical('A datamanager raised an exception in'
' tpc_finish, the data might be inconsistant',
exc_info=True)
diff -r bfe9c94cfb99 -r 9d1c6e94d686 trytond/wsgi.py
--- a/trytond/wsgi.py Sat Feb 29 23:50:59 2020 +0100
+++ b/trytond/wsgi.py Sun Mar 01 12:33:54 2020 +0100
@@ -227,5 +227,5 @@
kwargs = eval(config.get(section, 'kwargs'))
app.wsgi_app = Middleware(app.wsgi_app, *args, **kwargs)
-import trytond.protocols.dispatcher
-import trytond.bus
+import trytond.protocols.dispatcher # noqa: E402,F401
+import trytond.bus # noqa: E402,F401