From f9b199fa5fea39ae09cb52a593f4ddb4bb80d449 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 22 Jul 2010 15:28:35 +0200 Subject: [PATCH 1/5] [FIX] mutable default in ir lp bug: https://launchpad.net/bugs/525808 fixed bzr revid: ls@numerigraphe.fr-20100722132835-ffr0k22jcl1rfoqd --- bin/ir/ir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/ir/ir.py b/bin/ir/ir.py index 109faf95872..c4cc435765d 100644 --- a/bin/ir/ir.py +++ b/bin/ir/ir.py @@ -31,7 +31,7 @@ def ir_del(cr, uid, id): obj = pooler.get_pool(cr.dbname).get('ir.values') return obj.unlink(cr, uid, [id]) -def ir_get(cr, uid, key, key2, models, meta=False, context={}, res_id_req=False): +def ir_get(cr, uid, key, key2, models, meta=False, context=None, res_id_req=False): obj = pooler.get_pool(cr.dbname).get('ir.values') res = obj.get(cr, uid, key, key2, models, meta=meta, context=context, res_id_req=res_id_req) return res From 70fd90d33b2ebb25519d89b3505f616d2b6f7fa1 Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 22 Jul 2010 15:49:48 +0200 Subject: [PATCH 2/5] [FIX] mutable default in osv lp bug: https://launchpad.net/bugs/525808 fixed bzr revid: ls@numerigraphe.fr-20100722134948-5axugpkr0nwbda2a --- bin/osv/fields.py | 16 ++++++++-------- bin/osv/orm.py | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 3ef167600eb..851f5d4d432 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -63,7 +63,7 @@ class _column(object): _symbol_set = (_symbol_c, _symbol_f) _symbol_get = None - def __init__(self, string='unknown', required=False, readonly=False, domain=None, context={}, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args): + def __init__(self, string='unknown', required=False, readonly=False, domain=None, context=None, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args): self.states = states or {} self.string = string self.readonly = readonly @@ -75,7 +75,7 @@ class _column(object): self.ondelete = ondelete self.translate = translate self._domain = domain or [] - self._context = context + self._context = context or {} self.write = False self.read = False self.view_load = 0 @@ -375,7 +375,7 @@ class one2many(_column): assert(self.change_default != True) def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None): - if not context: + if context is None: context = {} if self._context: context = context.copy() @@ -734,7 +734,7 @@ class function(_column): class related(function): - def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}): + def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None): self._field_get2(cr, uid, obj, context) i = len(self._arg)-1 sarg = name @@ -750,7 +750,7 @@ class related(function): i -= 1 return [(self._arg[0], 'in', sarg)] - def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None): + def _fnct_write(self, obj, cr, uid, ids, field_name, values, args, context=None): if values and field_name: self._field_get2(cr, uid, obj, context) relation = obj._name @@ -835,7 +835,7 @@ class related(function): # TODO: improve here to change self.store = {...} according to related objects pass - def _field_get2(self, cr, uid, obj, context={}): + def _field_get2(self, cr, uid, obj, context=None): if self._relations: return obj_name = obj._name @@ -855,10 +855,10 @@ class related(function): # --------------------------------------------------------- class dummy(function): - def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}): + def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None): return [] - def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None): + def _fnct_write(self, obj, cr, uid, ids, field_name, values, args, context=None): return False def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None): diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 2ecca2aa3c6..4d63bdd805a 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -126,13 +126,11 @@ class browse_record_list(list): class browse_record(object): logger = netsvc.Logger() - def __init__(self, cr, uid, id, table, cache, context=None, list_class = None, fields_process={}): + def __init__(self, cr, uid, id, table, cache, context=None, list_class=None, fields_process=None): ''' table : the object (inherited from orm) context : dictionary with an optional context ''' - if not context: - context = {} self._list_class = list_class or browse_record_list self._cr = cr self._uid = uid @@ -141,8 +139,8 @@ class browse_record(object): self._table_name = self._table._name self.__logger = logging.getLogger( 'osv.browse_record.' + self._table_name) - self._context = context - self._fields_process = fields_process + self._context = context or {} + self._fields_process = fields_process or {} cache.setdefault(table._name, {}) self._data = cache[table._name] @@ -400,14 +398,16 @@ class orm_template(object): context=context ) - def view_init(self, cr , uid , fields_list, context=None): + def view_init(self, cr, uid, fields_list, context=None): """Override this method to do specific things when a view on the object is opened.""" pass def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None): raise NotImplementedError(_('The read_group method is not implemented on this object !')) - def _field_create(self, cr, context={}): + def _field_create(self, cr, context=None): + if context is None: + context = {} cr.execute("SELECT id FROM ir_model WHERE model=%s", (self._name,)) if not cr.rowcount: cr.execute('SELECT nextval(%s)', ('ir_model_id_seq',)) @@ -492,8 +492,8 @@ class orm_template(object): continue cr.commit() - def _auto_init(self, cr, context={}): - self._field_create(cr, context) + def _auto_init(self, cr, context=None): + self._field_create(cr, context=context) def __init__(self, cr): if not self._name and not hasattr(self, '_inherit'): @@ -509,7 +509,7 @@ class orm_template(object): if not self._table: self._table = self._name.replace('.', '_') - def browse(self, cr, uid, select, context=None, list_class=None, fields_process={}): + def browse(self, cr, uid, select, context=None, list_class=None, fields_process=None): """ Fetch records as objects allowing to use dot notation to browse fields and relations @@ -520,8 +520,6 @@ class orm_template(object): :rtype: object or list of objects requested """ - if not context: - context = {} self._list_class = list_class or browse_record_list cache = {} # need to accepts ints and longs because ids coming from a method @@ -529,7 +527,7 @@ class orm_template(object): if isinstance(select, (int, long)): return browse_record(cr, uid, select, self, cache, context=context, list_class=self._list_class, fields_process=fields_process) elif isinstance(select, list): - return self._list_class([browse_record(cr, uid, id, self, cache, context=context, list_class=self._list_class, fields_process=fields_process) for id in select], context) + return self._list_class([browse_record(cr, uid, id, self, cache, context=context, list_class=self._list_class, fields_process=fields_process) for id in select], context=context) else: return browse_null() @@ -1018,7 +1016,7 @@ class orm_template(object): def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'): raise NotImplementedError(_('The read method is not implemented on this object !')) - def get_invalid_fields(self,cr,uid): + def get_invalid_fields(self, cr, uid): return list(self._invalids) def _validate(self, cr, uid, ids, context=None): @@ -1409,14 +1407,14 @@ class orm_template(object): return arch - def __get_default_search_view(self, cr, uid, context={}): + def __get_default_search_view(self, cr, uid, context=None): def encode(s): if isinstance(s, unicode): return s.encode('utf8') return s - view = self.fields_view_get(cr, uid, False, 'form', context) + view = self.fields_view_get(cr, uid, False, 'form', context=context) root = etree.fromstring(encode(view['arch'])) res = etree.XML("" % root.get("string", "")) @@ -2228,7 +2226,9 @@ class orm(orm_template): if column['attnotnull']: cr.execute('ALTER TABLE "%s" ALTER COLUMN "%s" DROP NOT NULL' % (self._table, column['attname'])) - def _auto_init(self, cr, context={}): + def _auto_init(self, cr, context=None): + if context is None: + context = {} store_compute = False logger = netsvc.Logger() create = False From 666c4ec067ca4ecb1bf7dbb6c4cdd5ff3a58032a Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Thu, 22 Jul 2010 15:54:36 +0200 Subject: [PATCH 3/5] [FIX] mutable default in tools lp bug: https://launchpad.net/bugs/525808 fixed bzr revid: ls@numerigraphe.fr-20100722135436-grgj7vow495q65vf --- bin/tools/convert.py | 2 +- bin/tools/copy.py | 4 +++- bin/tools/pdf_utils.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 973e762cd2e..20f54e15f11 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -598,7 +598,7 @@ form: module.record_id""" % (xml_id,) self.pool.get('ir.model.data').ir_set(cr, self.uid, 'action', 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(pid))], action, True, True, xml_id=rec_id) return ('ir.ui.menu', pid) - def _assert_equals(self, f1, f2, prec = 4): + def _assert_equals(self, f1, f2, prec=4): return not round(f1 - f2, prec) def _tag_assert(self, cr, rec, data_node=None): diff --git a/bin/tools/copy.py b/bin/tools/copy.py index e6583dcfadf..badd4d51fc5 100644 --- a/bin/tools/copy.py +++ b/bin/tools/copy.py @@ -164,7 +164,7 @@ d[types.InstanceType] = _copy_inst del d -def deepcopy(x, memo=None, _nil=[]): +def deepcopy(x, memo=None, _nil=None): """Deep copy operation on arbitrary Python objects. See the module's __doc__ string for more info. @@ -172,6 +172,8 @@ def deepcopy(x, memo=None, _nil=[]): if memo is None: memo = {} + if _nil is None: + _nil = {} d = id(x) y = memo.get(d, _nil) diff --git a/bin/tools/pdf_utils.py b/bin/tools/pdf_utils.py index 4782e544429..0286b9cf46d 100644 --- a/bin/tools/pdf_utils.py +++ b/bin/tools/pdf_utils.py @@ -58,7 +58,7 @@ trailer %%EOF """ -def output_field( f ): +def output_field(f): return "\xfe\xff" + "".join( [ "\x00"+c for c in f ] ) def extract_keys(lines): From e013734045bbaae906748a8026455bac6786568e Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Fri, 12 Nov 2010 14:42:14 +0100 Subject: [PATCH 4/5] [REF] stricter checking of defauts in fields & orm __init__ bzr revid: ls@numerigraphe.fr-20101112134214-h27a1ewxr9c4g3id --- bin/osv/fields.py | 8 ++++++-- bin/osv/orm.py | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 851f5d4d432..c6186b9a052 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -64,6 +64,10 @@ class _column(object): _symbol_get = None def __init__(self, string='unknown', required=False, readonly=False, domain=None, context=None, states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args): + if domain is None: + domain = [] + if context is None: + context = {} self.states = states or {} self.string = string self.readonly = readonly @@ -74,8 +78,8 @@ class _column(object): self.change_default = change_default self.ondelete = ondelete self.translate = translate - self._domain = domain or [] - self._context = context or {} + self._domain = domain + self._context = context self.write = False self.read = False self.view_load = 0 diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 4d63bdd805a..c5a47d1201f 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -131,6 +131,10 @@ class browse_record(object): table : the object (inherited from orm) context : dictionary with an optional context ''' + if fields_process is None: + domain = {} + if context is None: + context = {} self._list_class = list_class or browse_record_list self._cr = cr self._uid = uid @@ -139,8 +143,8 @@ class browse_record(object): self._table_name = self._table._name self.__logger = logging.getLogger( 'osv.browse_record.' + self._table_name) - self._context = context or {} - self._fields_process = fields_process or {} + self._context = context + self._fields_process = fields_process cache.setdefault(table._name, {}) self._data = cache[table._name] From 8b3bd3cceea2c3861f9714de6c67decbd755547e Mon Sep 17 00:00:00 2001 From: Numerigraphe - Lionel Sausin Date: Fri, 12 Nov 2010 15:21:19 +0100 Subject: [PATCH 5/5] [FIX] typo in field name bzr revid: ls@numerigraphe.fr-20101112142119-e9gqnld7m5dd62kh --- bin/osv/orm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index f29d928d5ba..d4c66683999 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -132,7 +132,7 @@ class browse_record(object): context : dictionary with an optional context ''' if fields_process is None: - domain = {} + fields_process = {} if context is None: context = {} self._list_class = list_class or browse_record_list